- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的优化需要几个小时才能在高性能服务器上解决。我想将解决方案保存到磁盘,然后在我的笔记本电脑上将它们重新加载到模型实例中。这将使我能够在 python 命令行中以交互方式探索结果,并开发或测试新编写的导出代码。 pyomo 库有很多函数可以将数据转储到磁盘,但没有提供将数据加载回不同运行时环境的明确解决方案。
我理想的解决方案是在加载解决方案后对实例进行 pickle,以便它封装输入、解决方案和整个运行时状态。不幸的是,该实例附加了不可 pickle 的方法,pyomo 团队还没有编写自定义 pickle 函数。 2015 forum thread 中建议的解决方法是腌制结果对象。结果对象在 v5.1.1 中默认没有加载解决方案,但是 another post解释了如何解决这个问题。
我设法拼凑出一个适用于 pyomo v5.1.1 的解决方案,但想知道是否有更好的方法。
# ...Define abstract model
# ...Load data from input directory and create model instance
# Solve, get a results object that only contains execution metadata
results = opt.solve(instance)
# Load solution data into results object
instance.solutions.store_to(results)
# Archive results: solution & execution metadata
pickle.dump(results, open("results.pickle", "wb"))
...将代码、输入目录和 results.pickle 文件从服务器同步到我的笔记本电脑。
# ...Define abstract model
# ...Load data from input directory and create model instance
# Load results from pickle: metadata & solution
results = pickle.load(open("results.pickle", "wb"))
# Load solution data into instance object
instance.solutions.load_from(results)
最佳答案
如 this question 中所述,一个解决方案是使用 cloudpickle
来 pickle 实例:
import cloudpickle
with open('test.pkl', mode='wb') as file:
cloudpickle.dump(instance, file)
with open('test.pkl', mode='rb') as file:
instance = cloudpickle.load(file)
我做了一些基本测试,上面的内容似乎恢复了实例以及预期的结果。
关于pyomo - 如何保存 Pyomo 解决方案并重新加载到单独的运行时环境中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47212921/
我刚开始使用 Pyomo,我一直无法弄清楚如何编写双重求和代码。类似于 this . 有人可以给我提示吗?谢谢你们的帮助!! 最佳答案 假设您的模型声明如下: m = ConcreteModel()
我的优化需要几个小时才能在高性能服务器上解决。我想将解决方案保存到磁盘,然后在我的笔记本电脑上将它们重新加载到模型实例中。这将使我能够在 python 命令行中以交互方式探索结果,并开发或测试新编写的
我正在尝试从我的 pyomo 模型中输出目标值。我确实访问了变量值,但无法访问目标函数值。我的代码是: instance = model.create_instance(data) opt =
我不想在程序变量中设置初始值和对偶值。有没有具体的方法来做到这一点。我可以看到 Var 对象中有一个初始化选项,但我不确定如何以这种方式使用它 最佳答案 如果要在声明变量时设置变量的值,可以使用ini
我正在努力寻找一种有效的方法来检索优化问题的解决方案。该解决方案包含大约 200K 个变量,我希望在 pandas DataFrame 中使用这些变量。在网上搜索后,我发现访问变量的唯一方法是通过一个
我正在尝试使用 ANTIGONE 求解器(在 GAMS 中获得许可)解决 MINLP 问题,但我很难更改求解器的高级设置。 首先,我按如下方式从 Pyomo 调用求解器。 solver = pe.So
我尝试使用 pip 中的附加功能安装 pyomo,并使用后来的 Conda。一切都显示正常,但当我尝试使用它时,我收到以下错误。 from pyomo.environ import * 文件“C:..
我注意到 Pyomo 5.3 提供了一个 GAMS 求解器插件。 https://github.com/Pyomo/pyomo/blob/master/pyomo/solvers/plugins/so
我写信是因为我在安装时遇到问题 Pyomo使用 pip在 Mac OSX 10.14 上的 Python 3.6 我正在按照安装说明进行操作 here . 我可以成功执行第一个命令: pip inst
我对新算法有疑问,在这里我展示我的代码以便更好地理解它。 import pyomo.environ from pyomo.core import * from pyomo.opt import Sol
我正在使用 pyomo 构建许多模型,据我了解,pyomo 在求解模型之前会重新制定模型。 我想确切地知道模型在传递给求解器文件 ipopt 和 couenne 时是什么样子。 据我所见here我不清
我正在尝试将使用 CPLEX 求解器在 GAMS 中编写的模型传输到 Pyomo。 CPLEX 具有允许建模者在模型不可行时放宽约束和决策变量的功能 - FeasOpt(适用于可行优化)。我无法在 P
我是 Pyomo 的新手,我想知道如何更改具有一个或多个索引的现有模型参数的值。 我看过一些标量参数的例子,即没有索引。例如: model5 = ConcreteModel() model5.data
我有一个相当大的模型(大约 500 万个变量和约束)。 构建时间是几分钟,求解时间也是几分钟(使用 gurobi) 但是写模型需要很长时间(大约2小时) 这是我使用 model.write('mode
我正在尝试将一些数据转化为 PYOMO 模型以解决优化问题。 materials = ['steel', 'alum', 'carbon', 'cheese'] 每种 Material 都有 2 个属
我的脚本是: from __future__ import division import numpy import scipy from pyomo.environ
我在 Pyomo 中构建了一个抽象模型,效果很好。 但是,当我尝试使用字典来实例化抽象模型时,出现以下错误“错误:为目标值生成表达式时规则失败: RuntimeError:无法在抽象集“I”之前迭代
我一直在使用 Gurobi 来解决 MILP 问题,并使用 Pyomo 来生成模型。 Gurobi 支持返回一个解决方案池,我希望能够使用这个池生成多个解决方案。这在 Pyomo 中支持吗? 我试过使
Pyomo 中多目标优化的任何示例吗? 我正在尝试最小化 4 个目标(非线性),并且我想使用 pyomo 和 ipopt。还可以访问古罗比。 我想看一个非常简单的例子,我们尝试优化一系列决策变量(不仅
以下是我尝试运行的优化代码的一部分。 from pyomo.environ import * model = ConcreteModel() ## Define sets model.k = Set(
我是一名优秀的程序员,十分优秀!