Title: About the "horizon" parameter in the solve_ocp() method · Issue #782 · python-control/python-control · GitHub
Open Graph Title: About the "horizon" parameter in the solve_ocp() method · Issue #782 · python-control/python-control
X Title: About the "horizon" parameter in the solve_ocp() method · Issue #782 · python-control/python-control
Description: Discussed in #781 Originally posted by zhengzl18 October 17, 2022 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 ...
Open Graph Description: Discussed in #781 Originally posted by zhengzl18 October 17, 2022 Hi, I'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example When ca...
X Description: Discussed in #781 Originally posted by zhengzl18 October 17, 2022 Hi, I'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example Whe...
Opengraph URL: https://github.com/python-control/python-control/issues/782
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"About the \"horizon\" parameter in the solve_ocp() method","articleBody":"### Discussed in https://github.com/python-control/python-control/discussions/781\r\n\r\n\u003cdiv type='discussions-op-text'\u003e\r\n\r\n\u003csup\u003eOriginally posted by **zhengzl18** October 17, 2022\u003c/sup\u003e\r\nHi,\r\nI'm running the example code of the `optimal` module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example\r\nWhen calling the `solve_ocp` method, a parameter called \"horizon\" is required:\r\n```\r\nhorizon = np.linspace(0, Tf, 3, endpoint=True)\r\nresult = opt.solve_ocp(\r\n vehicle, horizon, x0, traj_cost, constraints,\r\n terminal_cost=term_cost, initial_guess=u0)\r\n```\r\nIn this setting, it works just fine.\r\n\r\nBut when I tried to change the horizon into something like (changing nothing but the number of points in the linspace):\r\n```\r\nhorizon = np.linspace(0, Tf, 4, endpoint=True)\r\n```\r\nthe result seemed to be extremely strange, with the inputs u always remaining the same:\r\n```\r\nSummary statistics:\r\n* Cost function calls: 9\r\n* Constraint calls: 20\r\n* System simulations: 27\r\n* Final cost: 16000.0\r\n cost: 16000.0\r\n fun: 16000.0\r\n inputs: array([[10., 10., 10., 10.],\r\n [ 0., 0., 0., 0.]])\r\n jac: array([ 0.00000000e+00, 2.44140625e-04, 1.22070312e-04, 0.00000000e+00,\r\n -3.62099047e+06, -6.84054738e+06, -2.12256850e+06, -7.49211857e+05])\r\n message: 'Optimization terminated successfully'\r\n nfev: 9\r\n nit: 5\r\n njev: 1\r\n problem: \u003ccontrol.optimal.OptimalControlProblem object at 0x7ff0cb281df0\u003e\r\n states: array([[ 0. , 33.33333333, 66.66666667, 100. ],\r\n [ -2. , -2. , -2. , -2. ],\r\n [ 0. , 0. , 0. , 0. ]])\r\n status: 0\r\n success: True\r\n time: array([ 0. , 3.33333333, 6.66666667, 10. ])\r\n x: array([10., 10., 10., 10., 0., 0., 0., 0.])\r\n\r\n```\r\n\r\nIt's the case for all `num` except 3 in the np.linspace(0, Tf, num).\r\n\r\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)\r\n\r\nHope for any help.\r\n\r\nThanks!\u003c/div\u003e","author":{"url":"https://github.com/zhengzl18","@type":"Person","name":"zhengzl18"},"datePublished":"2022-10-18T13:14:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/782/python-control/issues/782"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:60f76591-5161-4238-16ed-234f419689ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7D2:2846F6:E51DC9:13AD5D3:697A7D07 |
| html-safe-nonce | 540fa2f43d5da6bfa3a2b3216ada782a5dc07b14504991a4b85c4bb76274ed6d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0QyOjI4NDZGNjpFNTFEQzk6MTNBRDVEMzo2OTdBN0QwNyIsInZpc2l0b3JfaWQiOiIzMTYyOTA3NTg3NDg1NzkzNTQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 22e58d09ef98354b9af250d7d60130148fe4bcf179d26e38ac570b4596402931 |
| hovercard-subject-tag | issue:1413210079 |
| github-keyboard-shortcuts | repository,issues,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/issues/show/python-control/python-control/782/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d67bf3ec4ea76f711bf5e846b49bddfe04fbcf992cd5a2a56f5d6fdf4abcbb19/python-control/python-control/issues/782 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d67bf3ec4ea76f711bf5e846b49bddfe04fbcf992cd5a2a56f5d6fdf4abcbb19/python-control/python-control/issues/782 |
| og:image:alt | Discussed in #781 Originally posted by zhengzl18 October 17, 2022 Hi, I'm running the example code of the optimal module: https://python-control.readthedocs.io/en/0.9.2/optimal.html#example When ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zhengzl18 |
| hostname | github.com |
| expected-hostname | github.com |
| None | a9d1eabfb8cf0cb510bcf598032681675ad29b7ee4cb3bfb9a0a088a12803628 |
| 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 | 31bacebc3305d80609c1b175449c3d314bd1a855 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width