`# Import of the pyomo module
from pyomo.environ import *
# Creation of a Concrete Model
model = ConcreteModel()
## Define sets ##
# Sets
model.I = RangeSet(1, N, doc='Farms')
model.J = RangeSet(1, n_max, doc='Turbines')
model.T = RangeSet(1, T, doc='Time horizon')
model.T_minus_1 = RangeSet(1, T-1, doc='Time horizon up to T-1')
model.R = RangeSet(1, R, doc='Maintenance Crews')
## Define variables ##
# Variables
model.Xpm_ijt = Var(model.I, model.J, model.T, domain=Binary, doc='Binary variable for shipment decision')
model.Xcm_ijt = Var(model.I, model.J, model.T, domain=Binary, doc='Binary variable for shipment decision')
model.y_rt = Var(model.R, model.T, domain=Binary, doc='Binary variable for shipment decision')
model.z_rit = Var(model.R, model.I, model.T, domain=Binary, doc='Binary variable for shipment decision')
model.f_ijt = Var(model.I, model.J, model.T, domain=Binary, doc='Binary variable for shipment decision')
model.a_ijt = Var(model.I, model.J, model.T, domain=NonNegativeIntegers, bounds=(0, H*10), doc='Operating time of turbine j at farm i at time t')
#Constraints
#Constraint 1
def init_a_ijt_rule(model, i, j, t):
if t == 1 and i == 1:
if j == 1:
return 0
elif j == 2:
return 0
elif j == 3:
return 10
elif j == 4:
return 20
elif j == 5:
return 23
elif t == 1 and i == 2:
if j == 1:
return 12
elif j == 2:
return 20
elif j == 3:
return 34
else:
return 0
model.constraint_a_ijt = Var(model.I, model.J, model.T, initialize=init_a_ijt_rule, doc='Operating time of turbine j at farm i at time t')
#Constraint 2
def operating_time_rule(model, i, j, t):
if model.Xpm_ijt[i, j, t].value == 1 or model.Xcm_ijt[i, j, t].value == 1:
return model.a_ijt[i, j, t+1] == 0
else:
return model.a_ijt[i, j, t+1] == model.a_ijt[i, j, t] + 1
model.constraint_operating_time = Constraint(model.I, model.J, model.T_minus_1, rule=operating_time_rule)
#Constraint 3
def PM_rule(model, i, j, t):
if value(model.a_ijt[i, j, t]) = H:
return model.Xpm_ijt[i, j, t] == 0
else:
return Constraint.Skip
model.constraint_Xpm = Constraint(model.I, model.J, model.T, rule=PM_rule)`
Until the 3rd constraint everything runs fine but I get this error when I run the PM_rule:
ERROR: evaluating object as numeric value: a_ijt[1,1,1] (object: ) No value for uninitialized NumericValue object a_ijt[1,1,1] ERROR: Rule failed when generating expression for Constraint constraint_Xpm with index (1, 1, 1): ValueError: No value for uninitialized NumericValue object a_ijt[1,1,1] ERROR: Constructing component 'constraint_Xpm' from data=None failed: ValueError: No value for uninitialized NumericValue object a_ijt[1,1,1]
I'm a new Pyomo user, so any help is welcome ! Thank you :)
0 comments:
Post a Comment
Thanks