首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从IPOPT显示器Pyomo中获取值

从IPOPT显示器Pyomo中获取值
EN

Stack Overflow用户
提问于 2018-12-13 05:20:32
回答 1查看 685关注 0票数 1

这是我的罗森布罗克模型的代码。

代码语言:javascript
复制
from pyomo.environ import *
from pyomo.opt import SolverFactory
import numpy as np
import math
import statistics
import time

m = ConcreteModel()

m.x = Var()
m.y = Var()
m.z = Var()

def rosenbrock(model):
    return (1.0-m.x)2 + 100.0*(m.y - m.x2)2 + (1.0-m.y)2 + 100.0*(m.z - m.y2)2

m.obj = Objective(rule=rosenbrock, sense=minimize)

dist = 0.0
xval = yval = zval = error = times = []
for i in range(50):
    m.x = np.random.uniform(low=-5.0, high=5.0)
    m.y = np.random.uniform(low=-5.0, high=5.0)
    m.z = np.random.uniform(low=-5.0, high=5.0)
    solver = SolverFactory('ipopt')
    t1 = time.time()
    results = solver.solve(m, tee=True)

当传递solver.solve行时,tee=True会打印出各种精美信息的漂亮显示。我希望从打印输出中访问这些信息,并且已经浏览了Pyomo和IPOPT文档,并且似乎无法理解如何访问打印到屏幕上的值。我还提供了一个打印输出的简短示例,我希望保存每次运行中的值,以便可以迭代和收集整个范围的统计信息。

代码语言:javascript
复制
Number of nonzeros in equality constraint Jacobian...:        0
Number of nonzeros in inequality constraint Jacobian.:        0
Number of nonzeros in Lagrangian Hessian.............:        5

Total number of variables............................:        3
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
Total number of inequality constraints...............:        0
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

*省略*

代码语言:javascript
复制
Number of objective function evaluations             = 45
Number of objective gradient evaluations             = 23
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 0
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations             = 22
Total CPU secs in IPOPT (w/o function evaluations)   =      0.020
Total CPU secs in NLP function evaluations           =      0.000

我需要这些值中的一些,但我发现没有任何可行的接口可以通过我对文档的搜索来访问它们,任何向导都知道如何做到这一点?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-13 17:31:44

参见这个Ipopt解决器包装,它是对Pyomo的贡献。它本质上是Ipopt输出日志的解析器,您应该能够对它进行泛化/扩展,以收集当前未收集的任何值。

wrapper.py

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53755397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档