Search code examples
cplexopl

Problem Browser in IBM ILOG CPLEX Optimization Studio


I have a main() module with flow control and explicitly create model instances using "new IloOplModel()". Running the program in IBM ILOG CPLEX Optimization Studio (12.7) the results are not shown in the "Problem Browser". Is there any way to tell the IDE to show the results of a certain model instance in the Problem Browser?

Before switching to explicit creation of model instances, I relied on the implicit model instance (available through thisOplModel). With the implicit model instance the results are always shown in the "Problem Browser".

Thanks for your help!


Solution

  • That's normal.

    So what you could do is either

    rely on scripting to display what you need:

    https://github.com/AlexFleischerParis/zooopl/blob/master/zooprepostprocessing.mod

    int nbKids=300;
    float costBus40=500;
    float costBus30=400;
    
    // Preprocessing
    
    execute DISPLAY_BEFORE_SOLVE
    {
    writeln("The challenge is to bring ",nbKids," kids to the zoo.");
    writeln("We can use 40 and 30 seats buses and the costs are ",costBus40," and ",costBus30);
    writeln("So average cost per kid are ",costBus40/40, " and ",costBus30/30);
    }
    
    // Decision variables , the unknown
    
    dvar int+ nbBus40;
    dvar int+ nbBus30;
    
    // Objective
     
    minimize
     costBus40*nbBus40  +nbBus30*costBus30;
     
    // Constraints
     
    subject to
    {
     40*nbBus40+nbBus30*30>=nbKids;
    }
    
    // Postprocessing
    
    execute DISPLAY_After_SOLVE
    {
    writeln("The minimum cost is ",costBus40*nbBus40  +nbBus30*costBus30);
    writeln("We will use ",nbBus40," 40 seats buses and ",nbBus30," 30 seats buses ");
    }
    

    or write .dat in files so that you can use the problem browser with .mod and .dat without a main block

    Example:

    subvalue.mod

    float maxOfx = ...;
    dvar float x;
    
    maximize x;
    subject to {
      x<=maxOfx;
    }
    
    execute
    {
    writeln("x= ",x);
    }
    

    and then

    main {

      var source = new IloOplModelSource("subvalue.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
     
     
     
      for(var k=1;k<=10;k++)
      {;
      var opl = new IloOplModel(def,cplex);
        
      var data2= new IloOplDataElements();
      data2.maxOfx=k;
      opl.addDataSource(data2);
      opl.generate();
    
      if (cplex.solve()) {  
         opl.postProcess();
         writeln("OBJ = " + cplex.getObjValue());
         writeln(".dat");
         writeln(opl.printExternalData());
        
      } else {
         writeln("No solution");
      }
     opl.end();
    }  
    
    
    }
    

    that gives

    x= 1
    OBJ = 1
    .dat
    maxOfx = 1;
    
    x= 2
    OBJ = 2
    .dat
    maxOfx = 2;
    
    x= 3
    OBJ = 3
    .dat
    maxOfx = 3;
    
    x= 4
    OBJ = 4
    .dat
    maxOfx = 4;
    
    x= 5
    OBJ = 5
    .dat
    maxOfx = 5;
    
    x= 6
    OBJ = 6
    .dat
    maxOfx = 6;
    
    x= 7
    OBJ = 7
    .dat
    maxOfx = 7;
    
    x= 8
    OBJ = 8
    .dat
    maxOfx = 8;
    
    x= 9
    OBJ = 9
    .dat
    maxOfx = 9;
    
    x= 10
    OBJ = 10
    .dat
    maxOfx = 10;