我是CPLEX和C ++编程的初学者,我正在尝试解决中等规模的MIP问题。
我的问题是,我需要知道CPLEX花了多长时间才能获得第一个可行的解决方案并获得最佳可行解决方案(不一定是全球最佳解决方案)。
我已经知道如何配置时间限制,并且我一直在使用CPLEX的解决方案池来获取所有可行的解决方案,但不是时间。
CPLEX中是否有直接代码来获取每个可行解决方案的时间值?
由于
EDIT1:问题的代码如下:
IloEnv env;
IloModel model(env);
IloCplex cplex(model);
IloCplex::Param::TimeLimit;
IloExpr term2(env);
IloExpr term3(env);
IloExpr objetivo(env);
IloInt i,j;
double CP;
IloNumVarArray z(env, columnas-1, 0, INFTY,ILOBOOL);
IloNumVarArray a(env, columnas, -1*INFTY, INFTY, ILOFLOAT);
for (i = 0; i < filas; i++){
IloExpr term1(env);
for(j = 0; j < columnas-1; j++){
term1 += a[j]*(A[i+1][j+2]);
}
term2 += ((b[i+1])-(term1+a[columnas-1]))*((b[i+1])-(term1+a[columnas-1]));
term1.end();
}
for(j = 0; j < columnas-1; j++){
term3 += z[j];
}
objetivo=term2/(sigmasq)+2*(term3+1)-(filas);
model.add(IloMinimize(env, objetivo));
for (j = 0; j < columnas-1; j++) {
IloExpr restr(env);
restr = a[j] + (bigM)*z[j];
model.add(0 <= restr <= IloInfinity);
restr.end();
}
for (j = 0; j < columnas-1; j++) {
IloExpr restr(env);
restr = (bigM)*z[j] - a[j];
model.add(0 <= restr <= IloInfinity);
restr.end();
}
cplex.setParam(IloCplex::Param::ClockType, 2);
cplex.setParam(IloCplex::Param::TimeLimit, 3600);
cplex.solve();
PD:很抱歉,有些参数是西班牙语,但这是我的母语。
答案 0 :(得分:0)
您可以使用ValueResolvers来获取在此过程中找到的每个整数可行解决方案的时间(请参阅getCplexTime
函数)(并包括最终解决方案)。要开始使用,请查看CPLEX附带的ilomipex4.cpp
示例,以获取有关如何使用回调的示例。另外,请参阅incumbent callback以实现与Concert的回调。