0

This piece of example code: ''' import numpy as np import pydrake.solvers.mathematicalprogram as mp from pydrake.solvers.ipopt import IpoptSolver def foo(x): return np.sign(x)

prog = mp.MathematicalProgram()
x = prog.NewContinuousVariables(1)
prog.AddConstraint(foo, [1.], [1.], vars=x)
prog.AddLinearCost(1 * x[0])
result = mp.Solve(prog, np.array([10.]), None)
print(result.is_success())
print(result.GetSolution(x))

''' returns the error: Segmentation fault (core dumped), when I run it under termial opened by the jupyter notebook, provided by the course: http://underactuated.csail.mit.edu/Spring2019/install_drake_docker.html. (while the code itself already proved right here,https://github.com/RobotLocomotion/drake/issues/12410)

4

1 回答 1

0

使用 docker image drake-20190129,此代码无法运行。具体来说,这条线mp.Solve(prog, np.array([10.]), None)是有问题的。当时 Drake 不支持这个功能。您需要将此行替换为result = prog.Solve().

更换线路后,我的内核死了。

我不建议将 docker drake-20190129 用于您的代码。具体来说,prog.AddConstraint(foo, [1.], [1.], vars=x)当时(2019 年 1 月 29 日)不支持这条线。我通常使用最新版本的 drake,如https://drake.mit.edu/python_bindings.html中所述

于 2019-12-03T03:58:24.063 回答