So, I am dealing with a problem where I have certain types of service nodes that should only be assigned if a condition is met. In my case that is the length of tour should be longer than x hours.
This is the general approach
val cumulVarAtVehicleStartNode: IntVar = journeyDurationsDimension.cumulVar(routingIndexManager.getStartIndex(vehicleId))
val tourDurationMaxVar: IntVar = journeyDurationsDimension.cumulVar(routingIndexManager.getEndIndex(vehicleId))
val tourDurationVar = solver.makeDifference(tourDurationMaxVar, cumulVarAtVehicleStartNode).`var`()
// nodes can be unassigned
routingModel.addDisjunction(listOf(orToolsIndexForServiceNode).toLongArray(), 0)
val isServiceNodeActiveVar = routingModel.activeVar(orToolsIndexForServiceNode)
val tresholdInHours = 5
val isTourLongerThanThresholdVar = ourDurationVar.isGreaterOrEqual(tresholdInHours * 60 * 60)
val solver = routingModel.solver()
solver.addConstraint(
solver.makeEquality(
isTourLongerThanThresholdVar,
isServiceNodeActiveVar
)
)
This implementation fails to assign tours that are longer than the threshold. I suspect it is because when the solver assigns a pick-up and delivery pair that exceeds the threshold, the solution is rejected because the service node is inactive. And somehow, the service node is never assigned such that it meets the condition of the tour duration. An added complexity here is that the service nodes are tied to a vehicle. So they can only be assigned to a single vehicle.
What would be the appropriate approach for a conditional assignment of such a node that is not a pick-up or delivery pair, but otherwise identical to other nodes?