我正在用SNOPT解决PyDrake中的一个问题,我得到的解决方案看起来很合理,但是当我做result.is_success()时,它又返回了False,所以我希望研究为什么它认为这个问题没有解决。我假设我在某个地方有一个糟糕的约束,所以我使用以下代码来完成这个任务:
result = mp.Solve(prog)
if not result.is_success():
print("INFEASIBLE:")
infeasible = result.GetInfeasibleConstraints(prog)
for c in infeasible:
print(c)但是,它退出对result.GetInfeasibleConstraints(prog)的调用时会出现以下错误:
Traceback (most recent call last):
File "test_drake_distribution.py", line 250, in <module>
infeasible = result.GetInfeasibleConstraints(prog)
File "/home/adam/.miniconda3/envs/drake/lib/python3.6/site-packages/pydrake/solvers/_mathematicalprogram_extra.py", line 34, in _check_array_type
f"{var_name} must be of scalar type {expected_name}, but unable "
RuntimeError: PyFunctionConstraint: Output must be of scalar type float, but unable to infer scalar type.它说的是真的,因为我的约束函数正在利用Drake中的autodiff功能,所以它们使用dtype=AutoDiffXd返回数组。如果是这样的话,这是否意味着我不能使用约束不可行性检查器?当我使用autodiff时,对于检查不可行的约束有什么建议吗?
发布于 2022-01-14 21:21:56
我想您应该使用python函数来编写约束。我建议编写这个python函数来处理float和autodiffxd,所以类似这样
def my_evaluator(x: np.ndarray):
if x.dtype == np.object:
# This is the autodiff case
elif x.dtype == np.float:
# This is the float case https://stackoverflow.com/questions/70716513
复制相似问题