Decision Optimization

 View Only
Expand all | Collapse all

typeOfPrev throwing exception when sequence doesn't contain interval

  • 1.  typeOfPrev throwing exception when sequence doesn't contain interval

    Posted Mon May 16, 2022 11:45 AM

    Hello,

    So I have a sequence decision variable which is indexed by a machine.

    I also have an interval array that is optional and is indexed by the ordernumber and the task.

    However, in the sequence I filtered the ordernumber to match the machine's width, and now I needed to make use of the typeOfPrev function, however when I'm looping the ordernumbers, the tasks and the machines it has intervals that are not in the sequence. Is there a better way to do this loop, or a way to check if an interval belongs to a sequence?

    dvar interval tasks [o in Orders][t in Tasks] size (t == "MudEnfiado" ? 1000 : Duration[o])..(maxint div 2)-1 intensity F;
    	dvar interval opttasks [t in Teares][o in Orders][task in Tasks] optional in MinStartSpan[o][t]..(maxint div 2)-1 intensity F;
    	dvar sequence teares [t in Teares] in all(o in Orders,task in Tasks : OrdersWidth[o] <= TearWidth[t]) opttasks[t][o][task] types all(o in Orders,task in Tasks : OrdersWidth[o] <= TearWidth[t]) o;
    subject to {
    forall(t in Teares){
           forall(o in Orders){         
            presenceOf(opttasks[t][o]["MudEnfiado"]) ? typeOfPrev(teares[t],opttasks[t][o]["MudEnfiado"],0) == 1 : true ;
           }
         }
    }

    This last one gives the OPL Cannot extract expression error.

    This is my constraints full code:

    subject to {
       forall(o in Orders)
         {      
         
         	endOf(tasks[o]["MudEnfiado"]) == startOf(tasks[o]["Tecer"]);
         	endBeforeStart(tasks[o]["MudEnfiado"],tasks[o]["Tecer"]);
         	forall(task in Tasks){
    	     	alternative(tasks[o][task],all(t in Teares : TearWidth[t] >= OrdersWidth[o]) opttasks[t][o][task]);
    	     	endOf(tasks[o][task]) < (Due[o]-2940); 
    	     	forbidStart(tasks[o][task],F);
    	     	forbidEnd(tasks[o][task],F);
         	} 
         	
         	
         }
       forall(t in Teares)
         {       
    	     forall(o in Orders){
    	       presenceOf(opttasks[t][o]["MudEnfiado"]) == presenceOf(opttasks[t][o]["Tecer"]);
    	     }
      	  	noOverlap(teares[t]);
         }
         
         forall(t in Teares){
           forall(o in Orders){         
            presenceOf(opttasks[t][o]["MudEnfiado"]) ? typeOfPrev(teares[t],opttasks[t][o]["MudEnfiado"],0) == 1 : true ;
           }
         }
         
         workersUsage <= NbWorkers;
     }

    I would need this loop because one of the duration of the tasks i need to calculate based on the last one. 

    Thank you in advance!



    ------------------------------
    Vasco Ferreira
    ------------------------------


  • 2.  RE: typeOfPrev throwing exception when sequence doesn't contain interval

    Posted Wed June 22, 2022 08:52 AM

    Hello Vasco,

    I hope that I understand your question correctly.  You need to be able to define once and for all how you iterate over these variables.  Normally the simplest way to do this is to define some appropriate data structures containing the right information - often sets of tuples.  In your case, it should look something like this:

    ```

    tuple OT {
      int order;
      int task;
    };

    {OT} orderTaskPairs[t in Teares] = { <order,task> for order in Orders, task in Tasks : OrdersWidth[order] <= TearWidth[t] };

    ```

    You can then use orderTaskPairs[t] to tell you which optasks variables are in the sequence associated with 't'.

    Best regards,

    Paul



    ------------------------------
    Paul Shaw
    ------------------------------