Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  CPLEX model for LNS

    Posted 11/28/18 10:35 AM

    Originally posted by: p_arias


    Hi there,

     

    So I am currently working on a model that takes between 2min and 30min to build. My idea is to use a heuristic to build an initial solution and then destroy part of it and use CPLEX to optimize the destroyed part.

     

    1) I thought about building the model, write it in a .lp file  and call it in each iteration, bounding each variable to the value it corresponds and leave the rest unbounded. For example: x_1 UB=1, LB=1. X_2, LB = 0, UB = 1. X_1 is set to be 1 and then CPLEX will find the value for x_1. The problem with this is that when I try to set the bounds or initialize part of the solution when reading from a file is not straightforward as variable names and the order of them is quite messy (or I don't know how to properly do it). To do so, I use a code someone poseted in this forum about extracting variables from an .lp file.

     

    2) I want to build the model ONCE, and then iteratevily change the bounds and solve the problem, storing the solution. ine ach iteration Then I wouldn't need to build the model and only change the bounds of variables in each iteration. Is this possible? How would you do it? I know you can add cuts but in each iteration the prior ones should be removed and new ones added, that is what is confusing me a bit about this approach.

     

    Kind regards,

    Pol

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: CPLEX model for LNS

    Posted 11/28/18 11:00 AM

    The most important question is: which CPLEX API do you use? C, C++, Java, Python? Also, is there a reason you use LP files instead of SAV files?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: CPLEX model for LNS

    Posted 11/28/18 12:01 PM

    Originally posted by: p_arias


    Hi Daniel,

     

    Oops sorry! I use Java, the problem I have is not the time it takes writing or reading a model (but I think SAV is faster so I will check and use it) is how to access the information within the file if needed, which I think is the case also with SAV (correct me if I'm wrong as I'm new into SAV files).  I don't think it is a very efficient way of iterating through a LNS in any case, so I was looking more to implement the second point.

     

    Regards,

    Pol


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: CPLEX model for LNS

    Posted 11/29/18 03:59 AM

    I am not sure I understood completely what you are trying to do. But I hope this helps:

    1. In Java there are actually two "models": one model is the "Concert model" that is build by Concert Technology objects like IloNumVar, IloRange etc. The other model is the model that is extracted to the engine. The latter is more or less a big matrix. You can store both models in a file. In order to store the Concert model, just serialize the model to an ObjectOutputStream, see the CplexServer.java example that is shipped with CPLEX for details. In order to save the extracted model you use IloCplex.exportModel() and export to LP and SAV. If you export to LP then the names and order of variables may indeed be messed up. If you instead export to SAV then this is merely a memory dump of the extracted model. So you should be able to find back your variables by name easily.
    However, if you say that building your model takes 2-30 minutes, then I take it most of the time is spent in computing the data that is required to create the model? In that case it may be much easier to not store the model but instead store the data. Creating a model from the precomputed data should be fast.

    2. You can just use methods IloNumVar.setLB() and IloNumVar.setUB() to change bounds between iterations. That should be the best/fastest thing to do. Such a change will be propagated to the model that the engine has extracted and calling IloCplex.solve() after such a modification will start from scratch. Note that by default CPLEX will keep the solution of the previous solve as a MIP start. At the start of the subsequent solve it will check whether that solution is still feasible and if so use it to warm-start the solve. This may or may not be beneficial. To avoid this you can set the Advance parameter to 0, This is particularly useful if you know that the solution from the previous iteration is guaranteed to be infeasible. In that case CPLEX can just save all the work associated with checking feasibility.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: CPLEX model for LNS

    Posted 11/29/18 07:43 AM

    Originally posted by: p_arias


    Hi Daniel,

     

    That's great! My only concern with point 2 is that if for example, I have a binary variable x_1 = {0,1} and I change the UB and LB for x_1 in iteration 1 to be UB = 1 and LB = 1 (forcing it to be 1), call IloCplex.solve(), solve the problem, then in iteration 2, if I call IloCplex.solve() will the model still force x_1 to be 1 or will solve the problem without the UB and LB forced in iteration 1?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: CPLEX model for LNS

    Posted 11/29/18 08:55 AM

    Bound changes are permanent. You will have to explicitly reset the lower bound to 0 to unfix the variable.


    #CPLEXOptimizers
    #DecisionOptimization