gpt4 book ai didi

python - 当我运行 GEKKO 优化时,我得到了 'FileNotFoundError'

转载 作者:行者123 更新时间:2023-12-02 06:52:24 26 4
gpt4 key购买 nike

当我运行 GEKKO 优化时,我收到“FileNotFoundError”,请让我知道如何处理它。我的代码有问题吗?Y 是二元整数决策变量。

#initialize gekko
model = GEKKO(remote=False)
#APOPT is an Mixed Integer Nonlinear Problem solver
model.options.SOLVER = 1
model.time
#optional solver settings with APOPT
model.solver_options = ['minlp_maximum_iterations 500', \
# minlp iterations with integer solution
'minlp_max_iter_with_int_sol 10', \
# treat minlp as nlp
'minlp_as_nlp 0', \
# nlp sub-problem max iterations
'nlp_maximum_iterations 50', \
# 1 = depth first, 2 = breadth first
'minlp_branch_method 1', \
# maximum deviation from whole number
'minlp_integer_tol 0.05', \
# covergence tolerance
'minlp_gap_tol 0.01']

#parameter
X = total_PV_set
k = len(X)
eq = model.Param(value=len(X))
eq1 = model.Param(value=1)

#Decision Variable
# N = model.Var(value=1, lb=1, ub=k, integer=True)
N = 3
Y = model.Array(model.Var, (N, k), lb=0, ub=1, integer=True)
V = model.Array(model.Var, (N, 1))
W = model.Array(model.Var, (N, 1))
vary = model.Array(model.Var, (N, 1))
covary = model.Array(model.Var, (N, 1))

#Constraints
for i in range(N):
vary_buff = 0
for j in range(k):
vary_buff += model.Intermediate(variance(X[j]) * Y[i][j])
model.Equation(vary[i] == vary_buff)
for i in range(N):
covary_buff = 0
for j in range(k):
for e in range(k-1):
if j < (e+1):
covary_buff += model.Intermediate(2*covariance(X[j], X[e+1])*Y[i][j]*Y[i][e+1])
model.Equation(covary[i] == covary_buff)
for i in range(N):
model.Equation(V[i] == model.Intermediate(vary[i]+covary[i]))
for i in range(N):
model.Equation(W[i] == model.Intermediate(model.sum(Y[i][:])))
model.Equation(model.sum(Y) == eq)
for i in range(k):
model.Equation(model.sum(Y[:, i]) == eq1)


cc = model.Intermediate(model.sum([(W[i]*V[i]) for i in range(N)]))
model.Obj(cc/model.sum(W))

#minimize objective
# model.options.IMODE = 3
# model.options.MEAS_CHK = 0
model.solve()

#Print the results
print ('--- Results of the Optimization Problem ---')
print('Y: '+str(Y))
print('N: '+str(N))
print('V: '+str(V))
print('W: '+str(W))
print('Objective: '+str(model.options.objfcnval))

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 runfile('C:/Users/chldj/EOJIN/VPP_test.py', wdir='C:/Users/chldj/EOJIN') Backend TkAgg is interactive backend. Turning interactive mode on. C:/Users/chldj/EOJIN/VPP_test.py:91: DeprecationWarning: elementwise comparison failed; this will raise an error in the future. model.Equation(vary[i] == vary_buff) C:/Users/chldj/EOJIN/VPP_test.py:98: DeprecationWarning: elementwise comparison failed; this will raise an error in the future. model.Equation(covary[i] == covary_buff) C:/Users/chldj/EOJIN/VPP_test.py:100: DeprecationWarning: elementwise comparison failed; this will raise an error in the future. model.Equation(V[i] == model.Intermediate(vary[i]+covary[i])) C:/Users/chldj/EOJIN/VPP_test.py:102: DeprecationWarning: elementwise comparison failed; this will raise an error in the future. model.Equation(W[i] == model.Intermediate(model.sum(Y[i][:]))) ---------------------------------------------------------------- APMonitor, Version 0.9.2 APMonitor Optimization Suite ----------------------------------------------------------------

Error: Exception: Access Violation
At line 2391 of file custom_parse.f90
Traceback: not available, compile with -ftrace=frame or -ftrace=full
Error: 'results.json' not found. Check above for additional error details
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\pycharm\PyCharm Community Edition 2019.2.2\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\pycharm\PyCharm Community Edition 2019.2.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/chldj/EOJIN/VPP_test.py", line 114, in <module>
model.solve()
File "C:\python\lib\site-packages\gekko\gekko.py", line 2145, in solve
self.load_JSON()
File "C:\python\lib\site-packages\gekko\gk_post_solve.py", line 13, in load_JSON
f = open(os.path.join(self._path,'options.json'))
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\chldj\\AppData\\Local\\Temp\\tmpdgnw5ovqgk_model0\\options.json'

这是否意味着解是无穷大?我认为第一次迭代的 sum(W) 将是 0。因此它可以使目标函数“无穷大”。我该如何修复它?

最佳答案

函数 variancecovariance 不在 Gekko 库中。您需要删除这些函数并使用任何 Gekko 库函数。某些 Numpy 函数也允许进行矩阵运算,例如 numpy.dot 。您可以使用 Gekkonumpy 等函数的组合。

from gekko import GEKKO
import numpy as np
m = GEKKO()
A = m.Array(m.Var,(4,3))
b = m.Array(m.Param,3,value=1)
x = np.dot(A,b)
[m.Minimize(x[i]**2) for i in range(4)]
m.solve(disp=False)
print(A)

这是一个list of Gekko functions :

  • abs(x) 绝对值 |x|
  • abs2(x) MPCC 绝对值
  • abs3(x) 带二进制变量的绝对值开关
  • acos(x) 反余弦,cos^-1(x)
  • acosh(x) 反双曲余弦,cosh^-1(x)
  • Array(type,size) GEKKO 对象数组
  • arx自回归外生输入(时间序列)模型
  • asin(x) 反正弦,sin^-1(x)
  • asinh(x) 反双曲正弦,sinh^-1(x)
  • atan(x) 反正切,tan^-1(x)
  • atanh(x) 反双曲正切,tanh^-1(x)
  • bspline 2D 数据的 bspline
  • cos(x) 余弦
  • cspline 一维数据的三次样条
  • erf(x)误差函数
  • erfc(x)互补误差函数
  • exp(x) e^x
  • if3(cond,x1,x2) 在 x1 (cond<0) 和 x2 (cond>=0) 之间切换
  • log(x) log_e (x),自然对数
  • log10(x) log_10 (x),以 10 为底的对数
  • max2(x1,x2) MPCC 的最大值
  • max3(x1,x2) 开关二进制变量的最大值
  • min2(x1,x2) MPCC 最小值
  • min3(x1,x2) 开关二进制变量的最小值
  • periodic 动态问题的周期性(initial=final)
  • pwl 分段线性函数
  • sign2(x) 带有 MPCC 的符号运算符
  • sign3(x) 带有开关二进制变量的符号运算符
  • sin(x) 正弦
  • sinh(x) 双曲正弦
  • sqrt(x) 平方根
  • state_space 连续/离散和稠密/稀疏状态空间
  • sum 列表或 numpy 数组中元素的总和
  • tan(x) 正切
  • tanh(x) 双曲正切
  • vsum(x) 单个变量在数据方向上的垂直求和

函数库中没有诸如variancecovariance之类的其他函数。

关于python - 当我运行 GEKKO 优化时,我得到了 'FileNotFoundError',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60658075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com