I am trying to do something like below. I want to get the sum of the continuous variable Xbdt for all BlockBelow corresponding to Pbd.pitblockSet :
forall(i in Pbd.pitblockSet , d in DumpBlocks, t in TimePeriods ) {
sum(j in BlockBelow[i] ) Xbdt[j.id][d][t] == 0;
}
Seems I am not writing the Pbd.pitblockSet correctly. Any suggestions on how to write this ?
I get some errors : Cannot use the type {blockType}[Pbd] with "in" Cannot use type as index in {blockType}. Expecting a tuple type, found {Path}.
Where Pbd is a tuple of type Path and is read from excel data
tuple Path {
int id;
string source;
string dest;
{string} pitblockSet;
{string} roadPoints;
{string} dumpblockSet;
{string} others;
float dist;
};
{Path} Pbd={}; // set of paths from block b to dump d
DumpBlocks and PitBlocks are read from excel and are of type {String}
BlockBelow is calculated as below :
tuple blockType {
key string id;
int i;
int j;
int k;
};
{blockType} PitBlocksType = ...; //read from excel
//find one block below each block
{blockType} BlockBelow[b1 in PitBlocksType] =
{b | b in PitBlocksType: b1.i == b.i -1 &&
(b1.k == b.k ) &&
(b1.j == b.j) };
Xbdt is a decision variable
dvar float+ Xbdt[PitBlocks][DumpBlocks][TimePeriods];
-------------- ADDED AFTER ANSWER -----------------------
Thank you for the answer Daniel, I have tried the following :
forall (p in Pbd) {
forall(i in p.pitblockSet , d in DumpBlocks, t in TimePeriods ) {
sum(j in BlockBelow[i] ) Xbdt[j.id][d][t] == 0;
}
}
I get an error Cannot use type string for
I then tried :
forall (p in Pbd) {
forall(i in PitBlocksInPathD[p] , d in DumpBlocks, t in TimePeriods ) {
sum(j in BlockBelow[i] ) Xbdt[j.id][d][t] == 0;
}
}
Which seems to have worked. I had created the PitBlocksInPathD as below :
{blockType} PitBlocksInPathD[p in Pbd] = union(b in p.pitblockSet) {b2 | b2 in PitBlocksType : b2.id == b};