Thank you very much Alex. This is working now. Many thanks.
Original Message:
Sent: Tue October 03, 2023 07:59 AM
From: ALEX FLEISCHER
Subject: Help Needed
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]
Original Message:
Sent: Mon October 02, 2023 08:24 AM
From: Tarek Hegazy
Subject: Help Needed
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
Original Message:
Sent: Sun October 01, 2023 01:42 PM
From: ALEX FLEISCHER
Subject: Help Needed
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]
Original Message:
Sent: Sun October 01, 2023 11:58 AM
From: Tarek Hegazy
Subject: Help Needed
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
Original Message:
Sent: Thu September 21, 2023 08:17 AM
From: ALEX FLEISCHER
Subject: Help Needed
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]
Original Message:
Sent: Thu September 21, 2023 07:05 AM
From: Tarek Hegazy
Subject: Help Needed
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
Original Message:
Sent: Thu September 21, 2023 02:14 AM
From: ALEX FLEISCHER
Subject: Help Needed
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]
Original Message:
Sent: Wed September 20, 2023 06:22 PM
From: Tarek Hegazy
Subject: Help Needed
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 Tasks] size 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
------------------------------