简体   繁体   English

不可行性,未找到解决方案 - Gekko 错误

[英]Infeasibilities, Solution Not Found - Gekko Error

I'm Arthur.我是亚瑟。 I'm very new to gekko, thus I might be missing something very obvious here.我对gekko很陌生,因此我可能在这里遗漏了一些非常明显的东西。

I have been trying to find the solution to an optimal control problem, namely trajectory optimization of a spacecraft rendezvous problem (Chaser -> Target), under certain final constraints to the relative final distance and velocity and certain distance along their trip.我一直在努力寻找最优控制问题的解决方案,即航天器交会问题的轨迹优化(追赶者 - >目标),在相对最终距离和速度以及他们行程的特定距离的某些最终约束下。 In order to do this, I tried using soft constraints to the final path.为此,我尝试对最终路径使用软约束。 As a objective function, I use a norm 1 of the force generated from Thrusters.作为目标 function,我使用推进器产生的力的范数 1。

The computation keeps going until the maximum no.计算一直进行到最大数。 of iterations (2000) is reached and cancels.迭代次数 (2000) 已达到并取消。 Is there maybe a way to discretize the search space of this problem to make it solvable in acceptable time trading off computation time for accuracy?有没有办法离散化这个问题的搜索空间,使其在可接受的时间内解决,以牺牲计算时间来换取准确性?

import matplotlib.pyplot as plt
import numpy as np

from gekko import GEKKO

# create GEKKO model
m = GEKKO()
print(m.path)
nt = 501
m.time = np.linspace(0,500,nt)

# Variables

# Initial Position and Velocity - Chaser
r1_c = -1182.339411   # [km] 
r2_c = 6816.939420    # [km] 
r3_c = 904.891745     # [km] 
v1_c = 0.1175776      # [km/s] 
v2_c = -0.963776      # [km/s] 
v3_c = 7.494102       # [km/s] 

# Initial Position and Velocity - Target
r1_t = -1182.959348    # [km] 
r2_t = 6817.396210     # [km] 
r3_t = 904.495486      # [km] 
v1_t = 0.1175776       # [km/s] 
v2_t = -0.963776       # [km/s] 
v3_t = 7.494102        # [km/s] 

# initial values
x =  m.Var(value = r1_c)
y =  m.Var(value = r2_c)
z =  m.Var(value = r3_c)
vx =  m.Var(value = v1_c)
vy =  m.Var(value = v2_c)
vz =  m.Var(value = v3_c)


# initial values
x2 =  m.Var(value = r1_t)
y2 =  m.Var(value = r2_t)
z2 =  m.Var(value = r3_t)
vx2 =  m.Var(value = v1_t)
vy2 =  m.Var(value = v2_t)
vz2 =  m.Var(value = v3_t)

# Cost Initial - Integrated thrust (fuel usage)
J =  m.Var(value = 0)

# Manipulated Variable
U = m.MV(value=0, lb=-0.001, ub=0.001)

U.STATUS = 1

# Mask time
p = np.zeros(nt) # mask final time point
p[-1] = 500
final = m.Param(value=p)

# Parameters
RT =  m.Const(6378.139);            # [km] 
mu_t = m.Const(3.9860064*10**(5))   # [km^3/s^2] 


# Equations

# Define intermediate quantities - Chaser
Rc = m.Intermediate((x**2 + y**2 + z**2)**0.5)
v = m.Intermediate((vx**2 + vy**2 + vz**2)**0.5)

ax = m.Intermediate(x * -mu_t / Rc**3 + U *vx / v )
ay = m.Intermediate(y * -mu_t / Rc**3 + U *vy / v )
az = m.Intermediate(z * -mu_t / Rc**3 + U *vz / v )


# Define intermediate quantities - Target
Rt = m.Intermediate((x2**2 + y2**2 + z2**2)**0.5)
v2 = m.Intermediate((vx2**2 + vy2**2 + vz2**2)**0.5)

ax2 = m.Intermediate(x2 * -mu_t / Rt**3 )
ay2 = m.Intermediate(y2 * -mu_t / Rt**3 )
az2 = m.Intermediate(z2 * -mu_t / Rt**3 )


