Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Help on how to write a simple scheduling problem using IBM ILOG CP

  • 1.  Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/15/10 11:51 AM

    Originally posted by: SystemAdmin


    Hello to everyone,

    I am trying to solve a simple scheduling problem using the specific ILOG OPL CP ‘tools’ (as for example intervals). I have read some examples in the OPL manual, but since I am quite a beginner with OR and also with OPL I have some problems to define and structure the problem.
    I would ask if someone could post the OPL code for the following simple problem (since it is quite simple I believe it should be written in few minutes by some pro) or at least It would however be helpful to have some insight about how to structure (e.g. tuples, intervals etc) it. I think it could be really useful also for other beginners who are learning how to schedule with IBM ILOG CP.

    The problem is the following:

    A production facility must produce certain product types, by running some manufacturing in a given sequence. The production and the making sequence are the same for all the products (according to their numbering). Each product is manufactured in one batch. Some works may be executed on multiple machines, which are identical and work in parallel. Are known the processing time required by each unit of output for each type of work. The products are made in a predetermined sequence (according to their numbering).

    Each product can go to further processing only when the previous process is completed (for all the machines).
    Each product creates a different revenue. The goal is to determine the product mix that generates the maximum profit. All production must be completed within a work shift of 8 hours. The product is continuous, not discrete.

    The are 6 machines, 3 different jobs and seven types of products.

    Each machine can do only a specific work:

    Machine 1 Work 1

    Machine 2 Work 1

    Machine 3 Work 2

    Machine 4 Work 3

    Machine 5 Work 3

    Machine 6 Work 3

    Working Time (seconds/unit):

    Product 1 2 3 4 5 6 7
    WORK. 1 120 125 180 230 230 120 120

    WORK. 2 80 95 110 150 150 90 90

    WORK. 3 50 45 190 100 100 130 130
    Thank you very much in advance
    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/16/10 04:07 AM

    Originally posted by: SystemAdmin


    Hello,
    This is how I would model your problem with OPL using CP Optimizer.

    I would create an integer decision variable (nbProducts[p]) to represent the quantity of each product and an interval decision variable (ops[p][w]) for each operation of the jobs.

    Then, the constraints would:
    (1) Link the operation durations with the number of products to produce
    (2) Define precedence constraints between operations of the same job (endBeforeStart)
    (3) Model limited number of resources. Here for each work, we can use a cumul function (machineUsage[w]) that counts the number of operations simultaneously performing work w at a given time and constrain this cumul function to be lower than the number of machines available to perform this work (NumberOfMachines[w]).

    Here is the full OPL model. Note that I generated some values for the product revenues as these values where not given in your question. I chose values in such a way that the products are more or less equivalent when considering the ratio revenue/duration. I'm also changing the values of some parameters for the search to improve the performances. In particular, I'm using here a search phase to tell the engine to first work on the variables nbProducts.

    
    using CP;   
    
    int NbWorks = 3; range Works = 1..NbWorks; 
    
    int NumberOfMachines[Works] = [2, 1, 3]; 
    
    int NbProducts = 7; range Products = 1..NbProducts; 
    
    float Revenue[Products] = [550,  600, 1000, 1100,  990,  700,  720]; 
    
    int WorkingTime[Works][Products] = [ [120,  125,  180,  230,  230,  120,  120], [ 80,   95,  110,  150,  150,   90,   90], [ 50,   45,  190,  100,  100,  130,  130] ]; 
    
    int Horizon = 8*60*60; 
    // 8h shift in seconds (28800)   
    // Max number of products 
    
    int MaxNbProducts[p in Products] = Horizon div (sum(w in Works) WorkingTime[w][p]);   
    // Decision variables dvar 
    
    int nbProducts[p in Products] in 0..MaxNbProducts[p]; dvar interval ops[Products][Works] in 0..Horizon;   cumulFunction machineUsage[w in Works] = sum(p in Products) pulse(ops[p][w], 1);   execute 
    { cp.param.TimeLimit = 10; cp.param.CumulFunctionInferenceLevel = 
    "Extended"; cp.setSearchPhases(cp.factory.searchPhase(nbProducts)); 
    } maximize sum(p in Products) nbProducts[p]*Revenue[p]; subject to 
    { forall(p in Products) 
    { forall (w in Works) 
    { nbProducts[p] == sizeOf(ops[p][w]) div WorkingTime[w][p]; 
    // Constraint (1) 
    
    if (1<w) endBeforeStart(ops[p][w-1], ops[p][w]); 
    // Constraint (2) 
    } 
    } forall(w in Works) machineUsage[w] <= NumberOfMachines[w]; 
    // Constraint (3) 
    };
    


    After 10s, the best solution found is looking like the one attached in the gif file.
    Hope it helps,

    Philippe
    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/20/10 09:36 AM

    Originally posted by: SystemAdmin


    Thanks very much Philippe for your kindness and your generosity. You even posted the complete model. I hope that as anticipated it will be useful for many beginners, who are approaching scheduling with OPL.
    Thank you again!

    Fabio
    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/21/10 04:12 AM

    Originally posted by: SystemAdmin


    Hello Philippe, I wanted to ask one last thing, if you could please give me some more insights on the reason for the choices you made to configure the script for the search on this specific problem.

    (1) cp.param.CumulFunctionInferenceLevel = "Extended";
    (2) cp.setSearchPhases (cp.factory.searchPhase (nbProducts));

    I really noticed a huge difference in terms of speed of the algorithm in the search.
    What criteria did you use in order to define these settings?
    #ConstraintProgramming-General
    #DecisionOptimization


  • 5.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/21/10 04:44 AM

    Originally posted by: SystemAdmin


    The most important parameter change is the search phase (2). It helps because by default, the automatic search fixes the integer variables after the interval variables. In this problem, it is better to focus on fixing the integer variables (product quantities) before scheduling the interval variables. Once the product quantities, and thus the activities durations are fixed, the engine will "only" have to schedule the activities start/end times, as in a classical flowshop scheduling problem.

    This will work reasonably well if the engine can rule out infeasible values (from a scheduling point of view) from the domain of the integer variables. This is the reason why increasing the inference level of the cumul functions helps.

    Philippe
    #ConstraintProgramming-General
    #DecisionOptimization


  • 6.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/21/10 08:22 AM

    Originally posted by: SystemAdmin


    Thank you again very much Philippe, thank you!
    #ConstraintProgramming-General
    #DecisionOptimization


  • 7.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 01/20/12 09:58 PM

    Originally posted by: Y9AX_Pooyan_Kazemian


    Hi,
    Could you please let me know how you get the .gif file that you attached? Is it a part of CP Optimizer output?
    Thanks
    #ConstraintProgramming-General
    #DecisionOptimization


  • 8.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 01/21/12 10:53 AM

    Originally posted by: Robscher


    Hi Y9AX,

    the image in the .gif file is a Gantt chart and is automatically produced for every scheduling problem. You will find it by clicking the little arrow button next to the target value in the lower left corner. This will open all values for the selected output. On the bottom of this newly opened window is a lable "Gantt Chart". Thats where you'll find it. See the attached picture for more help.
    #ConstraintProgramming-General
    #DecisionOptimization


  • 9.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 01/21/12 03:37 PM

    Originally posted by: Y9AX_Pooyan_Kazemian


    Thanks, I got it.
    Is it possible to print this gantt chart or export it to another program? In general, how can I get nicer reports of the output?
    Thanks in advance
    #ConstraintProgramming-General
    #DecisionOptimization


  • 10.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 01/22/19 06:50 AM

    Originally posted by: Stan_Yin


    Hi,

     

    May I extend this model to multiple shifts (e.g 7 days) and alternative works? And, there are more constraints.

    1. The jobs of next shift can't be start at earlier shifts. If jobs of previous shift due to overload, the job(s) can be ponstone to next shifts.

    2. The jobs on work have setup time.

    3. A job can be done by alternative work with different production rate.

    4. The objective is that maximize production quantity and minimize setup time.

     

    Stan

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 11.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 01/28/19 06:40 AM

    Originally posted by: rdumeur


    Dear Stan,

     

    Please precise what you mean about shifts.

    To model setup times, I advise you to have a look at sched_setup which explains how to specify setup times using nOverlap and transition times.

    To model alternative work with different production rates, I suggest you look at sched_bridgebr and sched_calendar examples that specify intensity functions: : https://www.ibm.com/support/knowledgecenter/SSSA5P_12.5.0/ilog.odms.ide.help/OPL_Studio/opllang_quickref/topics/tlr_oplsch_intensity.html

    To maximize production quantity you can sum the "presenceOf(interval)" expressions on tasks

    To minimize setup time you have to use typeOfNext expression in order to retrieve setup costs for a given task transition. I suggest you have a look at the sched_tcost example.

     

    I hope this helps,

     

          Cheers,

     

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 12.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 02/20/19 09:50 PM

    Originally posted by: Stan_Yin


    Hi Rdumeur,

     

    I tried to use deterministic scheduling model.  I got a good result in CP. Thanks a lot for you(s)r help. Learn a lot from you(s).

     

    I am still interested in stochastic scheduling model, which likes Philippe's model above. Interval variable is with dynamic size.

     

    Stan

     

     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 13.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 02/22/19 10:56 AM

    Originally posted by: Petr Vilím


    Dear Stan,

    could you please specify what part of your model is non-deterministic so that you need stochastic model?

    The usual way to model uncertainty is to multiply the model by number of scenarios where each scenario differs e.g. in duration of tasks. Then the scenarios are linked together so that the solution for all scenarios are the same, in particular sameSequence constraint is useful to do such linking (or simple constraints such as startAtStart). Of course size of the model may increase dramatically.

    Regards, Petr


    #ConstraintProgramming-General
    #DecisionOptimization


  • 14.  Re: Help on how to write a simple scheduling problem using IBM ILOG CP

    Posted 09/21/10 04:12 AM

    Originally posted by: SystemAdmin


    One more question about the search settings
    #ConstraintProgramming-General
    #DecisionOptimization