Branch and Bound in or-tools works via a search monitor
In detail:
m = slv.Minimize(<variable>, <step>) # Minimization
m = slv.Maximize(<variable>, <step>) # Maximization
...
slv.NewSearch(<dec builder>, [m, <other mon.>])
Instead of a cost function, we have a cost variable
The <step>
parameter represents the required improvement
z≤zbest−step
Reified constraints in or-tools
We just need to use the constraint as a term in an expression
expr = 2 * (x <= y)
(x <= y)
represents the feasibility state of x≤y
Just a word of warning:
The sum
function in python repeatedl applies +
+
is redefined in or-tools...sum
to build expressionsIn python min
and max
are functions, not operators
slv.Min(<expr/var>, <expr/var>) # Binary min
slv.Min(<list of vars>) # Min with many terms
slv.Max(<expr/var>, <expr/var>) # Binary max
slv.Max(<list of vars>) # Max with many terms
A number of chemicals must be stored in an array of tanks.
A number of chemicals must be stored in an array of tanks.
tmaxi<tminj
or tmaxj<tmini
i
and j
cannot stay in adjacent tanksBuild a (CP based) solution approach for the problem
ch4-tanks.py
contains a template scriptpython ch4-tanks.py <instance file>
tank-data
data-tanks-debug.json
Use the following constraint library as reference:
+, -, *, /, abs...
==, !=, <, <=, >=, >
Try to build the model incrementally