具体模型阅读 xlsx 文档 Pyomo
Concrete Model reading xlsx document Pyomo
我目前正在研究具体模型,但是,由于参数大小,以这种形式编写将近 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
DataFrame
创建 Param
对象 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**])
我目前正在研究具体模型,但是,由于参数大小,以这种形式编写将近 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
DataFrame
创建 Param
对象 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**])