Search code examples
pythonoptimizationlinear-programmingpiecewise

unit commitment problem using piecewise-linear approximation become MIQP


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)

There are two optimization variables.

Generator power :P(continuous variables). Which line segment on cost curve to use :BN(binary variable). enter image description here,Used to linearize the quadratic cost function of the generator.

Only one line segment can be opened at a time. So there will be a Constraint. Bn1 + Bn2 + Bn3 <=1

Each line segment will have its own slope and intercept. I want to calculate the minimum cost. enter image description here This mathematical formula represents the sum of the cost of 1 to H hours.

This is how I code : sum(slope1* p * Bn1 +intercept1* Bn1 +slope2* p * Bn2 +intercept2* Bn2 +slope3* p * Bn3 +intercept3* Bn3 )

This way, the two optimization variables will be multiplied. Make the problem from MILP become to MIQP. I want to ask if there is any way can maintain my problem in MILP. thank you. ps : i use ibm cplex of python API to solve Optimization problem


Solution

  • You could use piecewise linear in docplex. Let me share the example from the zoo and bus example in python:

    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
    f=mdl.piecewise(0, [(0, 0),(4,4)], 0.8)
    
    mdl.minimize(f(nbbus40)*500 + f(nbbus30)*400)
    
    mdl.solve()
    
    mdl.export("c:\\buses.lp")
    
    for v in mdl.iter_integer_vars():
        print(v," = ",v.solution_value)
    

    which gives

    nbBus40  =  0
    nbBus30  =  10.0