C++ Reference: constraint_solver

This documentation is automatically generated.

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)

Classes

Assignment
AssignmentContainer
AssignmentElement
BaseObject
CastConstraint
Constraint
Decision
DecisionBuilder
DecisionVisitor
Demon
DisjunctiveConstraint
InitAndGetValues
IntervalVar
IntervalVarElement
IntExpr
IntVar
IntVarElement
IntVarIterator
ModelVisitor
NumericalRev
NumericalRevArray
OptimizeVar
Pack
PropagationBaseObject
RegularLimit
Rev
RevArray
SearchLimit
SearchMonitor
SequenceVar
SequenceVarElement
SolutionCollector
SolutionPool
Solver