2 from __future__
import print_function, division
4 from scipy.optimize
import (
16 class SciPyEndPoseSolver(object):
18 Uses SciPy to solve a constrained EndPoseProblem. Options for SciPy minimize
20 https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
23 def __init__(self, problem=None, method=None, debug=False):
24 print(
"Initialising SciPy Solver")
25 self.problem = problem
28 self.hessian_update_strategy =
None
29 if self.method !=
"SLSQP":
30 self.hessian_update_strategy = SR1()
31 self.max_iterations = 100
34 self.problem = problem
37 self.problem.update(x)
38 return self.problem.get_equality()
41 self.problem.update(x)
42 return self.problem.get_equality_jacobian()
45 self.problem.update(x)
47 return -1.0 * self.problem.get_inequality()
50 self.problem.update(x)
51 return -1.0 * self.problem.get_inequality_jacobian()
54 self.problem.update(x)
55 return self.problem.get_scalar_cost(), self.problem.get_scalar_jacobian()
58 self.problem.update(x)
59 return self.problem.get_scalar_jacobian()
63 x0 = self.problem.start_state.copy()
65 self.problem.pre_update()
69 if self.method !=
"trust-constr":
70 if self.neq_constraint_fun(np.zeros((self.problem.N,))).shape[0] > 0:
74 "fun": self.neq_constraint_fun,
75 "jac": self.neq_constraint_jac,
79 if self.eq_constraint_fun(np.zeros((self.problem.N,))).shape[0] > 0:
83 "fun": self.eq_constraint_fun,
84 "jac": self.eq_constraint_jac,
88 if self.neq_constraint_fun(np.zeros((self.problem.N,))).shape[0] > 0:
91 self.neq_constraint_fun,
94 jac=self.neq_constraint_jac,
95 hess=self.hessian_update_strategy,
99 if self.eq_constraint_fun(np.zeros((self.problem.N,))).shape[0] > 0:
102 self.eq_constraint_fun,
105 jac=self.eq_constraint_jac,
106 hess=self.hessian_update_strategy,
112 if self.problem.use_bounds:
114 self.problem.get_bounds()[:, 0], self.problem.get_bounds()[:, 1]
117 options = {
"disp": self.debug,
"maxiter": self.max_iterations}
118 if self.method ==
"trust-constr":
119 options[
"initial_tr_radius"] = 1000.0
128 hess=self.hessian_update_strategy,