GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — About the "horizon" parameter in the solve_ocp() method · Issue #782 · python-control/python-control

About the "horizon" parameter in the solve_ocp() method #782

New issue
Copy link
New issue
Copy link
Closed
#799
Closed
About the "horizon" parameter in the solve_ocp() method#782
#799
Copy link
Assignees
murrayrm
Labels
bug
Milestone
0.9.3

Description

@zhengzl18
zhengzl18
opened on Oct 18, 2022
Issue body actions

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 called "horizon" is required:

horizon = np.linspace(0, Tf, 3, endpoint=True)
result = opt.solve_ocp(
    vehicle, horizon, x0, traj_cost, constraints,
    terminal_cost=term_cost, initial_guess=u0)

In this setting, it works just fine.

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

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

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

Summary statistics:
* Cost function calls: 9
* Constraint calls: 20
* System simulations: 27
* Final cost: 16000.0
    cost: 16000.0
     fun: 16000.0
  inputs: array([[10., 10., 10., 10.],
       [ 0.,  0.,  0.,  0.]])
     jac: array([ 0.00000000e+00,  2.44140625e-04,  1.22070312e-04,  0.00000000e+00,
       -3.62099047e+06, -6.84054738e+06, -2.12256850e+06, -7.49211857e+05])
 message: 'Optimization terminated successfully'
    nfev: 9
     nit: 5
    njev: 1
 problem: <control.optimal.OptimalControlProblem object at 0x7ff0cb281df0>
  states: array([[  0.        ,  33.33333333,  66.66666667, 100.        ],
       [ -2.        ,  -2.        ,  -2.        ,  -2.        ],
       [  0.        ,   0.        ,   0.        ,   0.        ]])
  status: 0
 success: True
    time: array([ 0.        ,  3.33333333,  6.66666667, 10.        ])
       x: array([10., 10., 10., 10.,  0.,  0.,  0.,  0.])

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

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)

Hope for any help.

Thanks!

Activity

  1. murrayrm
    self-assigned this
    on Nov 19, 2022
  2. murrayrm
    added
    bug
    on Nov 19, 2022
  3. murrayrm
    added this to the 0.9.3 milestone on Nov 19, 2022
  4. murrayrm
    linked a pull request that will close this issueAdd collocation method for optimal control problems #799on Nov 26, 2022
  5. murrayrm
    closed this as completedin #799on Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @murrayrm
    murrayrm

Labels

bug

Type

No type

Projects

No projects

    Milestone

    • 0.9.3

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.