【问题标题】:Is there any differences between Pyomo Set and Python set?Pyomo Set 和 Python set 之间有什么区别吗?
【发布时间】:2019-02-06 00:40:38
【问题描述】:

这里是第一次使用pyomo的用户。

将优化模型中的集合声明为

model.A = Set(initialize = list_values) 

并使用像这样的内置 python 集?

A = set(list_values)

两者相比有什么优势吗?

【问题讨论】:

    标签: python python-3.x optimization pyomo


    【解决方案1】:

    首先可以通过以下方式调用约束规则中的模型变量、集合、参数:

    def some_constraint_rule(model):
        return model.some_set
    

    所以你不能通过 python 集做这样的事情,因为你在约束规则中输入的模型没有你的 python 集。

    其次你不能索引 python 集(到目前为止我知道,因此你需要一个 dict??),但是使用 pyomo 集,你可以做更多的事情,例如:

    m.t = pyomo.Set(
        within=m.index,
        initialize=something,
        ordered=True,
        doc='some documentation for your set?')
    

    【讨论】:

      猜你喜欢
      • 2016-03-26
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 2014-12-05
      • 2021-11-25
      • 2016-08-08
      • 2013-04-19
      • 1970-01-01
      相关资源
      最近更新 更多