我在 Cpp 中使用 CPLEX。经过谷歌搜索后,我发现需要设置哪些参数来避免 cplex 打印到终端,我这样使用它们:

IloCplex cplex(model);
std::ofstream logfile("cplex.log");
cplex.setOut(logfile);
cplex.setWarning(logfile);
cplex.setError(logfile);

cplex.setParam(IloCplex::MIPInterval, 1000);//Controls the frequency of node logging when MIPDISPLAY is set higher than 1.
cplex.setParam(IloCplex::MIPDisplay, 0);//MIP node log display information-No display until optimal solution has been found
cplex.setParam(IloCplex::SimDisplay, 0);//No iteration messages until solution
cplex.setParam(IloCplex::BarDisplay, 0);//No progress information
cplex.setParam(IloCplex::NetDisplay, 0);//Network logging display indicator

if ( !cplex.solve() ) {
....
}

但 cplex 却打印出这样的东西:

Warning:  Bound infeasibility column 'x11'.
Presolve time = 0.00 sec. (0.00 ticks)

Root node processing (before b&c):
  Real time             =    0.00 sec. (0.01 ticks)
Parallel b&c, 4 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    0.00 sec. (0.01 ticks)

有什么办法可以避免打印它们吗?

有帮助吗?

解决方案 2

这是根据CPLEX参数文档

cplex.setOut(env.getNullStream());
cplex.setWarning(env.getNullStream());
cplex.setError(env.getNullStream());
.

其他提示

使用 setOut 方法来自 IloAlgorithm 班级 (IloCplex 继承自 IloAlgorithm)。您可以将空输出流设置为参数并防止在屏幕上记录消息。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top