0

Currently I am working on a scheduling problem using IBM ILOG CPLEX using its OPL. I can only export the optimal solution using sheetWrite command but I would like to export the results of each feasible solution not only the optimal solution. Could you please advise on how to do this knowing that I am using CP solver and I don't have any prior knowledge on the number of the feasible solutions.

Thanks in advance Mohamed

rkersh
  • 4,447
  • 2
  • 22
  • 31

1 Answers1

0

what you could do is rely on a flow control main block.

You could add

main
{


thisOplModel.generate();
cp.startNewSearch();
while
(cp.next()) {  thisOplModel.postProcess(); }
}

at the end of your model and then postprocess will be called each time you get a new solution

Since my solutions seems not clear enough let me give a complete example out of the watehouse example:

.mod

using CP;

tuple sol
{
  int rank;
  float obj;
}

{sol} solutions;


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



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 int 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;

subject to {
  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("obj=",TotalFixedCost + TotalSupplyCost);

}

 main
{
var k=0;

thisOplModel.generate();

cp.startNewSearch();
while
(cp.next() && (k<=4)) 
{  
k++;
thisOplModel.postProcess();
thisOplModel.solutions.add(k,thisOplModel.TotalFixedCost + thisOplModel.TotalSupplyCost);
 }
} 

.dat

SheetConnection sheet("iter.xlsx");
solutions to SheetWrite(sheet,"A1:B4");

will write 4 solutions into the file iter.xls

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thanks Alex for your reply. I am looking for exporting the values of the objective function and decisions variables for each feasible solution. I could only do this this for the final solution. Is there a way to export these values (for each feasible solution) using sheetWrite command or something similar? – Mohamed Menessy Apr 16 '20 at 16:36