英文:
fix_final works for x_f=[0,0,0,0,0,0] but for absolutely no other final state - 'Solution Not Found'
问题
'x_f'在一个单独的文件中定义,但这里是GEKKO实现的代码:
m = GEKKO(remote=solverParams["remote"])
m.time = timeSeq
x = [m.Var(value=x_0[i], fixed_initial=True) for i in range(len(x_0))]
u = [m.Var(value=u_0[i], fixed_initial=False) for i in range(len(u_0))]
w = m.Param(value=w)
for i in range(len(x)):
m.fix_final(x[i], val=x_f[i])
if stateBounds[i]["lower"] != "-Inf":
x[i].lower = stateBounds[i]["lower"]
if stateBounds[i]["upper"] != "+Inf":
x[i].upper = stateBounds[i]["upper"]
for i in range(len(u)):
if forceBounds[i]["lower"] != "-Inf":
u[i].lower = forceBounds[i]["lower"]
if forceBounds[i]["upper"] != "+Inf":
u[i].upper = forceBounds[i]["upper"]
eqs = [x[i].dt() == np.matmul(A[i], x) + np.matmul(np.atleast_1d(B[i]), u)
for i in range(len(x))]
eqs = m.Equations(eqs)
startTime = time.time()
m.Minimize(np.add(np.matmul(np.subtract(x, x_f), np.atleast_1d(np.matmul(np.atleast_1d(Q), np.subtract(x, x_f)))),
np.matmul(u, np.atleast_1d(np.matmul(np.atleast_1d(R), u))))
* w)
m.options.IMODE = 6
m.options.SOLVER = 3
m.solve(disp=solverParams["disp"])
stopTime = time.time()
x_p = [x[i].value for i in range(len(x))]
u_p = [u[i].value for i in range(len(u))]
x_p = np.transpose(x_p)
u_p = np.transpose(u_p)
我的测试案例是:
x_0 = np.array([50.00, -25.00, 80.00, 0.00, 0.00, 0.00])
如果我将x_f设置为精确的零向量,它会给我一个解决方案,但如果我将其设置为,比如:
x_f = np.array([0.04, 0.00, 0.00, 0.00, 0.00, 0.00])
它会说它遇到了局部不可行的点。我怀疑这不是实际的不可行情况,因为这已经发生了对于多个x_0和x_f的情况。
在这里,Q矩阵是6x6的零矩阵,R是3x3的10*I矩阵,系统是线性时不变的。
英文:
'x_f' is defined in a separate file but here's the code for the GEKKO implementation:
m = GEKKO(remote = solverParams["remote"])
m.time = timeSeq
x = [m.Var(value = x_0[i], fixed_initial = True) for i in range(len(x_0))]
u = [m.Var(value = u_0[i], fixed_initial = False) for i in range(len(u_0))]
w = m.Param(value = w)
for i in range(len(x)):
m.fix_final(x[i], val = x_f[i])
if stateBounds[i]["lower"] != "-Inf":
x[i].lower = stateBounds[i]["lower"]
if stateBounds[i]["upper"] != "+Inf":
x[i].upper = stateBounds[i]["upper"]
for i in range(len(u)):
if forceBounds[i]["lower"] != "-Inf":
u[i].lower = forceBounds[i]["lower"]
if forceBounds[i]["upper"] != "+Inf":
u[i].upper = forceBounds[i]["upper"]
eqs = [x[i].dt() == np.matmul(A[i], x) + np.matmul(np.atleast_1d(B[i]), u)
for i in range(len(x))]
eqs = m.Equations(eqs)
startTime = time.time()
m.Minimize(np.add(np.matmul(np.subtract(x, x_f), np.atleast_1d(np.matmul(np.atleast_1d(Q), np.subtract(x, x_f)))),
np.matmul( u, np.atleast_1d(np.matmul(np.atleast_1d(R), u))))
*w)
m.options.IMODE = 6
m.options.SOLVER = 3
m.solve(disp = solverParams["disp"])
stopTime = time.time()
x_p = [x[i].value for i in range(len(x))]
u_p = [u[i].value for i in range(len(u))]
x_p = np.transpose(x_p)
u_p = np.transpose(u_p)
My test case is for:
x_0 = np.array([50.00, -25.00, 80.00, 0.00, 0.00, 0.00])
If I set x_f to be the exact zero vector, it gives me a solution but if I set it to, say,
x_f = np.array([ 0.04, 0.00, 0.00, 0.00, 0.00, 0.00])
it says that it hits a point of local infeasibility. I doubt that this is an actual scenario of infeasibility since this has happened for several cases of x_0 and x_f.
Here, the Q matrix is 0_{6x6} and R is 10*I_{3x3} and the system is linear time-invariant.
答案1
得分: 1
修复最终状态也会将最终状态的导数修复为零。这是Gekko的已知问题,已在其他地方报告过。
不要修复最终值,尝试使用终端方程,例如:
p = np.zeros_like(m.time); p[-1]=1
final = m.Param(p)
m.Equation(final*(x[i]-x_f[i])==0)
如果这不起作用,请尝试将软终端约束包括在目标函数中。这通常对求解器来说是最容易的,不会导致潜在的不可行解决方案。
m.Minimize(final*(x[i]-x_f[i])**2)
这是一个使用软终端约束来达到最终目标的双倒立摆示例。
英文:
Fixing the final state also fixes the derivative of the final state to zero. This is a known issue with Gekko that has been reported elsewhere.
Instead of fixing the final value, try a terminal equation such as:
p = np.zeros_like(m.time); p[-1]=1
final = m.Param(p)
m.Equation(final*(x[i]-x_f[i])==0)
If this doesn't work, try a soft terminal constraint that is included in the objective function. This is typically the easiest for the solver and doesn't result in a potential infeasible solution.
m.Minimize(final*(x[i]-x_f[i])**2)
Here is an example of a double inverted pendulum that uses the soft terminal constraint to reach a final target.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论