可以共享跨区块的约束吗?

huangapple go评论47阅读模式
英文:

is it possible to share constraint cross-blocks?

问题

I have a parent block (Block0) containing 3 sub-blocks:

  1. Block1 and Block2 formulate the same problem A, but with slightly different set of indexes
  2. Block3 formulates another problem B, which uses quadratic constraints
  3. Block1 and Block2 make use of decision variables within Block3 (which are constrained by such quadratic constraint) to determine the solution of problem A

The implementation logic is something along these lines:

block0 = pyo.ConcreteModel("Block0")

block3 = prepare_problemB_model(data3)
block0.add_component("Block3", block3)

block1 = prepare_problemA_model(data1, block3.component_objects(pyo.Var))
block2 = prepare_problemA_model(data2, block3.component_objects(pyo.Var))

block0.add_component("Block1", block1)
block0.add_component("Block2", block2)

block0.obj = pyo.Objective(expr=block1.obj + block2.obj + block3.obj)

I can solve block0 if the decision variables within Block3 (which are shared with Block1 and Block2) are fixed to a constant value. Otherwise I get the following error:

ERROR: Model contains an expression (*CONSTRAINT-NAME*)
    that contains a variable (*VAR-NAME*) that is not attached to an active
    block on the submodel being written

Do you have any ideas? Is there a straightforward way to copy Block3's model into Block1 and Block2?

I'm using pyomo 6.5.0 with the Gurobi solver.

Thanks.

英文:

I have a parent block (Block0) containing 3 sub-blocks:

  1. Block1 and Block2 formulate the same problem A, but with slightly different set of indexes
  2. Block3 formulates another problem B, which uses quadratic constraints
  3. Block1 and Block2 make use of decision variables within Block3 (which are constrained by such quadratic constraint) to determine the solution of problem A

The implementation logic is something along these lines:

block0 = pyo.ConcreteModel("Block0")

block3 = prepare_problemB_model(data3)
block0.add_component("Block3", block3)


block1 = prepare_problemA_model(data1, block3.component_objects(pyo.Var))
block2 = prepare_problemA_model(data2, block3.component_objects(pyo.Var))

block0.add_component("Block1", block1)
block0.add_component("Block2", block2)

block0.obj = pyo.Objective(expr=block1.obj + block2.obj + block3.obj)

I can solve block0 if the decision variables within Block3 (which are shared with Block1 and Block2) are fixed to a constant value. Otherwise I get the following error:

ERROR: Model contains an expression (*CONSTRAINT-NAME*)
    that contains a variable (*VAR-NAME*) that is not attached to an active
    block on the submodel being written

Do you have any ideas? is a straightforward way to copy Block3's model into Block1 and Block2?

I'm using pyomo 6.5.0 with gurobi solver

Thanks

答案1

得分: 1

简短的答案是升级到 Pyomo 6.6.1。

稍微长一点的解释是,原始的LP写入器在收集活动约束之前通过遍历模型(写入器所获得的块树)的方式“预先收集”模型变量。这是为了使某些操作更高效。您看到的错误是在约束引用了在初始收集中未找到的未固定变量时引发的。Pyomo在6.5中为NL写入器和6.6中为LP写入器取消了这个限制(Baron和GAMS接口仍然存在,希望在6.7中会放宽)。

英文:

The short answer is to upgrade to Pyomo 6.6.1.

The slightly longer explanation is that the original LP writer had a step where it “pre-collected” model variables by walking the model (block tree that the writer was handed) before collecting the active constraints. This was done to make certain operations more efficient. The error you are seeing was raised when a constraint referenced an unfixed variable that was not found by that initial collection. Pyomo removed this restriction in 6.5 for the NL writer and in 6.6 for the LP writer (the Baron and GAMS interfaces still have it, and will hopefully be relaxed in 6.7).

huangapple
  • 本文由 发表于 2023年6月8日 23:35:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433525.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定