Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Cumul function for setup times

    Posted 01/15/15 05:44 PM

    Originally posted by: _Hadi_


    We can observe the task duration and resource usage as in a cumul function. Is there any way I can capture the time spent for the setup too in a cumul fucntion? I have already setup the transition matrix but I don't know how to write a cumul fucntion for it. I need to know the times that resources unavailable due to performing a task and also due to setup times, in my case, resource has to travel. The setup is dependent to the previous task, so thats making it a little it hard. 

     

    Thanks,

    Hadi  


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Cumul function for setup times

    Posted 01/19/15 06:31 AM

    Originally posted by: ol


    Hello,

    I am not sure I understand well what you want when you say "The setup is not dependent to the previous task". Cannot the problem be modified such that the task and the setup time for this task are merged into a new task?

    Olivier

     


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Cumul function for setup times

    Posted 01/19/15 02:48 PM

    Originally posted by: _Hadi_


    Oliver, I am sorry, I had a typo, "setup is dependent", I am correcting my original post. But true if it was independent, your suggestion would work but still I don't know what to do for my case where setups are independent.

    Hadi


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: Cumul function for setup times

    Posted 01/20/15 08:40 AM

    Originally posted by: ol


    Hello,

    can you be more precise? What is exactly the problem? And how have you expressed it in CP Optimizer?

    Olivier


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: Cumul function for setup times

    Posted 01/20/15 10:42 AM

    Originally posted by: _Hadi_


    Hi,
    When I am looking at the resource utilization (I have multiple resources), I can see that the they are not been used to the max capacity during time, meaning resource utilization is not much high which is because of setup/travel times, but I want to double check this by looking at some sort of cumul function to make sure current solution best way of doing things (I have the optimal solution with some tolerance). I'd like to be able to see when a resource is involved in performing a task (I can do this part, using a cumul function or using intervals) and also when a resource is travelling (for capturing travel times between two tasks, I am using nooverlap and a transition matrix). For the latter, I can't visualize it the same way as I can visualize it for the actual task duration, and probably writing a code in postprocessing is the only way I can at least see where each travel between two consecutive tasks is happening. 
     
    Hadi

    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: Cumul function for setup times

    Posted 01/21/15 05:42 AM

    Originally posted by: ol


    Hello,

     

    If it is fine for you to do postprocessing, you can iterate on the sequenceVar, with:
    IloIntervalVar IloCP::getFirst(const IloIntervalSequenceVar seq)
    IloIntervalVar IloCP::getNext(const IloIntervalSequenceVar seq, const IloIntervalVar a)

    In order to store the type of the intervalVar, you can use setObject:
    task[i].setObject(type[i]);

    This is the simplest way, but if you want to add constraints on the sum of the setup times, you need to add to your model an expression reporesenting the sum of setup times, for example as follows:

    Assume you have m values 0,.., m-1 for the types of the tasks to specify the setup time. You can add a new value m for expressing that after the last task, is no setup.
    The setupDuration matrix needs to be extended with the m value, with a time 0.
      IloIntArray2 setupDuration(env, m);
      IloInt last = m;  // Type of next for the last activity on the machine
      for (IloInt ti=0; ti<m; ++ti) {
        setupDuration[ti]= IloIntArray(env, m+1);
        for (IloInt tj=0; tj<m; ++tj)
          setupDuration[ti][tj] = ...; // Length of setup activity between types ti and tj
        setupDuration[ti][last] = 0;   // Length of last setup activity
       }

    Then you can use IloTypeOfNext(mySequenceVar,task[i],last), which will returns m for the last task.
    For example:
    sumOfSetupTimes += setupDuration[type[i]][IloTypeOfNext(mySequenceVar,task[i],last)]);

     

    Regards,

    Olivier


    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: Cumul function for setup times

    Posted 02/01/15 07:17 PM

    Originally posted by: _Hadi_


    Olivier, thanks for your response. I prefer the second approach, but what I really like to do is that I would like to be able to add an interval after every task[location][resource] optional, which its length would be equal to the length of the travel time to the next location, let's say travel[location][resource] optional (travel required after completing task in location ) or maybe a three dimensional one such as travel [location][location][resource] optional. Then, I would like to add task and travel interval to a cumul function and then agfter the run I would like to check the histogram to see if there are times that my resources are not being performing a task or on the travel, to see if they are idle, why they are not involving in other tasks.

    To give you more insight to my problem, I have 49 resources, and the maximum resources that I can see working at the same time is about 25. I want to know what is the reason for not using the reaming resources, is it because they are on the route or is it because they are not being fully utilized. 

     

    Thanks,

    Hadi


    #CPOptimizer
    #DecisionOptimization


  • 8.  Re: Cumul function for setup times

    Posted 02/02/15 05:27 AM

    Originally posted by: PhilippeLaborie


    Hello Hadi,

    First, let me insist that, as Olivier said, if you just want to analyze the solution and try to see if resources are intensively used or not, the way to do is definitively to post-process the solution by iterating over the sequence values. If it makes things easier for you then you can use the class of step functions (IloNumToNumStepFunction in C++) to easily build the equivalent of the cumul function you mention that includes the travel times, in the post-processing. The main reason is that if you unnecessarily complexify the model (by adding new interval variables for the travel times), this will impact the efficiency of the automatic search (probably negatively), and maybe you even will not be able to produce the same type of solutions that you want to analyze.

    Now, if you really want to complexify the model with these additional interval variables, you can create these optional interval variables "travel", one for each task "task" on the resource, with equality constraint on their presence status. Then you constrain the length of the "travel" variable using an element expression like: TravelType[Origin][IloTypeOfNext(sequence,task)] as mentioned in Olivier's answer. For the redundant cumulative function, in the same way you probably have an alternative constraint between the "task", you would have an alternative between the "travel" with the resulting interval variable also contributing to the cumul function.

    Here is a small OPL example. Note the search phase that tells the automatic search to focus on interval variables taskR so as not to be distracted by the ttR interval variables.
     

    using CP;
    
    int n = 200; // Number of tasks
    int m = 50;  // Number of resources
    range T = 1..n;
    range R = 1..m;
    
    int TT[i in 0..n][j in 0..n] = ((i==0)||(j==0))?0:10+(i+j)%90;
    
    tuple tdist { int i; int j; int d; }
    {tdist} TDist = { <i,j,TT[i][j]> | i,j in 0..n };
    
    dvar interval task[T] size 10; 
    dvar interval taskR[T][R] optional;
    dvar sequence routeR[r in R] in all(i in T) taskR[i][r] types all(i in T) i;
    
    // Additional variables for transition times
    dvar interval tt[T];
    dvar interval ttR[T][R] optional;
    
    cumulFunction use = sum(i in T) pulse(task[i],1) + 
                        sum(i in T) pulse(tt[i],1);
    
    execute {
      cp.setSearchPhases(cp.factory.searchPhase(taskR));
      cp.param.Workers = 1;
    }
      
    minimize max(i in T) endOf(task[i]);
    
    subject to {
      forall(i in T) {
        alternative(task[i], all(r in R) taskR[i][r]);  
      }
      forall(r in R) {
       noOverlap(routeR[r], TDist);
      }
      
      forall(i in T) {
        forall(r in R) {
          endAtStart(taskR[i][r], ttR[i][r]);
          presenceOf(taskR[i][r]) == presenceOf(ttR[i][r]);
          lengthOf(ttR[i][r]) == TT[i][typeOfNext(routeR[r],taskR[i][r],0)];
        }
        alternative(tt[i], all(r in R) ttR[i][r]);  
        endAtStart(task[i],tt[i]);
      }
      
      use <= m;
    }
    



    But again, I would use this type of model only if you really need it during the optimization (to model additional constraints or objective) otherwise, post-process the solution.

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 9.  Re: Cumul function for setup times

    Posted 02/02/15 05:15 PM

    Originally posted by: _Hadi_


    Phillipe, 

     

    Thank you so much for your time and detailed response. The reason I wanted to this within the model and not in post processing  is because this model is currently in OPL and IloNumToNumStepFunction is not available in OPL (correct me if I 'm wrong) for post processing and I have to re-implement everything in the API. I think the only option is to write a JAVA class and pass the cumul function to there, and modify that based on the travel start and finish times and then call that java class from the post processing. But I'm not sure if a cumul function can be passed to an outside JAVA class and what will be data structure of the cumul function when it is passed to JAVA environment. 

     

    Thanks, 

    Hadi 


    #CPOptimizer
    #DecisionOptimization


  • 10.  Re: Cumul function for setup times

    Posted 02/03/15 05:00 AM

    Originally posted by: PhilippeLaborie


    I see. If you want to stay in OPL, you can still avoid to artificially complexify the model by doing your post-processing in a second model where all variables are fixed and that is dedicated to post-processing. I did it as an illustrative example in the attached project. Model model.mod is the model used for optimization. The piece of OPL script at the end runs the optimization model, stores the solution in some arrays (start, resource) and restores this solution in a secondary model (model-postprocess.mod, similar to the one I described earlier) whose role is only to compute the cumul function and display it. There is no search in the second model.

     


    #CPOptimizer
    #DecisionOptimization


  • 11.  Re: Cumul function for setup times

    Posted 02/03/15 01:28 PM

    Originally posted by: _Hadi_


    Hi Philippe, I really like the idea of the second model and I implemented it and now I can get what I wanted. 

    Thank you for all of your time and effort,

    Hadi


    #CPOptimizer
    #DecisionOptimization


  • 12.  Re: Cumul function for setup times

    Posted 02/20/15 04:30 PM

    Originally posted by: _Hadi_


    Philippe, 
     
    I have implemented my original model in JAVA API and  I wanted to add the travel part into the model.
     
    This is what I have written for this constraint which you mentioned: 
     
    endAtStart(taskR[i][r], ttR[i][r]);
          presenceOf(taskR[i][r]) == presenceOf(ttR[i][r]);
          lengthOf(ttR[i][r]) == TT[i][typeOfNext(routeR[r],taskR[i][r],0)];
     
     
    siteCounter = 0;
    for (SitesClass s : sites){
    vehicleCounter = 0 ;
    for(vehicleClass c : vehicles){
    name = s.siteCity + "*" + c.vehicleName;
    draftInterval = taskOpt_multimap.get(name); 
    ddraftInterval =travelOpt_multimap.get(name); 
     
    for (IloIntervalVar d :draftInterval){
    for (IloIntervalVar dd :ddraftInterval){
    cp.add(cp.imply(cp.presenceOf(d), cp.presenceOf(dd)));
    cp.endAtStart(d, dd);
     
    cp.eq(cp.lengthOf(dd), setup.getValue( siteCounter, cp.element(sitearray, cp.typeOfNext(VehicleSeqOpt[vehicleCounter], d, siteCounter, 0))));   )
     
    }
    }
    vehicleCounter++;
     
    }
    siteCounter++;
     
     
    but the issue here is cp.typeOfNext  has IntExpr type and JAVA won't accept this in the setup.getvalue since it only accepts integers. I assume using cp.element may help this case and I tried but I wasn't successful. Can you help me with this? 
     
     
     
    Thanks,
     
    Hadi

    #CPOptimizer
    #DecisionOptimization


  • 13.  Re: Cumul function for setup times

    Posted 02/26/15 10:40 AM

    Originally posted by: ChrisBr


    Hello Hadi,

    Yes "cp.typeOfNext" and "cp.element" return decision expressions, IloIntExpr or IloNumExpr depending on the type of the array used in the expression. Therefore, they cannot be used where a const integer is expected.

    What is the type of "setup" in your example?

    I think the way to write this part of code which is the closest that what is previously suggested in OPL is to use a 2D int array:
    int[][] setup;
    then apply the element-expression to the current sub-array:
    cp.eq(cp.lengthOf(dd),
            cp.element(setup[siteCounter],
                       cp.typeOfNext(VehicleSeqOpt[vehicleCounter], d, siteCounter, 0))));

    In the same way (to be closest to the OPL sample), I suggest you to use
    cp.eq(cp.presenceOf(d), cp.presenceOf(dd));
    instead of
    cp.imply(cp.presenceOf(d), cp.presenceOf(dd));

    I hope this helps,

    Chris.
     


    #CPOptimizer
    #DecisionOptimization