1

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?

k88
  • 1,858
  • 2
  • 12
  • 33
  • I think your code snippet is a bit too small to actually tell what the problem is, but in general, how to export the model to an LP file and make sure the constraint and variables appear as expected? – Daniel Junglas Sep 06 '21 at 13:33
  • Yup. I have looked at that and the constraint seems correct. Enabling the constraint seems to significantly slow down the solver. – k88 Sep 17 '21 at 08:41
  • 1
    It is not unexpected that additional constraints can slow down the solution process. Maybe it is best to take this up with the solver support directly. Different solvers perform differently on different problem formulations. There may be ways to formulate this in a more suitable way for the solver you are using. – Daniel Junglas Sep 17 '21 at 09:18
  • 1
    Did you try to add a higher penalty in the disjunction ? here solver has no incentive to add this node inside any route unless the added arc cost is zero... note: solver will try to visit as much node as possible unless this impact the objective value (kind of best effort approach). – Mizux Sep 17 '21 at 09:27
  • Thanks @Mizux, yes I tried. It doesn't make much of a difference. I suspect it is because of how the constraint is formulated. A local search operator basically needs to activate the nodes in such a way that the service node is activated together with the pickup and deliver pairs. I don't think this happens a lot, such most neighbourhood solutions are rejected. – k88 Sep 19 '21 at 02:52

0 Answers0