我使用from docplex.cp.model import CpoModel
编写了一个docplex代码。
模型定义如下。
mdl = CpoModel(name="HouseBuilding")
但是通过resolve()函数,它最终会在解决方案中打印出不必要的输出。
msol = mdl.solve(TimeLimit=10)
我相信它是在下面打印东西
solve status,
solver parameters,
solver information
output log
输出示例如下。如何避免仅打印解决方案而打印这些信息。
! -------------------------------------------------- CP Optimizer 12.10.0.0 --
! Maximization problem - 153 variables, 123 constraints
! TimeLimit = 10
! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
! . Log search space : 330.1 (before), 330.1 (after)
! . Memory usage : 926.0 kB (before), 926.0 kB (after)
! Using parallel search with 4 workers.
! ----------------------------------------------------------------------------
! Best Branches Non-fixed W Branch decision
0 153 -
+ New bound is 385
! Using iterative diving.
! Using temporal relaxation.
0 153 1 -
+ New bound is 372
* 309 155 0.12s 1 (gap is 20.39%)
* 313 387 0.12s 1 (gap is 18.85%)
* 315 552 0.12s 1 (gap is 18.10%)
315 1000 2 1 F !presenceOf(H4-facade(Jack))
* 340 1480 0.12s 1 (gap is 9.41%)
340 2000 2 1 230 = startOf(H3-garden(Jim))
* 346 2343 0.12s 1 (gap is 7.51%)
答案 0 :(得分:1)
您只需要设置log_output参数即可删除此不必要的输出
msol = mdl.solve(TimeLimit=10, log_output=False)
要打印令人反感的价值(又名解决方案):
print(msol.objective_value)
最后,如果需要访问变量的解决方案,则必须迭代Narray变量并使用:
msol[var_name[(i, j, ... , etc. )]]))
我希望这个答案对您有所帮助,对不起我的英语。