如何解决是否有可能确定无界变量?
尝试求解数学程序时,出现以下错误
IPOPT terminated after exceeding the maximum iteration limit. Hint: Remember that IPOPT is an interior-point method and performs badly if any variables are unbounded.
(我使用IPOPT是因为我认为它是唯一可用的免费求解器)
有什么方法可以确定哪些变量是无界的,以帮助调试问题?
解决方法
Drake的MathematicalProgram返回bounding_box_constraints()
函数中的所有边界,您可以查询每个边界框约束并获取变量的边界。这是python代码
# We will store the lower and upper bound of each variable in x_lo and x_up.
x_lo = np.full((prog.num_vars(),),-np.inf)
x_up = np.full((prog.num_vars(),np.inf)
for bb_con in prog.bounding_box_constraints():
# loop over each bounding box constraint
for i in range(bb_con.variables().shape[0]):
# loop over each variable associated with the constraint. First find the index of the variable
var_index = int(prog.decision_variable_index()[bb_con.variables()[i].get_id()])
# Update the lower bound for the variable.
x_lo[var_index] = np.max((x_lo[var_index],bb_con.evaluator().lower_bound()[i]))
# Update the upper bound for the variable.
x_up[var_index] = np.min((x_up[var_index],bb_con.evaluator().upper_bound()[i]))
# now x_lo and x_up stores the bounds for each variable
for i in range(prog.num_vars()):
if np.isinf(x_lo[i]) and np.isinf(x_up[i]):
# print out the variable with no lower and upper bound.
print(prog.decision_variables()[i])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。