Building AI Solutionswith Google OR-ToolsBarry S. StahlPrincipal Engineer - AZNerds.net@bsstahl@cognitiveinheritance.comhttps://CognitiveInheritance.com |
|
Favorite Physicists
Other notables: Stephen Hawking, Edwin Hubble, Leonard Susskind, Christiaan Huygens |
Favorite Mathematicians
Other notables: Blaise Pascal, Daphne Koller, Grady Booch, Evelyn Berezin, Pascal Van Hentenryck |
|
|
|
|
|
|
|
|
|
|
|
As an entity, constraints do 2 things
Infeasibility
Objective Function
Specified as a goal relative to an equation
One objective per Model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Constraint Programming is about narrowing choices
LP and MIP build on the same idea
|
|
|
|
|
|
|
|
|
|
|
|
|
| Room 1 | Room 2 | Room 3 | |
|---|---|---|---|
| Slot 1 | Session 1 | Session 2 | Session 3 |
| Slot 2 | Session 4 | Session 5 | Session 6 |
| Slot 3 | Session 7 | Session 8 | Session 9 |
| Slot 4 | Session 10 | Open | Open |
| Room 1 | Room 2 | Room 3 | |
|---|---|---|---|
| Slot 1 | Session 1 | Session 2 | Session 3 |
| Slot 2 | Session 4 | Session 5 | Session 6 |
| Slot 3 | Session 7 | Session 8 | Session 9 |
| Slot 4 | Session 10 | Open | Open |
| Room 1 | Room 2 | Room 3 | |
|---|---|---|---|
| Slot 1 | Session 1 | Session 2 | Session 3 |
| Slot 2 | Session 4 | Session 5 | Session 6 |
| Slot 3 | Session 7 | Session 8 | Session 9 |
| Slot 4 | Session 10 | Open | Open |
| Session 1 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 0 | 0 | 0 |
| Slot 2 | 0 | 0 | 0 |
| Slot 3 | 0 | 1 | 0 |
| Slot 4 | 0 | 0 | 0 |
| Session 2 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 1 | 0 | 0 |
| Slot 2 | 0 | 0 | 0 |
| Slot 3 | 0 | 0 | 0 |
| Slot 4 | 0 | 0 | 0 |
| Session 3 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 0 | 0 | 0 |
| Session 1 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 0 | 0 | 0 |
| Slot 2 | 0 | 0 | 0 |
| Slot 3 | 0 | 1 | 0 |
| Slot 4 | 0 | 0 | 0 |
| Session 1 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 0 | 0 | 0 |
| Slot 2 | 0 | 0 | 0 |
| Slot 3 | 0 | 1 | 0 |
| Slot 4 | 0 | 0 | 0 |
| Session 1 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 0 | 0 | 0 |
| Slot 2 | 0 | 0 | 0 |
| Slot 3 | 0 | 1 | 0 |
| Slot 4 | 0 | 0 | 0 |
Create a score that improves with the desirability of the solution
| Session 1 | Room 1 | Room 2 | Room 3 |
|---|---|---|---|
| Slot 1 | 0 | 0 | 0 |
| Slot 2 | 0 | 0 | 0 |
| Slot 3 | 0 | 1 | 0 |
| Slot 4 | 0 | 0 | 0 |
Maximize # of sessions in the same room with Sessions 2 & 4 (a track)
|
|
We don't need to implement Simplex ourselves
|
|
Variable Definitions
Implementation
var xS = solver.MakeIntVar(0.0, maxSmall, "xS");var xL = solver.MakeIntVar(0.0, maxLarge, "xL");Clay Constraint Definition
Similar for Glaze Constraint
Implementation
var cClay = solver.MakeConstraint(0.0, claySupply);cClay.SetCoefficient($x_S$, 1);cClay.SetCoefficient($x_L$, 4);\(\max \; 3 x_S + 9 x_L\)
var obj = solver.Objective();obj.SetCoefficient($x_S$, 3);obj.SetCoefficient($x_L$, 9);obj.SetMaximization();int resultStatus = solver.Solve();var xSmall = xS.SolutionValue();var xLarge = xL.SolutionValue();
|
|