问题
everyone!
I'm having problems to get variables x values after solving the model.
x variables are a four index variables.
I define the structs:
#define ILOARRAYNUM2 IloArray<IloNumArray>
#define ILOARRAYNUM3 IloArray<ILOARRAYNUM2 >
#define ILOARRAYNUM4 IloArray<ILOARRAYNUM3 >
typedef IloArray<IloNumVarArray> NumVar2Array;
typedef IloArray<NumVar2Array> NumVar3Array;
typedef IloArray<NumVar3Array> NumVar4Array;
The variables x are defined as:
NumVar4Array x;
ILOARRAYNUM4 _x;
mono.x = NumVar4Array(env, n);
for(int i = 0; i < n; i++) {
mono.x[i] = NumVar3Array(env, n);
for(int j = 0; j < n; j++) {
mono.x[i][j] = NumVar2Array(env, n);
for (int k = 0; k < n; k++) {
mono.x[i][j][k] = IloNumVarArray(env, n, 0.0, 1.0, ILOFLOAT);
}
}
}
mono._x = ILOARRAYNUM4(env,n);
for (int i = 0; i < n; i++){
mono._x[i] = ILOARRAYNUM3(env,n);
for (int j = 0; j < n; j++){
mono._x[i][j] = ILOARRAYNUM2(env,n);
for (int k = 0; k < n; k++) {
mono._x[i][j][k] = IloNumArray(env,n);
}
}
}
To get the values of x, I do:
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (w[i][j] != 0){
for (int k = 0; k < n; k++) {
for (int m = 0; m < n; m++) {
if ( (k != m && k != j && m != i) or (k == m) ) {
mono.cplex.getValue(mono.x[i][j][k][m], mono._x[i][j][k][m]);
}
}
}
}
}
}
But, then, the error message below appears:
The referenced IloExtractable has not been extracted by the IloAlgorithm
What am I doing wrong?
回答1:
Most likely your constraints in your problem do not include all the variables; there may be some variable which is not involved in any constraint. Does your code get values for some of the variables? Have you tried debugging through this code to see which variable is not extracted to CPLEX?
See CPLEX - Error in accessing solution C++
来源:https://stackoverflow.com/questions/49289021/problems-with-function-getvalues-cplex-c