Extension - NLP interface: Low-level NLP formulation and solving
This is completely independent from all robotics code. Provides a generic interface to NLP formulation and calling various solvers.
[ ]:
import robotic as ry
import numpy as np
Define a function to compute differentiable features
[ ]:
#the function needs to have the signature (array) -> (array, array) with dimensionalities (n) -> (d, d-times-n)
def sqrPot(x):
y = np.array(x)
y[0] = y[0] - 1.
J = np.eye(y.size)
return y,J
Define a NLP (non-linear mathematical program)
[ ]:
nlp = ry.NLP_Factory()
nlp.setDimension(3)
nlp.setBounds([-2,-2,-2],[2,2,2])
nlp.setFeatureTypes([ry.OT.sos, ry.OT.sos, ry.OT.sos])
nlp.setEvalCallback(sqrPot)
Define a solver
[ ]:
solver = ry.NLP_Solver()
solver.setProblem(nlp)
solver.setSolver(ry.NLP_SolverID.newton)
[ ]:
solver.solve(True)
[ ]:
solver.getTrace_x()
[ ]:
solver.getTrace_costs()
[ ]: