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

same betts 10 1 simulation but new branch #308

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Peter230655
Copy link
Contributor

@Peter230655 Peter230655 commented Jan 28, 2025

This is the same betts 10 1 as before. As I could not fix the branch, I put it into a new one and made a new PR. I will close the old PR.

@Peter230655 Peter230655 mentioned this pull request Jan 28, 2025
@moorepants
Copy link
Member

I'll merge this one as the demonstration of how to handle inequalities (until we have native support).


This is example 10.1 from Betts' book "Practical Methods for Optimal Control
Using NonlinearProgramming", 3rd edition, Chapter 10: Test Problems.
More details are in sectionn 4.11.7 of the book.
Copy link
Member

Choose a reason for hiding this comment

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

Can you cite Bett's book using RST citation notation, i.e. [Betts2010]_.

:math:`y_1^2 + y_2^2 + y_3^2 + y_4^2 \\geq function(time, parameters)`

As presently *opty* does not support inequality constraints, I introduced a new
state variable `fact` to take care of the inequality. The inequality is then
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
state variable `fact` to take care of the inequality. The inequality is then
state variable ``fact`` to take care of the inequality. The inequality is then

double back ticks give monspace font

- :math:`u_1, u_2` : control variables

Note: I simply copied the equations of motion, the bounds and the constants
from the book. I do not know their meaning.
Copy link
Member

Choose a reason for hiding this comment

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

The why is the name of the problem "Alp Rider"? what does that mean? Please clarify.

Copy link
Contributor Author

@Peter230655 Peter230655 Feb 2, 2025

Choose a reason for hiding this comment

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

I simply took the name give to this problem by Dr. Betts.
Below it says:
Stiff ODE, terrain following [Betts2010] Sect. 4.7.6

But my 3rd edition does not seem to have this section.
I will send an email to Dr. Betts and will ask ihm.
In chapter 4.11.7 are more details about this problem.

I will correct the issues and push.

Copy link
Member

Choose a reason for hiding this comment

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

We should just name it something that has a meaning to the reader of opty documentation, as they may not have the book.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In chapter 4.11.7 it is described what the system does:
It must follow steep peaks as closely as possible, see fig 4.6 there.
Maybe: System following uneven terrain ?

integration_method=integration_method,
)

#prob.add_option('nlp_scaling_method', 'gradient-based')
Copy link
Member

Choose a reason for hiding this comment

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

remove commented lines

print(f'minimum value of fact = {np.min(solution[4*num_nodes: 5*num_nodes]):.4e}')

# %%
# sphinx_gallery_thumbnail_number = 2
Copy link
Member

Choose a reason for hiding this comment

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

This is displaying in the rendered notebook, so I guess it not correctly specified. It should not show up in the rendered version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is displaying in the rendered notebook, so I guess it not correctly specified. It should not show up in the rendered version.

corrected.

@Peter230655
Copy link
Contributor Author

Betts_10_1_peaks.pdf

These are the peaks the system (whatever it is, I do not know) has to follow.

@moorepants
Copy link
Member

moorepants commented Feb 2, 2025

I am not so concerned with what Bett's has, but I just would like the examples to be understandable without having his book. Can you make sure to provide enough information so that is the case. The name "Alp Rider" was no where else in your text so I don't know what it means.

@Peter230655
Copy link
Contributor Author

Peter230655 commented Feb 2, 2025

I am not so concerned with what Bett's has, but I just would like the examples to be understandable without having his book. Can you make sure to provide enough information so that is the case. The name "Alp Rider" was no were else in your text so I don't know what it means.

As I understand it from section 4.11.7, this was designed to be a stiff system, without apparent physical meaning. It was proposed to check optimization routines. The inequality constraint forces the norm of the state vector has to be larger than a wildly fluctuating function (the function in the picture), and the objective forces it to be close to this function.
Being stiff, it would 'like' to move without 'turns', but inequality and objective force it to 'turn' wildly. Hence a good system to test optimization routines.

More I cannot find out about it.
Maybe like this:
Title: Stiff Set of Differential Equations
Below something like the 'explanation' I just gave ?

@moorepants
Copy link
Member

Yes, perfect!

@Peter230655
Copy link
Contributor Author

Yes, perfect!

Thanks!
I will change and push.

@Peter230655
Copy link
Contributor Author

Peter230655 commented Feb 2, 2025

NB:
opty's minimum is over 5% lower that Betts', while all constraints are met very well.
Shows how good opty is! :-)

@moorepants
Copy link
Member

We're probably not comparing apples to apples though. Opty does not do many of the fancy things (like mesh refinement, variable node spacing, higher order integrators, etc.)

@Peter230655
Copy link
Contributor Author

We're probably not comparing apples to apples though. Opty does not do many of the fancy things (like mesh refinement, variable node spacing, higher order integrators, etc.)

Fair enough, but if opty's minimum is lower and all the constraints are met very closely, does this not mean it works very well?

@moorepants
Copy link
Member

I think it still depends on the integrator and steps you use, as the constraints are a function of those choices.

@Peter230655
Copy link
Contributor Author

I think it still depends on the integrator and steps you use, as the constraints are a function of those choices.

I think you are right: If I understand opty correctly, the results are "correct" only at the points in time given by num_nodes, and by continuity one hopes they are about right in between, too. And this is a tricky system as I now remember again. It took me a while to get it to converge.

@moorepants
Copy link
Member

Yes, this suffers from the same effects that any integration routine faces and the accuracy is effected by truncation error and floating point error. opty uses very simple integration algorithms relative to what Bett's recommends. Maybe one day I'll have time to include better integrators, but we could also move to pycollo and build that out instead.

@Peter230655
Copy link
Contributor Author

Yes, this suffers from the same effects that any integration routine faces and the accuracy is effected by truncation error and floating point error. opty uses very simple integration algorithms relative to what Bett's recommends. Maybe one day I'll have time to include better integrators, but we could also move to pycollo and build that out instead.

I just looked around a bit. It seems, pycollo has been kinda dormant for more than a year?

@moorepants
Copy link
Member

Sam wrote pycollo for his 2021 dissertation. He worked on it some when he was a post doc with me (we used it for the skateboard ollie) and then he moved on to other things. So, yes, it is dormant but it has all of the more advanced collocation methods and it works with SymPy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants