Hello
I am new to Pyomo+GLPK and have some questions regarding a price optimization model I’m trying to get off the ground. I purchased and reviewed the Pyomo Optimization modeling book but am still stumped.
The objective is to maximize revenue as defined as:
Pricew*Demandw + Pricesalvage*Inventoryfinal.
I want to optimize the former term on weekly basis and iteratively such that the optimal price for week,w, factors in the subsequent price/demand dynamics for subsequent weeks. The summary the mathematical objective is:
Max ΣPwλw + ΣPsalvgIfinal
Where:
• Pw = price in week, w;
• λw = demand in week, w;
• Psalv = Salvage price
• Ifinal = Final salvage inventory
Here is my model thus far:
model = AbstractModel()
*******Params and Vars *******************
# Number of weeks
model.Wks = RangeSet(1,12)
# Salvage price
model.Psalv = Param(initialize=15)
# Inventory at end of week, w
model.Inv_end = Var(model.Wks, within=NonNegativeIntegers, initialize=inv)
# Demand in week, w
model.Wk_dmd = Var(model.Wks, within=NonNegativeIntegers)
#Price in week , w
model.Pwk = Var(model.Wks, within=NonNegativeReals, initialize=5)
*******Objective*******************
def objective_rule(model):
return sum((model.Wk_dmd[w]*model.Pwk[w] for w in model.Wks) + model.Psalv * model.Inv_end[12])
model.objective = Objective(rule=objective_rule, sense=maximize)
************Constraints**********************
def Dmd_dynamics_rule(model, w):
###Calcs demand for given week###
if w == 1:
return model.Wk_dmd[w] == inv*.15
else:
# Main demand equation
return model.Wk_dmd[w] == model.Wk_dmd[w-1]*.3+og_ct*.001+30*(200/age)+.01*inv+2000/model.Pwk[w] #vars og_ct, age, and inv are global vats
model.Dmd_dynamics = Constraint(model.Wks,rule=Dmd_dynamics_rule)
def Inv_dmd_dynam_rule(model, w):
### Prev w End inv is ceiling to current w demand###
if w > 1:
return (model.Wk_dmd[w] <= model.Inv_end[w-1])
return Constraint.Skip
model.Inv_dmd_dynam =Constraint(model.Wks, rule=Inv_dmd_dynam_rule)
def Price_dynam_rule(model, w):
###Price can not go up, only down###
if w > 1:
return model.Pcrrnt[w] <= model.Pcrrnt[w-1]
return Constraint.Skip
model.Price_dynam = Constraint(model.Wks,rule=Price_dynam_rule)
def Calc_inv(model, w):
### Calculates Ending inventory in week, w ###
if w >> 1:
return model.Inv_end[w] == model.Inv_end[w-1] - model.Wk_dmd[w]
return Constraint.Skip
model.Inv_end_dynamics = Constraint(model.Wks, rule=Calc_inv)
When I run the model I get the following 2 errors:
- ’ ValueError: Cannot write legal LP file. Constraint 'Dmd_dynamics[2]' has a body with nonlinear terms.’
- It appears this refers specifically to the 2000/model.Pcrrnt[w] term in the dmd_dynamics_rule fct
- 'Selected solver is unable to handle objective functions with quadratic terms. Objective at issue: objective.'
I believe from looking at some other resource iterative LP could be different implementation that resolve error 2 but unclear how to execute that in this environment.
Any guidance or recommendations on how to resolve either errors (or recs on another open source solver that can handle this model) would be much appreciated!