integerlinear-programmingcplexibm-ilog-opl

Changing array's length as I typed number.(IBM ILOG CPLEX OPL)


Now I'm trying to make a array that change their lengths to what I typed variables.

Let me show you a sample code that makes understand you easier.

int ANum = 3;   // Number of Equipment A
int BNum = 2;   // Number of Equipment B
int QNum = 8;   // Number of Equipment Q

range ARange = 1..ANum;
range BRange = 1..BNum;
range CRange = 1..(ANum+BNum);

range QRange = 1..QNum;

float Ar1[ARange] = [1.3, 5, 3]
float Ar2[BRange] = [0.9, 2.2]
float Ar3[CRange] = [Ar1[ARange], Ar2[BRange]]   <== "This is Error"

float Ar4[QRange] = [0.8, 1.1, 0.5, 2, 0.3, 1.8, 1.1, 0.6]

----------first Question-------------------------------
In this case, we can see array "Ar4".

What I want is when I change variable of "QNum" to (<= 8), ex) 5 or 3 or elses. The Ar2 is automatically changes their own length to 5 or 3 or elses.

like as, if typed 'int ANum = 5;' => "Ar2[QRange] = [0.8, 1.1, 0.5, 2, 0.3]"

---------Second Question --------------------------
As you See, 'AR1 and AR2, AR3'
I'd like to combine AR1 and AR2, so make new array AR3.


The reason why I do this is the number of equipment changes regularly. That means everytime I run this code for a changed number of equipment, I need to type this variables. And for iteration code on diversity environments.


Solution

  • One way you might use is:

    float Ar3[i in CRange] = ((i<=ANum) ? Ar1[i] : Ar2[i-ANum]);