【问题标题】:OR Tools Constraint_SetCoefficient returned NULL without setting an error或工具 Constraint_SetCoefficient 返回 NULL 而不设置错误
【发布时间】:2020-12-13 14:02:44
【问题描述】:

我一般是 python 新手,特别是 OR 优化工具和我尝试运行的任何模型都会收到此错误。

根据我所做的研究,它可能与 ortools 本身有关,id 必须更改其代码中的某些内容,但我不确定。有什么想法吗?

【问题讨论】:

  • 你需要提供更多信息然后这个。人们所能看到的只是发生了错误。请上传一个重现错误的最小示例。

标签: python or-tools


【解决方案1】:

我也遇到了这个问题,结果发现,根据the documentation,我试图在一个“不属于求解器”的变量上设置一个系数。

例如,以下代码(借用自this example)重现了该问题:

from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('GLOP')
ct = solver.Constraint(0, 2, 'ct')
x = None # This is a contrived bug
ct.SetCoefficient(x, 1)

x 的值是错误的,它需要类似于x = solver.NumVar(0, 1, 'x') 以便solver 在我们尝试对其设置系数之前知道x

您不太可能犯我在代码示例中设计的错误,但可能在您的代码中的某个地方,您的变量混淆了,并且您向 SetCoefficient 发送了第一个参数的错误值,导致它与SystemError: <built-in function Constraint_SetCoefficient> returned NULL without setting an error 出错。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-14
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 2012-11-19
    • 1970-01-01
    • 2019-05-27
    相关资源
    最近更新 更多