what difference between IntVar.setRange and solver.addConstraints #4063
-
Version: v9.6. **Which solver are you using ** When modeling with RoutingModel, use IntVar.setRange(0, upperValue) more efficient than |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In general, propagators (build by constraints) are tasked to wait for triggers and then remove values from variable-domains within a fixpoint-iteration loop. This happens a lot during search. If you can remove those values a-priori, you don't need a propagator anymore and don't pay for it's overhead (listener = wait; propagation-work) as the domain was changed at the root-lvl before any decisions/branchings are made which usually trigger fixpoint-search / propagation. Every non-toy solver, when seeing So in a good solver, there is no difference but a small presolve-operation which is done ONCE before the core solve-loop aka it doesn't matter. I'm 99.9% sure, ortools' cp-solver does this presolve transform. |
Beta Was this translation helpful? Give feedback.
In general, propagators (build by constraints) are tasked to wait for triggers and then remove values from variable-domains within a fixpoint-iteration loop. This happens a lot during search.
If you can remove those values a-priori, you don't need a propagator anymore and don't pay for it's overhead (listener = wait; propagation-work) as the domain was changed at the root-lvl before any decisions/branchings are made which usually trigger fixpoint-search / propagation.
Every non-toy solver, when seeing
solver.addConstraints(solver.makeLessOrEqual(IntVar, upperValue))
will transform / lift / rewrite this into a domain-change and don't add/post a propagator or get rid of it later during pres…