Skip to content

Commit

Permalink
Merge pull request #221 from Peter230655/handle_variable_h
Browse files Browse the repository at this point in the history
Handle variable h
  • Loading branch information
moorepants authored Sep 9, 2024
2 parents 2c0bb1d + eba2348 commit b393a5c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions opty/direct_collocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def plot_constraint_violations(self, vector, axes=None):
If the uses gives at least two axis, the method will tell the user
how many are needed, unless the correct amount is given.
Notes
=====
Expand All @@ -465,7 +466,7 @@ def plot_constraint_violations(self, vector, axes=None):
rotation = -45

# find the number of bars per plot, so the bars per plot are arroximately
# the same on each bar.
# the same on each plot.
hilfs = []
len_constr = len(self.collocator.instance_constraints)
for i in range(6, 11):
Expand Down Expand Up @@ -530,12 +531,25 @@ def plot_constraint_violations(self, vector, axes=None):
axes[0].set_xlabel('Node Number')
axes[0].set_ylabel('EoM violation')

# reduce the instance constrtaints to 2 significant digits.
# reduce the instance constrtaints to 2 digits after the decimal point.
# give the time in tha variables with 2 digits after the decimal point.
# if variable h is used, use the result for h in the time.
instance_constr_plot = []
a_before = ''
a_before_before = ''
for exp1 in self.collocator.instance_constraints:
for a in sm.preorder_traversal(exp1):
if isinstance(a, sm.Float):
exp1 = exp1.subs(a, round(a, 2))
if ((isinstance(a_before, sm.Integer) or
isinstance(a_before, sm.Float)) and
(a == self.collocator.node_time_interval)):
a_before = float(a_before)
hilfs = a_before * vector[-1]
exp1 = exp1.subs(a_before_before, sm.Float(round(hilfs, 2)))
elif (isinstance(a_before, sm.Float) and
(a != self.collocator.node_time_interval)):
exp1 = exp1.subs(a_before, round(a_before, 2))
a_before_before = a_before
a_before = a
instance_constr_plot.append(exp1)

if plot_inst_viols:
Expand Down

0 comments on commit b393a5c

Please sign in to comment.