IC5Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
Topic
  • 1 reply
  • Latest Post - ‏2013-01-27T08:09:55Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic How to initialize a tupleset that having a tuple key member from database?

‏2013-01-25T14:11:55Z |
Here I have two indexing set: Gasolines and Periods


tuple gasType 
{ key 

int GasId; string GasName; 
}   setof(gasType) Gasolines = ...;   setof(

int) Periods = ...;


If I want to populate an array index by Gasolines and Periods from a database table, I can do it this way:



float GasDemandArray[Gasolines][Periods] = ...;   GasDemandArray from DBRead(db,
"SELECT GasId, Periods, Demands FROM GasDemandTable");

OPL seem to found that the first field is the key of gasType (GasId;) and didn't ask for the second field of tuple (GasName).

If I want to do it for a tupleset instead of an array, I expect OPL to do the same deduction:


tuple gasDemandType
{ key gasType Gaz; key 

int Periods; 

float Demand; 
}   setof(gasDemandType) GasDemandTupleSet =...;   GasDemandTupleSet from DBRead(db,
"SELECT GasId, Periods, Demands FROM GasDemandTable");


But this didn't work. OPL expect to receive:

GasDemandTupleSet from DBRead(db,
"SELECT GasId, GasName, Periods, Demands FROM GasDemandTable");


Is there another way to initialize a tupleset with a tuple as a key memeber? Also, maybe it's a bad idea to have a tupleset that have a tuple as key member?
Updated on 2013-01-27T08:09:55Z at 2013-01-27T08:09:55Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: How to initialize a tupleset that having a tuple key member from database?

    ‏2013-01-27T08:09:55Z  
    Use GasId instead of gasType as indexes everywhere. I remember encountering a problem with one tuple inside another tuple (don't remember what was it exactly) so probably that structure support is partial.