我目前正在研究具体模型,但是,由于参数大小,用这种形式编写近 200 个参数似乎非常困难:
model.time = Param(model.WORKS, model.MODELS, initialize={(1,1):2, (2,1):1, (3,1):4, (4,1):2, (5,1):3, (6,1):3, (7,1):1, (8,1):2, (1,2):1, (2,2):2, (3,2):1, (4,2):3, (5,2):3, (6,2):2, (7,2):1, (8,2):1.....})
这只是参数之一。 我想从 xls 文档中读取表格,如下所示:
data.load(filename="excel.xlsx", range="Btable", format='set', set='B')
由于字典和具体公式的数量,将模型转化为抽象模型非常困难。
请知道如何做?提前致谢。
最佳答案
这绝对是你能够做到的事情。 Bill Hart 比我更熟悉 Pyomo 提供的 DataPortal
界面。
我个人会使用 pandas
导入 Excel 数据,然后编写一个函数(规则)来使用 pandas
创建 Param
DataFrame
对象xls_data
:
xls_data = pandas.read_excel(**see pandas documentation**)
print(xls_data) # This can help with debugging
@model.Param(model.WORKS, model.MODELS)
def time(m, wrks, mods):
return float(xls_data[**appropriate index from pandas**])
关于python - 具体模型阅读 xlsx 文档 Pyomo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51733113/