# Governing equations
m.Equations((vx.dt() == ax, vy.dt() == ay, vz.dt() == az))
m.Equations((x.dt() == vx, y.dt() == vy, z.dt() == vz))

m.Equations((vx2.dt() == ax2, vy2.dt() == ay2, vz2.dt() == az2))
m.Equations((x2.dt() ==  vx2, y2.dt() ==  vy2, z2.dt() == vz2))

# Equation relating thrust to fuel usage
m.Equation(J.dt() == m.abs2(U))


# Path Constraints

# specify endpoint conditions

m.fix(x, pos=len(m.time)-1, val=x2)
m.fix(y, pos=len(m.time)-1, val=y2)
m.fix(z, pos=len(m.time)-1, val=z2)
m.fix(vx, pos=len(m.time)-1, val=vx2)
m.fix(vy, pos=len(m.time)-1, val=vy2)
m.fix(vz, pos=len(m.time)-1, val=vz2)

# Constraints 

m.Equations((m.abs2(Rc - RT) > 200, m.abs2(Rc - RT) < 1000, m.abs2(Rc*final - Rt*final) == 0, m.abs2(v*final - v2*final) == 0))


# Objective, minimizing fuel usage
m.Obj(J * final)

# Set solver mode - Optimal Control
m.options.IMODE = 6

# Increase maximum number of allowed iterations
m.options.MAX_ITER = 2000

# Set number of nodes per time segment
m.options.NODES = 3

# Run solver and display progress
m.solve(disp=True)
---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :    3663.92820000000      sec
 Objective      :    185346862893.104     
 Unsuccessful with error code            0
 ---------------------------------------------------
 
 Creating file: infeasibilities.txt
 Use command apm_get(server,app,'infeasibilities.txt') to retrieve file
 @error: Solution Not Found
---------------------------------------------------------------------------

It does not find the solution and I do not find the file infeasibilities.txt .它没有找到解决方案,我也没有找到文件infeasibilities.txt

Can you help me please?你能帮我吗?

I would like to find the reason from results (Solution Not Found).我想从结果中找到原因(未找到解决方案)。 However someone can help me with structure of the problem becoming it feasible.但是,有人可以帮助我解决问题的结构,使其变得可行。

One infeasible set of constraints is that Rc-RT is set to >200 and <1000 everywhere, but it must also equal zero at the final time.一组不可行的约束是Rc-RT在所有地方都设置为>200<1000 ,但它在最后时刻也必须等于 0。 The solver can't satisfy these constraints.求解器无法满足这些约束。

m.abs2(Rc - RT) > 200
m.abs2(Rc - RT) < 1000
m.abs2(Rc*final - Rt*final) == 0

I recommend replacing these constraints with something that is numerically simple with the definition of a new variable with upper and lower bounds and the **2 to avoid sqrt() and abs() .我建议将这些约束替换为在数值上简单的东西,即定义一个具有上限和下限的新变量以及**2以避免sqrt()abs()

RcRT = m.Var(lb=200,ub=1000)
m.Equation(RcRT**2 == (Rc-RT)**2)

The MPCC m.abs2() does not work very well for most problems. MPCC m.abs2()不能很好地解决大多数问题。 m.abs3() works better, but can take more time to solve as a mixed integer form. m.abs3()效果更好,但可能需要更多时间来解决混合 integer 形式。 Try to avoid the use of abs() in the model, when there is an alternative.当有替代方法时,尽量避免在 model 中使用abs() Equations such as m.abs2(v*final - v2*final) == 0 will have no solution if the Chaser is not able to match the velocity of the Target.如果 Chaser 无法匹配 Target 的速度,诸如m.abs2(v*final - v2*final) == 0等方程式将无解。 Try a different soft constraint (objective-based) that allows the problem to remain feasible and minimize the difference.尝试不同的软约束(基于目标),使问题保持可行并最小化差异。

m.Minimize(final*(v-v2)**2)

Likewise, these hard constraints may be infeasible:同样,这些硬约束可能是不可行的:

