Originally posted by: SystemAdmin
Not sure I fully understand your question.
Here is how to fill a tupleSet with subTuple via comprehension, via direct data, via scripting.
//X and X1 are just to make the sample work.
{string} X = {"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10"}
;
{string} X1 = {"f0", "f2", "f4", "f6", "f8", "f10"};
tuple Asset{
key string id;
int cost;
}
tuple Customer{
key string id;
int budget;
}
tuple CustomerUsesAsset{
key Customer c;
key Asset a;
}
{Asset} listOfAssets = {<item(X,i),i+5> | i in 1..10};
{Customer} listOfCustomers = {<item(X, i),i+10> | i in 1..10};;
// fill with via iterators with some filtering.
{CustomerUsesAsset} C2 = {<<id1, cost>, <id2, budget>> | <id1, cost> in listOfAs
sets, <id2, budget> in listOfAssets : id1 not in X1 && id2 not in X1};
//fill it with direct data (from .dat file, the separator must be removed in some places)
{CustomerUsesAsset} C3 = {<<"f1", 6>, <", 12>>, <<"f2",7>, <",13>>};
// another equivalent formula:
{CustomerUsesAsset} C4 = {<t1, t2> | t1 in listOfAssets, t2 in listOfAssets : t1.id not in X1 && t2.id not in X1};
//fill with via scripting: give all the components.
execute{
C2.add("f3",8,"f4",14);
}
execute{
writeln(C2);
writeln("\n");
writeln(C3);
writeln("\n");
writeln(C4);
writeln("\n");
}
// to find tuples in the tupleSet, you can use the keys:
// in general, you can use the keys to find and iterate on tupleSets.
execute{
writeln(C2.find("f3", "f4"));
}
#DecisionOptimization#OPLusingCPLEXOptimizer