Search code examples
python-3.xoptimizationmathematical-optimizationor-toolscp-sat

AddMultplicationEquality() for multiple variables


I want to use AddMultiplicationEquality() for multiple variables and use the result of multiplication. I guess we cannot perform the multiplication of multiple decision variables. I am using CP-SAT solver v9.5.2237. This does not give what I want:

product_var = model.NewIntVar(1, 1000, 'product_var')
decision_var = [model.NewIntvar(1, 10, 'name_{i}') for _ in range(4)]

#some processing on 'decision_var' and some values are assigned here based on other constrains
# then I want the product of those assigned values in 'decision_var'

model.AddMultiplicationEquality(product_var, constant, decision_var)

I get:

Invalid model: An int_prod constraint should have exactly 2 terms: int_prod

Then I tried:

for i in range(4):
    model.AddMultiplicationEquality(product_var, [product_var, decision_var[i])

I got this error after presolve:

Unsat after presolving constraint #17 (warning, dump might be inconsistent): int_prod...

How to carry out the multiplication and get the product?


Solution

  • currently, only x == y * z is supported. No more than 2 variables in the right hand side.

    The unsat means your model is inconsistent. This is another issue.