CVPR的PYOMO-约束

发布于 2025-02-13 16:59:34 字数 348 浏览 0 评论 0原文

我正在尝试创建一个约束

def rest1(modelo, i):
    return sum(sum(modelo.M[r, i, j] for j in modelo.j) for r in modelo.r if i!=j)==1

modelo.restr1 = pyenv.constraint(modero.i,rule = rets1)

,但我会得到此错误:

valueerror:无效约束表达式。约束表达式解决了琐碎的布尔(false)而不是pyomo对象。请修改您的规则以返回约束。不可行而不是false。

modelo.m是var

I'm trying to create a constraint

def rest1(modelo, i):
    return sum(sum(modelo.M[r, i, j] for j in modelo.j) for r in modelo.r if i!=j)==1

modelo.restr1 = pyEnv.Constraint(modelo.i, rule= rest1)

but i get this error:

ValueError: Invalid constraint expression. The constraint expression resolved to a trivial Boolean (False) instead of a Pyomo object. Please modify your rule to return Constraint.Infeasible instead of False.

modelo.M is a Var

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老子叫无熙 2025-02-20 16:59:34

提供最小的工作示例是最好的做法,以便社区成员可以尝试产生您的错误。

我认为问题源于两个原因之一:

  1. 对象modelo.mparam,指定索引上的总和是一个不等于1的常数必需的。
  2. 总和在空集上。在空集上总和评估为常数0,0!= 1。

It is best practice to provide a minimal working example so that community members can attempt to produce your error.

I imagine the issue stems from one of two reasons:

  1. The object modelo.M is a Param and the sum over the specified indices is a constant that is not equal to 1 as required.
  2. The sum is over an empty set. Sums over empty sets evaluate to a constant 0, and 0 != 1.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文