|
12 | 12 | // limitations under the License. |
13 | 13 |
|
14 | 14 | /** @file constraint_solver.h |
15 | | -* Declaration of the core objects for the constraint solver. |
16 | | -* |
17 | | -* The literature around constraint programming is extremely dense but one |
18 | | -* can find some basic introductions in the following links: |
19 | | -* - http://en.wikipedia.org/wiki/Constraint_programming |
20 | | -* - http://kti.mff.cuni.cz/~bartak/constraints/index.html |
21 | | -* |
22 | | -* Here is a very simple Constraint Programming problem: |
23 | | -* |
24 | | -* If we see 56 legs and 20 heads, how many two-legged pheasants |
25 | | -* and four-legged rabbits are we looking at? |
26 | | -* |
27 | | -* Here is some simple Constraint Programming code to find out: |
28 | | -* @code{.cpp} |
29 | | -* void pheasant() { |
30 | | -* Solver s("pheasant"); |
31 | | -* // Create integer variables to represent the number of pheasants and |
32 | | -* // rabbits, with a minimum of 0 and a maximum of 20. |
33 | | -* IntVar* const p = s.MakeIntVar(0, 20, "pheasant")); |
34 | | -* IntVar* const r = s.MakeIntVar(0, 20, "rabbit")); |
35 | | -* // The number of heads is the sum of pheasants and rabbits. |
36 | | -* IntExpr* const heads = s.MakeSum(p, r); |
37 | | -* // The number of legs is the sum of pheasants * 2 and rabbits * 4. |
38 | | -* IntExpr* const legs = s.MakeSum(s.MakeProd(p, 2), s.MakeProd(r, 4)); |
39 | | -* // Constraints: the number of legs is 56 and heads is 20. |
40 | | -* Constraint* const ct_legs = s.MakeEquality(legs, 56); |
41 | | -* Constraint* const ct_heads = s.MakeEquality(heads, 20); |
42 | | -* s.AddConstraint(ct_legs); |
43 | | -* s.AddConstraint(ct_heads); |
44 | | -* DecisionBuilder* const db = s.MakePhase(p, r, |
45 | | -* Solver::CHOOSE_FIRST_UNBOUND, |
46 | | -* Solver::ASSIGN_MIN_VALUE); |
47 | | -* s.NewSearch(db); |
48 | | -* CHECK(s.NextSolution()); |
49 | | -* LOG(INFO) << "rabbits -> " << r->Value() << ", pheasants -> " |
50 | | -* << p->Value(); |
51 | | -* LOG(INFO) << s.DebugString(); |
52 | | -* s.EndSearch(); |
53 | | -* } |
54 | | -* @endcode |
55 | | -* which outputs: |
| 15 | +Declaration of the core objects for the constraint solver. |
| 16 | +
|
| 17 | +The literature around constraint programming is extremely dense but one |
| 18 | +can find some basic introductions in the following links: |
| 19 | + - http://en.wikipedia.org/wiki/Constraint_programming |
| 20 | + - http://kti.mff.cuni.cz/~bartak/constraints/index.html |
| 21 | +
|
| 22 | +Here is a very simple Constraint Programming problem: |
| 23 | +
|
| 24 | + If we see 56 legs and 20 heads, how many two-legged pheasants |
| 25 | + and four-legged rabbits are we looking at? |
| 26 | +
|
| 27 | +Here is some simple Constraint Programming code to find out: |
| 28 | +@code{.cpp} |
| 29 | + void pheasant() { |
| 30 | + Solver s("pheasant"); |
| 31 | + // Create integer variables to represent the number of pheasants and |
| 32 | + // rabbits, with a minimum of 0 and a maximum of 20. |
| 33 | + IntVar* const p = s.MakeIntVar(0, 20, "pheasant")); |
| 34 | + IntVar* const r = s.MakeIntVar(0, 20, "rabbit")); |
| 35 | + // The number of heads is the sum of pheasants and rabbits. |
| 36 | + IntExpr* const heads = s.MakeSum(p, r); |
| 37 | + // The number of legs is the sum of pheasants * 2 and rabbits * 4. |
| 38 | + IntExpr* const legs = s.MakeSum(s.MakeProd(p, 2), s.MakeProd(r, 4)); |
| 39 | + // Constraints: the number of legs is 56 and heads is 20. |
| 40 | + Constraint* const ct_legs = s.MakeEquality(legs, 56); |
| 41 | + Constraint* const ct_heads = s.MakeEquality(heads, 20); |
| 42 | + s.AddConstraint(ct_legs); |
| 43 | + s.AddConstraint(ct_heads); |
| 44 | + DecisionBuilder* const db = s.MakePhase(p, r, |
| 45 | + Solver::CHOOSE_FIRST_UNBOUND, |
| 46 | + Solver::ASSIGN_MIN_VALUE); |
| 47 | + s.NewSearch(db); |
| 48 | + CHECK(s.NextSolution()); |
| 49 | + LOG(INFO) << "rabbits -> " << r->Value() << ", pheasants -> " |
| 50 | + << p->Value(); |
| 51 | + LOG(INFO) << s.DebugString(); |
| 52 | + s.EndSearch(); |
| 53 | + } |
| 54 | +@endcode |
| 55 | +which outputs: |
56 | 56 | @verbatim |
57 | 57 | rabbits -> 8, pheasants -> 12 |
58 | 58 | Solver(name = "pheasant", |
@@ -1034,7 +1034,7 @@ class Solver { |
1034 | 1034 | /// are relative to this time. |
1035 | 1035 | absl::Time Now() const; |
1036 | 1036 |
|
1037 | | - /// DEPRECATED: Use Now() instead. |
| 1037 | + /// @deprecated Use Now() instead. |
1038 | 1038 | /// Time elapsed, in ms since the creation of the solver. |
1039 | 1039 | int64_t wall_time() const; |
1040 | 1040 |
|
|
0 commit comments