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

How to know how long GEKKO took to solve my model?

如何从 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

您可以看到求解器报告的时间 m.options.SOLVETIME 例如:

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

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