Problems with function getValue(s) cplex c++

喜你入骨 提交于 2020-01-06 05:28:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!