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

Possible wider applications of opty #265

Open
Peter230655 opened this issue Nov 14, 2024 · 3 comments
Open

Possible wider applications of opty #265

Peter230655 opened this issue Nov 14, 2024 · 3 comments

Comments

@Peter230655
Copy link
Contributor

Peter230655 commented Nov 14, 2024

I have tried maybe 20 examples out of John T. Betts' book Practical Method for Optimal Control Using Nonlinear Programming, 3rd edition. Some are on pst-notebooks, some I pushed to examples-gallery, some I simply did not mange to get to converge.
The two major 'hindrances' to do more examples seem to be:

  • opty cannot accept inequalities in the DAEs. In some cases this may be circumvented by adding state variables, see e.g. PR Betts 10 1 #269
  • opty cannot accept (I believe) instance constraints or bounds which depend on the values of other state or control variables at some point in time (see also 'idea' # 264. In some cases this may be circumvented by adding state variables, see e.g. PR Examples 10.73 and 10.74 from Betts' book #271 Update as of 10-12-24: opty CAN accept instance constraints such as $x_2(t_0) = x_1(t_f)$. I have not checked this for bounds.

Update: It does not seem to work for bounds. If I set, say, bounds = {x1 = (u1(t0), u2(tf)} I get an error saying, as I understand it, that the values in (..., ...) must be floats.

@Peter230655
Copy link
Contributor Author

Peter230655 commented Dec 15, 2024

Update:
I believe, inequalities of the form $g(x(t), u(t), params) \leq h_i \leq f(x(t), u(t), params), t_0 \leq t \leq t_f$ , x(t) state variables, u(t) controls, $h_i$ either a state or a control variable can be handled by introducing additional state variables $aux_i$, one for each inequality.
set $aux_i = h_i - g(...)$ as an additional equation in the eoms and force $aux_i \geq 0.0$ using the bounds, see e.g. PR #278, #277 for such simulations. ( of course $aux_j = f(...) - h_i$ for the other inequality)

if an inequality $f(x(t), u(t), params) \geq 0$ only holds for $t = t_f$ one can introduce an additional state variable $aux$, and additional unknown parameter $help$, and add $aux = g(...) - help$ to the eoms. Set $aux(t_f) = 0$ in the instance constraints, and bound $help > 0.0$. #271 is an example along these lines.

Of course, this crutch comes at the expense of enlarging the system.

@Peter230655
Copy link
Contributor Author

Peter230655 commented Dec 26, 2024

To the best of my knowledge, opty does not allow inequalities in the instance constraints. A way around may be this:
Say x is a state variable, $t_m$ some time and one would want $a < x(t_m) < b$, with, for simplicity a, b > 0.
One way to do this:
introduce additional state variables top and bottom, and additional specifieds $top_h, bottom_h$.
add $top = top_h \cdot x$ and $bottom = bottom_h \cdot x$ to the equations of motion.
In the bounds set: { $top_h: (1, \infty), bottom_h: (0, 1)$ }, in the instance constraints set $top(t_m) - b, bottom(t_m) - a$.
An example is on pst-notebooks, called car_on_street_gate_opty.ipynb.

Again, this crutch enlarges the system substantially.

Update: if $t_0$ is the starting time of the simulation, the above does not work if $t_m = t_0$!
$t_m$ must be at least $t_0$ + interval_value, it seems.
What I am suggesting here is a crutch!

@Peter230655
Copy link
Contributor Author

I pushed point_on_street_gate.ipynb to pst-notebooks.
It shows how to handle inequalities in the eoms and in the instance constraints.
I think, this may execute fast enough for examples-gallery.

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

No branches or pull requests

1 participant