0
votes

I am trying to merge four arrays of a different size to one array (subVolume). This array should contain 12 float values that correspond to the inputted strings. The append function does not work for me, because it only works with integer values. What is the proper way to code this?

{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];
2

2 Answers

1
votes

then you could try

{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); 
 }
0
votes

you could try

{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); 
 }

which gives [0.6 0.8 0.66 0.88]