Decision Optimization

 View Only
Expand all | Collapse all

How to add the below constraint as an incremental constraint because it depends on {inner_beams} subset which is an after executing subset. The below code is not working

  • 1.  How to add the below constraint as an incremental constraint because it depends on {inner_beams} subset which is an after executing subset. The below code is not working

    Posted Mon December 12, 2022 09:31 AM
           //I have tried the below main but it's not working
    Main {
          for(i in thisOplModel.inner_beams) 
         {
           thisOplModel.const02[i].setCoef(thisOplModel.beam_firstchannel[i-1],1);
           thisOplModel.const02[i].setCoef(thisOplModel.beam_nomusedchannel[i-1],1);
    thisOplModel.const02[i].setBounds(thisOplModel.beam_firstchannel[i],thisOplModel.beam_firstchannel[i]);   
         }  
         cplex.solve();
         thisOplModel.postProcess(); 
    }
    
     
    Subject to
    {
    const02:
     forall (i in beams: i in inner_beams) //Not working because the inner beams is not calculated yet
     (beam_firstchannel[i]==beam_firstchannel[i-1]+ beam_nomusedchannel[i-1]); 
    }
    
    {int} inner_beams={2,3,4,6,7,8,9,11,12,13};  // this is the results of the after executing set


    ------------------------------
    Mohamed Mandour
    ------------------------------

    #DecisionOptimization


  • 2.  RE: How to add the below constraint as an incremental constraint because it depends on {inner_beams} subset which is an after executing subset. The below code is not working

    Posted Tue December 13, 2022 02:32 AM
    Hi

    similar question at https://stackoverflow.com/questions/74771991/how-to-add-an-incremental-constrain-based-on-after-executing-subset-in-cplex/74772455?noredirect=1#comment131964997_74772455 and https://stackoverflow.com/questions/74774939/how-to-copy-the-after-executing-subset-inner-beams-results-value-to-another-su/74776168#74776168

    where I shared a small example

    sub.mod

    {int} inner_beams=...;
    
    execute
    {
    writeln("inner_beams=",inner_beams);
    }
    
    dvar int x in 0..12;
    
    maximize x;
    subject to {
     forall(i in inner_beams) x!=i;
    }
    
    execute
    {
    writeln("x=",x);
    }​
    and then

    {int} inner_beams={};
    {int} s2={2,3,4,6,7,8,9,11,12,13}; 
    
        main {
          var source = new IloOplModelSource("sub.mod");
          var cplex = new IloCplex();
          var def = new IloOplModelDefinition(source);
         
         
          
          
          var opl1 = new IloOplModel(def,cplex);
            
          var data1= new IloOplDataElements();
         
          data1.inner_beams=thisOplModel.inner_beams;
        
          opl1.addDataSource(data1);
          opl1.generate();
    
          if (cplex.solve()) {
             writeln("OBJ = " + cplex.getObjValue());
          } else {
             writeln("No solution");
          }
         data1.end();
         thisOplModel.inner_beams.add(opl1.x.solutionValue);
         for(var i in thisOplModel.s2) thisOplModel.inner_beams.add(i);
         opl1.end();
         
         var opl2 = new IloOplModel(def,cplex);
            
          var data2= new IloOplDataElements();
         
          data2.inner_beams=thisOplModel.inner_beams;
        
          opl2.addDataSource(data2);
          opl2.generate();
    
          if (cplex.solve()) {
             writeln("OBJ = " + cplex.getObjValue());
          } else {
             writeln("No solution");
          }
         data2.end();
        
         
        }​


    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------