如何知道GEKKO花了多长时间来解决我的模型?

2024-04-29 00:48:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我怎样才能从GEKKO那里得到解决我的模型需要多长时间的结果?根据Measure time elapsed in Python,我知道我可以让我的代码打印运行代码所花费的总时间,但我不知道如何隔离解算器时间

from gekko import GEKKO
import time
start = time.time()
m = GEKKO(remote=False)
x = m.Var(value=0)
y = m.Var(value=1)
m.Equations([x + 2*y==0, x**2+y**2==1])
s1 = time.time()
m.solve(disp=True)
e1 = time.time()
print([x.value[0],y.value[0]])
end = time.time()
print('Total Elapsed: ' + str(end-start))
print('Solver Time 1: ' + str(e1-s1))

解算器时间1列为0.18468秒,但这不同于IPOPT报告的时间0.0156秒。如何以编程方式获取解算器报告的时间

EXIT: Optimal Solution Found.

 The solution was found.

 The final value of the objective function is  0.

 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :  0.0156 sec

Tags: 代码importtimevaluevar时间startend
1条回答
网友
1楼 · 发布于 2024-04-29 00:48:26

您可以使用m.options.SOLVETIME查看解算器报告的时间,例如:

print('Solver Time 2: ', m.options.SOLVETIME)

Solver Time 1包括设置和解决方案传输。您可以通过不使用disp=False显示解算器输出并在本地而不是在远程服务器上使用remote=False进行解算来加快总时间。本地解算通常可以减少发送到服务器和检索解算所需的时间,但使用本地解算的解算器选项较少

相关问题 更多 >