Created
March 18, 2019 22:58
-
-
Save rejuvyesh/e09e1b7a9f03ba2a4a82e91db64f367a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Author
rejuvyesh
commented
Mar 18, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment