Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Error with CPLEX basis

    Posted 03/10/16 01:01 PM

    Originally posted by: hugotorres


    Hello,

    I'm trying to replicate the idea present on the mulprod example by having a loop where the data is changed and the model is ran again. The problem is that It always finds an issue with the CPLEX basis, saying "warm start preparation failed: 1262". I tried to search if this value had any special meaning but with no sucess. I'll leave my code here and appreciate any help you can give :)

     

    int p=...;
     int m=...;
     
     range pecas=1..p;
     range machines=1..m;
     
     int whours=...;
     
     int processTimes[pecas][machines]=...;
     int availableMachines[machines]=...;
     
     dvar int+ x[pecas][machines];
     dvar int+ y;
     
     dexpr int Z = y;
     
     maximize Z;
     
     subject to
     {
       forall(i in machines)
         sum(j in pecas) (processTimes[j][i]*x[j][i]) <= whours*60*availableMachines[i];
       
       forall(j in pecas)
         sum(i in machines) (x[j][i])-y >= 0;
     }  
    
    main
    {
            var status = 0;
            thisOplModel.generate();
    
            var model = thisOplModel;
            
            var woHours = model.whours;
            var best;
            var curr = Infinity;
            var basis = new IloOplCplexBasis();
            
            while(woHours != 0)
            {
              best = curr;
          writeln("Solve with working hours = ",woHours);
         if (cplex.solve()) {
          curr = cplex.getObjValue();
          writeln();
          writeln("OBJECTIVE: ",curr);
            }
        
        else {
          writeln("No solution!");
          break;
        } 
        
        if ( !basis.getBasis(cplex) ) {
          writeln("warm start preparation failed: ",basis.status);
          break;
        }
    
        // prepare next iteration
        var def = produce.modelDefinition;
        var data = produce.dataElements;
          
        if ( produce!=thisOplModel ) {
          produce.end();
        }
        
        produce = new IloOplModel(def,cplex);
        woHours--;
        data.whours = woHours;
        produce.addDataSource(data);
        produce.generate();
        
          if ( !basis.setBasis(cplex) ) {
          writeln("warm start ",basis.Nrows,"x",basis.Ncols," failed: ",basis.status);
          break;
        }
      }
      basis.end();
      if (Math.abs(cplex.getObjValue() - 393.5)>=0.01) {
          status = -1;
      }
      if (best != Infinity) {
        writeln("plan = ",produce.Plan);
      }
      if ( model!=thisOplModel ) {
        model.end();
      }
    
      status;
    } 
    

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Error with CPLEX basis

    Posted 03/11/16 01:01 PM

    Originally posted by: hugotorres


    No one? I really need some help on this :S


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Error with CPLEX basis

    Posted 03/12/16 04:32 AM

    Originally posted by: Stanko_86


    The problem is here:

        // prepare next iteration
        var def = produce.modelDefinition;
        var data = produce.dataElements;
    
    
    
    You used here variable "produce" (probably copied from multiprod example), 
    but you should use "model" instead, because the model has been defined above.
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Error with CPLEX basis

    Posted 03/13/16 02:53 PM

    Originally posted by: hugotorres


    Changed that and all the instances of Produce to Model but the problem keeps the same =\ 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Error with CPLEX basis

    Posted 03/14/16 03:51 AM

    Originally posted by: Stanko_86


    It is not allowed to have integer variables when you are using IloOplCplexBasis. It is applicable only for linear programming models.

    As @AlexFleischer a1d4492b-6cf8-402d-ae3c-dd656c427dc7 suggests, the example how to use warm start in MIP problem is given in opl\examples\opl\warmstart


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Error with CPLEX basis

    Posted 03/15/16 10:23 AM

    Originally posted by: hugotorres


    I tried to adapt that code to my situation and got an error saying "Expected CPLEX, got CP". I tried to remove the line of "using CP" but if I do, CPLEX won't recognize the .dat file, and consequently won't have the values needed for solving this. Are both of these things incompatible or there's a way to work around this?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Error with CPLEX basis

    Posted 03/16/16 03:47 AM

    Hi,

    can you post all your models and data files ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Error with CPLEX basis

    Posted 03/16/16 05:54 PM

    Originally posted by: hugotorres


    I ended up solving that problem. Right now my main issue is that I get an error saying "unknown property addDataSource". 

     

    /*********************************************
     * OPL 12.6.3.0 Model
     * Author: Hugo
     * Creation Date: 16 de Mar de 2016 at 18:56:26
     *********************************************/
    
    //using CP;
     
     int p=...;
     int m=...;
     
     range pecas=1..p;
     range machines=1..m;
     
     int whours=...;
     
     int processTimes[pecas][machines]=...;
     int availableMachines[machines]=...;
     
     dvar int+ x[pecas][machines];
     dvar int+ y;
     
     maximize y;
     
     subject to
     {
       forall(i in machines)
         sum(j in pecas) (processTimes[j][i]*x[j][i]) <= whours*60*availableMachines[i];
       
       forall(j in pecas)
         sum(i in machines) (x[j][i])-y >= 0;
     }  
    
    main
    {
      var def = thisOplModel.modelDefinition;
      var data = thisOplModel.dataElements;
      def.addDataSource(data);   
      var cplex1 = new IloCplex();
      var opl1 = new IloOplModel(def, cplex1);
      
      opl1.generate();
                    if ( cplex.solve() ) 
                            {
                                    curr = cplex.getObjValue();
                                    writeln();
                                    writeln("OBJECTIVE: ",curr);
                            } 
                    else 
                            {
                                    writeln("No solution!");
                            }                     
     }                     
    

     

    /*********************************************
     * OPL 12.6.3.0 Data
     * Author: Hugo
     * Creation Date: 16 de Mar de 2016 at 18:56:26
     *********************************************/
    
    p=2;
    m=2;
    
    whours = 8;
    
     SheetConnection mysheet("dataSheet.xlsx");
     
     processTimes from SheetRead(mysheet,"processTimes");
     availableMachines from SheetRead(mysheet,"availableMachines");
     
     x to SheetWrite(mysheet,"File");
    

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Error with CPLEX basis

    Posted 03/17/16 03:14 AM

    Originally posted by: Stanko_86


    Hi,

    instread of 

      def.addDataSource(data);

    try:

      opl1.addDataSource(data); // this goes after opl1 has been defined

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Error with CPLEX basis

    Posted 03/17/16 10:23 AM

    Originally posted by: hugotorres


    Worked! Thank you so much! Since this is getting far from the original question, I'll mark this as solved and start another thread if I need to :)


    #DecisionOptimization
    #OPLusingCPLEXOptimizer