Skip to content

Latest commit

 

History

History
90 lines (71 loc) · 3.87 KB

README.md

File metadata and controls

90 lines (71 loc) · 3.87 KB

ECOS.jl

Build Status Coverage Status Build status

ECOS ECOS

Julia wrapper for the ECOS embeddable second-order cone problem (SOCP) interior point solver.

Installation

You can install ECOS.jl through the Julia package manager:

julia> Pkg.add("ECOS")

ECOS.jl will automatically setup the ECOS solver itself:

  • On Linux it will build from source
  • On OS X it will download a binary via Homebrew.jl.
  • On Windows it will download a binary.

Usage

The ECOS interface is completely wrapped: the package exports the functions setup, solve, and cleanup; it provides but does not export ECOS_ver. Function arguments are extensively documented in the source, and an example of usage can be found in test/direct.jl.

ECOS.jl also supports the JuliaOpt MathProgBase standard solver interface. This interface can be used to solve LPs using loadproblem! and SOCPs through loadconicproblem! (documentation). Thanks to this support ECOS can be used as a solver with both the JuMP and Convex.jl modeling languages.

All ECOS solver options can be set through the direct interface and through MathProgBase. The list of options is defined the ecos.h header, which we reproduce here:

gamma          # scaling the final step length
delta          # regularization parameter
eps            # regularization threshold
feastol        # primal/dual infeasibility tolerance
abstol         # absolute tolerance on duality gap
reltol         # relative tolerance on duality gap
feastol_inacc  # primal/dual infeasibility relaxed tolerance
abstol_inacc   # absolute relaxed tolerance on duality gap
reltol_inacc   # relative relaxed tolerance on duality gap
nitref         # number of iterative refinement steps
maxit          # maximum number of iterations
verbose        # verbosity bool for PRINTLEVEL < 3

To use these settings you can either pass them as keyword arguments to setup (direct interface) or as arguments to the ECOSSolver constructor (MathProgBase interface), e.g.

# Direct
my_prob = ECOS.setup(n, m, ..., c, h, b; maxit=10, feastol=1e-5)
# MathProgBase (with JuMP)
m = Model(solver=ECOS.ECOSSolver(maxit=10, feastol=1e-5))

JuMP example

This example shows how we can model a simple knapsack problem with JuMP and use ECOS to solve it.

using JuMP
import ECOS

items  = [:Gold, :Silver, :Bronze]
values = [:Gold => 5.0,  :Silver => 3.0,  :Bronze => 1.0]
weight = [:Gold => 2.0,  :Silver => 1.5,  :Bronze => 0.3]

m = Model(solver=ECOS.ECOSSolver())
@defVar(m, 0 <= take[items] <= 1)  # Define a variable for each item
@setObjective(m, Max, sum{ values[item] * take[item], item in items})
@addConstraint(m, sum{ weight[item] * take[item], item in items} <= 3)
solve(m)

println(getValue(take))
# take
# [  Gold] = 0.9999999680446406
# [Silver] = 0.46666670881026834
# [Bronze] = 0.9999999633898735

ECOS.jl is licensed under the MIT License (see LICENSE.md), but note that ECOS itself is GPL v3.