Skip to content
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

better initial guess and fps = 20 for reduced running time #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
20 changes: 11 additions & 9 deletions examples-gallery/plot_ball_rolling_on_spinning_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ def obj_grad(free):
)

# %%
# The initial guess should meet the configuration constrains. It will be
# plotted below.
# The initial guess should meet the configuration constraints. Those below are
# used to get a better initial guess, stored in
# ```ball_rolling_on_spinning_disc_solution.npy```.

i1b = np.zeros(num_nodes)
i2 = np.linspace(initial_state_constraints[x],
final_state_constraints[x], num_nodes)
Expand All @@ -361,25 +363,25 @@ def obj_grad(free):
i4 = np.zeros(8*num_nodes)
initial_guess = np.hstack((i1,i1a, i1b, i2, i3, i4, 0.01))

fig1, ax1 = plt.subplots(14, 1, figsize=(7.25, 0.75*14), sharex=True,
layout='constrained')
prob.plot_trajectories(initial_guess, ax1)

Copy link
Member

@moorepants moorepants Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you delete a figure, then the thumbnail figure may change, have you checked that? There will no longer be a figure 7, right?

I don't see any reason to delete the figure.

Copy link
Contributor Author

@Peter230655 Peter230655 Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you delete a figure, then the thumbnail figure may change, have you checked that? There will no longer by a figure 7, right?

I don't see any reason to delete the figure. Is this related the the mixed up PRs?

I did not intentionally delete this. No idea what happened. Is this related to the mixed up PRs?
I will check and push again.

# %%
# This way the maximum number of interations may be changed.
# Default is 3000.
prob.add_option('max_iter', 1000)

# %%
# Find the optimal solution.

initial_guess = np.load('ball_rolling_on_spinning_disc_solution.npy')
solution, info = prob.solve(initial_guess)
print('message from optimizer:', info['status_msg'])
print('Iterations needed', len(prob.obj_value))
print(f'Optimal h = {solution[-1]:.3e} sec')

# %%
# PLot the objective value.
# This way the solution may be saved for later use.
# ```np.save('ball_rolling_on_spinning_disc_solution.npy', solution)```

# %%
# Plot the objective value.
prob.plot_objective_value()

# %%
Expand Down Expand Up @@ -466,7 +468,7 @@ def func (x, *args):

# %%
# Animate the system.
fps = 30
fps = 20

def add_point_to_data(line, x, y):
old_x, old_y = line.get_data()
Expand Down
Loading