René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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:

\n
horizon = 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
\n

In this setting, it works just fine.

\n

But when I tried to change the horizon into something like (changing nothing but the number of points in the linspace):

\n
horizon = np.linspace(0, Tf, 4, endpoint=True)\n
\n

the result seemed to be extremely strange, with the inputs u always remaining the same:

\n
Summary 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
\n

It's the case for all num except 3 in the np.linspace(0, Tf, num).

\n

I'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)

\n

Hope for any help.

\n

Thanks!

","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-controllervoltron_discussions_fragments
route-actiondiscussion_layout
fetch-noncev2:acab9674-e75b-3c9f-9e57-abee4215aef7
current-catalog-service-hash9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be
request-idCBB0:2EF7CD:1374DE3:1BC934B:697A388E
html-safe-nonceb675e0ce0be9e05f3bdfdf254b60cfe154a6a227f48a7b8e1ce01c4ff2af8fff
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkIwOjJFRjdDRDoxMzc0REUzOjFCQzkzNEI6Njk3QTM4OEUiLCJ2aXNpdG9yX2lkIjoiODY3ODgxNjQ3NjY0OTEwOTY0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac32c612daee8e32e7992216a85de3a279c972916fa82759db5bb1c5aa3d330817
hovercard-subject-tagdiscussion:4480052
github-keyboard-shortcutsrepository,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/discussions_fragments/discussion_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-control/python-control/781/discussion_layout
twitter:imagehttps://opengraph.githubassets.com/9bb0dc24ad057ecc022a5d02ca0ce081e53871df089dad02c4a0488cf7365d15/python-control/python-control/discussions/781
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9bb0dc24ad057ecc022a5d02ca0ce081e53871df089dad02c4a0488cf7365d15/python-control/python-control/discussions/781
og:image:altHi, 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneaf6de804ceb83ad30bb9b348cdeaccaa30cdcb566762d5e74e21e2bad88885d0
turbo-cache-controlno-preview
go-importgithub.com/python-control/python-control git https://github.com/python-control/python-control.git
octolytics-dimension-user_id2285872
octolytics-dimension-user_loginpython-control
octolytics-dimension-repository_id22791752
octolytics-dimension-repository_nwopython-control/python-control
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id22791752
octolytics-dimension-repository_network_root_nwopython-control/python-control
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2d980605f0959039ddebcbcf522b072508302977
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-control/python-control/discussions/781#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-control%2Fpython-control%2Fdiscussions%2F781
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-control%2Fpython-control%2Fdiscussions%2F781
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fdiscussions_fragments%2Fdiscussion_layout&source=header-repo&source_repo=python-control%2Fpython-control
Reloadhttps://github.com/python-control/python-control/discussions/781
Reloadhttps://github.com/python-control/python-control/discussions/781
Reloadhttps://github.com/python-control/python-control/discussions/781
python-control https://github.com/python-control
python-controlhttps://github.com/python-control/python-control
Notifications https://github.com/login?return_to=%2Fpython-control%2Fpython-control
Fork 447 https://github.com/login?return_to=%2Fpython-control%2Fpython-control
Star 2k https://github.com/login?return_to=%2Fpython-control%2Fpython-control
Code https://github.com/python-control/python-control
Issues 87 https://github.com/python-control/python-control/issues
Pull requests 8 https://github.com/python-control/python-control/pulls
Discussions https://github.com/python-control/python-control/discussions
Actions https://github.com/python-control/python-control/actions
Projects 0 https://github.com/python-control/python-control/projects
Wiki https://github.com/python-control/python-control/wiki
Security 0 https://github.com/python-control/python-control/security
Insights https://github.com/python-control/python-control/pulse
Code https://github.com/python-control/python-control
Issues https://github.com/python-control/python-control/issues
Pull requests https://github.com/python-control/python-control/pulls
Discussions https://github.com/python-control/python-control/discussions
Actions https://github.com/python-control/python-control/actions
Projects https://github.com/python-control/python-control/projects
Wiki https://github.com/python-control/python-control/wiki
Security https://github.com/python-control/python-control/security
Insights https://github.com/python-control/python-control/pulse
Answered https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712
murrayrmhttps://github.com/murrayrm
zhengzl18 https://github.com/zhengzl18
Q&Ahttps://github.com/python-control/python-control/discussions/categories/q-a
About the "horizon" parameter in the solve_ocp() method https://github.com/python-control/python-control/discussions/781#top
zhengzl18 https://github.com/zhengzl18
Answered https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712
murrayrmhttps://github.com/murrayrm
Return to tophttps://github.com/python-control/python-control/discussions/781#top
Please reload this pagehttps://github.com/python-control/python-control/discussions/781
https://github.com/python-control/python-control/discussions/781
zhengzl18 https://github.com/zhengzl18
Oct 17, 2022 https://github.com/python-control/python-control/discussions/781#discussion-4480052
https://python-control.readthedocs.io/en/0.9.2/optimal.html#examplehttps://python-control.readthedocs.io/en/0.9.2/optimal.html#example
Give feedback.https://github.com/python-control/python-control/discussions/781
murrayrm https://github.com/murrayrm
Nov 26, 2022 https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712
#799https://github.com/python-control/python-control/pull/799
View full answer https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712
Oldest https://github.com/python-control/python-control/discussions/781?sort=old
Newest https://github.com/python-control/python-control/discussions/781?sort=new
Top https://github.com/python-control/python-control/discussions/781?sort=top
Please reload this pagehttps://github.com/python-control/python-control/discussions/781
https://github.com/python-control/python-control/discussions/781
petterogren https://github.com/petterogren
Oct 27, 2022 https://github.com/python-control/python-control/discussions/781#discussioncomment-3980792
Give feedback.https://github.com/python-control/python-control/discussions/781
Please reload this pagehttps://github.com/python-control/python-control/discussions/781
https://github.com/python-control/python-control/discussions/781
murrayrm https://github.com/murrayrm
Oct 27, 2022 https://github.com/python-control/python-control/discussions/781#discussioncomment-3982769
Give feedback.https://github.com/python-control/python-control/discussions/781
https://github.com/murrayrm
Please reload this pagehttps://github.com/python-control/python-control/discussions/781
https://github.com/python-control/python-control/discussions/781
Please reload this pagehttps://github.com/python-control/python-control/discussions/781
https://github.com/python-control/python-control/discussions/781
murrayrmhttps://github.com/murrayrm
Nov 20, 2022 https://github.com/python-control/python-control/discussions/781#discussioncomment-4186325
https://python-control.readthedocs.io/en/0.9.2/kincar-flatsys.htmlhttps://python-control.readthedocs.io/en/0.9.2/kincar-flatsys.html
Give feedback.https://github.com/python-control/python-control/discussions/781
Please reload this pagehttps://github.com/python-control/python-control/discussions/781
https://github.com/python-control/python-control/discussions/781
murrayrm https://github.com/murrayrm
Nov 26, 2022 https://github.com/python-control/python-control/discussions/781#discussioncomment-4240712
#799https://github.com/python-control/python-control/pull/799
Give feedback.https://github.com/python-control/python-control/discussions/781
murrayrmhttps://github.com/murrayrm
Sign up for freehttps://github.com/join?source=comment-repo
Sign in to commenthttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-control%2Fpython-control%2Fdiscussions%2F781
🙏 Q&A https://github.com/python-control/python-control/discussions/categories/q-a
https://github.com/zhengzl18
https://github.com/murrayrm
https://github.com/petterogren
https://github.com/python-control/python-control/discussions/781
https://github.com/settings/replies?return_to=1
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.