Decision Optimization

Decision Optimization

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

 View Only
  • 1.  URGENT! Creating an execute block for time windows

    Posted Thu May 12, 2016 04:38 AM

    Originally posted by: Ghostwriter_muc


    Hi everyone,

     

    I need a execute block that gives us the different W[A] (time-Windows) as Output.

    Probably this is quite easy, but I have no clue how to implement this as I'am about to getting started with Cplex.

     

    .Mod

     

    .Data

     

    There is a number of Patients, each Patient has a defined set of activities. I defined the subsets for each activity, precedessor, successor and Minimum time lag (clinicalPathwaysPerPatient). 

    Each Patient has his defined date of Arrival at the Hospital (alpha in the Data.file).  Each activity has an earliest and latest starting time (E and L in the Data.file). 

    The earliest starting time additionally depends on the Arrival date, the sequence of the predeccesors (Activity 2 can not start before 1 is finished) and the Minimum time lag given as int dmin. 

     

    Example:

    Patient 1:

     

    calculating earliest starting time:

    Activity 1: E=1, Arrival of Patient 1 is 1, there is no int dist given, therefore 0 (This is a problem for me, because i don't know how to implement this)--> earliest Starting time 1

    Activity 2: E=1, Arrival of Patient 1 is 1, int dmin =0 --> earliest Starting time 1

    Activity 3: E=1, Arrival of Patient 1 is 1, int dmin =3 --> earliest Starting time 4

     

    calculating latest starting time backwards:

    Activity 3: L=6, int dmin= 0 --> Latest starting time = 6

    Activity 2: L=6, int dmin= 3 --> Latest starting time = 3

    Activity 1: L=6, there is no int dist given, therefore 0 (This is a problem for me, because i don't know how to implement this) --> Latest starting time = 3

     

    At the end i want to have time windows as followed: So I can sum t from 1 to 3 or from 4 to 6 and not from 1 to 6.

    Activity 1: W1=[1,2,3]

    Activity 2: W2=[1,2,3]

    Activity 3: W3=[4,5,6]

     

    I would be grateful for you're help and any tips! Do not hesitate to ask if you need further information.

     

    Many thanks in advance!!

     

    Kind regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: URGENT! Creating an execute block for time windows

    Posted Thu May 12, 2016 06:28 AM

    Hi,

    instead of attaching screenshots, can you attach .mod and .dat files so that other users may try ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: URGENT! Creating an execute block for time windows

    Posted Thu May 12, 2016 06:33 AM

    Originally posted by: Ghostwriter_muc


    I attached the .mod and .data files.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: URGENT! Creating an execute block for time windows

    Posted Thu May 12, 2016 11:00 AM

    Hi,

    you could start with

    int earliest[p in P][a in A];
     
     {int} activitiesWithoutOffset={pre | <pre,succ,d> in clinicalPathways};
     
     
     execute
     {
     
     
     for(var p in P) for(var a in A)
     {
         var temp=1000;
         if ( activitiesWithoutOffset.contains(a)) temp=E[a];
         for(var pathway in clinicalPathwaysPerPatient[p] )
         {
           if (pathway.succ==a) temp=earliest[p][pathway.pre]+pathway.dmin;
         }
         earliest[p][a]=temp;
    }
    writeln(earliest);
    }

    int startWindow[a in A]=min(p in P) earliest[p][a];

    execute
    {
    writeln(startWindow);
    }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: URGENT! Creating an execute block for time windows

    Posted Thu May 12, 2016 06:09 PM

    Originally posted by: Ghostwriter_muc


    WOW! Thank you very very much. This helps a lot.

     

    Is it possible to separate the startWindow into [1 1 4] for patient 1 and [1 1 4] for patient 2?

     

     


    #DecisionOptimization


  • 6.  Re: URGENT! Creating an execute block for time windows

    Posted Fri May 13, 2016 02:57 AM

    Hi,

    if you write

    {clinicalPathway} clinicalPathways = ...;

    {clinicalPathway} clinicalPathwaysPerPatient[p in P] = {c | c in clinicalPathways : (firstOne[p] <= c.pre <= PHI[p]) || (firstOne[p] <= c.succ <= PHI[p])};

     // subset of activities
     execute {
         writeln(clinicalPathwaysPerPatient);
     }
     
     int earliest[p in P][a in A];
     
     {int} activitiesWithoutOffset[p in P]={pre | <pre,succ,d> in clinicalPathwaysPerPatient[p]};
     
     int noActivity=1000;
     
     execute
     {
     
     
     for(var p in P) for(var a in A)
     {
         var temp=noActivity;
         if ( activitiesWithoutOffset[p].contains(a)) temp=E[a];
         for(var pathway in clinicalPathwaysPerPatient[p] )
         {
           if (pathway.succ==a) temp=earliest[p][pathway.pre]+pathway.dmin;
         }
         earliest[p][a]=temp;
    }
    writeln(earliest);
    }

    int startWindow[a in A]=min(p in P) earliest[p][a];

    execute
    {
    writeln(startWindow);
    }
     

    then you see

     

    [[1 1 4 1000 1000 1000]
             [1000 1000 1000 1 1 4]]
     [1 1 4 1 1 4]

    Do you have a specific hospital in mind or do you target a generic use case ?

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: URGENT! Creating an execute block for time windows

    Posted Sun May 15, 2016 11:40 AM

    Originally posted by: Ghostwriter_muc


    The implementation is very good and I'am deeply grateful for your time and hard work.

     

    I forgot to tell you that alpha[P] is a very important condition. Alpha is the admission date for a patient. The result for patient 1 is right, but for patient 2 it is not. For patient 2 the admission period is period 2.  The earliest starting time can not begin before the admission date. The right result would be [ 1 1 4 2 2 5 ]. In which way can I implement this condition?

     

    Regarding the format of the result, the time windows should look like the following example. A combination of the earliest (e.g = 1) and latest (e.g = 3) starting time, including the period 2. Because i need all 3 periods for my constraint.

     

    . Because i have to sum 

     

    Example

    For patient 1: 

    W[1] = [ 1 2 3]

    W[2] = [ 1 2 3]

    W[3] = [ 4 5 6]

     

    For patient 2:

    W[4] = [ 2 3]

    W[5] = [ 2 3]

    W[6] = [ 5 6]

     

    It should like this W= [ 1 2 3 ], [ 1 2 3 ], [ 4 5 6 ],[  2 3  ], [ 2 3 ], [ 5 6 ],

     

    I tried to solve this problem every day but i can't. It is really difficult for a beginner. Can you please help??!

    Kind regards


    #DecisionOptimization


  • 8.  Re: URGENT! Creating an execute block for time windows

    Posted Sun May 15, 2016 04:42 PM

    Originally posted by: Ghostwriter_muc


    I've tried to calculate the latest time windows, but i don't know how to calculate it. I've to start with the last activity. 

     

    {clinicalPathways} clinicalPathwaysPerPatient = {< 1, 2, 0 > < 2, 3, 3 >} {< 4, 5, 0 > < 5, 6, 3 >}

    L(i in A) - pathway.dmin --> ( 6 - 3) = 3 and then (3 - 0)

    Is it possible to start from the back to the front?

     

    The solution should be [ 3 3 6 3 3 6 ].

     

    I solved the problem with the alpha. The solution is now [ 1 1 4 2 2 5 ]. I replaced E[i] with alpha[p]

     

    Is it possible to combine the results from startWindow and FinsihWindow? 

    --> W[ i in A ] = [ 1 2 3 ], [ 1 2 3 ], [ 4 5 6 ],[  2 3  ], [ 2 3 ], [ 5 6 ] 

     

    kind regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: URGENT! Creating an execute block for time windows

    Posted Mon May 16, 2016 04:25 AM

    Hi,

    let me give you a small example:

    setof(int) A = asSet(1..6);
     
     int startWindow[A]=[1,1,4,1,1,4];
    int endWindow[A]=[ 1, 1, 4, 2, 2,5 ];

    {int} W[a in A]=asSet(startWindow[a]..endWindow[a]);
    execute
    {
    writeln(W);
    }

    which gives

     [{1} {1} {4} {1 2} {1 2} {4 5}]

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer