All Projects → EmbersArc → Epigraph

EmbersArc / Epigraph

Licence: mit
A C++ interface to formulate and solve linear, quadratic and second order cone problems.

Labels

Projects that are alternatives of or similar to Epigraph

surface splatting
OpenGL demo of a point rendering and texture filtering technique called Surface Splatting.
Stars: ✭ 125 (+23.76%)
Mutual labels:  eigen
eigenpy
Bindings between Numpy and Eigen using Boost.Python
Stars: ✭ 88 (-12.87%)
Mutual labels:  eigen
Towr
A light-weight, Eigen-based C++ library for trajectory optimization for legged robots.
Stars: ✭ 410 (+305.94%)
Mutual labels:  eigen
ign-math
General purpose math library for robot applications.
Stars: ✭ 35 (-65.35%)
Mutual labels:  eigen
OpenImageDebugger
An advanced in-memory image visualization plugin for GDB and LLDB on Linux, MacOS and Windows (experimental). Previously known as gdb-imagewatch.
Stars: ✭ 115 (+13.86%)
Mutual labels:  eigen
Pybind11 examples
Examples for the usage of "pybind11"
Stars: ✭ 280 (+177.23%)
Mutual labels:  eigen
URT
Fast Unit Root Tests and OLS regression in C++ with wrappers for R and Python
Stars: ✭ 70 (-30.69%)
Mutual labels:  eigen
Eigendocinchinese
Eigen3.3.7 Doc中文版
Stars: ✭ 28 (-72.28%)
Mutual labels:  eigen
qpmad
ROS-compatible Eigen-based Goldfarb-Idnani quadratic programming solver
Stars: ✭ 41 (-59.41%)
Mutual labels:  eigen
Optim
OptimLib: a lightweight C++ library of numerical optimization methods for nonlinear functions
Stars: ✭ 411 (+306.93%)
Mutual labels:  eigen
learned indices
A C++11 implementation of the B-Tree part of "The Case for Learned Index Structures"
Stars: ✭ 68 (-32.67%)
Mutual labels:  eigen
numpyeigen
Fast zero-overhead bindings between NumPy and Eigen
Stars: ✭ 75 (-25.74%)
Mutual labels:  eigen
Stats
A C++ header-only library of statistical distribution functions.
Stars: ✭ 292 (+189.11%)
Mutual labels:  eigen
h5pp
A C++17 interface for HDF5
Stars: ✭ 60 (-40.59%)
Mutual labels:  eigen
Math
The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
Stars: ✭ 494 (+389.11%)
Mutual labels:  eigen
GA SLAM
🚀 SLAM for autonomous planetary rovers with global localization
Stars: ✭ 40 (-60.4%)
Mutual labels:  eigen
Poisson blend
Seamless copy-and-paste of images with Poisson Blending.
Stars: ✭ 277 (+174.26%)
Mutual labels:  eigen
Numpycpp
A c++ header library for matrix operation inspired Numpy Scipy, MATLAB only using Eigen.
Stars: ✭ 30 (-70.3%)
Mutual labels:  eigen
Cppnumericalsolvers
a lightweight C++17 library of numerical optimization methods for nonlinear functions (Including L-BFGS-B for TensorFlow)
Stars: ✭ 638 (+531.68%)
Mutual labels:  eigen
Ifopt
An Eigen-based, light-weight C++ Interface to Nonlinear Programming Solvers (Ipopt, Snopt)
Stars: ✭ 372 (+268.32%)
Mutual labels:  eigen

Epigraph is a modern C++ interface to formulate and solve linear, quadratic and second order cone problems. It makes use of Eigen types and operator overloading for straightforward problem formulation.

Features

  • Flexible and intuitive way to formulate LPs, QPs and SOCPs
  • Dynamic parameters that can be changed without re-formulating the problem
  • Automatically clean up the problem and remove unused variables
  • Print the problem formulation and solver data for inspection

Dependencies

Supported Solvers

The solvers are included as submodules for convenience. Note that some solvers have more restrictive licenses which automatically override the Epigraph license when activated. Pass the listed argument to cmake during configuration to enable the solvers.

QP

  • OSQP -DENABLE_OSQP=TRUE. Apache-2.0 License.

SOCP

  • ECOS -DENABLE_ECOS=TRUE. GPLv3 License.

Usage

CMake

To use Epigraph with a cmake project, simply enable the desired solvers, include the subdirectory and link the library.

