Originally posted by: SystemAdmin
[T.B. said:]
In many cases, we will give data to a two dimension array by the following way:
#include <ilcplex/ilocplex.h>
ILOSTLBEGIN
typedef IloArray<IloNumArray> IloNumArray2;
ââ¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦
int main(void){
IloEnv env;
IloNumArray2 cost(env,4);
cost[0]=IloNumArray(env,8,6,2,6,7,4,2,9,5);
cost[1]=IloNumArray(env,8,4,9,5,3,8,5,8,2);
cost[2]=IloNumArray(env,8,5,2,1,9,7,4,3,3);
cost[3]=IloNumArray(env,8,7,6,7,3,9,2,7,1);
ââ¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦Ã¢â¬Â¦
}
But this time suppose we have a matrix price[4][8], and how can I send the data in the matrix [i]price [/i] to the IloNumArray2 cost?
This is very important, for very often we have to read data from outer file, such as database, excel, and so on. I have tried the following way, but fail:
ââ¬Â¦..
int main(void){
IloEnv env;
IloNumArray2 cost(env,4);
int price[4][8]={
{6,2,6,7,4,2,9,5},
{4,9,5,3,8,5,8,2},
{5,2,1,9,7,4,3,3},
{7,6,7,3,9,2,7,1}};
IloNumArray x(env,8);
for(int i=0;i<4;i++){<br /> for(int j=0;j<8;j++){<br /> x[j]=price[i][j];
}
cost[i]=x;
}
ââ¬Â¦Ã¢â¬Â¦.
}
Is there any way to do the job?
P.S. 1. the cplex version is cplex9.0
2. the model should be built by row.
#CPLEXOptimizers#DecisionOptimization