#python #drake
#python #drake
Вопрос:
При попытке решить мою математическую программу я получаю следующую ошибку
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, потому что я думаю, что это единственный доступный бесплатный решатель)
Есть ли какой-либо способ определить, какие переменные не ограничены, чтобы помочь отладить проблему?
Ответ №1:
Математическая программа Дрейка возвращает все границы в 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])
Комментарии:
1. Спасибо за ответ! Я заметил, что ограничения равенства (добавленные через
prog.AddLinearConstraint(eq(...))
) не увеличивают количество ограничений ограничивающей рамки. Считаются ли переменные, ограниченные равенством, неограниченными??2. Ограничение линейного равенства хранится внутри
prog.linear_equality_constraints()
вместоbounding_box_constraint
. Я не знаю, обрабатывает ли IPOPT эти переменные как ограниченную переменную или нет. Вы всегда можете сделатьprog.AddBoundingBoxConstraint(val, val, var)
, если хотите добавить ограничение в виде ограничительной рамки val <= var <= val (что эквивалентно var == var).