Global AI and Data Science

 View Only
Expand all | Collapse all

limiting number of solution and getting rapid solutions

  • 1.  limiting number of solution and getting rapid solutions

    Posted Thu March 04, 2021 04:11 PM
    Dear, I want to keep only one or two best solutions instead of 20 or more solutions in cplex. How to set this.
    Also, how can I set relaxation to get solutions faster.

    Best Regards

    Ismail

    ------------------------------
    Muhammad Ismail
    ------------------------------

    #GlobalAIandDataScience
    #GlobalDataScience


  • 2.  RE: limiting number of solution and getting rapid solutions

    Posted Fri March 05, 2021 02:58 AM
    Hi

    the CPLEX / Decision Optimization community : ibm.biz/DOcommunity

    For the solution pools question let me change a bit the example from https://github.com/AlexFleischerParis/zooopl/blob/master/zooseveral.mod


    I add


    cplex.solnpoolcapacity=2;
    cplex.solnpoolreplace=1;

    So I use

        int nbKids=300;
        float costBus40=500;
        float costBus30=400;
         
        dvar int+ nbBus40;
        dvar int+ nbBus30;
         
        minimize
         costBus40*nbBus40  +nbBus30*costBus30;
         
        subject to
        {
         40*nbBus40+nbBus30*30>=nbKids;
        }
    
        execute
        {
        writeln("nbBus40 = ",nbBus40," and nbBus30 = ",nbBus30," and the cost is ",costBus40*nbBus40  +nbBus30*costBus30);
        }
    
         main {
        cplex.solnpoolintensity=4;
        cplex.solnpoolcapacity=2;
        cplex.solnpoolreplace=1;
    
            thisOplModel.generate();
            cplex.solve();
            if (cplex.populate()) {
              var nsolns = cplex.solnPoolNsolns;
              
              
              writeln("Number of solutions found = ",nsolns);
              writeln();
              for (var s=0; s<nsolns; s++) {
                thisOplModel.setPoolSolution(s);
                thisOplModel.postProcess();
              }
            }
        }​


    which gives

    Number of solutions found = 2
    
    nbBus40 = 6 and nbBus30 = 2 and the cost is 3800
    nbBus40 = 3 and nbBus30 = 6 and the cost is 3900


    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------