C++ Reference
C++ Reference: Routing
Go to the source code of this file.
Functions | |
DECLARE_int64 (cp_random_seed) | |
Declaration of the core objects for the constraint solver. More... | |
Function Documentation
◆ DECLARE_int64()
DECLARE_int64 | ( | cp_random_seed | ) |
Declaration of the core objects for the constraint solver.
The literature around constraint programming is extremely dense but one can find some basic introductions in the following links:
- http://en.wikipedia.org/wiki/Constraint_programming
- http://kti.mff.cuni.cz/~bartak/constraints/index.html
Here is a very simple Constraint Programming problem:
Knowing that we see 56 legs and 20 heads, how many pheasants and rabbits are we looking at?
Here is some simple Constraint Programming code to find out:
void pheasant() { Solver s("pheasant"); IntVar* const p = s.MakeIntVar(0, 20, "pheasant")); IntVar* const r = s.MakeIntVar(0, 20, "rabbit")); IntExpr* const legs = s.MakeSum(s.MakeProd(p, 2), s.MakeProd(r, 4)); IntExpr* const heads = s.MakeSum(p, r); Constraint* const ct_legs = s.MakeEquality(legs, 56); Constraint* const ct_heads = s.MakeEquality(heads, 20); s.AddConstraint(ct_legs); s.AddConstraint(ct_heads); DecisionBuilder* const db = s.MakePhase(p, r, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_MIN_VALUE); s.NewSearch(db); CHECK(s.NextSolution()); LOG(INFO) << "rabbits -> " << r->Value() << ", pheasants -> " << p->Value(); LOG(INFO) << s.DebugString(); s.EndSearch(); }
which outputs:
rabbits -> 8, pheasants -> 12 Solver(name = "pheasant", state = OUTSIDE_SEARCH, branches = 0, fails = 0, decisions = 0 propagation loops = 11, demons Run = 25, Run time = 0 ms)