Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我刚刚开始使用 Pyomo,我一直无法弄清楚如何编写双重求和。像这样的东西。
有人可以给我一个提示吗?谢谢你们的帮助!!
假设您的模型声明如下:
m = ConcreteModel() m.C = Set(initialize=[1,2,3]) m.D = Set(initialize=['a','b','c']) m.P = Var(m.C, m.D)
那么以下任何一项都适用于双重求和
sum( sum( m.P[c,d] for d in m.D) for c in m.C)
或者
sum( m.P[i] for i in m.C*m.D)