使用BigM方程最小化变量

发布于 2025-02-13 00:05:07 字数 1174 浏览 0 评论 0原文

我正在尝试最大程度地减少以下方程式:

p_ch_max = min(22,e_need*m_int),其中e_need*m_int可以根据数据大于或低于22。

我正在使用pyomo中的以下方程式来完成:

m.C6 = ConstraintList()
for t in m.ts2:
    m.C6.add(expr = m.char_power - m.var_E_need[0,t]*m_int  <= 100*m.Y[t])
    m.C6.add(expr = m.var_E_need[0,t]*m_int - m.char_power <= 100 * (1-m.Y[t]))
    m.C6.add(expr = m.var_P_ch_max[0,t] <= m.var_E_need[0,t]*m_int  )
    m.C6.add(expr = m.var_P_ch_max[0,t]  <= m.char_power)
    m.C6.add(expr = m.var_P_ch_max[0,t] >= m.var_E_need[0,t]*m_int - 100*(1-m.Y[t]))
    m.C6.add(expr = m.var_P_ch_max[0,t]  >= m.char_power - 100*m.Y[t])

m.char_power = 22;我的boolean; 100在这种情况下是我的大`

当我手动替换y的值时,这些方程是有道理的: 当y = 0我得到p_ch_max&lt; = 22p_ch_max&gt; = 22它会使p_ch_max == 22。 当y = 1我得到p_ch_max&lt; = e_need*m_intp_ch_max&gt; = e_need*m_int*m_int,它会产生p_ch_max = e_need = e_need = e_need *m_int

但是,当我在pyomo中运行代码时,它说它是不可行的或无限的,我不明白为什么。还有其他方法吗?还是可以告诉我我是否做错了什么?

I am trying to minimize the following equation:

P_ch_max = min(22, E_need*m_int) where E_need*m_int can be bigger or lower than 22 depending on the data.

I am using the following equations in pyomo to do it:

m.C6 = ConstraintList()
for t in m.ts2:
    m.C6.add(expr = m.char_power - m.var_E_need[0,t]*m_int  <= 100*m.Y[t])
    m.C6.add(expr = m.var_E_need[0,t]*m_int - m.char_power <= 100 * (1-m.Y[t]))
    m.C6.add(expr = m.var_P_ch_max[0,t] <= m.var_E_need[0,t]*m_int  )
    m.C6.add(expr = m.var_P_ch_max[0,t]  <= m.char_power)
    m.C6.add(expr = m.var_P_ch_max[0,t] >= m.var_E_need[0,t]*m_int - 100*(1-m.Y[t]))
    m.C6.add(expr = m.var_P_ch_max[0,t]  >= m.char_power - 100*m.Y[t])

m.char_power = 22; m.Y is a boolean; 100 is my big` in this case

When I substitute the values of Y manually, these equations make sense:
When Y=0 I get that P_ch_max<= 22 and P_ch_max>= 22 which would make P_ch_max == 22.
When Y=1 I get that P_ch_max<= E_need*m_int and P_ch_max>= E_need*m_int which would make P_ch_max = E_need*m_int.

However, when I run the code in pyomo it says it's unfeasible or unbounded and I don't understand why. Is there any other way to do this? Or can you tell me if I am doing something wrong pls?

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

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

发布评论

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

评论(1

走过海棠暮 2025-02-20 00:05:07

It's pretty difficult to unwind your equations and figure out why it is infeasible. But you can do a couple things rather quickly to tackle this.

首先,您可以开始“评论”约束,并查看是否可以获取模型呼吸(因此求解器不会抱怨不可行),然后从那里进行调查。

其次,如果您认为自己知道一个可行的解决方案(正如您在评论中提出的那样),则只需分配值,然后display您的模型就可以很快脱颖而出。违反哪些约束。例如:

import pyomo.environ as pyo

m = pyo.ConcreteModel()

m.x = pyo.Var()

m.c1 = pyo.Constraint(expr=m.x >= 5)

m.x = 4

m.display()

产量:

Model unknown

  Variables:
    x : Size=1, Index=None
        Key  : Lower : Value : Upper : Fixed : Stale : Domain
        None :  None :     4 :  None : False : False :  Reals

  Objectives:
    None

  Constraints:
    c1 : Size=1
        Key  : Lower : Body : Upper
        None :   5.0 :    4 :  None
[Finished in 210ms]

It's pretty difficult to unwind your equations and figure out why it is infeasible. But you can do a couple things rather quickly to tackle this.

First, you can start to "comment out" constraints and see if you can get the model breathing (such that the solver doesn't complain about infeasibility), and then investigate from there.

Second, if you think you know a feasible solution (as you suggest in your comment about plugging in), then just plug in your values by assigning them and then display your model and it should stand out very quickly which constraints are violated. For example:

import pyomo.environ as pyo

m = pyo.ConcreteModel()

m.x = pyo.Var()

m.c1 = pyo.Constraint(expr=m.x >= 5)

m.x = 4

m.display()

Yields:

Model unknown

  Variables:
    x : Size=1, Index=None
        Key  : Lower : Value : Upper : Fixed : Stale : Domain
        None :  None :     4 :  None : False : False :  Reals

  Objectives:
    None

  Constraints:
    c1 : Size=1
        Key  : Lower : Body : Upper
        None :   5.0 :    4 :  None
[Finished in 210ms]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文