Originally posted by: ShunjiTanaka
Hello.
I found that the following code does not work as I expected.
tuple TupA {
int no;
{int} set;
};
tuple TupB {
int no;
{string} set;
};
{TupA} A = { <0, {0}>, <1, {0}>, <2, {0}>, <3, {1}>, <4, {1}> };
{TupB} B = { <0, {"0"}>, <1, {"0"}>, <2, {"0"}>, <3, {"1"}>, <4, {"1"}> };
tuple Tup {
int a;
int b;
};
// It works.
{Tup} x = {<a.no, b.no> | ordered a, b in A : item(a.set, 0) == item(b.set, 0)};
// It does not work.
{Tup} y = {<a.no, b.no> | ordered a, b in B : item(a.set, 0) == item(b.set, 0)};
// A simple workaround is to introduce another tuple.
tuple TupC {
int a_no;
int b_no;
string a_string;
string b_string;
};
{TupC} C = {<a.no, b.no, item(a.set, 0), item(b.set, 0)> | ordered a, b in B};
{Tup} z = {<u.a_no, u.b_no> | u in C : u.a_string == u.b_string};
execute {
writeln(x);
writeln(y);
writeln(z);
}
The three sets, x, y, and z should be the same, but y is {<0 1> <0 2> <3 4>} instead of {<0 1> <0 2> <1 2> <3 4>}.
This happens when elements of string sets in a tuple are compared by item(). I would like to know if it is a specification of OPL or not.
I tested the code by:
-
platforms: Linux x86-64 and Windows 7 x86-64
-
versions: 12.6.0 and 12.6.1
-
executables: oplide and oplrun
Regards,
Shunji
#DecisionOptimization#OPLusingCPOptimizer