Python-如何为CVXOPT中的整数线性规划(ILP)函数设置时间限制

Python-How to set time limit for The integer linear programming(ILP) function in CVXOPT

如何设置CVXOPT中整数线性规划(ILP)函数的时限? 假设这是我的求解器:

status,solution = glpk.ilp(W, G.T, h,B=set(range(len(W))))

尝试以下操作:

from cvxopt import solvers
solvers.options['glpk'] = {'tm_lim' : 1000}  # time-limit of 1s (glpk expects [ms])
status,solution = glpk.ilp(W, G.T, h,B=set(range(len(W))))

文档 here.

中描述了传递求解器选项(在 cvxopt 中)

glpk 的可用选项在它的手册中有描述here

编辑: 如评论中所述,tm_lim 是要设置的变量,而不是 tm lim!

Sascha 的回答中的解决方案对我不起作用,这可能是由于导入样式所致。但是,您也可以在函数调用中只传递一个 options 字典,即

glpk.ilp(W, G.T, h,B=set(range(len(W))), options={'tm_lim': 1000})