Decision Optimization

 View Only
  • 1.  How to declare conditional-optional dvar in CP?

    Posted 12 days ago
    Hi,

    I have a question on how to declare a conditional-optional decision variable in CP. I have a decision variable (i.e., activity) which is declared over two tuples (i.e., allActivities_tri & allActivities_2). These tuples are as follow:

    tuple ActivityInfo {
       key string   		activity;
       string			 	activity_type;
       string			 	export_string;
       int      			duration;
       int					lb_duration;
       int					ub_duration;
       int 					wait;
       int					lb_wait;
       int					ub_wait;
       float				mu_p;
       float				sigma_p;
       float				mu_w;
       float				sigma_w;
       {string} 			precedences;
       float				slope_p;
       float				intercept_p;
       float				error_p;
       float				slope_w;
       float				intercept_w;
       float				error_w;
    };
    
    {ActivityInfo} activities[ProductTypes] = ...;
    
    tuple BatchActivityMatch {
       ActivityInfo 		activity;
       string       		ProductTypes;  
       int          		nOrders;             
    };
    
    {BatchActivityMatch} allActivities = {<a,c,j> | c in ProductTypes,
    					 a in activities[c],
    					 j in 1..requiredQuantities[c]}; 
    tuple R{
      BatchActivityMatch    allActivities;
      int			trig_process;
      int			trig_wait;
      int 			trig_process_energy;
      int 			trig_wait_energy;
      }
      
    {R} allActivities_tri={<a,c,e,f,g> | a in allActivities,c in tringular_processing[a]..tringular_processing[a],e in tringular_waiting[a]..tringular_waiting[a],f in tringular_processing_energy[a]..tringular_processing_energy[a],g in tringular_waiting_energy[a]..tringular_waiting_energy[a]};
    
    
    tuple Y{
        string ProductTypes ;  
        int requiredQuantities; 
    };		 
    {Y} allActivities_2 = {<c,j> | c in ProductTypes, 
    					              j in 1..requiredQuantities[c]};					 
    

    The decision variable is declared as follows:
    dvar interval activity[a in allActivities_tri][b in allActivities_2] optional size 5;​


    The problem that there are many ProductTypes with different requiredQuantities/nOrders. When I declare the decision variable in that way, the number of variables and their associated constraints increases exponentially. I would like to make the activity decision variable present if:

    a.allActivities.ProductTypes==b.ProductTypes && a.allActivities.nOrders==b.requiredQuantities

    and absent if:

    a.allActivities.ProductTypes!=b.ProductTypes || a.allActivities.nOrders!=b.requiredQuantities

     I would like to do that to decrease the number of the variables in the model to avoid running out of memory. Is it possible to do that?

    Best regards,
    Mohamed






    ------------------------------
    Mohamed Awad
    ------------------------------


  • 2.  RE: How to declare conditional-optional dvar in CP?

    Posted 11 days ago
    Hello,
    the OPL model you sent seems not very clear, can you describe what you want to do in math or English?

    ------------------------------
    Olivier Lhomme
    ------------------------------



  • 3.  RE: How to declare conditional-optional dvar in CP?

    Posted 11 days ago
    Hi Olivier,

    Thank you for you reply. I sent a small part of the OPL model I am working on. That's why it wasn't clear. The decision variable activity is declared over two arrays;  allActivities_tri & allActivities_2. I am looking for something like:

    dvar interval activity[a in allActivities_tri][b in allActivities_2] (a.allActivities.ProductTypes==b.ProductTypes && a.allActivities.nOrders==b.requiredQuantities)?present:absent size 5;​

    In other words, can I avoid declaring a variable (making it absent) if a certain condition is not achieved and vice versa?

    Best regards,
    Mohamed

    ------------------------------
    Mohamed Awad
    ------------------------------



  • 4.  RE: How to declare conditional-optional dvar in CP?

    Posted 11 days ago
    Hi,

    you can choose in OPL whether the interval is optional or not, and you can do that per interval in an array of intervals

    using CP;
    
    range r=1..5;
    
    dvar interval itvs[i in r] optional (i mod 2) in 0..10 size 2;
    
    minimize max(i in r) endOf(itvs[i]);
    subject to
    {
      
    }
    
    execute
    {
      writeln(itvs);
    }​
    gives

     [<0 0 0 0> <1 0 2 2> <0 0 0 0> <1 0 2 2> <0 0 0 0>]​


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



  • 5.  RE: How to declare conditional-optional dvar in CP?

    Posted 11 days ago
    Edited by Mohamed Awad 11 days ago

    Hi Alex,

    Thank you for you reply. In the code you sent, there were 5 itvs intervals, 3 of them were absent however, they were declared and no values were assigned to them. This will consume memory even if no values were assigned to the absent decision intervals. Is there a way to make the results of your code as follows in order to avoid declaring a variable then making it absent:

     [<1 0 2 2> <1 0 2 2>]


    I am looking to have something like:

    dvar interval activity[a in allActivities_tri][b in allActivities_2] (a.allActivities.ProductTypes==b.ProductTypes && a.allActivities.nOrders==b.requiredQuantities)?present:absent size 5;​
    

    Is that possible?

    Best regards,
    Mohamed



    ------------------------------
    Mohamed Awad
    ------------------------------



  • 6.  RE: How to declare conditional-optional dvar in CP?

    Posted 11 days ago
    Hi

    yes you can turn

    using CP;
    
    range r=1..5;
    
    {int} s={i | i in 1..10 :(i mod 2)==1};
    
    dvar interval itvs[i in r] optional (i in s) size 2;
    
    minimize max(i in r) endOf(itvs[i]);
    subject to
    {
      
    }
    
    execute
    {
      writeln(itvs);
    }​

    into

    using CP;
    
    range r=1..5;
    
    {int} s={i | i in 1..10 :(i mod 2)==1};
    
    dvar interval itvs[i in s]  size 2;
    
    minimize max(i in s) endOf(itvs[i]);
    subject to
    {
      
    }
    
    execute
    {
      writeln(itvs);
    }


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



  • 7.  RE: How to declare conditional-optional dvar in CP?

    Posted 11 days ago
    Edited by Mohamed Awad 11 days ago
    Hi Alex,

    Thanks a million. That's close to what I am looking for.

    Best regards,
    Mohamed

    ------------------------------
    Mohamed Awad
    ------------------------------