Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Adding constraint to an existing example

    Posted Tue June 13, 2017 11:02 AM

    Originally posted by: positionguy


    Hello :)

    I am super new to coding on this software and I am trying to learn how things work.

    For the past few days I am trying to add an additional constraint to the existing example "sched_tasks".

    What I want to do is the following:

    Imagine there is a limited number of cars that the technicians need to go around to do the tasks, lets say 3.

    A car is needed from the starting time of a task until the task finishes (which implies other people cannot use that car

    for that period of time so the next task needs to wait for an available car to be scheduled).

     

    What I figured out so far:

    carNeeded (j, t) [0,1]   - a boolean decision variable

    if t >= starting time of task j && t <= finishing time of task j

    then carNeeded == 1

    forall t and j

    sum(carNeeded [ j ][ t ] < capacity (or in our case 3)

     

    I have problems putting this in the model and getting it to work, however.

    Anyone willing to help out? :) 


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Adding constraint to an existing example

    Posted Wed June 14, 2017 01:04 AM

    Can you please be more specific? What exactly did you try? What is the problem? Do you have trouble with the syntax, do have trouble formulating certain conditions, ...?

    Also note that their is a Forum dedicated to constraint programming here. Since sched_tasks is a CP optimizer example, you may be better off on that Forum.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Adding constraint to an existing example

    Posted Wed June 14, 2017 07:49 AM

    Originally posted by: positionguy


    Hello Mr. Junglas,

    Thank you for the quick reply!

    I myself am not quite sure what I am doing... this is one of the major problems ha-ha.

    What I did is that I defined the following data:

    range timeWindow = 0..500;
    range numberOfRequests = 0..5;
    dvar boolean carNeeded[numberOfRequests][timeWindow];

    Which then I try to constrain in the "subject to" section of the program like this:

    forall(n in numberOfRequests){
        forall(t in timeWindow, r in requests){
          if (r.id == n && t > startOf(tirequests[r]) && t < endOf(tirequests[r])){
            carNeeded[n][t] = 1; 
    }
    }
    }   
     forall(n in numberOfRequests){
         sum (t in timeWindow) carNeeded[n][t] < 3;
    }

    There is a syntax error for the carNeeded[n][t] = 1; (unexpected "="), BUT I doubt this is the only problem... Maybe my entire formulation is wrong.

    My idea is to have this boolean variable carNeeded that becomes 1 if in a specific instant of the whole time (from 0 to 500) there is a current on-going request.

    Then, the sum of all these ones has to be less than the capacity of cars (which is 3).

     

    I hope this clears out more or less what I am trying to do.

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Adding constraint to an existing example

    Posted Wed June 14, 2017 09:37 AM

    Hi,

    I think you try to use CPO.

    The following model works:

     using CP;
     
     range timeWindow = 0..500;
    range numberOfRequests = 0..5;

    tuple req
    {
    int id;

    }

    {req} requests={<1>,<2>};

     

    dvar boolean carNeeded[numberOfRequests][timeWindow];
    dvar interval tirequests[requests];

    subject to
    {

    forall(n in numberOfRequests)
        forall(t in timeWindow, r in requests)
          (r.id == n && t >= startOf(tirequests[r]) && t < endOf(tirequests[r]))
           =>  (carNeeded[n][t] == 1);

     

     forall(n in numberOfRequests){
         sum (t in timeWindow) carNeeded[n][t] <= 2;
    }
    }

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Adding constraint to an existing example

    Posted Thu June 15, 2017 02:37 PM

    Originally posted by: positionguy


    Thank you for the answer, Alex!

    It works now! 

    Kind regards


    #CPLEXOptimizers
    #DecisionOptimization