Skip to content

Instantly share code, notes, and snippets.

@rejuvyesh
Created March 18, 2019 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rejuvyesh/e09e1b7a9f03ba2a4a82e91db64f367a to your computer and use it in GitHub Desktop.
Save rejuvyesh/e09e1b7a9f03ba2a4a82e91db64f367a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
#
# File: test_dircol.py
#
import numpy as np
import torch
from optimalcontrol.dircolproblem import DIRCOLProblem
from mechamodlearn import utils
dt = 0.05
maxiter = 100
def objective(x, *args):
cost = torch.sum(x**2)
return cost
def constraints(x, *args):
return x.view(-1)
params = utils.objectview({
'x_dim': 2,
'u_dim': 2,
'duration': 100 * dt,
'dt': None,
'default_dt': dt,
'maxForce': 120,
})
x_guess = np.ones((100, 2))
prob = DIRCOLProblem(params, objective, constraints, no_u=True)
prob.set_Ns([x_guess.shape[0]])
# set general bounds
x_ub = np.inf * np.ones_like(x_guess[0])
x_lb = -np.inf * np.ones_like(x_guess[0])
prob.set_bounds(x_lb, x_ub, None, None)
prob.give_init_guess(x_guess, None)
t, x, u, run_params, info = prob.run(maxiter, verbosity=5)
import ipdb
ipdb.set_trace()
@rejuvyesh
Copy link
Author

ipdb> info
{'obj': 0.0, 'constraint_multipliers': array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0., -0.])}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment