我正在尝试将四个不同大小的数组合并到一个数组(subVolume)。此数组应包含12个与输入字符串对应的浮点值。 append函数对我不起作用,因为它只适用于整数值。编码的正确方法是什么?
{string} drySegment = ...;
{string} liquidSegment = ...;
{string} breakSegment = ...;
{string} contSegment = ...;
{string} subSegment = ...;
dvar float dryVolume[drySegment];
dvar float liquidVolume[liquidSegment];
dvar float breakVolume[breakSegment];
dvar float contVolume[contSegment];
dvar float subVolume[subSegment];
答案 0 :(得分:1)
然后你可以尝试
{string} s1={"1","2"};
{string} s2={"3","4"};
dvar float f1[s1];
dvar float f2[s2];
{string} s12=s1 union s2;
dexpr float f12[i in s12]=(i in s1)?f1[i]:f2[i];
subject to
{
f1["1"]==1.1;
f1["2"]==1.2;
f2["3"]==1.3;
f2["4"]==1.4;
}
execute
{
writeln(f12);
}
答案 1 :(得分:0)
你可以尝试
{string} s1={"1","2"};
{string} s2={"3","4"};
float f1[s1]=[0.6,0.8];
float f2[s2]=[0.66,0.88];
{string} s12=s1 union s2;
float f12[i in s12]=(i in s1)?f1[i]:f2[i];
execute
{
writeln(f12);
}
得到[0.6 0.8 0.66 0.88]