Title: About the "horizon" parameter in the solve_ocp() method · python-control/python-control · Discussion #781 · GitHub
Open Graph Title: About the "horizon" parameter in the solve_ocp() method · python-control/python-control · Discussion #781
X Title: About the "horizon" parameter in the solve_ocp() method · python-control/python-control · Discussion #781
Description: About the "horizon" parameter in the solve_ocp() method
Open Graph Description: Hi, I'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example When calling the solve_ocp method, a parameter called "horizon" is requir...
X Description: Hi, I'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example When calling the solve_ocp method, a parameter called "horizon&q...
Opengraph URL: https://github.com/python-control/python-control/discussions/781
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"About the \"horizon\" parameter in the solve_ocp() method","text":"Hi,
\nI'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example
\nWhen calling the solve_ocp method, a parameter called \"horizon\" is required:
\nhorizon = np.linspace(0, Tf, 3, endpoint=True)\nresult = opt.solve_ocp(\n vehicle, horizon, x0, traj_cost, constraints,\n terminal_cost=term_cost, initial_guess=u0)\n
\nIn this setting, it works just fine.
\nBut when I tried to change the horizon into something like (changing nothing but the number of points in the linspace):
\nhorizon = np.linspace(0, Tf, 4, endpoint=True)\n
\nthe result seemed to be extremely strange, with the inputs u always remaining the same:
\nSummary statistics:\n* Cost function calls: 9\n* Constraint calls: 20\n* System simulations: 27\n* Final cost: 16000.0\n cost: 16000.0\n fun: 16000.0\n inputs: array([[10., 10., 10., 10.],\n [ 0., 0., 0., 0.]])\n jac: array([ 0.00000000e+00, 2.44140625e-04, 1.22070312e-04, 0.00000000e+00,\n -3.62099047e+06, -6.84054738e+06, -2.12256850e+06, -7.49211857e+05])\n message: 'Optimization terminated successfully'\n nfev: 9\n nit: 5\n njev: 1\n problem: <control.optimal.OptimalControlProblem object at 0x7ff0cb281df0>\n states: array([[ 0. , 33.33333333, 66.66666667, 100. ],\n [ -2. , -2. , -2. , -2. ],\n [ 0. , 0. , 0. , 0. ]])\n status: 0\n success: True\n time: array([ 0. , 3.33333333, 6.66666667, 10. ])\n x: array([10., 10., 10., 10., 0., 0., 0., 0.])\n\n
\nIt's the case for all num except 3 in the np.linspace(0, Tf, num).
\nI'm confused by this results and wonder what's the actual use of 'horizon'? (I do notice from the comments that it's a \"List of times at which the optimal input should be computed\", but I still can't understand)
\nHope for any help.
\nThanks!
","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"This problem is addressed in PR #799 by switching to using collocation as the default method for solving optimal control problems. This is much more numerically stable and provides good solutions to the example problem from the documentation (and without the issues are the solution only working for a specific number of time points).
","upvoteCount":1,"url":"https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:acab9674-e75b-3c9f-9e57-abee4215aef7 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | CBB0:2EF7CD:1374DE3:1BC934B:697A388E |
| html-safe-nonce | b675e0ce0be9e05f3bdfdf254b60cfe154a6a227f48a7b8e1ce01c4ff2af8fff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkIwOjJFRjdDRDoxMzc0REUzOjFCQzkzNEI6Njk3QTM4OEUiLCJ2aXNpdG9yX2lkIjoiODY3ODgxNjQ3NjY0OTEwOTY0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 32c612daee8e32e7992216a85de3a279c972916fa82759db5bb1c5aa3d330817 |
| hovercard-subject-tag | discussion:4480052 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-control/python-control/781/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/9bb0dc24ad057ecc022a5d02ca0ce081e53871df089dad02c4a0488cf7365d15/python-control/python-control/discussions/781 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9bb0dc24ad057ecc022a5d02ca0ce081e53871df089dad02c4a0488cf7365d15/python-control/python-control/discussions/781 |
| og:image:alt | Hi, I'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example When calling the solve_ocp method, a parameter called "horizon" is requir... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | af6de804ceb83ad30bb9b348cdeaccaa30cdcb566762d5e74e21e2bad88885d0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-control/python-control git https://github.com/python-control/python-control.git |
| octolytics-dimension-user_id | 2285872 |
| octolytics-dimension-user_login | python-control |
| octolytics-dimension-repository_id | 22791752 |
| octolytics-dimension-repository_nwo | python-control/python-control |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22791752 |
| octolytics-dimension-repository_network_root_nwo | python-control/python-control |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2d980605f0959039ddebcbcf522b072508302977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width