Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Solving times in solution pool

    Posted 07/17/18 08:40 AM

    Originally posted by: Redhat11


    Hi,

    I am using the solution pool to print the found soulutions. However, I have two problems:

    1. the order of the found solutions is not the correct order of when the solutions have been found. It seems mixed up, not even the reversed order.

    2. I want to print out the solvling times when each solution has been found. The code snippet below does not work, it always prints out the entire time it took to find the global optimal solution.

     

     

    var before = new Date();
    var temp = before.getTime();
     
    if (cplex.solve()) {
     
     
    writeln("x = " + thisOplModel.x);
    writeln("y = " + thisOplModel.y);
     
    var nsolns = cplex.getSolnPoolNsolns();
    writeln("Number of Solutions found = " + nsolns);
     
          
          writeln();
          for (var solution=nsolns; solution>0; solution--) {
            thisOplModel.setPoolSolution(solution);
            writeln("y = " + thisOplModel.y);
            writeln(cplex.getObjValue());
            var after = new Date();
             writeln("solving time ~= ",after.getTime()-temp);

         }

     }

     

    Anyone can help me?

    Cheers

     

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Solving times in solution pool

    Posted 07/17/18 10:31 AM

    Hi,

    what you descrive is normal since you fill the solution pool and then you read it. Once the solution pool is there, it takes 0 s to get a solution.

    If you want to see solutions one by one you could use many cplex solves. And then you can get all time measures.

    Let me give you an example:

    Modify scalablewarehouse.mod into

     

    int Fixed        = 100;
    int NbWarehouses = 200;
    int NbStores     = 600;


    assert( NbStores > NbWarehouses );

    range Warehouses = 1..NbWarehouses;
    range Stores     = 1..NbStores;
    int Capacity[w in Warehouses] =
      NbStores div NbWarehouses +
      w % ( NbStores div NbWarehouses );
    int SupplyCost[s in Stores][w in Warehouses] =
      1 + ( ( s + 10 * w ) % 100 );
    dvar int Open[Warehouses] in 0..1;
    dvar float Supply[Stores][Warehouses] in 0..1;
    dexpr int TotalFixedCost = sum( w in Warehouses ) Fixed * Open[w];
    dexpr float TotalSupplyCost = sum( w in Warehouses, s in Stores )  SupplyCost[s][w] * Supply[s][w];
    //minimize TotalFixedCost + TotalSupplyCost;
    dvar float obj;
    minimize obj;
    subject to {
    ctObj:obj==TotalFixedCost + TotalSupplyCost;


      forall( s in Stores )
        ctStoreHasOneWarehouse:
          sum( w in Warehouses )
            Supply[s][w] == 1;
      forall( w in Warehouses )
        ctOpen:
          sum( s in Stores )
            Supply[s][w] <= Open[w] * Capacity[w];
    }

    execute
    {
    writeln("Open=",Open);
    }

    And then you may write

    include "scalableWarehouse.mod";

    main {
        thisOplModel.generate();
        cplex.intsollim=1;
        
        var i=1;
        while (i<=30)
        {
           cplex.solve();
           i++;
           writeln(new Date());
           writeln(cplex.getObjValue());
        }   
        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("solution #", s, ": objective = ", cplex.getObjValue(s));
            write("Open = [ ");
            for (var i in thisOplModel.Warehouses)
              write(thisOplModel.Open[i], " ");
            writeln("]");  
            writeln("---------");
          }
        }
    }

     

    In the first part you get all the solutions and then you visit the solution pool

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer