0

I am trying to solver the Unit Commitment problem (MIQP problem) by modelling the problem in CVXPY and using the CPLEX solver. I have been successful in getting everything to work with CVXPY using CPLEX. However, this was for a small system. Now I would like to do the same with a much larger system.

Side Note: I have successfully solved the MIQP problem in MATLAB using CPLEX. For larger system in MATLAB, I have used an initial solution from a MILP formulation of the problem and limited the CPLEX solver time using the "timelimit" parameter. This has successfully given me optimal solution in a short amount of time.

Now when I try to do the same with CVXPY and CPLEX, the CPLEX solver fails for the larger system. Also for the smaller system, I dont notice any difference in time to solve the problem. I have noted this based on the "solver.stats.solve_time" value. Therefore, I am unsure of whether the initial solution is getting used or neglected. This is some sample code for what I have done. These are my optimization variables:

power = cp.Variable((nUnits, nHours))
isOn = cp.Variable((nUnits, nHours), integer=True)
startup = cp.Variable((nUnits, nHours), integer=True)

I then have the section where I create my objective and constraints. Then I read in the initial solution from Excel and make the necessary adjustments to get it to look like the solution:

initial_power_soln_df = pd.read_excel(r'C:\Users\micah\Downloads\OneDrive-2020-04-17\init.xlsx', sheet_name='Sheet1', header=None)
initial_isOn_soln_df = pd.read_excel(r'C:\Users\micah\Downloads\OneDrive-2020-04-17\init.xlsx', sheet_name='Sheet2', header=None)
initial_startup_soln_df = pd.read_excel(r'C:\Users\micah\Downloads\OneDrive-2020-04-17\init.xlsx', sheet_name='Sheet3', header=None)

power.value = initial_power_soln_df.to_numpy().T
isOn.value = initial_isOn_soln_df.to_numpy().T
startup.value = initial_startup_soln_df.to_numpy().T

Finally, I create my problem and set up the solver:

problem = cp.Problem(cp.Minimize(cost), constr)
problem.solve(solver=cp.CPLEX, cplex_params={"timelimit": 300})

Not sure if this is the proper way to do this. Also NB. the initial solution comes from a MILP formulation and the optimization variables will be different from that of the MIQP formulation. So I cant just take the solution from the MILP and plug it in to the MIQP formulation. I first need to process the results.

  • Does the answer from https://stackoverflow.com/questions/52314581 help? – rkersh Apr 28 '20 at 19:45
  • That's what I initially looked at when writing my code. But for some reason I don't think it works. There is no reduction in time taken to find the solution compared to what happens if I follow what Alex posted below. However, I can't implement something like this, as I am using an initial solution from another optimization approach and need to manually set my initial solution. – Edmund Blackadder Apr 29 '20 at 02:24
  • If using the cvxpy warmstart functionality doesn’t work for you then you may be better off using one of the CPLEX interfaces directly (e.g., the CPLEX Python API or docplex). – rkersh Apr 29 '20 at 03:11
  • I had thought about that, but my problem is too complex to implement with the CPLEX Python API. That's why I use CVXPY or MATLAB so I can symbolically model the problem. – Edmund Blackadder Apr 29 '20 at 17:35

2 Answers2

1

let me change a bit the bus and zoo example.

# Import packages.
import cvxpy as cp


# Define and solve the CVXPY problem.
nbBus40 = cp.Variable(integer=True)
nbBus30 = cp.Variable( integer=True)
cost = 500*nbBus40+400*nbBus30
prob = cp.Problem(cp.Minimize(cost),[40*nbBus40+30*nbBus30>=300,
                                     nbBus40==8,nbBus30==0
                                     ])

prob.solve(solver=cp.CPLEX,verbose=True)

prob = cp.Problem(cp.Minimize(cost),[40*nbBus40+30*nbBus30>=300,
                                     nbBus40>=0,nbBus30>=0
                                     ])

prob.solve(solver=cp.CPLEX,verbose=True,warm_start=True)

print("status = ",prob.status)

# Print result.
print("\nThe minimal cost is", prob.value)

print("number buses 40 seats = ",nbBus40.value)
print("number buses 30 seats = ",nbBus30.value)
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • How to warmstart a solution with cvxpy Cplex – Alex Fleischer Apr 28 '20 at 18:12
  • Ok I see, but what if I want to manually set my initial solution? The simulation for my large system is very long. Left it running for over a day and never got a solution but I know there is s solution because I got it in MATLAB. So I cant apply this approach. – Edmund Blackadder Apr 28 '20 at 18:25
  • I am tring to use a two set approach. One where I formulate the problem as a MILP problem because it is easier to solve but suboptimal but then plug this solution into the MIQP approach. – Edmund Blackadder Apr 28 '20 at 18:35
1

I have determined that the warm start functionality does not work with the CPLEX solver or that this is NOT the proper way to use the warm start functionality with CPLEX. This was done by using the example associated with the warm start section in https://www.cvxpy.org/tutorial/advanced/index.html#solve-method-options. When specifying the solver as CPLEX, there is no difference in solve time.