Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Finding k-best solutions for a problem

    Posted 07/05/18 09:10 AM

    Originally posted by: mshpd


    Hi

    By using the populate option and creating a solution pool, we can get several feasible solutions to a problem.

    But is there an option to find, lets say, the ten best solutions for a problem using this approach?

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Finding k-best solutions for a problem



  • 3.  Re: Finding k-best solutions for a problem

    Posted 07/05/18 11:54 PM

    Originally posted by: mshpd


    Thank you.

    So i take it that there are no setting changes we can make or parameters we can define so as to do this


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Finding k-best solutions for a problem

    Posted 07/06/18 01:56 AM

    Hi,

    if you rely on the solution pools you could use

    Replace the solution which has the worst objective

    But this won t do exactly what you look for.

    Let me give you a complete example.

    Suppose you want the 8 best solutions for maximize x+y

    You could write

    dvar int x in 0..10;
    dvar int y in 0..10;

    int maxNbSolutions=8;
    dvar int nbForbiddenSolutions in 0..0;
    dvar int forbidx[1..maxNbSolutions];
    dvar int forbidy[1..maxNbSolutions];     
                
    maximize x+y;

    subject to
    {


       forall(i in 1..maxNbSolutions) ((forbidx[i]==x) && (forbidy[i]==y))=> (nbForbiddenSolutions<=i-1) ;  
          
    }

    execute
    {
        writeln("x=",x,"   and y=",y);
    }

    main {
       var nbsol=0;

       thisOplModel.generate();
       while ((1==cplex.solve()) && (nbsol<thisOplModel.maxNbSolutions))
       {
                 thisOplModel.postProcess();
                 nbsol++;
                 var tempx=thisOplModel.x.solutionValue;
                 var tempy=thisOplModel.y.solutionValue;
                 thisOplModel.nbForbiddenSolutions.UB=nbsol;   
                 thisOplModel.nbForbiddenSolutions.LB=nbsol;   
                 thisOplModel.forbidx[nbsol].UB=tempx;  
                 thisOplModel.forbidx[nbsol].LB=tempx;
                 thisOplModel.forbidy[nbsol].LB=tempy;   
                 thisOplModel.forbidy[nbsol].UB=tempy;      
       }
       writeln("nb solutions = ",nbsol);
    }

     

    which gives

     

    x=10   and y=10
    x=10   and y=9
    x=9   and y=10
    x=8   and y=10
    x=9   and y=9
    x=10   and y=8
    x=8   and y=9
    x=7   and y=10
    nb solutions = 8

    regards

     

    https://www.linkedin.com/pulse/how-opl-alex-fleischer/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Finding k-best solutions for a problem

    Posted 07/09/18 12:28 AM

    Originally posted by: mshpd


    Thank You


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Finding k-best solutions for a problem

    Posted 07/31/18 01:31 AM

    Hi,

    with the solution pools you could write

     dvar int x in 0..10;
    dvar int y in 0..10;

    tuple sol
    {
    int su; // sum

    int x;
    int y;
    }

    reversed {sol} solutions;
        
                
    maximize x+y;

    subject to
    {


         
    }

    execute
    {
        writeln("x=",x,"   and y=",y);
    }

    main {
        thisOplModel.generate();
        //cplex.solve();
        cplex.solnpoolreplace=1;
        cplex.solnpoolintensity=4;
        cplex.solnpoolcapacity=8;
        
        if (cplex.populate()) {
          var nsolns = cplex.solnPoolNsolns;

          writeln("Number of solutions found = ",nsolns);
          writeln();
          for (var s=0; s<nsolns; s++) {
            thisOplModel.setPoolSolution(s);
            
            writeln(thisOplModel.x, " ",thisOplModel.y);
            thisOplModel.solutions.add(
            thisOplModel.x+thisOplModel.y,thisOplModel.x,thisOplModel.y);
            
            
          }
        }
        
     writeln("solutions :");
     writeln(thisOplModel.solutions);   
    }

    and then get

    Number of solutions found = 8

    10 10
    8 10
    10 9
    9 9
    10 8
    7 10
    8 9
    9 10
    solutions :
     {<20 10 10> <19 10 9> <19 9 10> <18 10 8> <18 9 9> <18 8 10>
         <17 8 9> <17 7 10>}

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Finding k-best solutions for a problem

    Posted 08/03/18 02:53 AM

    Originally posted by: mshpd


    Thank you for this solution.

    I think this is a better alternative for my case compared to the earlier one.

     

    Regards 

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Finding k-best solutions for a problem

    Posted 09/11/18 04:05 AM

    Originally posted by: mshpd


    Hi

     

    http://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=123004

    This is an RFE that I had raised regarding this problem.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer