Skip to content

Division by float: convert ProdExpr -> Expr #213

@ramabile

Description

@ramabile

Dear SCIPers,
Following this #212 (comment) I am here to ask for a clarification.

Consider:

from pyscipopt import Model
model = Model()
x = model.addVar(vtype="c")
print((2*x).__class__.__name__)
# Expr
print((x/2.).__class__.__name__)
# ProdExpr
print((2.*x).__class__.__name__)
# Expr
print((x/2).__class__.__name__)
# ProdExpr

It seems like ProdExpr is not casted as Expr in any case the division is defined. This provokes:

model.setObjective(.5*x) # accepted
model.setObjective(x/2.) # not accepted
# AssertionError: given coefficient is neither Expr or number but ProdExpr

Is this a design choice? Is SCIP behaviour?

As a Python user, I would expected a full support of the division of a continuous variable with a float number.
In other cases like integer variable divided by float or continuous variable divided by integer, I would expect a division btw. floats since integers are casted to floats in these cases.
In case of division between an integer variable and an integer number I would keep the ProdExpr until there is no support for division with remainders (that is why I wrote this).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions