Originally posted by: SystemAdmin
[UDOPS said:]
Thanks, that works. Now how about the average?
tuple domestic {
string name;
float price;
string source;
}
tuple import {
string name;
float price;
}
tuple retail {
string name;
float saleprice;
}
{domestic} skus = {<", 2.65, "OH">, <", 1.75, "CA">, <", 0.5, "CA">, <", 1.5, "TX">, <", 1.5, "CA">, <", 1.6, "OH">};
{import} europe = {<", 1.25>,<", 4.55>, <", 6.77>};
//merge sets (lists) on three columns
{domestic} sale_all = skus union {<n,p,"ER">| <n,p> in europe};
//intersection of sets, only members in both sets
{retail} sale_intersection = {<f,x> | <f, x, src> in skus, <f, p> in europe};
//set of all fruits, lowest price
{retail} sale_low= {<f.name, min(<f.name,p,src> in sale_all) p> | f in sale_all};
//set of all fruits, highest price
{retail} sale_high= {<f.name, max(<f.name,p,src> in sale_all) p> | f in sale_all};
//set of all fruits, average price
{retail} sale_avg= {<f.name, sum(<f.name,p,src> in sale_all) p> | f in sale_all};
//card(A in sale_all: A.name==f.name) does not work
execute{ //display constructed sets, add carriage return between results
writeln("Intersection "+sale_intersection)
writeln("\nAll "+sale_all)
writeln("\nLow "+sale_low)
writeln("\nHigh "+sale_high)
writeln("\nAverage "+sale_avg)
};
#DecisionOptimization#OPLusingCPLEXOptimizer