有没有办法同时优化时间和路径?

Is there any way to optimize time and path simultaneously?

我在时间和路径优化方面遇到了问题。我无法同时为时间和路径定义两个 objective。 Python 读取最后一个 objective 并根据该方式给出结果。 你能帮我解决这个优化问题吗?谢谢..

import matplotlib.pyplot as plt
from gekko import GEKKO

# Gekko model
m = GEKKO(remote=False)

# Time points
nt = 501                    # nt=101
tm = np.linspace(0, 1, nt)  # tm = np.linspace(0, 100, nt)
m.time = tm

# Variables
g = m.Const(value=9.80665)
V = m.Const(value=200)  # velocity

Xi = m.Var(value=0, lb=-2*np.pi, ub=2*np.pi)       # Heading angle  value=-np.pi dene
x = m.Var(value=0, lb=-100000, ub=100000)      # x position
y = m.Var(value=0, lb=-100000, ub=100000)      # y position

pathx = m.Const(value=70000)  # intended distance in x direction
pathy = m.Const(value=20000)  # intended distance in y direction

p = np.zeros(nt) # final time=1
p[-1] = 1.0
final = m.Param(value=p)

m.options.MAX_ITER = 1000000  # iteration number

# Optimize Final Time
tf = m.FV(value=1.0, lb=0.0001, ub=1000.0)
tf.STATUS = 1

# Controlled parameters
Mu = m.MV(value=0, lb=-1, ub=1)  # solver controls bank angle
Mu.STATUS = 1
Mu.DCOST = 1e-3

# Equations
m.Equation(x.dt() == tf * (V * (m.cos(Xi))))  
m.Equation(y.dt() == tf * (V * (m.sin(Xi))))  
m.Equation(Xi.dt() == tf * (g * m.tan(Mu)) / V )

# Objective Function
w = 1e4
m.Minimize(w * (x * final - pathx) ** 2)  # 1D part (x)
m.Minimize(w * (pathy - y * final) ** 2)  # 2D part (y)

m.Obj(tf)
'''

多个 objective 组合成一个 objective 并在 Gekko 中求和。如果有多个单独的 objective 应该单独考虑,那么帕累托前沿是评估权衡的一种可能方法(参见 Section 6.5 of the Optimization book)。然而,这并没有在 Gekko 中实现。

一个正确的是 m.Equation(y * final <= pathy ) 应该是 m.Equation((y-pathy) * final <= 0) 以避免在 pathy<0.

时出现潜在的不可行的解决方案

import matplotlib.pyplot as plt
from gekko import GEKKO
import numpy as np

# Gekko model
m = GEKKO(remote=False)

# Time points
nt = 51                    # nt=101
tm = np.linspace(0, 1, nt)  # tm = np.linspace(0, 100, nt)
m.time = tm

# Variables
g = m.Const(value=9.80665)
V = m.Const(value=200)  # velocity

Xi = m.Var(value=0, lb=-2*np.pi, ub=2*np.pi)       # Heading angle  value=-np.pi dene
x = m.Var(value=0, lb=-100000, ub=100000)      # x position
y = m.Var(value=0, lb=-100000, ub=100000)      # y position

pathx = m.Const(value=70000)  # intended distance in x direction
pathy = m.Const(value=20000)  # intended distance in y direction

p = np.zeros(nt) # final time=1
p[-1] = 1.0
final = m.Param(value=p)

m.options.MAX_ITER = 1000000  # iteration number

# Optimize Final Time
tf = m.FV(value=1.0, lb=0.0001, ub=1000.0)
tf.STATUS = 1

# Controlled parameters
Mu = m.MV(value=0, lb=-1, ub=1)  # solver controls bank angle
Mu.STATUS = 1
Mu.DCOST = 1e-3

# Equations
m.Equation(x.dt() == tf * (V * (m.cos(Xi))))  
m.Equation(y.dt() == tf * (V * (m.sin(Xi))))  
m.Equation(Xi.dt() == tf * (g * m.tan(Mu)) / V )

m.Equation((x-pathx) * final <= 0)
m.Equation((y-pathy) * final <= 0)

# Objective Function
w = 1e4
m.Minimize(w * (x * final - pathx) ** 2)  # 1D part (x)
m.Minimize(w * (y * final - pathy) ** 2)  # 2D part (y)

#in here python reads the last objective how can i run this two objectives simultaneously.
#m.Obj(Xi * final) 
m.Minimize(tf)

#m.Maximize(0.2 * mass * final)  # objective function
m.options.IMODE = 6
#m.options.NODES = 2
#m.options.MV_TYPE = 1
#m.options.SOLVER = 3
# m.open_folder() # to search for infeasibilities
m.solve(disp=False)
print('Final Time: ' + str(tf.value[0]))
tm = np.linspace(0,tf.value[0],nt)
#tm = tm * tf.value[0]

fig, axs = plt.subplots(3)
fig.suptitle('Results')
axs[0].plot(tm, Mu.value, 'b-', lw=2, label=r'$Bank$')
axs[0].legend(loc='best')
axs[1].plot(tm, x.value, 'r--', lw=2, label=r'$x$')
axs[1].legend(loc='best')
axs[2].plot(tm, y.value, 'p-', lw=2, label=r'$y$')
axs[2].legend(loc='best')
plt.xlabel('Time')
#plt.ylabel('Value')
plt.show()


plt.figure()
plt.plot(x.value, y.value)
plt.show()