更改PuLP(对于Python)的约束公差 [英] change PuLP's (for Python) constraint tolerance

查看:68
本文介绍了更改PuLP(对于Python)的约束公差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python的PuLP线性编程模块来解决线性问题.

I am using the PuLP linear programming module for Python to solve a linear problem.

我设置了问题,约束条件,并使用了PuLP随附的默认求解器CBC(出于显而易见的原因,我的Mac上的求解器可执行文件称为 cbc-osx-64 ).运行此可执行文件时:

I set up the problem, the constraints, and I use the default solver provided with PuLP which is CBC (the solver executable on my mac is called cbc-osx-64 for obvious reasons). When running this executable:

 Welcome to the CBC MILP Solver
 Version: 2.7.6
 Build Date: Mar  3 2013
 Revision Number: 1770

好的,我通过PuLP运行求解器并获得解决方案.当验证满足约束条件时,我得到了解决方案与我所要求的差异(对于某些约束,不是全部),该差异小于1e-6但大于1e-7(例如1.6e-7).

OK, I run the solver via PuLP and get a solution. When verifying that the constraints are satisfied I get a difference between the solution and what I requested (for some of the constraints, not all), which is less than 1e-6 but greater than 1e-7 (1.6e-7, e.g.).

当然,具有约束公差是很有意义的.但是我需要能够控制这一点,并且我认为这应该是任何LP任务中非常重要的重要参数?

Of course it makes sense to have a constraint tolerance, that is fine. But I need to be able to control this and I think this should be a very central and important parameter in any LP task?

因此,让我们看一下CBC求解器中的帮助"(运行可执行文件并键入?"),这些是我可以更改的参数:

So let us look at the "help" from the CBC solver (run the executable and type "?"), these are the arguments I can change:

 Commands are:
 Double parameters:
   dualB(ound) dualT(olerance) primalT(olerance) primalW(eight) zeroT(olerance)
 Branch and Cut double parameters:
   allow(ableGap) cuto(ff) inc(rement) integerT(olerance) preT(olerance)
   pumpC(utoff) ratio(Gap) sec(onds)
 Integer parameters:
   force(Solution) idiot(Crash) maxF(actor) maxIt(erations) output(Format)
   slog(Level) sprint(Crash)
 Branch and Cut integer parameters:
   cutD(epth) cutL(ength) depth(MiniBab) hot(StartMaxIts) log(Level) maxN(odes)
   maxS(olutions) passC(uts) passF(easibilityPump) passT(reeCuts) pumpT(une)
   strat(egy) strong(Branching) trust(PseudoCosts)
 Keyword parameters:
   allC(ommands) chol(esky) crash cross(over) direction error(sAllowed)
   fact(orization) keepN(ames) mess(ages) perturb(ation) presolve
   printi(ngOptions) scal(ing) timeM(ode)
Branch and Cut keyword parameters:
   clique(Cuts) combine(Solutions) combine2(Solutions) cost(Strategy) cplex(Use)
   cuts(OnOff) Dins DivingS(ome) DivingC(oefficient) DivingF(ractional)
   DivingG(uided) DivingL(ineSearch) DivingP(seudoCost) DivingV(ectorLength)
   feas(ibilityPump) flow(CoverCuts) gomory(Cuts) greedy(Heuristic)
   heur(isticsOnOff) knapsack(Cuts) lagomory(Cuts) lift(AndProjectCuts)
   local(TreeSearch) mixed(IntegerRoundingCuts) node(Strategy)
   pivotAndC(omplement) pivotAndF(ix) preprocess probing(Cuts)
   rand(omizedRounding) reduce(AndSplitCuts) residual(CapacityCuts) Rens Rins
   round(ingHeuristic) sos(Options) two(MirCuts) Vnd(VariableNeighborhoodSearch)
 Actions or string parameters:
   allS(lack) barr(ier) basisI(n) basisO(ut) directory dualS(implex)
   either(Simplex) end exit export gsolu(tion) help import initialS(olve)
   max(imize) min(imize) para(metrics) primalS(implex) printM(ask) quit
   saveS(olution) solu(tion) stat(istics) stop
 Branch and Cut actions:
   branch(AndCut) doH(euristic) prio(rityIn) solv(e)

这些参数的值具有以下值:

The values of these parameters have values:

 dualTolerance has value 1e-07
 primalTolerance has value 1e-07
 zeroTolerance has value 1e-20
 allowableGap has value 0
 integerTolerance has value 1e-06
 preTolerance has value 1e-08
 ratioGap has value 0

唯一可以与约束公差相关并与我的观察一致的参数是"integerTolerance".

The only parameter which could be associated with the constraint tolerance and also consistent with my observations is the "integerTolerance".

因此,我将此容差更改为1e-8,但得到了相同的结果(也就是说,解决方案与基本事实相差超过1e-7).

So, I changed this tolerance to 1e-8 but got the same result (that is, the solution differed from the ground truth by more than 1e-7).

问题:谁能对此有所启发?特别是,是否有一种方法可以设置约束公差(找到的解决方案与我们要求的解决方案之间的差异)?如果不是CBC,您是否知道可以设置此数量的任何其他求解器(GLPK,Gurobi等)?

Questions: Can anyone shed some light on this? In particular, is there a way to set the constraint tolerance (the difference between a found solution and what we requested)? If not for CBC, do you know of any other solver (GLPK, Gurobi, etc.) where this quantity can be set?

谢谢.

推荐答案

至少在最新的纸浆版本中,您可以直接通过参数进行设置.

At least in the latest pulp Version you can set it directly via parameter.

https://pythonhosted.org/PuLP/solvers.html

参数fracgap应该为我做和做.

Parameter fracgap should do and does for me.

这篇关于更改PuLP(对于Python)的约束公差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