# hard constraints
m.fix(x, pos=len(m.time)-1, val=x2)
m.fix(y, pos=len(m.time)-1, val=y2)
m.fix(z, pos=len(m.time)-1, val=z2)
m.fix(vx, pos=len(m.time)-1, val=vx2)
m.fix(vy, pos=len(m.time)-1, val=vy2)
m.fix(vz, pos=len(m.time)-1, val=vz2)

Try soft constraints:尝试软约束:

# soft constraints
m.Minimize(final*(v-v2)**2)
m.Minimize(final*(x-x2)**2)
m.Minimize(final*(y-y2)**2)
m.Minimize(final*(z-z2)**2)
m.Minimize(final*(vx-vx2)**2)
m.Minimize(final*(vy-vy2)**2)
m.Minimize(final*(vz-vz2)**2)    

Here is the complete problem:这是完整的问题:

import matplotlib.pyplot as plt
import numpy as np

from gekko import GEKKO

# create GEKKO model
m = GEKKO()
print(m.path)
nt = 101
m.time = np.linspace(0,500,nt)

# Variables

# Initial Position and Velocity - Chaser
r1_c = -1182.339411   # [km] 
r2_c = 6816.939420    # [km] 
r3_c = 904.891745     # [km] 
v1_c = 0.1175776      # [km/s] 
v2_c = -0.963776      # [km/s] 
v3_c = 7.494102       # [km/s] 

# Initial Position and Velocity - Target
r1_t = -1182.959348    # [km] 
r2_t = 6817.396210     # [km] 
r3_t = 904.495486      # [km] 
v1_t = 0.1175776       # [km/s] 
v2_t = -0.963776       # [km/s] 
v3_t = 7.494102        # [km/s] 

# initial values
x =  m.Var(value = r1_c)
y =  m.Var(value = r2_c)
z =  m.Var(value = r3_c)
vx =  m.Var(value = v1_c)
vy =  m.Var(value = v2_c)
vz =  m.Var(value = v3_c)


# initial values
x2 =  m.Var(value = r1_t)
y2 =  m.Var(value = r2_t)
z2 =  m.Var(value = r3_t)
vx2 =  m.Var(value = v1_t)
vy2 =  m.Var(value = v2_t)
vz2 =  m.Var(value = v3_t)

# Cost Initial - Integrated thrust (fuel usage)
J =  m.Var(value = 0)

# Manipulated Variable
U = m.MV(value=0, lb=-0.001, ub=0.001)
U.STATUS = 1

# Mask time
p = np.zeros(nt) # mask final time point
p[-1] = 500
final = m.Param(value=p)

# Parameters
RT =  m.Const(6378.139);            # [km] 
mu_t = m.Const(3.9860064*10**(5))   # [km^3/s^2] 

# Equations

# Define intermediate quantities - Chaser
Rc = m.Intermediate((x**2 + y**2 + z**2)**0.5)
v = m.Intermediate((vx**2 + vy**2 + vz**2)**0.5)

ax = m.Intermediate(x * -mu_t / Rc**3 + U *vx / v )
ay = m.Intermediate(y * -mu_t / Rc**3 + U *vy / v )
az = m.Intermediate(z * -mu_t / Rc**3 + U *vz / v )

# Define intermediate quantities - Target
Rt = m.Intermediate((x2**2 + y2**2 + z2**2)**0.5)
v2 = m.Intermediate((vx2**2 + vy2**2 + vz2**2)**0.5)

ax2 = m.Intermediate(x2 * -mu_t / Rt**3 )
ay2 = m.Intermediate(y2 * -mu_t / Rt**3 )
az2 = m.Intermediate(z2 * -mu_t / Rt**3 )


# Governing equations
m.Equations((vx.dt() == ax, vy.dt() == ay, vz.dt() == az))
m.Equations((x.dt() == vx, y.dt() == vy, z.dt() == vz))

m.Equations((vx2.dt() == ax2, vy2.dt() == ay2, vz2.dt() == az2))
m.Equations((x2.dt() ==  vx2, y2.dt() ==  vy2, z2.dt() == vz2))

# Equation relating thrust to fuel usage
#m.Equation(J.dt() == m.abs2(U))
m.Equation(J.dt()**2 == U**2)


# Path Constraints

# specify endpoint conditions
# soft constraints
m.Minimize(final*(v-v2)**2)
m.Minimize(final*(x-x2)**2)
m.Minimize(final*(y-y2)**2)
m.Minimize(final*(z-z2)**2)
m.Minimize(final*(vx-vx2)**2)
m.Minimize(final*(vy-vy2)**2)
m.Minimize(final*(vz-vz2)**2)    

# Constraints 
# m.abs2(Rc - RT) > 200
# m.abs2(Rc - RT) < 1000
# m.abs2(Rc*final - Rt*final) == 0
RcRT = m.Var(lb=200,ub=1000)
m.Equation(RcRT**2 == (Rc-RT)**2)

# Objective, minimizing fuel usage
m.Minimize(J * final)

# Set solver mode - Optimal Control
m.options.IMODE = 6

# Increase maximum number of allowed iterations
m.options.MAX_ITER = 2000

# Set number of nodes per time segment
m.options.NODES = 3

# Run solver and display progress
m.solve(disp=True)

IPOPT finds an optimal solution after 1375 iterations with a reduced the number of time points to 101 for testing. IPOPT 在 1375 次迭代后找到了一个最优解,测试的时间点数量减少到 101 个。 You can try to increase the number of time points and resolve.您可以尝试增加时间点的数量并解决。

1375 -1.3996401e+02 2.04e-09 8.64e-07 -10.5 1.61e-06    -  1.00e+00 1.00e+00h  1
Number of Iterations....: 1375
                                   (scaled)                 (unscaled)
Objective...............:  -4.4944986703206206e-03   -1.3996401074391898e+02
Dual infeasibility......:   8.6432001202008113e-07    2.6915948656834957e-02
Constraint violation....:   7.7449958484773991e-10    2.0372681319713593e-09
Complementarity.........:   3.3628245954861400e-11    1.0472233998435268e-06
Overall NLP error.......:   8.6432001202008113e-07    2.6915948656834957e-02

Number of objective function evaluations             = 1974
Number of objective gradient evaluations             = 1149
Number of equality constraint evaluations            = 1982
Number of inequality constraint evaluations          = 1982
Number of equality constraint Jacobian evaluations   = 1389
Number of inequality constraint Jacobian evaluations = 1389
Number of Lagrangian Hessian evaluations             = 1375
Total CPU secs in IPOPT (w/o function evaluations)   =     83.311
Total CPU secs in NLP function evaluations           =    112.375

EXIT: Optimal Solution Found.
 The solution was found.
 The final value of the objective function is   -139.964010743919     
 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :    199.320599999999      sec
 Objective      :   -139.964010743919     
 Successful solution
 ---------------------------------------------------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gekko 错误:2 和 -13 显示未找到解决方案 - Gekko error: 2 and -13 showing no solution found 如何修复 Python GEKKO 最优控制代码中的“Solution Not Found”错误 - How to Fix "Solution Not Found" Error in Python GEKKO Optimal Control Code 使用 gekko 进行优化时返回“@Error:未找到解决方案” - '@Error: Solution not found' being returned when using gekko for optimization 如何从 Gekko 中检索“infeasibilities.txt” - How to retrieve the 'infeasibilities.txt' from the gekko 使用 Gekko 的最优控制问题:“未找到解决方案” - Optimal control problem using Gekko: “Solution Not Found” Gekko错误“未找到结果文件。 APM没有找到解决方案或服务器无法访问“ - Gekko error “ Results files not found. APM did not find a solution or the server is unreachable” 在更改参数、目标 function 和初始条件时使用 Gekko 优化套件出现“未找到解决方案”错误 - “Solution Not Found” error using Gekko optimization suite when changing parameters, objective function, and initial condition GEKKO - 超时错误 - ImportError: No solution or server unreachable - GEKKO - timeout error - ImportError: No solution or server unreachable Gekko:获得的解决方案有问题 - Gekko: Problem with the obtained solution Gekko 求解器不提供任何解决方案 - Gekko solver offers no solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM