Skip to content

component_data_objects(active=False) does not yield correct objects #443

Open
@qtothec

Description

@qtothec

Test case

Discovered by @sjkale. Simple GDP test example. Trying to find inactive disjunctions using component_data_objects not working. Tested on fd2bd02.

from __future__ import division

from pyomo.environ import *
from pyomo.gdp import *

model = ConcreteModel()
model.lt = Var(initialize=0)
model.x1 = Var(initialize=0, bounds=(0, 15))
model.x2 = Var(initialize=0, bounds=(0, 15))
model.x3 = Var(initialize=0, bounds=(0, 15))
model.y1 = Var(initialize=6, bounds=(6, 10))
model.y2 = Var(initialize=7, bounds=(7, 10))
model.y3 = Var(initialize=3, bounds=(3, 10))

model.c1 = Constraint(expr=model.lt >= model.x1 + 6)
model.c2 = Constraint(expr=model.lt >= model.x2 + 5)
model.c3 = Constraint(expr=model.lt >= model.x3 + 4)


def disjunct11(disj):
    disj.indicator_var.value = 1
    disj.c = Constraint(expr=model.x1 + 6 <= model.x2)


def disjunct12(disj):
    disj.indicator_var.value = 0
    disj.c = Constraint(expr=model.x2 + 5 <= model.x1)


def disjunct13(disj):
    disj.indicator_var.value = 0
    disj.c = Constraint(expr=model.y1 - 6 >= model.y2)


def disjunct14(disj):
    disj.indicator_var.value = 0
    disj.c = Constraint(expr=model.y2 - 7 >= model.y1)


def disjunct21(disj):
    disj.indicator_var.value = 1
    disj.c = Constraint(expr=model.x1 + 6 <= model.x3)


def disjunct22(disj):
    disj.indicator_var.value = 0
    disj.c = Constraint(expr=model.x3 + 4 <= model.x1)


def disjunct23(disj):
    disj.indicator_var.value = 0
    disj.c = Constraint(expr=model.y1 - 6 >= model.y3)


def disjunct24(disj):
    disj.indicator_var.value = 0
    disj.c = Constraint(expr=model.y3 - 3 >= model.y1)


model.d11 = Disjunct(rule=disjunct11)
model.d12 = Disjunct(rule=disjunct12)
model.d13 = Disjunct(rule=disjunct13)
model.d14 = Disjunct(rule=disjunct14)
model.d21 = Disjunct(rule=disjunct21)
model.d22 = Disjunct(rule=disjunct22)
model.d23 = Disjunct(rule=disjunct23)
model.d24 = Disjunct(rule=disjunct24)


def disjunction1(m):
    return [m.d11, m.d12, m.d13, m.d14]


def disjunction2(m):
    return [m.d21, m.d22, m.d23, m.d24]


model.d1 = Disjunction(rule=disjunction1, xor=True)
model.d2 = Disjunction(rule=disjunction2, xor=True)

model.obj = Objective(expr=model.lt, sense=minimize)

active_disj = list(
    model.component_data_objects(ctype=Disjunction, active=True))
for disj in active_disj:
    disj.deactivate()
print(active_disj)

inactive_disj = list(
    model.component_data_objects(ctype=Disjunction, active=False))
print(inactive_disj)

Expected output

[<pyomo.gdp.disjunct.SimpleDisjunction object at 0x7f04c6d18890>, <pyomo.gdp.disjunct.SimpleDisjunction object at0x7f04a52c9ef0>]
[<pyomo.gdp.disjunct.SimpleDisjunction object at 0x7f04c6d18890>, <pyomo.gdp.disjunct.SimpleDisjunction object at0x7f04a52c9ef0>]

Actual output

[<pyomo.gdp.disjunct.SimpleDisjunction object at 0x7f04c6d18890>, <pyomo.gdp.disjunct.SimpleDisjunction object at0x7f04a52c9ef0>]
[]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions