Changing distance matrix elements on forbidden arc causes solver to fail in unexpected way #2979
Unanswered
ecotner
asked this question in
Routing (and legacy CP) questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What version of OR-tools and what language are you using?
Version: 7.5.7466
Language: Python
Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
Routing Solver
What operating system (Linux, Windows, ...) and version?
Linux 16.04 LTS
What did you do?
I am using the routing package to create optimized delivery routes for my work. One of the business constraints that I need to ensure is that enough vehicles will return from the AM delivery routes by a certain time to be ready to go for the PM routes. To do this, I added several dummy stops (one for each vehicle needed to return early), set time windows such that these dummies needed to be visited before the "return time", and manipulated the elements of the distance/time matrices such that there is no penalty for going from depot <--> dummy, the cost of going from customer -> dummy is the same as customer -> depot, and an "infinite" cost to go from dummy <--> dummy or dummy -> customer. This forces the dummy to be the last stop on the route before returning to the depot in a timely manner, and each truck can only visit one dummy max.
However, I found that implementing this constraint was causing the solver to fail without finding any solutions. The weird thing I noticed is that it would fail in scenarios where the solution to the unconstrained problem just happened to satisfy the constraints by chance. After doing some debugging, I found the difficulty comes in when trying to set the matrix elements to "infinity". As I have learned, ortools represents all internal calculations using 64-bit integers, so the largest value that can be used is
MAX_INT = 2**63 - 1, which is more than enough for my purposes. Unfortunately, setting the distance/time from dummy -> customer toMAX_INTcauses the solver to fail. Setting the distance/time from dummy <--> dummy toMAX_INT, however, works just fine. So it doesn't appear to be a problem with the value itself.I have set up the problem such that the maximum distance/time matrix element values have both been normalized to the same value, let's call it
PRECISION(I've typically been using values of 1e3 - 1e4 for this, even as high as 1e6 in the course of debugging). It turns out that by replacingMAX_INTwith the "finite" valueC * PRECISION(whereCis some O(1) value) I can get the solver to start working again. However, because the distance from dummy -> customer is now comparable to the largest distance between customers, it is not guaranteed that the arc from dummy -> customer is forbidden anymore (and I have observed several cases where this does happen). Like I said before, in chance scenarios I have been able to get the unconstrained solution to satisfy the constrained problem, but usingMAX_INTinstead ofC * PRECISIONcauses it to fail.What did you expect to see
Expected solver to return solutions to the constrained problem (when the constrained problem is feasible).
What did you see instead?
Solver fails, even when unconstrained solutions to the problem happen to satisfy the constrained problem.
Anything else we should know about your project / environment
I have attempted to make a minimal reproduction of this issue below. Running this snippet with
C = 25works fine, but withC = 30causes the solver to fail to find a route. I know setting the seed isn't guaranteed to create reproducible result across machines, but if you play around with it a bit you can probably reproduce the effect.Here is a screenshot of my terminal output after running the script three times for the values
C = 25, 30, 5(in that order). You can see the dummy stops (in red) are at the end of the route whenC=25, the solver fails forC=30, and the desired constraint is not satisfied whenC = 5(one of the dummies is the first stop on route 3, not last). The values I use forCin my full problem need to be much closer to 1, otherwise the solver fails.My initial thoughts on this are
ortools' solverHoping someone could help me out!
Beta Was this translation helpful? Give feedback.
All reactions