Topic
  • 2 replies
  • Latest Post - ‏2013-12-17T10:58:40Z by SatishKumarA
SatishKumarA
SatishKumarA
22 Posts

Pinned topic How to get Conflict Information into Excel/DB

‏2013-12-12T10:44:47Z |

Hi All,

I am working on a CP model through OPL Studio. Whenever my model is infeasible, I can see the conflict information in the IDE.

I would like to relax or block some constraints based on the conflict information. But I want to see this information in the excel interface or in DB.

I tried using main block to read  the information into a variable and then exporting this information using DB Update, but I couldn't get the second part right.

My question is whether we can do this or not? If not what are all the other ways by which I can get this done.?

Can somebody help me out by providing related source.

 

 

Thanks,

Satish

 

  • AlexFleischer
    AlexFleischer
    108 Posts
    ACCEPTED ANSWER

    Re: How to get Conflict Information into Excel/DB

    ‏2013-12-16T15:32:17Z  

    Hi,

    here a model that iterates over conflicts in CPO.

    writeln(excelString);
      writeln(opl1.ctInConflict);

    displays the excel cells that will be changed and the set of constraints in conflicts.

    In order to have them in a spreadsheet you need to call this .mod and then do sheetWrite in the postProcess

     

     


    using CP;

    range r = 1..10;
    dvar int+ x[r] in 1..20;

    {string} ctInConflict={};



    // Preferences are stated as data of the opl model.
    // prefs[i] will be used to represent the preference of seeing cts[i] in the conflict.
    float prefs[i in r] = i;

    minimize sum(i in r) x[i];
    subject to {
       
       forall(i in r)
         cts: x[i] >= i+5;
         
         
       forall(i in r)
         cts2: x[i] <= i+5-2;
    }





    main {
       thisOplModel.generate();
       var def = thisOplModel.modelDefinition;   
       // Default behavior
       writeln("Default Behavior");
       var opl1 = new IloOplModel(def, cp);
       opl1.generate();
       writeln(opl1.printConflict());
       
      // now iterating manually
     
      var f2 = new IloOplOutputFile("conflicts.csv", false);
     
     
     
       writeln("now iterating manually");
       writeln();
       var iter = opl1.conflictIterator;  

          for(var c in iter)
          {
           var ct=c.ct;
           writeln(ct.name, " with status ", c.status);
           opl1.ctInConflict.add(ct.name);
           f2.writeln(ct.name,";");
     
     
          }  
          
           f2.close();
      var excelString="A1:A"+opl1.ctInConflict.size;
      writeln(excelString);
      writeln(opl1.ctInConflict);
          
    opl1.end();
    writeln();
       // With user-defined preferences
       writeln("With user-defined preferences");   
       var opl2 = new IloOplModel(def, cp);
       opl2.generate();
       // We attach prefs (defined as data in the opl model) as preferences
       // for constraints cts for the conflict refinement.
       opl2.conflictIterator.attach(opl2.cts, opl2.prefs);
       writeln(opl2.printConflict());   
       
       
       
           
       opl2.end();
       
    }

     regards

    Updated on 2013-12-16T15:44:51Z at 2013-12-16T15:44:51Z by AlexFleischer
  • AlexFleischer
    AlexFleischer
    108 Posts

    Re: How to get Conflict Information into Excel/DB

    ‏2013-12-16T15:32:17Z  

    Hi,

    here a model that iterates over conflicts in CPO.

    writeln(excelString);
      writeln(opl1.ctInConflict);

    displays the excel cells that will be changed and the set of constraints in conflicts.

    In order to have them in a spreadsheet you need to call this .mod and then do sheetWrite in the postProcess

     

     


    using CP;

    range r = 1..10;
    dvar int+ x[r] in 1..20;

    {string} ctInConflict={};



    // Preferences are stated as data of the opl model.
    // prefs[i] will be used to represent the preference of seeing cts[i] in the conflict.
    float prefs[i in r] = i;

    minimize sum(i in r) x[i];
    subject to {
       
       forall(i in r)
         cts: x[i] >= i+5;
         
         
       forall(i in r)
         cts2: x[i] <= i+5-2;
    }





    main {
       thisOplModel.generate();
       var def = thisOplModel.modelDefinition;   
       // Default behavior
       writeln("Default Behavior");
       var opl1 = new IloOplModel(def, cp);
       opl1.generate();
       writeln(opl1.printConflict());
       
      // now iterating manually
     
      var f2 = new IloOplOutputFile("conflicts.csv", false);
     
     
     
       writeln("now iterating manually");
       writeln();
       var iter = opl1.conflictIterator;  

          for(var c in iter)
          {
           var ct=c.ct;
           writeln(ct.name, " with status ", c.status);
           opl1.ctInConflict.add(ct.name);
           f2.writeln(ct.name,";");
     
     
          }  
          
           f2.close();
      var excelString="A1:A"+opl1.ctInConflict.size;
      writeln(excelString);
      writeln(opl1.ctInConflict);
          
    opl1.end();
    writeln();
       // With user-defined preferences
       writeln("With user-defined preferences");   
       var opl2 = new IloOplModel(def, cp);
       opl2.generate();
       // We attach prefs (defined as data in the opl model) as preferences
       // for constraints cts for the conflict refinement.
       opl2.conflictIterator.attach(opl2.cts, opl2.prefs);
       writeln(opl2.printConflict());   
       
       
       
           
       opl2.end();
       
    }

     regards

    Updated on 2013-12-16T15:44:51Z at 2013-12-16T15:44:51Z by AlexFleischer
  • SatishKumarA
    SatishKumarA
    22 Posts

    Re: How to get Conflict Information into Excel/DB

    ‏2013-12-17T10:58:40Z  

    Hi,

    here a model that iterates over conflicts in CPO.

    writeln(excelString);
      writeln(opl1.ctInConflict);

    displays the excel cells that will be changed and the set of constraints in conflicts.

    In order to have them in a spreadsheet you need to call this .mod and then do sheetWrite in the postProcess

     

     


    using CP;

    range r = 1..10;
    dvar int+ x[r] in 1..20;

    {string} ctInConflict={};



    // Preferences are stated as data of the opl model.
    // prefs[i] will be used to represent the preference of seeing cts[i] in the conflict.
    float prefs[i in r] = i;

    minimize sum(i in r) x[i];
    subject to {
       
       forall(i in r)
         cts: x[i] >= i+5;
         
         
       forall(i in r)
         cts2: x[i] <= i+5-2;
    }





    main {
       thisOplModel.generate();
       var def = thisOplModel.modelDefinition;   
       // Default behavior
       writeln("Default Behavior");
       var opl1 = new IloOplModel(def, cp);
       opl1.generate();
       writeln(opl1.printConflict());
       
      // now iterating manually
     
      var f2 = new IloOplOutputFile("conflicts.csv", false);
     
     
     
       writeln("now iterating manually");
       writeln();
       var iter = opl1.conflictIterator;  

          for(var c in iter)
          {
           var ct=c.ct;
           writeln(ct.name, " with status ", c.status);
           opl1.ctInConflict.add(ct.name);
           f2.writeln(ct.name,";");
     
     
          }  
          
           f2.close();
      var excelString="A1:A"+opl1.ctInConflict.size;
      writeln(excelString);
      writeln(opl1.ctInConflict);
          
    opl1.end();
    writeln();
       // With user-defined preferences
       writeln("With user-defined preferences");   
       var opl2 = new IloOplModel(def, cp);
       opl2.generate();
       // We attach prefs (defined as data in the opl model) as preferences
       // for constraints cts for the conflict refinement.
       opl2.conflictIterator.attach(opl2.cts, opl2.prefs);
       writeln(opl2.printConflict());   
       
       
       
           
       opl2.end();
       
    }

     regards

    Excellent Alex.

    Thank you very much.

     

    Thanks,

    Satish