简体   繁体   English

保存Pyomo模型变量

[英]Save Pyomo model Variable

I'm doing an optimization problem and after give the command: 我正在做一个优化问题,并给出命令后:

results = solver.solve(model,tee=True)

I will have all my variables solved inside the model object. 我将在模型对象内部解决所有变量。

There is a way to save and load this model object? 有没有一种方法可以保存和加载此模型对象?

The variables will be inside your "model" object, if you have a variable called "A": 如果您有一个名为“ A”的变量,则这些变量将在“模型”对象内:

model.A.value

will give you its value (or model.A[index].value if it is indexed) 将为您提供其值(如果已建立索引,则为model.A [index] .value)

  • If you just want to use the results later in your code just call the value when needed (as shown above) 如果您只想稍后在代码中使用结果,则在需要时调用该值(如上所示)
  • If you want to save them for later The best is to have a function that exports the results towards dictionaries, panda dataframes, and then you can save to txt, csv or excel files using pickle or pandas for excel. 如果要保存它们以备后用,最好的方法是将结果导出到字典,熊猫数据框,然后可以使用pickle或pandas保存为txt,csv或excel文件。
  • You can also save your entire model to a file using "cloudpickle" (it will however not work if you try to open it with a too different environment) 您也可以使用“ cloudpickle”将整个模型保存到文件中(但是,如果尝试在过于不同的环境中打开它,则将无法使用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM