0

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};
Ranajit
  • 49
  • 6

1 Answers1

1

The error is Pdb.pitblockSet. According to your definition, Pdb is a set of tuples, so it does not have a pitblockSet property. You need a concrete tuple to be able to reference the pitblockSet property.

In case you want this constraint for each path, this is the way to write it

forall (p in Pdb) {
  forall(i in p.pitblockSet , d in DumpBlocks, t in TimePeriods ) {
    sum(j in BlockBelow[i] ) Xbdt[j.id][d][t] == 0;
  }
}
Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22
  • Thank you again Daniel, Your and Alex's answers have been very helpful to me. As I did not have a formal training in OPL my knowledge of OPL is limited, may be at some stage I will find more on a OPL training. – Ranajit Mar 31 '20 at 12:21