In
https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/you have many examples but not yet that one.
from docplex.cp.model import CpoModel
mdl = CpoModel(name='buses')
nbbus40 = mdl.integer_var(0,1000,name='nbBus40')
nbbus30 = mdl.integer_var(0,1000,name='nbBus30')
mdl.add(nbbus40*40 + nbbus30*30 >= 300)
mdl.minimize(nbbus40*500 + nbbus30*400)
sol=mdl.create_empty_solution()
sol[nbbus40]=8
sol[nbbus30]=0
mdl.set_starting_point(sol)
msol=mdl.solve()
print(msol[nbbus40]," buses 40 seats")
print(msol[nbbus30]," buses 30 seats")
works fine
and gives
! -------------------------------------------------- CP Optimizer 12.10.0.0 --
! Minimization problem - 2 variables, 1 constraint
! Using starting point solution
! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
! . Log search space : 19.9 (before), 19.9 (after)
! . Memory usage : 267.0 kB (before), 267.0 kB (after)
! Using parallel search with 12 workers.
! ----------------------------------------------------------------------------
! Best Branches Non-fixed W Branch decision
0 2 -
+ New bound is 0
! Starting point is complete and consistent with constraints.
* 4000 0 0.01s 1 (gap is 100.0%)
4000 0 2 1 -
+ New bound is 3800 (gap is 5.00%)
* 3800 0 0.01s 1 (gap is 0.00%)
! ----------------------------------------------------------------------------
! Search completed, 2 solutions found.
! Best objective : 3800 (optimal - effective tol. is 0)
! Best bound : 3800
! ----------------------------------------------------------------------------
! Number of branches : 232
! Number of fails : 188
! Total memory usage : 5.3 MB (5.3 MB CP Optimizer + 0.0 MB Concert)
! Time spent in solve : 0.01s (0.01s engine + 0.00s extraction)
! Search speed (br. / s) : 21090.9
! ----------------------------------------------------------------------------
6 buses 40 seats
2 buses 30 seatsregards
------------------------------
ALEX FLEISCHER
------------------------------