-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Huawei wang homotopy direct collocation #40
base: master
Are you sure you want to change the base?
Changes from 5 commits
78847a1
c380243
2a129a9
8f115d7
76cbc51
7298aa6
8c026ef
452ae0c
c5370e0
a0d3674
fba7daf
59494be
49f051d
8c77a9c
c0adee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ class ConstraintCollocator(object): | |
def __init__(self, equations_of_motion, state_symbols, | ||
num_collocation_nodes, node_time_interval, | ||
known_parameter_map={}, known_trajectory_map={}, | ||
homotopy_control, tracing_dynamic_control, | ||
instance_constraints=None, time_symbol=None, tmp_dir=None, | ||
integration_method='backward euler'): | ||
""" | ||
|
@@ -166,6 +167,12 @@ def __init__(self, equations_of_motion, state_symbols, | |
ndarrays of floats of shape(N,). Any time varying parameters in | ||
the equations of motion not provided in this dictionary will | ||
become free trajectories optimization variables. | ||
homotopy_control: float, optional | ||
A parameter in homotopy method that controls the change of | ||
motion equations. | ||
tracing_dynamic_control: float, optional | ||
A parameter in homotopy method that adjust the dynamics of extra | ||
'data tracing' term. | ||
integration_method : string, optional | ||
The integration method to use, either `backward euler` or | ||
`midpoint`. | ||
|
@@ -188,7 +195,13 @@ def __init__(self, equations_of_motion, state_symbols, | |
to a directory here. | ||
|
||
""" | ||
self.eom = equations_of_motion | ||
Lamda_matrix = sym.zeros(num_states) | ||
Lamda_matrix[num_states/2:, num_states/2:] = homotopy_control * sym.eye(num_states/2) | ||
|
||
k_matrix = sym.zeros(num_states) | ||
k_matrix[num_states/2:, num_states/2:] = tracing_dynamic_control * sym.eye(num_states/2) | ||
|
||
# self.eom = equations_of_motion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete this line |
||
|
||
if time_symbol is not None: | ||
self.time_symbol = time_symbol | ||
|
@@ -205,13 +218,32 @@ def __init__(self, equations_of_motion, state_symbols, | |
|
||
self.known_parameter_map = known_parameter_map | ||
self.known_trajectory_map = known_trajectory_map | ||
|
||
self.num_know_trajectory_map = len(self.known_trajectory_map) | ||
|
||
self.instance_constraints = instance_constraints | ||
|
||
self.num_constraints = self.num_states * (num_collocation_nodes - 1) | ||
|
||
self.tmp_dir = tmp_dir | ||
|
||
self.eom = (1-Lamda_matrix)*equations_of_motion + Lamda_matrix | ||
*(self.state_derivative_symbols - K_matrix* | ||
(known_trajectory_map[self.num_know_trajectory_map | ||
- self.num_states:]-self.state_symbols)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be: self.eom = (1-Lamda_matrix)*equations_of_motion + Lamda_matrix *(self.state_derivative_symbols - K_matrix*
(sympy.Matrix([predefined symbols]) - self.num_states:]-self.state_symbols)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a given state is named |
||
""" | ||
add extra term in equations of motion, the goal is to have the following formula: | ||
homotopy motion equations = [1 0 0 0 ] [f1(x, xd, p, r) ] | ||
0 1 0 0 * f2(x, xd, p, r) | ||
0 0 1-la 0 f3(x, xd, p, r) | ||
[0 0 0 1-la] [f4(x, xd, p, r) ] | ||
|
||
[0 0 0 0 ] [x1_dot] [e1] [x1] | ||
+ 0 0 0 0 * ( x2_dot - K*( e2 - x2 ) ) | ||
0 0 la 0 x3_dot e3 x3 | ||
[0 0 0 la] [x4_dot] [e4] [x4] | ||
""" | ||
|
||
self._sort_parameters() | ||
self._check_known_trajectories() | ||
self._sort_trajectories() | ||
|
@@ -409,7 +441,6 @@ def _discrete_symbols(self): | |
tuple([sym.Symbol(f.__class__.__name__ + 'n', real=True) | ||
for f in self.known_input_trajectories]) | ||
|
||
|
||
# The current and next unknown input trajectories. | ||
self.current_unknown_discrete_specified_symbols = \ | ||
tuple([sym.Symbol(f.__class__.__name__ + 'i', real=True) | ||
|
@@ -460,6 +491,7 @@ def _discretize_eom(self): | |
xdot_sub = {d: (n - i) / h for d, i, n in zip(xd, xi, xn)} | ||
x_sub = {d: (i + n) / 2 for d, i, n in zip(x, xi, xn)} | ||
u_sub = {d: (i + n) / 2 for d, i, n in zip(u, ui, un)} | ||
|
||
self.discrete_eom = me.msubs(self.eom, xdot_sub, x_sub, u_sub) | ||
|
||
def _identify_functions_in_instance_constraints(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make these as keyword arguments with defaults settings:
homotopy=0
,tracing=1
.