当我运行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'
这是否意味着解是无穷大的? 我认为第一次迭代的和(W)将是0。因此,它可以使目标函数“无穷大”。 我怎样才能修好它
函数
variance
和covariance
不在Gekko库中。您需要删除这些函数,而不是使用任何Gekko库函数。一些Numpy函数也允许用于矩阵运算,如numpy.dot
。您可以使用函数的组合,例如fromGekko
和numpy
这是一个list of Gekko functions:
abs(x)
绝对值| x |abs2(x)
带MPCC的绝对值abs3(x)
开关用二进制变量的绝对值acos(x)
反余弦,cos^-1(x)Array(type,size)
GEKKO对象数组arx
自回归外生投入(时间序列)模型atan(x)
反切线,tan^-1(x)bspline
用于二维数据的bsplinecos(x)
余弦erf(x)
错误函数erfc(x)
互补误差函数exp(x)
e^xif3(cond,x1,x2)
在x1(cond<;0)和x2(cond>;=0)之间切换log(x)
log_e(x),自然对数log10(x)
log_10(x),log base 10max2(x1,x2)
MPCC的最大值max3(x1,x2)
开关二进制变量的最大值min2(x1,x2)
具有MPCC的最小值min3(x1,x2)
开关二进制变量的最小值pwl
分段线性函数sign3(x)
带二进制变量的signum运算符用于开关sin(x)
正弦sinh(x)
双曲正弦sqrt(x)
平方根state_space
连续/离散和稠密/稀疏状态空间sum
列表或numpy数组中元素的总和tan(x)
切线tanh(x)
双曲正切vsum(x)
数据方向上单个变量的垂直和其他函数如
variance
和covariance
不在函数库中相关问题 更多 >
编程相关推荐