Decision Optimization

 View Only
  • 1.  Help Needed

    Posted Wed September 20, 2023 06:23 PM

    Hi,

    I appreciate very much if you help me resolve the error in the following simple example. Here are the mod and dat files:

    // mod file

    using CP;

    tuple Task {        // tuple to define a Task

      key int id;

      int   duration;

      {int} FSSuccs;  // set with ids of linked Tasks

      {int} FSLags;    // set with values associated with the FSSuccs set

    }

    {Task} Tasks = ...;

    dvar interval task[t in Taskssize t.duration;

    minimize   max(tt in Tasks) endOf(task[tt]);

    subject to {

                                                      //This gives errors. Is there a better way to represent this

      forall (t1 in Tasks, t2 in t1.FSSuccs) endBeforeStart(task[t1], task[<t2>], item(t1.FSLags,t2));  

    }

    execute {

     }

    /*.dat File

    Tasks = {

      < 1, 8, {6},{6}>,

      < 2, 8, {5,3,4},{2,0,3}>,

      < 3, 7, {5},{0} >,

      < 4, 4, {5,6},{7,0} >,   //here the value 7 is associated with Task id 5. Also, value 0 is associated with Task id 6

      < 5, 9, {8},{8} >,

      < 6, 6, {},{}>,

      < 7, 12, {},{} >,

      < 8, 4, {},{} >,

     };  */



    ------------------------------
    Tarek Hegazy
    ------------------------------


  • 2.  RE: Help Needed

    Posted Thu September 21, 2023 02:14 AM

    Hi,

    i would rewrite your forall into

    forall (t1 in Tasks, t2 in t1.FSSuccs:t2<card(t1.FSLags)) endBeforeStart(task[t1], task[<t2>], item(t1.FSLags,t2));

    to make sure you do not try to get any item out of the set t1.FSLags



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: Help Needed

    Posted Thu September 21, 2023 07:06 AM

    Hi Alex,

    Thank you for the revised statement. The good thing is that it gives NO error, but the solution shows that it did not read any of the FSLags values. I appreciate if you help me with this.



    ------------------------------
    Tarek Hegazy
    ------------------------------



  • 4.  RE: Help Needed

    Posted Thu September 21, 2023 08:18 AM

    So you understood why you got an error.

    Now if you want to pick the right lag fot the right task you could write

    forall (t1 in Tasks, t2 in t1.FSSuccs) 
      endBeforeStart(task[t1], task[<t2>], item(t1.FSLags,ord( t1.FSSuccs,t2)));  


    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 5.  RE: Help Needed

    Posted Thu September 21, 2023 11:54 AM

    Hi Alex,

    This worked correctly. Thank you very much. I will keep testing and will let you know. Much Apperciated.

    Tarek



    ------------------------------
    Tarek Hegazy
    ------------------------------



  • 6.  RE: Help Needed

    Posted Sun October 01, 2023 11:59 AM

    Hi Alex,

    I found another problem. When there are duplicate items in the FSLags tuple, it gives error. Here are the dat and mod files. I appreciate your help.

    // mod file

    using CP;
    tuple Task {
      key int id;
      int duration;
      {int} FSSuccs; // set with ids of linked Tasks
      {int} FSLags;  // set with values associated with the FSSuccs set
    }
     
    {Task} Tasks =...;
     
    dvar interval task[t in Tasks] size t.duration;
     
    minimize  max(tt in Tasks) endOf(task[tt]);
     
    subject to {
      forall (t1 in Tasks, t2 in t1.FSSuccs) endBeforeStart(task[t1], task[<t2>], item(t1.FSLags, ord (t1.FSSuccs,t2)));
      }
    execute {
    }

    // dat file

    Tasks = {
    <1,8,{6},{6}>,
    <2,8,{5,3,4},{2,2,3}>,    //fives error because 2 is repeated. No error when {2,0,3}
    <3,7,{5},{0}>,
    <4,4,{5,6},{0,0}>,      //fives error because 0 is repeated. No error when {1,0}
    <5,9,{8},{8}>,
    <6,6,{},{}>,
    <7,12,{},{}>,
    <8,4,{},{}>,
    };



    ------------------------------
    Tarek Hegazy
    ------------------------------



  • 7.  RE: Help Needed

    Posted Sun October 01, 2023 01:42 PM

    Then instead or sets you should use arrays:

    .mod

    int nbMaxSucc=10;
    
    tuple Task {
      key int id;
      int duration;
      {int} FSSuccs; // set with ids of linked Tasks
      int FSLags[1..nbMaxSucc];  // set with values associated with the FSSuccs set
    }
     
    {Task} Tasks =...;

    .dat

    Tasks = {
    <1,8,{6},[6]>,
    <2,8,{5,3,4},[2,0,0]>,    //fives error because 2 is repeated. No error when {2,0,3}
    <3,7,{5},[0]>,
    <4,4,{5,6},[0,0]>,      //fives error because 0 is repeated. No error when {1,0}
    <5,9,{8},[8]>,
    <6,6,{},[]>,
    <7,12,{},[]>,
    <8,4,{},[]>,
    };


    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 8.  RE: Help Needed

    Posted Mon October 02, 2023 08:24 AM

    Hi Alex,

    Still gives an error. So, I thought of separating tasks from relations in separate tuples to makes things easier. However the "endBeforeStart: statement gives an error. Please help.

    //mod 
     
    using CP;
     
    tuple Task {
      key int id;
      int duration;
    }
    {Task} Tasks =...;
     
    tuple Relation {
      key int id;
      int Pred;
      int Succ;
      int Lag;  
    }
    {Relation} Relations =...;
     
    dvar interval task[t in Tasks] size t.duration;
     
    minimize  max(tt in Tasks) endOf(task[tt]);
                                                    
    subject to {
      forall (r1 in Relations) endBeforeStart(task[r1.Pred], task[r1.Succ], r1.Lag);   //gives error
     }
     
    execute {
    }
     
    //dat
    Tasks = {
    <1,8>,
    <2,8>,
    <3,7>,
    <4,4>,
    <5,9>,
    <6,6>,
    <7,12>,
    <8,4>,
    };
    Relations = {
    <1,6,0>,
    <2,5,0>,
    <2,3,1>,
    <3,5,0>,
    <4,5,0>,
    <4,6,0>,
    <5,8,0>,
    };


    ------------------------------
    Tarek Hegazy
    ------------------------------



  • 9.  RE: Help Needed

    Posted Tue October 03, 2023 07:59 AM
    Edited by ALEX FLEISCHER Tue October 03, 2023 07:59 AM

    You could use item:

    forall (r1 in Relations)
         endBeforeStart(task[item(Tasks,<r1.Pred>)], task[item(Tasks,<r1.Succ>)], r1.Lag); 



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 10.  RE: Help Needed

    Posted Tue October 03, 2023 11:06 AM

    Thank you very much Alex. This is working now. Many thanks.

    Tarek



    ------------------------------
    Tarek Hegazy
    ------------------------------