Skip to content

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

Closed

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

Activity

  1. changed the title [-]โ€œTypeError in CP-SAT when evaluating x - y - 2*zโ€[/-] [+]TypeError in CP-SAT when evaluating x - y - 2*z[/+] on May 21, 2025
  2. lperron commented on May 21, 2025

    @lperron
    Collaborator

    Fixed. Thanks

  3. added 2 commits that reference this issue on May 21, 2025
    6dc6888
    a4d2653
  4. added this to the v9.13 milestone on May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions