【发布时间】:2015-11-23 12:24:23
【问题描述】:
我正在使用 CPLEX 库在 C++ 中编写 MILP,但在向模型添加约束时遇到问题。代码很长,所以这里我只包括代码的一般结构和约束之一(以及所涉及的变量)。
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include "ilcplex/ilocplex.h"
using namespace std;
ILOSTLBEGIN
int main(){
//CPLEX environment and definition of the modelling object
IloEnv env;
IloModel model(env);
//Define the multi dimensional arrays for float and bool variables
typedef IloArray<IloBoolVarArray> BoolVar2D;
typedef IloArray<IloFloatVarArray> FloatVar2D;
typedef IloArray<IloArray<IloBoolVarArray> > BoolVar3D;
typedef IloArray<IloArray<IloFloatVarArray> > FloatVar3D;
typedef IloArray<IloArray<IloArray<IloBoolVarArray> > > BoolVar4D;
//Definition of the variable involved in the constraint
FloatVar3D U(env, I); //all alternatives except the opt-out
for(int i=0; i < I; i++){
U[i] = FloatVar2D(env, N);
for(int n=0; n < N; n++){
U[i][n] = IloFloatVarArray(env, R);
}
}
//Construction of the constraint (chi, beta, lambda, p are parameters)
for(int i =0; i < I; i++){
for(int n=0; n < N; n++){
int L_in = L[i][n];
for(int r=0; r < R; r++){
IloExpr sum(env);
sum += chi[i][n][r];
for(int l=0; l < L_in; l++){
sum += beta[i][n] * lambda[i][n][l] * p[i][n][l];
}
model.add(U[i][n][r] == sum);
}
}
}
env.end();
}
运行代码时,我收到以下错误消息:
libc++abi.dylib: terminating with uncaught exception of type IloWrongUsage
有谁知道以这种方式定义约束有什么问题?我尝试了同样的方法来解决更简单的问题,它奏效了。
谢谢!
【问题讨论】:
标签: c++ netbeans linear-programming cplex