OpEn

OpEn

  • Docs
  • Blog
  • Rust API
  • Opengen API
  • Chat
  • Github

›Optimal Control

OpEn Guide

  • Introduction
  • Installation

Python

  • Opengen basics
  • Additional options
  • C/C++ Bindings
  • Direct interface
  • TCP Sockets
  • ROS packages
  • Examples

Optimal Control

  • Getting started
  • Constructing OCPs
  • Building OCPs
  • Solving OCPs

Rust

  • Introduction
  • ALM/PM
  • Features

MATLAB

  • MATLAB
  • Examples

Docker

  • Docker

Extras

  • Algorithm
  • FAQ
  • Cite OpEn
  • Contributing

Building OCPs

Info: The functionality presented here was introduced in opengen version 0.10.0a1. The API is still young and is likely to change in version 0.11.

Once an OCP has been defined, it can be turned into a generated optimizer using og.ocp.OCPBuilder. This builder lowers the high-level OCP to the standard OpEn problem format and then invokes the usual code-generation pipeline.

At a minimum, you need:

  • the OCP definition,
  • optimizer metadata,
  • a build configuration, and
  • a solver configuration.

For example:

ocp_optimizer = og.ocp.OCPBuilder(
    ocp,
    metadata=og.config.OptimizerMeta().with_optimizer_name("my_ocp"),
    build_configuration=og.config.BuildConfiguration()
        .with_build_python_bindings(),
    solver_configuration=og.config.SolverConfiguration()
        .with_tolerance(1e-5)
        .with_delta_tolerance(1e-5),
).build()

The call to .build() generates the solver and returns a GeneratedOptimizer, which can then be used directly:

result = ocp_optimizer.solve(x0=[0.4, 0.2], xref=[0.0, 0.0])

If you prefer to access the generated solver over TCP instead of direct Python bindings, use with_tcp_interface_config(...) in the build configuration:

ocp_optimizer = og.ocp.OCPBuilder(
    ocp,
    metadata=og.config.OptimizerMeta().with_optimizer_name("my_ocp_tcp"),
    build_configuration=og.config.BuildConfiguration()
        .with_tcp_interface_config(),
    solver_configuration=og.config.SolverConfiguration(),
).build()

In both cases, the high-level interface remains the same:

result = ocp_optimizer.solve(x0=[0.4, 0.2], xref=[0.0, 0.0])

For more details on build configurations, TCP servers, Python bindings, and the low-level code-generation pipeline, see the main Python interface documentation.

← Constructing OCPsSolving OCPs →
OpEn
Docs
Getting StartedPython interfaceMATLAB interfaceDocker
Community
User ShowcaseDiscord communityChat on GitterTwitter
More
BlogGitHubOpenhubStar

Tweet
Copyright © 2026 Pantelis Sopasakis and Emil Fresk
Box Icon made by Freepik from www.flaticon.com