Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraint for putting a set of nodes on the same vehicle (VRP) #2155

Closed
KeremAslan opened this issue Sep 16, 2020 · 2 comments
Closed

Constraint for putting a set of nodes on the same vehicle (VRP) #2155

KeremAslan opened this issue Sep 16, 2020 · 2 comments
Assignees
Labels
Lang: Java Java wrapper issue OS: Mac MacOS Solver: Routing Uses the Routing library and the original CP solver
Milestone

Comments

@KeremAslan
Copy link

What version of OR-tools and what language are you using?
Version: 7.7.7810
Language: Java/Kotlin

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
Routing Solver

What operating system (Linux, Windows, ...) and version?
Mac OS

What did you do?
I want to set a hard constraint that enforces a set of nodes to be visited by the same vehicle. I found various links that describe this problem and the suggested approach, see here, here and 9.5.5.3 for examples.

Given this, I have crafted the following extension function in Kotlin:

fun RoutingModel.addVehicleEqualityConstraint(firstNodeIndex: Long, secondNodeIndex: Long) {
    val solver = this.solver()
    // This forces to solver to build solutions by adding both nodes, simultaneously. Otherwise, the solver
    // will add the nodes one by one, but that will never satisfy the pick-up and delivery constraint
    this.addPickupAndDelivery(firstNodeIndex, secondNodeIndex)
    // sets the constraint that each index should be handled by the same vehicle
    solver.addConstraint(
            solver.makeEquality(this.vehicleVar(firstNodeIndex), this.vehicleVar(secondNodeIndex))
    )
}

If you are unfamiliar with Kotlin, here is a short description of an extension function.

Anyway, my problem is that this suggested approach seems to work for a problem set with 2 nodes that have to be on the same vehicle, but not three.

Setting the constraint for two nodes is straightforward:

val firstIndex = routingIndexManager.nodeToIndex(firstNode)
val secondIndex = routingIndexManager.nodeToIndex(secondNode)
routingModel.addVehicleEqualityConstraint(firstIndex, secondIndex)

Setting the constraint on three nodes I would expect to do this:

val firstIndex = routingIndexManager.nodeToIndex(firstNode)
val secondIndex = routingIndexManager.nodeToIndex(secondNode)
val thirdIndex = routingIndexManager.nodeToIndex(thirdNode)
routingModel.addVehicleEqualityConstraint(firstIndex, secondIndex)
routingModel.addVehicleEqualityConstraint(secondIndex, thirdIndex)

However, OR-Tools seems to hang when I do this. This is the output in the search log:

I0916 13:03:19.088389 129110016 search.cc:254] Start search (memory used = 351.98 MB)
I0916 13:03:19.088438 129110016 search.cc:254] Root node processed (time = 0 ms, constraints = 35, memory used = 351.98 MB)
I0916 13:03:19.088558 129110016 search.cc:254] Solution #0 (2, time = 0 ms, branches = 34, failures = 1, depth = 33, memory used = 351.99 MB, limit = 0%)

Removing the addPickupAndDelivery() from addVehicleEqualityConstraint() seems to work, but I am suspecting that is something that works by chance rather than that is how it should work (as it contradicts all the comments and documentation).

I believe this is a bug?

Also, it'd be good to refactor the function name addPickupAndDelivery to something like addNodeAssociation as it is more generic than the pick up and delivery constraint.

@lperron lperron closed this as completed Sep 16, 2020
@lperron
Copy link
Collaborator

lperron commented Sep 16, 2020 via email

@Mizux Mizux added Lang: Java Java wrapper issue OS: Mac MacOS Solver: Routing Uses the Routing library and the original CP solver labels Sep 16, 2020
@KeremAslan
Copy link
Author

Posted on Google Groups https://groups.google.com/g/or-tools-discuss/c/ewH4VjfkvMg

@Mizux Mizux added this to the v8.0 milestone Sep 21, 2020
@Mizux Mizux self-assigned this Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang: Java Java wrapper issue OS: Mac MacOS Solver: Routing Uses the Routing library and the original CP solver
Projects
None yet
Development

No branches or pull requests

3 participants