0

I am trying to use google CP-SAT solver, version 9.11.4210 in a project. Part of the problem includes dividing a sum of two variables with another variable but the solver returns MODEL_INVALID. I have simplified the problem in the following:

model = CpModel()
v1 = model.NewIntVar(1, 1, "var1")
v2 = model.NewIntVar(1, 1, "var2")
div = model.NewIntVar(2, 2, "div")
model.add_division_equality(div, v1 + v2, v2)
solver = CpSolver()
status = solver.solve(model)

if status == MODEL_INVALID:
    print("The model is invalid")

The model is not invalid when I replace the numerator with, e.g. v1 + 1. Any ideas why this is happening or how to solve?

1 Answer 1

1

Have you checked the error message ?

See how to enable logging

It will tell you that product, division, modulo all accepts 1-var affine expressions as arguments (a * var + v).

So you need to create intermediate variables for linear expressions with more than 1 term.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.