更换纸浆';s(用于Python)约束公差

更换纸浆';s(用于Python)约束公差,python,constraints,pulp,Python,Constraints,Pulp,我正在使用Python的线性规划模块来解决一个线性问题 我设置了问题和约束条件,并使用了纸浆提供的默认解算器,即CBC(出于明显的原因,mac上的解算器可执行文件名为CBC-osx-64)。运行此可执行文件时: Welcome to the CBC MILP Solver Version: 2.7.6 Build Date: Mar 3 2013 Revision Number: 1770 好的,我通过纸浆运行解算器,得到一个解决方案。当验证是否满足约束条件时,我得到的解决方案与我要

我正在使用Python的线性规划模块来解决一个线性问题

我设置了问题和约束条件,并使用了纸浆提供的默认解算器,即CBC(出于明显的原因,mac上的解算器可执行文件名为CBC-osx-64)。运行此可执行文件时:

 Welcome to the CBC MILP Solver
 Version: 2.7.6
 Build Date: Mar  3 2013
 Revision Number: 1770
好的,我通过纸浆运行解算器,得到一个解决方案。当验证是否满足约束条件时,我得到的解决方案与我要求的(对于某些约束条件,并非所有约束条件)之间的差异小于1e-6但大于1e-7(例如,1.6e-7)

当然,有一个约束公差是有意义的,这很好。但我需要能够控制它,我认为这应该是任何LP任务中非常核心和重要的参数

让我们看看CBC解算器的“帮助”(运行可执行文件并键入“?”),以下是我可以更改的参数:

 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)
这些参数的值具有以下值:

 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
唯一与约束公差相关且与我的观察结果一致的参数是“积分公差”

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

问题: 有人能解释一下吗?特别是,是否有办法设置约束容差(找到的解决方案与我们要求的解决方案之间的差异)? 如果不适用于CBC,您是否知道任何其他解算器(GLPK、Gurobi等)可以设置此数量


谢谢。

我不能给你一个确切的答案,但我会试试原始或双重宽容。整数公差对我来说对约束没有意义


您知道如何通过Python接口更改这些选项吗(我想尝试一下,但不想调用命令行工具,而且我无法将选项传递给解算器)?

至少在最新版本中,您可以通过参数直接设置选项


参数fracgap应该对我有用。

无关:我认为这个答案更适合SO的指导方针作为评论。