简体   繁体   中英

Using the piecewise function of the IBM CPLEX python API, but the problem cannot be solved

I try to use MILP (Mixed Integer Linear Programming) to calculate the unit commitment problem. (unit commitment: An optimization problem trying to find the best scheduling of generator) Because the relationship between generator power and cost is a quadratic function, so I use piecewise function to convert power to cost.

enter image description here

I modify the answer on this page: enter link description here

The simple program structure is like this::

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')

#after 4 buses, additional buses of a given size are cheaper
f1=mdl.piecewise(0, [(0,0),(4,2000),(10,4400)], 0.8) 
f2=mdl.piecewise(0, [(0,0),(4,1600),(10,3520)], 0.8) 
cost1= f1(nbbus40)
cost2 = f2(nbbus30)

mdl.minimize(cost1+ cost1)
mdl.solve()
mdl.report()

for v in mdl.iter_integer_vars():
    print(v," = ",v.solution_value) 

which gives

* model buses solved with objective = 3520.000
nbBus40  =  0
nbBus30  =  10.0 

The answer is perfect but there is no way to apply my example. I used a piecewise function to formulate a piecewise linear relationship between power and cost, and got a new object (cost1), and then calculated the minimum value of this object. The following is my actual code(simply): enter image description here (min1,miny1), (pw1_1,pw1_1y),(pw1_2,pw1_2y),(max1,maxy1)Are the breakpoints on the power-cost curve

pwl_func_1phase = ucpm.piecewise(0, [(0,0),(min1,miny1), (pw1_1,pw1_1y),(pw1_2,pw1_2y),(max1,maxy1)], 0)
#df_decision_vars_spinning is a dataframe store Optimization variables
df_decision_vars_spinning.at[(units,period),'variable_cost'] = pwl_func_1phase(df_decision_vars_spinning.at[(units,period),'production'] )

total_variable_cost = ucpm.sum((df_decision_vars_spinning.variable_cost))
ucpm.minimize(total_variable_cost )

I don't know what causes this optimization problem can't be solve. here is my complete code: https://colab.research.google.com/drive/1JSKfOf0Vzo3E3FywsxcDdOz4sAwCgOHd?usp=sharing

Not an answer, but to illustrate my comment.

Let's say we have as the cost curve

cost = α + β⋅power^2

Furthermore, we are minimizing cost.

We can approximate using a few linear curves. Here I have drawn a few:

在此处输入图像描述

Let's say each linear curve has the form

cost = a(i) + b(i)⋅power

for i=1,...,n ( n =number of linear curves).

It is easy to see that is we write:

min cost
cost ≥ a(i) + b(i)⋅power   ∀i

we have a good approximation for the quadratic cost curve. This is exactly as I said in the comment.

No binary variables were used here.

With an unlimited edition of CPLEX, your model solves (though very slowly). Here are two ideas to better control what happens in solve()

  1. use solve(log_output=True) to print the log: you'll see the gap going down
  2. set a mip gap: setting mip gap to 5% stops the solve at 36s

    ucpm.parameters.mip.tolerances.mipgap = 0.05

    ucpm.solve(log_output=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM