Quickstart
Pychoco’s API is quite close to Choco’s Java API. The first thing to do is to import the library and create a model object:
from pychoco import Model
model = Model("My Choco Model")
Then, you can use this model object to create variables:
intvars = model.intvars(10, 0, 10)
sum_var = model.intvar(0, 100)
You can also create views from this Model object:
b6 = model.int_ge_view(intvars[6], 6)
Create and post (or reify) constraints:
model.all_different(intvars).post()
model.sum(intvars, "=", sum_var).post()
b7 = model.arithm(intvars[7], ">=", 7).reify()
Solve your problem:
model.get_solver().solve()
And retrieve the solution:
print("intvars = {}".format([i.get_value() for i in intvars]))
print("sum = {}".format(sum_var.get_value()))
print("intvar[6] >= 6 ? {}".format(b6.get_value()))
print("intvar[7] >= 7 ? {}".format(b7.get_value()))
> "intvars = [3, 5, 9, 6, 7, 2, 0, 1, 4, 8]"
> "sum = 45"
> "intvar[6] >= 6 ? False"
> "intvar[7] >= 7 ? False"