Pablo
Pablo

Reputation: 27

Non-fixed bound Error in Pyomo to solve MILP

I'm new in Pyomo. I'm trying to solve the following MILP problem: enter image description here

I tried with the following script:

import numpy as np
from pyomo.environ import *
from pyomo.gdp import *
import pyomo.environ as aml

OMEGA = ['Bus 01','Bus 06','Bus 32']

K = ['G 03','Line 15-16']

MARGINS = {
         'G 03' : 0.28,
         'Line 15-16': 0.30,
         }

BMAX = {
        'Bus 01':3,
        'Bus 06':3,
        'Bus 32':3,
        }

BMIN = {
        'Bus 01':0.001,
        'Bus 06':0.001,
        'Bus 32':0.001,
        }

SENSITIVITIES = {
    ('Bus 01','G 03') : {'S': 0.001},
    ('Bus 06','G 03') : {'S': 0.016},
    ('Bus 32','G 03') : {'S': 0.008},
    ('Bus 01','Line 15-16') : {'S': 0.004},
    ('Bus 06','Line 15-16') : {'S': 0.010},
    ('Bus 32','Line 15-16') : {'S': 0.015},
    }
Cv = 0.41
Cf = 1.3
Mr = 0.35

model = ConcreteModel()

model.Omega = Set(initialize = (i for i in OMEGA))
model.K = Set(initialize = (i for i in K))

model.M = Param(model.K,initialize = MARGINS)

model.b = Var(model.Omega, within = NonNegativeReals)
model.q = Var(model.Omega, within = Binary)
model.b_k = Var(model.Omega,model.K, within = NonNegativeReals)

model.Bmax = Param(model.Omega, initialize=BMAX)
model.Bmin = Param(model.Omega, initialize=BMIN)

def obj_rule(model):
    return sum(Cv*model.b[i] + Cf*model.q[i] for i in model.Omega)
model.obj = Objective(rule = obj_rule, sense = minimize)

def margin_rule(model,k):
    value = sum(SENSITIVITIES[(i,k)]['S']*model.b_k[i,k] for i in model.Omega) + model.M[k]
    return value >= Mr
model.margin = Constraint(model.K,rule=margin_rule)

def minmargin_rule(model,i,k):
    return aml.inequality(model.Bmin[i],model.b_k[i,k],model.b[i])
model.minmargin = Constraint(model.Omega,model.K, rule=minmargin_rule)

def powerlimits_rule(model,i):
    return  aml.inequality(model.Bmin[i]*model.q[i],model.b[i],model.Bmax[i]*model.q[i])
model.powerlimits = Constraint(model.Omega,rule=powerlimits_rule)

results = SolverFactory('glpk').solve(model)
results.write()

But returns "ValueError: non-fixed bound or weight: b[Bus 01]" for "minmargin" constraint and "ValueError: No value for uninitialized NumericValue object q[Bus 01]" for "powerlimits" constraint. I would appreciate some help or advice to solve these issues.

Upvotes: 1

Views: 289

Answers (1)

AirSquid
AirSquid

Reputation: 11913

For some reason, pyomo doesn't seem to like chained inequality constraints that have multiple variable references. I just did some tinkering.

This will fail when solved, as your model does:

from pyomo.environ import *

m = ConcreteModel()

m.A = Set(initialize = [1,2,3])

m.X = Var(m.A, domain=NonNegativeReals)
m.Y = Var(m.A, domain=NonNegativeReals)

def x_sandwich(m, a):
    return inequality(5, m.X[a], m.Y[a])
m.c2 = Constraint(m.A, rule=x_sandwich)

However, this works just fine:

def x_sandwich(m, a):
    return inequality(5, m.X[a], 10)
m.c2 = Constraint(m.A, rule=x_sandwich)

Perhaps somebody who knows the guts of the chained inequality functionality can comment. I didn't find anything in a quick search that would say that either of these is sour.

I was able to get your model to process/solve by chopping the chained inequality into independent constraints as such (you probably need to do same for your powerlimits constraint, which I commented out):

def minmargin_rule_lower(model, i, k):
    return model.Bmin[i] <= model.b_k[i, k]
model.mm_l = Constraint(model.Omega, model.K, rule=minmargin_rule_lower)

def minmargin_rule_upper(model, i, k):
    return model.b_k[i, k] <= model.b[i]
model.mm_u = Constraint(model.Omega, model.K, rule=minmargin_rule_upper)

Upvotes: 3

Related Questions