Ranajit
Ranajit

Reputation: 49

Getting error in using Tuple in CPLEX OPL to read data from a set in the tuple

I have a tuple for reading a set of paths.

tuple Path {
int id;
string source;
string dest;
{string} pitblockSet;
{string} roadPoints; // not used
{string} dumpblockSet;
{string} others;
float dist;
};
{Path} Pbd= {} // a set read using into Pbd

There is another tuple blockType

tuple blockType {
    string id;
    int i;
    int j;
    int k;
 };

{blockType} PitBlocksType = ...; This is read from excel..and the data looks like below

P1  1   1   2
P2  1   1   3
P3  1   1   4
P4  1   1   5
P5  1   1   6
P6  1   1   7
P7  1   1   8
P8  1   1   9
P9  1   1   10
P10 1   1   11

BlockBelow is defined as below.

{blockType} BlockBelow[b1 in PitBlocksType] =
     {b | b in PitBlocksType: b1.i == b.i -1 &&
                        (b1.k  == b.k ) &&
                         (b1.j  == b.j) };

I am using constraints such as the two below. But I am getting error. I want to have the sum of BlockBelow for all blocks in the pitblockSet as shown below. But I am making some mistake in accessing the pitblockSet in the tuple Pbd ( of type Path)

forall( i in Pbd.pitblockSet,  t in TimePeriods) { 
       // blockabove exposed Pbd:
        sum(j in BlockBelow[i]) schedulePit[j.id][t] * totalVolume[j.id] <= 
        (sum(j in BlockBelow[i],r in TimePeriods : r <= t,d in DumpBlocks)(Xbdt[j.id][d][r])  
        + sum(j in BlockBelow[i],r in TimePeriods : r <= t, s in Stockpiles)(Xbst[j.id][s][r]/density[j.id])
        +sum(j in BlockBelow[i],r in TimePeriods : r <= t, m in Plants)(Xbmt[j.id][m][r]/density[j.id]))  ;      
        }        



 forall(d in Pbd.dumpblockSet, t in TimePeriods) {   
  //DumpblocksBelow
  sum( b in PitBlocks,j in OnBelowDump[d],  r in TimePeriods: r<=t)(Xbdt[b][j.id][r]*SwellFactor)
 - scheduleDump[d.id][t]* sum(j in OnBelowDump[d])(dumpVolume[j.id]) >= 0;
   }

The error I get is : Expecting a tuple type, found {Path}.
Need suggestions please on how to access the pitblockSet or dumpblockSet in Pbd

Upvotes: 0

Views: 728

Answers (1)

Daniel Junglas
Daniel Junglas

Reputation: 5930

The statement

forall( i in Pbd.pitblockSet,  t in TimePeriods) 

looks wrong. According to your definition, Pbd is a set of paths, so it does not have a pitblockSet property. Only the elements in this set have this property.

I am not sure what youre trying to do here. If you want to have all paths that intersect a certain block type B you can use:

forall (p in Pbd : `B` in p.pitblockSet)

If you want a set with all block types you can form the union over all p.pitblockSet for all paths.

EDIT after you gave some clarification in the comments:

As far as I understand, your blockType is indexed by id. If that is true then I suggest to mark this as key:

tuple blockType {
  key string id;
  int i;
  int j;
  int k;
}

If you do so, then you can get the block types and block ids below each path as follows:

{blockType} BlockTypeBelowPath[p in Pbd] = union(b in p.pitblockSet) BlockBelow[<b>];
{string} BlockIDBelowPath[p in Pbd] = { b.id | b in BlockTypeBelowPath[p] };
execute {
  writeln("BlockTypeBelowPath: ", BlockTypeBelowPath);
  writeln("BlockIDBelowPath: ", BlockIDBelowPath);
}

Upvotes: 0

Related Questions