Search code examples
pyomo

Unexpected behavior in pyomo Port Extensive


I observed some unexpected behavior in the Port class of pyomo.network. The following example is not feasible although the logical solution should be 1. The problem is that the bounds of the destination port variable (X_IN, Block 3) also overwrite the bounds of the source variable (X_OUT, Block 2). In my opinion this is correct for the Equality but not for the Extensive rule. Am I getting something wrong here or is it a problem?

import pyomo.environ as pyomo
import pyomo.network as network
import pyomo.opt as opt

m = pyomo.ConcreteModel()

# Block 1
m.block_1 = pyomo.Block()
m.block_1.X_OUT = pyomo.Var(domain=pyomo.NonNegativeReals)
m.block_1.OUT = network.Port()
m.block_1.OUT.add(m.block_1.X_OUT, 'X', network.Port.Extensive)

# Block 2
m.block_2 = pyomo.Block()
m.block_2.X_OUT = pyomo.Var(domain=pyomo.Reals, bounds=(2, 2))
m.block_2.OUT = network.Port()
m.block_2.OUT.add(m.block_2.X_OUT, 'X', network.Port.Extensive)

# Block 3
m.block_3 = pyomo.Block()
m.block_3.X_IN = pyomo.Var(domain=pyomo.NonNegativeReals, bounds=(3, 3))
m.block_3.IN = network.Port()
m.block_3.IN.add(m.block_3.X_IN, 'X', network.Port.Extensive)

# Objective
m.obj = pyomo.Objective(expr=pyomo.summation(m.block_1.X_OUT),
                        sense=pyomo.maximize)

# Arcs
m.arc_block_1_block_3 = network.Arc(src=m.block_1.OUT, dest=m.block_3.IN)
m.arc_block_2_block_3 = network.Arc(src=m.block_2.OUT, dest=m.block_3.IN)

# Expand the arcs and solve
pyomo.TransformationFactory("network.expand_arcs").apply_to(m)
opt.SolverFactory('cbc').solve(m, tee=True)

Solution

  • This behavior was noted in Pyomo issue 893, was fixed on the master branch in PR 1186, and will be generally available in the next release (likely Pyomo 5.6.9).