A2Zebra
A2Zebra

Reputation: 3

pyomo: Connector for blocks not working

I'm trying to connect two blocks with the "Connector" class implemented in pyomo, using the following simple examplary code.

from pyomo.environ import *

m = ConcreteModel()

# Block 01
m.block_01 = Block()
m.block_01.flow = Var(within=NonNegativeReals, bounds=(2, 10))
m.block_01.OUT = Connector(initialize= {'flow': m.block_01.flow})

# Block 02
m.block_02 = Block()
m.block_02.flow = Var(within=NonNegativeReals)
m.block_02.IN = Connector(initialize= {'flow': m.block_02.flow})

m.con = Constraint(expr=m.block_01.OUT == m.block_02.IN)

def _obj(_m):
    return _m.block_01.flow + _m.block_02.flow
m.obj = Objective(rule=_obj)

After "optimization" all variables take their lower bound values (m.block_01.flow = 2 and m.block_02.flow = 0). So the Connector seems not to transfer any data for the variables.

If I'm using:

m.con = Constraint(expr=m.block_01.flow == m.block_02.flow)

instead, it works. However this is not the idea of Connectors, right?

Any ideas about the reason for the problem?

Upvotes: 0

Views: 249

Answers (1)

Bethany Nicholson
Bethany Nicholson

Reputation: 2818

Did you apply the expand_connectors transformation before sending your model to a solver?

TransformationFactory('core.expand_connectors').apply_to(m)

Upvotes: 1

Related Questions