Optaplanner: Different behaviour when optaplanner solver initialize a planning variable than when I initialize it

Posted on

Hello I'm using optaplanner to schedule tasks. I've created a filter for swap move, the swap move get one planning variable (called startingTimeGrain) from the planning entity (called TaskAssignment) and try to change it with other planning entity. The filter check if the planning variable to change is in the range (visibility range) allow for the planning entity. The range is defined in each planning entity. The following code are the filter configured in the xml and the filter class.

        <swapMoveSelector>
            <filterClass>com.gmv.g2gmps.model.solution.SwapSelectionFilter</filterClass>
            <variableNameInclude>startingTimeGrain</variableNameInclude>
        </swapMoveSelector> 

Here, the filter class.

public class SwapSelectionFilter implements SelectionFilter<TaskSchedule, SwapMove> {

@Override
public boolean accept(ScoreDirector<TaskSchedule> scoreDirector, SwapMove move) {


    TaskAssignment leftTask = (TaskAssignment) move.getLeftEntity();
    TaskAssignment rightTask = (TaskAssignment) move.getRightEntity();

    // Accept the movement if the index of the task to change are 
    // in the range of his visibility.

    int startIndexLeft = leftTask.getStartingTimeGrain().getGrainIndex();
    int stopIndexLeft = leftTask.getLastTimeGrainIndex();
    int startIndexRight = rightTask.getStartingTimeGrain().getGrainIndex();
    int stopIndexRight = rightTask.getLastTimeGrainIndex();

    if(leftTask.getId() == rightTask.getId() ||
    startIndexLeft == startIndexRight){
        return false;
    }

    //check if the new indices can fit in the original visibilities.
    if(startIndexLeft > rightTask.getVisibility().getStartIndex() && 
        stopIndexLeft < rightTask.getVisibility().getStopIndex() &&
        startIndexRight > leftTask.getVisibility().getStartIndex() &&
        stopIndexRight < leftTask.getVisibility().getStopIndex()){
            return true;
    }
    else{
        return false;
    }

}
}

When I run the optaplanner without initialize the planning variable "startingTimeGrain", letting the solver of optaplanner initialize it, the swap move works. The problem comes when I try to initialize the planning variable of every planning entity of the problem and then run the optaplanner in order to improve the score in the local search phase. (Note that the CH not run because every planning variable is initialized before run the solver).

When I run the solver in trace log, I see that all swap moves are "not doable". However, without initialize the planning variable the solver accept the swap moves. I checked the swap moves "not doable" and none of these have the same value for the planning variable (so, in fact the move change the current solution) and neither are are outside the physical range of the planning variable (so, it's possible to make the move).

I initialized the planning variable with the set method of the planning variable from the planning entity class.

Thanks in advance.

Responses