Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Difficult MIP not converging

  • 1.  Difficult MIP not converging

    Posted Tue April 10, 2018 04:07 AM

    Originally posted by: P2S5_Rakesh_Kumar


    I am solving multiperiod production planning problem where constraints related to minimum batch size, SKU priorities, resource priorities, changeovers, etc are modelled and objective is to maximize the On-Time-In-Full (OTIF). I have modelled it as mixed integer programming model but this model is not converging even by 1% after running for 2 hours... I am uploading output log file fore reference


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Difficult MIP not converging

    Posted Tue April 10, 2018 04:08 PM

    Given the rather large values for the objective function, it might be worth checking the numerical properties of your model. Ill-conditioning can slow convergence. Try computing kappa statistics and reporting them here. (If you don't know how to get kappa statistics, or what they are, you can search the forum for "kappa" and probably find sufficient information to get started.)

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Difficult MIP not converging

    Posted Wed April 11, 2018 06:18 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Thanks for very quick responce! Really appreciate it.

    I will definitely try this

    What is the good reference value of kappa statistics for a numerically stable model?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Difficult MIP not converging

    Posted Wed April 11, 2018 03:34 PM

    Check the CPLEX user manual, Discrete optimization > Solving mixed integer ... > Troubleshooting ... > MIP kappa: ...


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Difficult MIP not converging

    Posted Wed April 11, 2018 09:23 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Dear Paul,

    I am facing another issue which is related to different versions of cplex. My model which is running absolutely fine and giving solution in CPLEX 12.5, but for CPLEX 12.6.3 there is not solution generated for the same model. CPLEX 12.6.3 is installed on windows server while CPLEX 12.5 is on my local machine. I am really clueless about this really weird behaviour from 2 different versions of CPLEX. 

    Kind Regards,

    Rakesh


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Difficult MIP not converging

    Posted Wed April 11, 2018 03:37 PM

    First, each new version of CPLEX changes the solver logic in a few places. Sometimes those changes make a particular problem solve faster, but sometimes they make a particular problem solve slower. (MIPs are very contrary beasts.) So it is not unheard of for a problem instance to solve more slowly on a newer version of CPLEX.

    Second, there are other differences to consider beside the CPLEX version. Are you running the same operating system (Windows) and same version of it on both machines? Do they have the same processor and same amount of memory? Is the server busy doing other compute-intensive jobs while it is running yours?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Difficult MIP not converging

    Posted Thu April 12, 2018 11:04 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Operating systems are same, and server has 16 GB of RAM  compared to 8GB on my local machine and this server is dedicated for CPLEX only. Though server has only single core processor (Intel xeon, 2.1 GHz) while my machine has 4 core processor (Intel i5-6300U, 2.4 GHz). Can you suggest if increasing the RAM on server can help?

     

    I have used XPRESS-MP also but never faced such issues ever... Also, uploading solution from previous run is so easy in XPRESS that it becomes a cakewalk while implementation.. Sadly, CPLEX is forced on me by my client, otherwise I would have never used it and would have never recommended it to anyone.. :(


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Difficult MIP not converging

    Posted Thu April 12, 2018 02:46 PM

    You might look at the CPLEX log from the server, and see how large the node tree gets. (This is printed out periodically in the log.) Compare that to your setting for the tree size limit (or the default setting if you did not change it). If the log shows the tree approaching the limit, there's a good chance CPLEX starts swapping chunks of the tree out to disk. A larger limit will reduce the swapping, and hopefully speed things up a bit. Whether that requires more RAM depends on whether the program footprint overall is getting close to the current memory size.

    The server being dedicated for CPLEX only is not the issue. The issue is whether the server is dedicated for your use only (meaning that your program is the only application running on it, other than the usual background stuff).

    I used XPRESS-MP once upon a time and was quite happy with it. That said, I'm back using CPLEX (and quite happy with it). On any given problem, any of the three major solvers (Gurobi being the third) might be the fastest (or slowest).


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Difficult MIP not converging

    Posted Fri April 13, 2018 02:34 AM

    Well, did you solve the same problem with XPRESS-MP? Like Paul already suggested, the large numbers in your objective may indicate an numerically instable model. Since solvers become more and more numerically stable over time, it could well be that newer versions of solvers have a harder time on solving models that are numerically challenging (or even questionable).

    WRT your initial question: from the log file it seems that CPLEX spends a lot of time at the root node for separating cuts. You could try to cut down on the cut effort or disable cuts entirely or disable cuts that are not effective.


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Difficult MIP not converging

    Posted Fri April 13, 2018 02:35 AM

    By the way, since you are using CPLEX for commercial purposes, you should be entitled to support. You can file a support ticket if you have troubles with CPLEX performance.


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Difficult MIP not converging

    Posted Fri April 13, 2018 06:36 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Well, My job here is not to evaluate XPRESS-MP versus CPLEX, my job here is to develop optimization solutions that solves client problems in reasonable time and solution should be of reasonable quality ... Rather doing my actual job, I am breaking my head figuring out this weird behaviour from 2 different versions of cplex i.e. 12.5 and 12.6.3. I am attaching log for same file from cplex 12.5 and 12.6.3. While,I am getting solution from 12.5 version but there is no solution from 12.6.3. I am attaching log files from both for your reference. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Difficult MIP not converging

    Posted Sat April 14, 2018 05:53 PM

    There are some differences in what the respective presolvers end up with, which is not unexpected given the change from one version to another. You're using four threads on your PC versus one on the server, which is going to have some impact on the solution process. The fact that the solver does not find an initial feasible solution has me wondering whether numerics are a problem. Try collecting kappa statistics on both machines and see if either set indicates stability issues. I don't think you need to do long runs, since the problem (if there is one) appears to manifest at the root node. You can just run each machine for a few minutes. I suggested this before.


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Difficult MIP not converging

    Posted Sun April 15, 2018 04:42 PM

    Originally posted by: P2S5_Rakesh_Kumar


    If numerics would have been the problem then this problem could not have been solved on either of the version of the cplex, which is not the case here, this problem is being solved with cplex 12.5 version easily but not be 12.6.3.... 


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: Difficult MIP not converging

    Posted Sun April 15, 2018 05:13 PM

    You are making an incorrect assumption. Numerics can affect the decision making of the algorithms in CPLEX, and those algorithms change from one version to the next. So, for example, there might be some comparison in one version but not in the other that gets tripped up by subtracting a tiny number from a huge number and appearing to get the huge number back as the difference.


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 12:52 AM

    There is a fundamental difference between your runs for 12.5 and 12.6.3: 12.5 uses 4 threads while 12.6.3 uses only 1. With 4 threads available, CPLEX can run additional heuristics in parallel to the root cut loop. From the log it seems it are these heuristics that find a solution in 12.5. In the single-threaded 12.6.3 run these heuristics are just not executed. I don't think it is surprising that performance of a single-threaded run is worse than that of a multi-threaded run. What happens if you run 12.6.3 on 4 threads?

    To settle the issue with numerics, can you show the model's problem statistics ("disp prob stats" in the interactive) or even share the model?


    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 06:11 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Thanks Daniel, I tried running model on cplex 12.5 with single thread for 1 hour and there is no initial integer solution even after 1 hour of run time.. so what you are suggesting is right. Can you suggest a workaround ? if machine is single core or dual, how can we get integer solution within reasonable run time?

     

    I am attaching log file for run on 12.5 with single thread for your reference.


    #CPLEXOptimizers
    #DecisionOptimization


  • 17.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 07:24 AM

    From the log it is hard to tell where exactly CPLEX spends all its time. Two things stick out: probing and cuts. Have you tried disabling or cutting down on the effort for either of them?


    #CPLEXOptimizers
    #DecisionOptimization


  • 18.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 07:41 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Yes, I can do that, should I disable the cuts/probe completely?


    #CPLEXOptimizers
    #DecisionOptimization


  • 19.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 08:57 AM

    Originally posted by: P2S5_Rakesh_Kumar


    I have run with probing and cuts disabled for 1 hour. I am attaching the log for reference. Still, there is no solution even after running for 1 hour.


    #CPLEXOptimizers
    #DecisionOptimization


  • 20.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 09:29 AM

    Can you share the model?


    #CPLEXOptimizers
    #DecisionOptimization


  • 21.  Re: Difficult MIP not converging

    Posted Tue April 17, 2018 11:52 AM

    Originally posted by: P2S5_Rakesh_Kumar


    I am attaching the model in .mps format


    #CPLEXOptimizers
    #DecisionOptimization


  • 22.  Re: Difficult MIP not converging

    Posted Thu April 19, 2018 09:26 AM

    The MPS file seems invalid. There are lots of duplicate row names (it seems like each row appears twice?). How did you create this file? Did you export it from CPLEX?


    #CPLEXOptimizers
    #DecisionOptimization


  • 23.  Re: Difficult MIP not converging

    Posted Fri April 20, 2018 05:27 AM

    Originally posted by: P2S5_Rakesh_Kumar


    I exported it from opl...let me check my model again


    #CPLEXOptimizers
    #DecisionOptimization


  • 24.  Re: Difficult MIP not converging

    Posted Fri April 20, 2018 09:35 AM

    If you exported from OPL then I think there must be a problem in OPL somewhere. I don't think there is anything you could do in your model that would create a corrupted MPS file. Can you export in SAV format instead? That should avoid any sort of issue.


    #CPLEXOptimizers
    #DecisionOptimization


  • 25.  Re: Difficult MIP not converging

    Posted Sun April 22, 2018 10:14 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Please find attached model file in .sav format...


    #CPLEXOptimizers
    #DecisionOptimization


  • 26.  Re: Difficult MIP not converging

    Posted Tue April 24, 2018 02:04 AM

    Thanks a lot for your model.

    I have started to look into this. I have a feeling that your run that finds a feasible solution is just incredibly lucky in a particular heuristic. I can find a feasible solution like you but as soon as I start changing the thread count or the random seed, CPLEX has a hard time finding a first feasible solution.

    However, here is a strategy that quickly (in less than one minute) and consistently (across 30 random seeds) finds a first feasible solution with a single thread:

    - disable cuts
    - instead of `optimize` run `feasopt` (see here) and allow relaxation of constraints
    - change parameter settings as you please and call `optimize`

    Since your model is feasible, feasopt will stop with an integer feasible solution. This solution can then be used as a starting point for the "real" optimization. If you don't want to change parameters between `feasopt` and `optimize` then you can do everything in one call: set feasopt mode to 1 and call feasopt.


    #CPLEXOptimizers
    #DecisionOptimization


  • 27.  Re: Difficult MIP not converging

    Posted Tue April 24, 2018 05:47 AM

    Originally posted by: P2S5_Rakesh_Kumar


    Thanks Daniel for looking into this issue...

    Looks like my client also have to be 'incredibly' lucky everytime he/she runs the optimizer and he need to run optimizer every week for 2 plants and 3 product categories and if he is not satisfied with result quality then he might have to run all or some of the scenarios twice or thrice after changing the parameters. And now I am sure that our client needs more luck than a optimizer to generate production plans everyweek.

    I tried setting feasoptmode to 1 in opl (cplex 12.6.3) , but looks like cplex.feasoptmode=1 does not work in cplex 12.6.3.. Can you suggest a workaround?

     

    Though feasopt worked in interactive optimizer..


    #CPLEXOptimizers
    #DecisionOptimization


  • 28.  Re: Difficult MIP not converging

    Posted Thu April 26, 2018 04:38 AM

    Are you solving this from the IDE, from oplrun or from some programming API?

    From an API you should be able to call feasOpt() directly, for oplrun there is option '-relax'. If you want to solve from the IDE then you may have to create the relaxed model explicitly (I can give an example if you need that).


    #CPLEXOptimizers
    #DecisionOptimization


  • 29.  Re: Difficult MIP not converging

    Posted Thu April 26, 2018 07:16 AM

    Originally posted by: P2S5_Rakesh_Kumar


    I am solving it in IDE, so please give me an example how to create relaxed model explicitly in OPL IDE. Is probe parameter also deprecated in cplex 12.6.3 from OPL?


    #CPLEXOptimizers
    #DecisionOptimization


  • 30.  Re: Difficult MIP not converging

    Posted Fri April 27, 2018 05:11 AM

    Here is a tiny "tutorial" how to use the feasopt approach directly from the IDE. It is build on the opl/examples/opl/prodmilp example shipped with CPLEX.

    The idea is that you relax all constraints and try to find a solution that minimizes violation of the constraints.

    The original model is this

    {string} Products = ...;
    {string} Resources = ...;
    {string} Machines = ...;
    float MaxProduction = ...;

    tuple typeProductData {
      float demand;
      float incost;
      float outcost;
      float use[Resources];
      string machine;
    }

    typeProductData Product[Products] = ...;
    float Capacity[Resources] = ...;
    float RentCost[Machines] = ...;

    dvar boolean Rent[Machines];
    dvar float+ Inside[Products];
    dvar float+ Outside[Products];


    minimize
      sum( p in Products )
        ( Product[p].incost * Inside[p] +
          Product[p].outcost * Outside[p] ) +
      sum( m in Machines )
        RentCost[m] * Rent[m];
       
    subject to {
      forall( r in Resources )
        ctCapacity:
          sum( p in Products )
            Product[p].use[r] * Inside[p] <= Capacity[r];

      forall( p in Products )
        ctDemand:
          Inside[p] + Outside[p] >= Product[p].demand;

      forall( p in Products )
        ctMaxProd:
          Inside[p] <= MaxProduction * Rent[Product[p].machine];
    }

    In order to apply this relaxation approach we first create a data file phase.dat with this content

    findFeasible = [0];

    and add that file to the project and its run configuration. We will modify the .mod file so that we can either solve the original model (findFeasible[0] = 0) or the relaxed model (findFeasible[0] = 1).

    To this end we add the following block to the data definition of the model:

    // Data and variables related to finding a first feasible solution.
    // We have a one-element array findFeasible[] that tells us what model we are solving.
    // If findFeasible[0] is 0 then we want to solve the original model. If findFeasible[0]
    // is 1 then we want to solve a relaxation of the model that is aimed at finding a
    // (first) feasible solution. In the phase.dat file the value of findFeasible[0] is
    // set to 0 so that by default we solve the original model.
    // In addition we have a continuous non-negative variable for each constraint we want
    // to relax when going for a first feasible solution.
    int findFeasible[0..0] = ...;
    dvar float+ relaxCtCapacity[Resources];
    dvar float+ relaxCtDemand[Products];
    dvar float+ relaxCtMaxProd[Products];

    and modify the objective function as follows:

    minimize
      // The objective function consists of two parts: The original objective function and
      // the sum of constraint violations. If findFeasible[0] is 0 then only the first part
      // is active, if findFeasible[0] is 1 then only the second part is active.
      (1 - findFeasible[0]) * (
        // Original objective function
        sum( p in Products )
          ( Product[p].incost * Inside[p] +
            Product[p].outcost * Outside[p] ) +
        sum( m in Machines )
          RentCost[m] * Rent[m]
      ) +
      findFeasible[0] * (
        // Sum of violation of constraints.
        sum(r in Resources) relaxCtCapacity[r] +
        sum(p in Products) relaxCtDemand[p] +
        sum(p in Products) relaxCtMaxProd[p]
      );

    This is essentially two completely different objective functions, depending on the value of findFeasible[0]. In case findFeasible[0] is 0, no relaxation of constraints is allowed, so we add the following constraints:

      // If we are not looking for a first feasible solution then constraint
      // violation is not allowed and all the variables indicating a violation
      // are fixed to 0.
      if ( findFeasible[0] == 0) {
        forall (r in Resources) relaxCtCapacity[r] == 0;
        forall (p in Products) relaxCtDemand[p] == 0;
        forall (p in Products) relaxCtMaxProd[p] == 0;  
      }

    Finally, we add the new variables to the constraints in the original model so that these constraints can be relaxed in case findFeasible[0] = 1 (in case findFeasible[0] = 0 all variables are fixed to 0 and no relaxation is possible):

      forall( r in Resources )
        ctCapacity:
          sum( p in Products )
            Product[p].use[r] * Inside[p] <= Capacity[r] + relaxCtCapacity[r];

      forall( p in Products )
        ctDemand:
          Inside[p] + Outside[p] >= Product[p].demand - relaxCtDemand[p];

      forall( p in Products )
        ctMaxProd:
          Inside[p] <= MaxProduction * Rent[Product[p].machine] + relaxCtMaxProd[p];

    With all this in place, we have to do the following:

    • Solve the relaxed model.
    • If we find a solution with objective value 0 then this solution does not violate any constraints. In that case we can install that solution as objective for the original model.
    • Solve the original model.

    We do all that by adding the following scripting block to the end of the .mod file:

    main {
      thisOplModel.generate();

      // Create a copy of the original model. In that copy set findFeasible[0] to 1
      // so that the model aims at finding a first feasible solution.
      // Solve that model.
      var def = thisOplModel.modelDefinition;
      var dat = thisOplModel.dataElements;  
      var feasCplex = new IloCplex();
      var feasOpl = new IloOplModel(def, feasCplex);
      dat.findFeasible[0] = 1;
      feasOpl.addDataSource(dat);
      feasOpl.generate();
      writeln("Solve model to find a (first) feasible solution ...");
      feasCplex.solve();

      // The objective in the solved model is the sum of constraint violations. If
      // that is 0 then no constraints are violated and we have found a feasible
      // solution. We can use that solution as a MIP start for the original model.
      var objval = feasCplex.getObjValue();
      writeln("Objective after feasopt: " + objval);
      if ( Opl.abs(objval) < 1e-6 ) {
        writeln("-> feasible solution found");
        var start = new IloOplCplexVectors();
        start.attach(thisOplModel.Rent, feasOpl.Rent.solutionValue);
        start.setStart(cplex);
      }    
      else {
        writeln("-> no feasible solution found");
      }

     
      // Release memory acquired for the copied model.
      feasOpl.end();
      feasCplex.end();
     
      // Now solve the original model with the MIP start installed above.
      writeln("Solve original model ...");
      cplex.solve();
      writeln("Objective for real model: " + cplex.getObjValue());
      thisOplModel.postProcess();

      0;

    }

    I am also attaching the relevant files here.

    (for the probe parameter I am not aware of any deprecation, what makes you think it is deprecated?)


    #CPLEXOptimizers
    #DecisionOptimization