Skip to content

TypeError in CP-SAT when evaluating x - y - 2*z #4654

@Taro1994

Description

@Taro1994

What version of OR-Tools and what language are you using?
Version: 9.12.4544
Language: Python

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
CP-SAT

What operating system (Linux, Windows, ...) and version?
Linux

What did you do?
Steps to reproduce the behavior:

  1. Run the following script
from ortools.sat.python import cp_model
model = cp_model.CpModel();
x = model.NewIntVar(0,1,"x")
y = model.NewIntVar(0,2,"y")
z = model.NewIntVar(0,3,"z")
expr = x - y - 2*z
  1. See error
TypeError                                 Traceback (most recent call last)
[<ipython-input-6-688283dcb9b1>](https://localhost:8080/#) in <cell line: 0>()
      5 y = model.NewIntVar(0,2,"y")
      6 z = model.NewIntVar(0,3,"z")
----> 7 expr = x - y - 2*z

TypeError: __rsub__(): incompatible function arguments. The following argument types are supported:
    1. (self: ortools.sat.python.cp_model_helper.IntAffine, cst: int) -> ortools.sat.python.cp_model_helper.LinearExpr
    2. (self: ortools.sat.python.cp_model_helper.IntAffine, cst: float) -> ortools.sat.python.cp_model_helper.LinearExpr

What did you expect to see

No error occur.

Make sure you include information that can help us debug (full error message, model Proto).

Note that the expression x - y + 2*z does not produce an error.

from ortools.sat.python import cp_model
model = cp_model.CpModel();
x = model.NewIntVar(0,1,"x")
y = model.NewIntVar(0,2,"y")
z = model.NewIntVar(0,3,"z")
expr = x - y + 2*z

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions