我试图用GEKKO解决一个MINLP问题。我的代码类似于Gekko:MINLP-Error options.json文件中的代码。直到今天早上,它一直在完美地工作,似乎无法找到解决方案。我得到以下错误:(我正在Windows上工作)
回溯(最近一次调用):文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\urllib\request.py”,第 1350 行,在 do_open encode_chunked=req.has_header('Transfer- encoding')) 文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\http\client.py”,第 1277 行,在请求 self._send_request(method, url, body, headers, encode_chunked ) 文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\http\client.py”,第 1323 行,在 _send_request self.endheaders(body, encode_chunked=encode_chunked) 文件“C:\Users \Zineb\AppData\Local\Programs\Python\Python37\lib\http\client.py”,第 1272 行,在 endheaders self._send_output(message_body, encode_chunked=encode_chunked) 文件“C:\Users\Zineb\AppData\Local\ Programs\Python\Python37\lib\http\client.py”,第 1032 行,在 _send_output self.send(msg) 文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\http\client .py”,第 972 行,发送 self.connect() 文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\http\clie nt.py", line 944, in connect (self.host,self.port), self.timeout, self.source_address) 文件 "C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\socket .py”,第 728 行,在 create_connection 中引发错误文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\socket.py”,第 716 行,在 create_connection sock.connect(sa) TimeoutError 中: [WinError 10060] Une Tentative de connexion a échoué car le parti connecté n'a pas répondu convenablement au-delà d'une suree durée ou une connexion établie a échoué car l'hôte de connexion n'a 在上面的处理过程中异常,另一个异常发生:回溯(最近一次调用最后一次):文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\site-packages\gekko\gekko.py”,第 2190 行,在解决结果 = byte2str(get_file(self._server,self._model_name,'results.json')) 文件 "C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\site-packages\gekko\apm .py", line 154, in get_file ip = get_ip(server) File "C:\Users\Zineb\ AppData\Local\Programs\Python\Python37\lib\site-packages\gekko\apm.py”,第 144 行,在 get_ip f = urllib.request.urlopen(url_base) 文件“C:\Users\Zineb\AppData\Local \Programs\Python\Python37\lib\urllib\request.py", line 222, in urlopen return opener.open(url, data, timeout) File "C:\Users\Zineb\AppData\Local\Programs\Python\Python37 \lib\urllib\request.py”,第 525 行,打开 response = self._open(req, data) 文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\urllib\request. py", line 543, in _open '_open', req) 文件 "C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain result = func (*args) 文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\urllib\request.py”,第 1378 行,在 http_open 中 return self.do_open(http.client.HTTPConnection, req)文件“C:\Users\Zineb\AppData\Local\Programs\Python\Python37\lib\urllib\request.py”,第 1352 行,在 do_open 中引发 URLError(err) urllib.error.URLError:
这是我的密码:
import numpy as np
from gekko import GEKKO
# Define matrices A,A_eq, and vectors b, b_eq for the optimization
def Optimise_G(t,ob, jofbuses, q, qc, s, oa, k, l, T, G_next, C, Y, G_previous, G_max, G_min):
Mbig_1 = T*C
Mbig_2 = C
nb_phases = len(G_next)
b_max = len(t)
no_lanegroups = len(q)
A_eq = np.zeros(((nb_phases+1)*b_max + 1, (3*nb_phases+3)*b_max+nb_phases))
for i in range(nb_phases):
A_eq[0][i] = 1
B_eq = np.zeros((nb_phases+1)*b_max + 1)
B_eq[0] = C - sum(Y[0:nb_phases])
counter_eq = 0
# G(i)=Ga(i,b)+Gb(i,b)+Gc(i,b)
for b in range(b_max):
for i in range(nb_phases):
counter_eq = counter_eq + 1
A_eq[counter_eq][i] = 1
A_eq[counter_eq][nb_phases*(b+1)+ i] = -1
A_eq[counter_eq][nb_phases*b_max + nb_phases*(b+1) + i] = -1
A_eq[counter_eq][2*nb_phases*b_max + nb_phases*(b+1) + i] = -1
# ya(b)+y(b)+y(c)=1
for b in range(b_max):
counter_eq = counter_eq + 1
A_eq[counter_eq][3*nb_phases*b_max + nb_phases + b] = 1
A_eq[counter_eq][(3*nb_phases+1)*b_max + nb_phases + b] = 1
A_eq[counter_eq][(3*nb_phases+2)*b_max + nb_phases + b] = 1
B_eq[counter_eq] = 1
A = np.zeros((no_lanegroups + (2*3*nb_phases+4)*b_max, (3*nb_phases+3)*b_max+nb_phases))
B = np.zeros(no_lanegroups + (2*3*nb_phases+4)*b_max)
counter = -1
# Sum Gi (i in Ij)>=Gj,min
for j in range(no_lanegroups):
counter = counter + 1
for i in range(k[j], l[j]+1):
A[counter][i-1] = -1
B[counter] = -C*qc[j]/s[j]
# ya(b)G_lb(i)<=Ga(i,b), yb(b)G_lb(i)<=Gb(i,b), yc(b)G_lb(i)<=Gc(i,b)
for b in range(b_max):
for i in range(nb_phases):
counter = counter + 1
A[counter][nb_phases*(b+1)+i] = -1
A[counter][3*nb_phases*b_max + nb_phases + b] = G_min[i]
B[counter] = 0
counter = counter + 1
A[counter][nb_phases*b_max + nb_phases*(b+1) + i] = -1
A[counter][(3*nb_phases+1)*b_max + nb_phases + b] = G_min[i]
B[counter] = 0
counter = counter + 1
A[counter][2*nb_phases*b_max + nb_phases*(b+1) +i] = -1
A[counter][(3*nb_phases+2)*b_max + nb_phases + b] = G_min[i]
B[counter] = 0
# ya(b)Gmax(i)>=Ga(i,b), yb(b)Gmax(i)>=Gb(i,b), yc(b)Gmax(i)>=Gc(i,b)
for b in range(b_max):
for i in range(nb_phases):
counter = counter + 1
A[counter][nb_phases*(b+1) +i] = 1
A[counter][3*nb_phases*b_max + nb_phases + b] = -G_max[i]
B[counter] = 0
counter = counter + 1
A[counter][nb_phases*b_max + nb_phases*(b+1) + i] = 1
A[counter][(3*nb_phases+1)*b_max + nb_phases + b] = -G_max[i]
B[counter] = 0
counter = counter + 1
A[counter][2*nb_phases*b_max + nb_phases*(b+1) +i] = 1
A[counter][(3*nb_phases+2)*b_max + nb_phases + b] = -G_max[i]
B[counter] = 0
# (1-yc(b))t(b)<=(T-1)C+sum(Gi(1:l(jofbuses(b))))+sum(Y(1:l(jofbuses(b))-1))
for b in range(b_max):
counter = counter + 1
A[counter][0:l[jofbuses[b]-1]] = -np.ones((1,l[jofbuses[b]-1]))
A[counter][(3*nb_phases+2)*b_max+nb_phases+b] = -t[b]
B[counter] = -t[b] + (T-1)*C + sum(Y[0:l[jofbuses[b]-1]-1])
# (T-1)C+sum(Gi(1:l(jofbuses(b))))+sum(Y(1:l(jofbuses(b))-1))<=yc(b)t(b)+(1-yc(b))Mbig_1
for b in range(b_max):
counter = counter + 1
A[counter][0:l[jofbuses[b]-1]] = np.ones((1,l[jofbuses[b]-1]))
A[counter][(3*nb_phases+2)*b_max+nb_phases+b] = -t[b] + Mbig_1
B[counter] = Mbig_1 - (T-1)*C - sum(Y[0:l[jofbuses[b]-1]-1])
# -Mbig_2(1-yb(b))<=db(b)=right-hand side of Equation (6)
for b in range(b_max):
counter = counter + 1
constant = q[jofbuses[b]-1]/s[jofbuses[b]-1]*(t[b] - (T-1)*C + sum(G_previous[l[jofbuses[b]-1]:nb_phases]) + sum(Y[l[jofbuses[b]-1] -1:nb_phases]))+ (T-1)*C + sum(Y[0:k[jofbuses[b]-1]-1]) - t[b]
A[counter][0:k[jofbuses[b]-1]-1] = -np.ones((1,k[jofbuses[b]-1]-1))
A[counter][(3*nb_phases+1)*b_max + nb_phases + b] = Mbig_2
B[counter] = constant + Mbig_2
# db(b)<=Mbig_2 yb(b)
for b in range(b_max):
counter = counter + 1
constant = q[jofbuses[b]-1]/s[jofbuses[b]-1]*(t[b] - (T-1)*C +sum(G_previous[l[jofbuses[b]-1]:nb_phases]) + sum(Y[l[jofbuses[b]-1] -1:nb_phases]))+ (T-1)*C + sum(Y[0:k[jofbuses[b]-1]-1]) - t[b]
A[counter][0:k[jofbuses[b]-1]-1] = np.ones((1,k[jofbuses[b]-1]-1))
A[counter][(3*nb_phases+1)*b_max + nb_phases + b] = -Mbig_2
B[counter] = -constant
#Lower Bound LB
LB_zeros = np.zeros(3*b_max*(nb_phases+1))
G_min = np.array(G_min)
LB = np.append(G_min, LB_zeros)
#Upper Bound UB
UB = np.ones(3*b_max)
G_max = np.array(G_max)
for i in range(3*b_max+1):
UB = np.concatenate((G_max,UB))
xinit = np.array([(a+b)/2 for a, b in zip(UB, LB)])
sol = MINLP(xinit, A, B, A_eq, B_eq, LB ,UB, t, ob, jofbuses, q, qc, s, oa, k, l, T, G_previous, C, Y, G_previous)
def objective_fun(x, t, ob, jofbuses, q, qc, s, oa, k, l, T, G_next, C, Y, G_previous):
nb_phases = len(G_next)
b_max = len(t)
no_lanegroups = len(q)
obj = 0
obj_a = 0
obj_b = 0
G = x[0:nb_phases]
for j in range(no_lanegroups):
delay_a = 0.5*q[j]/(1-q[j]/s[j]) * (pow((sum(G_previous[l[j]:nb_phases]) + sum(G[0:k[j]-1]) + sum(Y[l[j]-1:nb_phases]) + sum(Y[0:k[j]-1])),2) + pow(sum(G[l[j]:nb_phases]) + sum(G_next[0:k[j]-1]) + sum(Y[l[j]-1:nb_phases]) + sum(Y[0:k[j]-1]),2))
obj = obj + oa*delay_a
obj_a = obj_a + oa*delay_a
for b in range(b_max):
delay_b1 = x[(3*nb_phases+1)*b_max + nb_phases + b]*(q[jofbuses[b]-1]/s[jofbuses[b]-1] * (t[b] - (T-1)*C + sum(G_previous[l[jofbuses[b]-1]:nb_phases]) + sum(Y[l[jofbuses[b]-1] -1:nb_phases])) + (T-1)*C - t[b] + sum(Y[0:k[jofbuses[b]-1]-1]))
delay_b2 = x[(3*nb_phases+2)*b_max + nb_phases + b-1]*(q[jofbuses[b]-1]/s[jofbuses[b]-1] * (t[b] - (T-1)*C - sum(Y[0:l[jofbuses[b]-1]-1])) + T*C + sum(G_next[0:k[jofbuses[b]-1]-1]) + sum(Y[0:k[jofbuses[b]-1]-1]) - t[b])
delay_b3 = sum(x[nb_phases*b_max + nb_phases*b:nb_phases*b_max + nb_phases*b+k[jofbuses[b]-1]-1]) - q[jofbuses[b]-1]/s[jofbuses[b]-1]*sum(x[2*nb_phases*b_max + nb_phases*b:2*nb_phases*b_max + nb_phases*b +l[jofbuses[b]-1]])
delay_b = delay_b1+delay_b2 +delay_b3
obj = obj + delay_b*ob[b]
obj_b = obj_b + delay_b*ob[b]
return obj
def MINLP(xinit, A, B, A_eq, B_eq, LB ,UB, t, ob, jofbuses, q, qc, s, oa, k, l, T, G_next, C, Y, G_previous):
nb_phases = len(G_next)
b_max = len(t)
m_APOPT = GEKKO(remote = True)
m_APOPT.options.SOLVER = 1 #(APOPT)
# Array Variable
rows = nb_phases + 3*b_max*(nb_phases+1)
x_initial = np.empty(rows,dtype=object)
x = np.empty(rows,dtype=object)
for i in range(3*nb_phases*b_max+nb_phases+1):
x[i] = m_APOPT.Var(value = x_initial[i], lb = LB[i], ub = UB[i], integer = False)
for i in range(3*nb_phases*b_max+nb_phases+1, (3*nb_phases+3)*b_max+nb_phases):
x[i] = m_APOPT.Var(value = x_initial[i], lb = LB[i], ub = UB[i], integer = True)
# Constraints
m_APOPT.axb(A,B,x,etype = '<=',sparse=False)
m_APOPT.axb(A_eq,B_eq,x,etype = '=',sparse=False)
# Objective Function
f = objective_fun(x, t, ob, jofbuses, q, qc, s, oa, k, l, T, G_next, C, Y, G_previous)
m_APOPT.Obj(f)
#Solver
m_APOPT.solve(disp = True)
return x
C = 60
T = 2
G_base = [15,18,8,7]
G_min = [7,7,7,7]
G_previous = [15,18,8,7]
Y = [3,2,3,3,1]
jofbuses = [1,2]
k = [1,1,4,5]
l = [1,1,5,7]
oa = 1.25
ob = [42,32]
t = [99, 104]
q = [176,68,80,8]
qc = [220,85,100,10]
s = [3600,3600,5400,5400]
nb_phases = len(G_base)
G_max = []
for i in range(nb_phases):
G_max.append(C - sum(Y[0:nb_phases]))
Optimise_G(t,ob, jofbuses, q, qc, s, oa, k, l, T, G_previous, C, Y, G_previous, G_max, G_min)
我也尝试了一个本地解决(远程=假),但我得到了以下错误:
错误:未找到results.json。检查上面的其他错误详细信息Traceback(最近的最后一次调用): File"stack_gekko.py", line 212, inOptimise_G(t, ob, jofbus, q, qc, s, oa, k, l, T,G_previous, C, Y,G_previous,G_max,G_min)File"stack_gekko.py,第133行,Optimise_Gsol=MINLP(sinit, A, B,A_eq,B_eq, LB, UB, t, ob, jofbus, q, qc, s, oa, k, l, T,G_previous, C, Y,G_previous)File"stack_gekko.py",第187行,在MINLPm_APOPT. Solutions(disp=True)文件"C:\用户\Zineb\AppData\本地\程序\Python\Python37\lib\site-包\gekko\gekko.py",第2222行,在解决self.load_JSON()文件"C:\用户\Zineb\AppData\本地\程序\Python\Python37\lib\site-包\gekko\gk_post_solve.py",第13行,load_JSONf=open(os.path.join(_path,'options.json'))FileNotFoundError:[Errno 2]No this file or目录:'C:\用户\Zineb\AppData\本地\Temp\tmp2dgyi354gk_model0\options.json'
非常感谢你的帮助!
当用于远程解决这些问题的服务器崩溃或脱机时,会发生这种情况。我最近也有同样的问题。
解决这个问题最简单的方法是将您的模型切换到本地解决,而不是远程解决。
m = GEKKO(remote=False)
另一个选择是切换到使用不同的服务器,如果你可以访问一个或设置一个。默认服务器http://byu.apmonitor.com/,但您可以按照说明在Windows或Linux上设置自己的服务器。
m = GEKKO(server="server address here")
接口通用问题解决方案 通用错误码,错误信息及解决方案 400(非法的client_id) 400(非法的client_secret) 402(未传当前用户手机号) 402(手机号不合法) 403,10002(IP不在白名单中,本次请求ip:xxx.xxx.xxx.xxx) 403(无权访问该接口) 406(该用户不存在,请管理员添加后再使用) 408(未传timestamp或者timestamp格
本章内容包含常见错误码及错误信息描述,并给出解决问题的步骤。如果在开发过程中遇到报错,请先在本章中搜索解决方案,谢谢! 通用错误码,错误信息及解决方案 400(非法的client_id) client_id是否正确填写 client_id对应的申请应用是否通过审核 400(非法的client_secret) client_secret是否和client_id对应,有可能client_id是A应用的
本文向大家介绍解决“无法启动mysql服务 错误1069”的方法,包括了解决“无法启动mysql服务 错误1069”的方法的使用技巧和注意事项,需要的朋友参考一下 今天还在路上的时候,同事就发来消息,说网站后台无法访问了,那个急啊! 赶到公司,登陆服务器,正常,还好,看来不是服务器自身的问题,看错误提示,应该是mysql的问题了。 到服务选项里已查看,果然,未启动状态,启动MYSQL的时候提示错误
本文向大家介绍Nginx服务器中414错误和504错误的配置解决方法,包括了Nginx服务器中414错误和504错误的配置解决方法的使用技巧和注意事项,需要的朋友参考一下 414 Request-URI Too Large 当http 的URI太长或者request header过大时会报414 Request URI too large或400 bad request错误。 可能原因 场景1.c
现在我正在尝试从git运行克隆应用程序https://github.com/frinder/frinder-app但问题是该应用程序制作了很长时间,所以应该改变bulid.gradle 但是当我尝试相同的同步实现“com.android.支持:动画矢量可绘制:28.0.0”,但如果我删除它,请继续向我显示错误28.0.0它显示如下 但我不知道是什么造成了不完全相同的版本 这是应用程序build.g
我有一个问题已经一个月了,但我没有找到解决办法。我的笔记本电脑和个人电脑都有这些问题(我以前启动过mongod): 错误:无法连接到服务器 127.0.0.1:27017 src/mongo/shell/mongo.js:91 异常:连接失败 错误:无法连接到服务器127.0.0.1:27017 src/mongo/shell/mongo。js:93异常:连接失败 错误:无法连接到服务器127.0