-
Notifications
You must be signed in to change notification settings - Fork 124
Usage from Python
To solve an SOCP ECOS can either be used directly in Python (see instructions below) or the problem can be solved via the CVXPY interface. Please find the instructions to use CVXPY here.
After installing the ECOS interface through regular python channels such as pip
, you must import the module
with
import ecos
This module provides a single function ecos with one of the following calling sequences:
solution = ecos.solve(c,G,h,dims)
solution = ecos.solve(c,G,h,dims,A,b,**kwargs)
The arguments c
, h
, and b
are Numpy arrays (i.e. matrices with a single column). The arguments G
and
A
are Scipy sparse matrices in compressed sparse column (CSC) format; if they are not of the proper format
(e.g. in compressed sparse row (CSR) format), ECOS will attempt to convert them. The argument dims
is a
dictionary with three fields, dims['l']
, dims['q']
and dims['e']
. These are the same fields as in the
MATLAB® case. If the fields are omitted or empty, they default to 0. The argument kwargs
can include the
keywords feastol
, abstol
, reltol
, feastol_inacc
, abstol_innac
, and reltol_inacc
for tolerance values,
max_iters
for the maximum number of iterations, the Boolean verbose
, and integer_vars_idx
a Numpy array of
int
s which index the integer variables. The arguments A
, b
, and kwargs
are optional.
The returned object is a dictionary containing the fields solution['x']
, solution['y']
, solution['s']
,
solution['z']
, and solution['info']
. The first four are Numpy arrays containing the relevant solution. The
last field contains a dictionary with the same fields as the info struct in the MATLAB® interface.