Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2.02k stars 518 forks source link

bug in core/base/sos.py #875

Closed DLWoodruff closed 10 months ago

DLWoodruff commented 5 years ago

taken from core/base/sos.py docstring and modified slightly

import pyomo.environ as pyo
model = pyo.ConcreteModel()
model.A = pyo.Set(initialize = range(2))
model.B = pyo.Set(model.A, initialize={1: "hello", 2: "goodbye"})
model.X = pyo.Var(model.B)
model.C1 = pyo.SOSConstraint(model.A, var=model.X, set=model.B, sos=1)

According to the docstring in core/base/sos.py:

This constraint actually creates one SOS-1 constraint for each
element of model.A (e.g., if |A| == N, there are N constraints).
In each constraint, model.X is indexed by the elements of
model.B[a], where 'a' is the current index of model.A.

But, this example cannot run at all because a Var cannot be indexed by an indexed Set.

#So maybe this is sort of what was meant :
import pyomo.environ as pyo
model = pyo.ConcreteModel()
model.A = pyo.Set(initialize = range(2))
model.B = pyo.Set(initialize=["hello", "goodbye"])
model.C = model.A * model.B
model.X = pyo.Var(model.C)
model.C1 = pyo.SOSConstraint(model.A, var=model.X, set=model.C, sos=1)

This example results in:

ValueError: Unexpected keyword options found while constructing 'IndexedSOSConstraint':
    set
tkorvola commented 5 years ago

More bugs in the SOSConstraint docstring:

mrmundt commented 10 months ago

This theoretically was addressed in the linked PR, so closing this issue. Please open a new one if there are still concerns.