set(ENABLE_OSQP TRUE)
set(ENABLE_ECOS TRUE)
add_subdirectory(Epigraph)
target_link_libraries(my_library epigraph)

Documentation

While the example below is likely enough to get you started, more explanation is provided below. The full reference can be found here.

Example

#include "epigraph.hpp"

#include <iostream>

// This example solves the portfolio optimization problem in QP form

using namespace cvx;

int main()
{
    size_t n = 5; // Assets
    size_t m = 2; // Factors

    // Set up problem data.
    double gamma = 0.5;          // risk aversion parameter
    Eigen::VectorXd mu(n);       // vector of expected returns
    Eigen::MatrixXd F(n, m);     // factor-loading matrix
    Eigen::VectorXd D(n);        // diagonal of idiosyncratic risk
    Eigen::MatrixXd Sigma(n, n); // asset return covariance

    mu.setRandom();
    F.setRandom();
    D.setRandom();

    mu = mu.cwiseAbs();
    F = F.cwiseAbs();
    D = D.cwiseAbs();
    Sigma = F * F.transpose();
    Sigma.diagonal() += D;

    // Formulate QP.
    OptimizationProblem qp;

    // Declare variables with...
    // addVariable(name) for scalars,
    // addVariable(name, rows) for vectors and
    // addVariable(name, rows, cols) for matrices.
    VectorX x = qp.addVariable("x", n);

    // Available constraint types are equalTo(), lessThan(), greaterThan() and box()
    qp.addConstraint(greaterThan(x, 0.));
    qp.addConstraint(equalTo(x.sum(), 1.));

    // Make mu dynamic in the cost function so we can change it later
    qp.addCostTerm(x.transpose() * par(gamma * Sigma) * x - dynpar(mu).dot(x));

    // Print the problem formulation for inspection
    std::cout << qp << "\n";

    // Create and initialize the solver instance.
    osqp::OSQPSolver solver(qp);

    // Print the canonical problem formulation for inspection
    std::cout << solver << "\n";

    // Solve problem and show solver output
    const bool verbose = true;
    solver.solve(verbose);

    std::cout << "Solver message:  " << solver.getResultString() << "\n";
    std::cout << "Solver exitcode: " << solver.getExitCode() << "\n";

    // Call eval() to get the variable values
    std::cout << "Solution:\n" << eval(x) << "\n";

    // Update data
    mu.setRandom();
    mu = mu.cwiseAbs();

    // Solve again
    // OSQP will warm start automatically
    solver.solve(verbose);

    std::cout << "Solution after changing the cost function:\n" << eval(x) << "\n";
}

See the tests for more examples, including the same problem in SOCP form.

Variables

Variables are created by directly adding them to a problem:

    OptimizationProblem qp;
    cvx::Scalar scalar_var = qp.addVariable("x");
    cvx::VectorX vector_var = qp.addVariable("x", n);
    cvx::MatrixX matrix_var = qp.addVariable("x", n, m);

They contain the solution values after the problem has been solved successfully. Those values can be retrieved with the eval function, or by casting the value to a double.

    double scalar_sol = cvx::eval(scalar_var);
    Eigen::VectorXd vector_sol = cvx::eval(vector_var);
    Eigen::MatrixXd matrix_sol = cvx::eval(matrix_var);

Parameters

There are three kinds of parameters:

Constant

A value that can't be changed after instantiating the solver. Use the par function to turn scalars or Eigen types into constant parameters.

Dynamic

A value that can be changed after instantiating the solver. Use the dynpar function to turn scalars or Eigen types into dynamic parameters. Internally, this stores a pointer to the original data and will fetch the data each time the problem is solved. Important: Do not move or let this data go out of scope before the solver instance.

Operation

This parameter type is created when using the operations +, -, * or / with dynamic parameters. This records the operations and will later execute them again to build the new problem based on the changed dynamic parameters. Using said operations with constant parameters will again yield constant parameters and not result in any additional computations.

Problem Formulation

The following terms may be passed to the constraint functions:

Function Allowed expressions
equalTo() Affine == Affine
lessThan() Affine <= Affine or Norm2 + Affine <= Affine (SOCP)
greaterThan() Affine >= Affine or Affine >= Norm2 + Affine (SOCP)
box() Affine <= Affine <= Affine
addCostTerm() Affine (SOCP) or QuadForm + Affine (QP)

With the following expressions:

Expression Form
Affine p1 * x1 + p2 * x2 + ... + c
Norm2 (Affine1^2 + Affine2^2 + ...)^(1/2)
QuadForm x' * P * x where P is Hermitian
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].