Skip to content

Commit

Permalink
Merge branch 'parameters_selection'
Browse files Browse the repository at this point in the history
  • Loading branch information
bstellato committed Mar 29, 2017
2 parents fcc4fba + 15386f4 commit 9036153
Show file tree
Hide file tree
Showing 30 changed files with 418 additions and 348 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ out/
# Data Files
# -------------------------------------------------------------------
interfaces/python/tests/qp_problems/results/
interfaces/python/tests/qp_problems/results_bak
interfaces/python/tests/qp_problems/figures/
tests/**/*data.h
interfaces/python/*.so
Expand Down
4 changes: 3 additions & 1 deletion docs/interfaces/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ The keyword arguments :code:`**settings` specify the solver settings as follows
+====================================+=====================================+================+
| :code:`scaling` | Perform data scaling | True |
+------------------------------------+-------------------------------------+----------------+
| :code:`rho` | ADMM rho step | 0.1 |
| :code:`rho` | ADMM rho step | Auto computed |
+------------------------------------+-------------------------------------+----------------+
| :code:`auto_rho` | ADMM rho step automatic selection | True |
+------------------------------------+-------------------------------------+----------------+
| :code:`sigma` | ADMM sigma step | 0.001 |
+------------------------------------+-------------------------------------+----------------+
Expand Down
6 changes: 6 additions & 0 deletions include/auxil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ extern "C" {
* Auxiliary functions needed to compute ADMM iterations * *
***********************************************************/

/**
* Automatically compute rho
* @param work Workspace
*/
void compute_rho(OSQPWorkspace * work);

/**
* Swap c_float vector pointers
* @param a first vector
Expand Down
4 changes: 4 additions & 0 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ extern "C" {
#define POLISH (1)
#define POL_REFINE_ITER (3)
#define VERBOSE (1)
#define AUTO_RHO (1)
#define AUTO_RHO_OFFSET (1.07838081E-03) // Not settable by the user
#define AUTO_RHO_SLOPE (2.31511262) // Not settable by the user
#define AUTO_RHO_MAX (10.) // Not settable by user
#endif

#define EARLY_TERMINATE (1)
Expand Down
18 changes: 17 additions & 1 deletion include/lin_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,29 @@ i.e. scale the columns of A by d
*/
void mat_postmult_diag(csc *A, const c_float *d);


#ifndef EMBEDDEED
/* Elementwise square matrix M */
void mat_ew_sq(csc * A);

/* Elementwise absolute value of matrix M */
void mat_ew_abs(csc * A);

/**
* Trace of matrix M in cdc format
* @param M Input matrix
* @return Trace
*/
c_float mat_trace(csc * M);

/**
* Frobenius norm squared of matrix M
* @param M Input matrix
* @return Frobenius norm squared
*/
c_float mat_fro_sq(csc * M);
#endif // ifndef embedded


/* Matrix-vector multiplication
* y = A*x (if plus_eq == 0)
* y += A*x (if plus_eq == 1)
Expand Down
1 change: 1 addition & 0 deletions include/osqp.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ c_int osqp_update_pol_refine_iter(OSQPWorkspace * work, c_int pol_refine_iter_ne
*/
c_int osqp_update_verbose(OSQPWorkspace * work, c_int verbose_new);


#endif // #ifndef EMBEDDED


Expand Down
1 change: 1 addition & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ typedef struct {
c_int pol_refine_iter; /* iterative refinement steps in polish */

c_int verbose; /* boolean, write out progress */
c_int auto_rho; // boolean, true if rho is chosen automatically
#endif

c_int early_terminate; // boolean, terminate if stopping criterion is met
Expand Down
3 changes: 3 additions & 0 deletions interfaces/matlab/osqp_mex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const char* OSQP_SETTINGS_FIELDS[] =
"delta", //c_float
"polish", //c_int
"pol_refine_iter", //c_int
"auto_rho", //c_int
"verbose", //c_int
"early_terminate", //c_int
"early_terminate_interval", //c_int
Expand Down Expand Up @@ -641,6 +642,7 @@ mxArray* copySettingsToMxStruct(OSQPSettings* settings){
mxSetField(mxPtr, 0, "delta", mxCreateDoubleScalar(settings->delta));
mxSetField(mxPtr, 0, "polish", mxCreateDoubleScalar(settings->polish));
mxSetField(mxPtr, 0, "pol_refine_iter", mxCreateDoubleScalar(settings->pol_refine_iter));
mxSetField(mxPtr, 0, "auto_rho", mxCreateDoubleScalar(settings->auto_rho));
mxSetField(mxPtr, 0, "verbose", mxCreateDoubleScalar(settings->verbose));
mxSetField(mxPtr, 0, "early_terminate", mxCreateDoubleScalar(settings->early_terminate));
mxSetField(mxPtr, 0, "early_terminate_interval", mxCreateDoubleScalar(settings->early_terminate_interval));
Expand Down Expand Up @@ -810,6 +812,7 @@ void copyMxStructToSettings(const mxArray* mxPtr, OSQPSettings* settings){
settings->delta = (c_float)mxGetScalar(mxGetField(mxPtr, 0, "delta"));
settings->polish = (c_int)mxGetScalar(mxGetField(mxPtr, 0, "polish"));
settings->pol_refine_iter = (c_int)mxGetScalar(mxGetField(mxPtr, 0, "pol_refine_iter"));
settings->auto_rho = (c_int)mxGetScalar(mxGetField(mxPtr, 0, "auto_rho"));
settings->verbose = (c_int)mxGetScalar(mxGetField(mxPtr, 0, "verbose"));
settings->early_terminate = (c_int)mxGetScalar(mxGetField(mxPtr, 0, "early_terminate"));
settings->early_terminate_interval = (c_int)mxGetScalar(mxGetField(mxPtr, 0, "early_terminate_interval"));
Expand Down
2 changes: 1 addition & 1 deletion interfaces/matlab/unittests/feasibility_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function setup_problem(testCase)
% Setup solver
testCase.solver = osqp;
testCase.solver.setup(testCase.P, testCase.q, testCase.A, testCase.l, testCase.u, ...
'verbose', 0, 'eps_abs', 1e-05, 'eps_rel', 1e-05);
'auto_rho', 0, 'rho', 1e-01, 'verbose', 0, 'eps_abs', 1e-05, 'eps_rel', 1e-05);

% Get options
testCase.options = testCase.solver.current_settings();
Expand Down
1 change: 1 addition & 0 deletions interfaces/matlab/unittests/warm_start_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function setup_problem(testCase)
testCase.options.eps_abs = 1e-04;
testCase.options.eps_rel = 1e-04;
testCase.options.early_terminate_interval = 1;
testCase.options.auto_rho = 0;

% Setup tolerance
testCase.tol = 1e-04;
Expand Down
12 changes: 7 additions & 5 deletions interfaces/python/extension/include/osqpobjectpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,25 @@ static PyObject * OSQP_setup(OSQP *self, PyObject *args, PyObject *kwargs) {
"scaling", "scaling_norm", "scaling_iter",
"rho", "sigma", "max_iter",
"eps_abs", "eps_rel", "eps_prim_inf", "eps_dual_inf", "alpha",
"delta", "polish", "pol_refine_iter", "verbose",
"delta", "polish", "pol_refine_iter", "auto_rho", "verbose",
"early_terminate", "early_terminate_interval",
"warm_start", NULL}; // Settings


#ifdef DLONG

#ifdef DFLOAT
static char * argparse_string = "(ll)O!O!O!O!O!O!O!O!O!|lllfflffffffllllll";
static char * argparse_string = "(ll)O!O!O!O!O!O!O!O!O!|lllfflfffffflllllll";
#else
static char * argparse_string = "(ll)O!O!O!O!O!O!O!O!O!|lllddlddddddllllll";
static char * argparse_string = "(ll)O!O!O!O!O!O!O!O!O!|lllddlddddddlllllll";
#endif

#else

#ifdef DFLOAT
static char * argparse_string = "(ii)O!O!O!O!O!O!O!O!O!|iiiffiffffffiiiiii";
static char * argparse_string = "(ii)O!O!O!O!O!O!O!O!O!|iiiffiffffffiiiiiii";
#else
static char * argparse_string = "(ii)O!O!O!O!O!O!O!O!O!|iiiddiddddddiiiiii";
static char * argparse_string = "(ii)O!O!O!O!O!O!O!O!O!|iiiddiddddddiiiiiii";
#endif

#endif
Expand Down Expand Up @@ -256,6 +256,7 @@ static PyObject * OSQP_setup(OSQP *self, PyObject *args, PyObject *kwargs) {
&settings->delta,
&settings->polish,
&settings->pol_refine_iter,
&settings->auto_rho,
&settings->verbose,
&settings->early_terminate,
&settings->early_terminate_interval,
Expand Down Expand Up @@ -799,6 +800,7 @@ static PyObject *OSQP_update_pol_refine_iter(OSQP *self, PyObject *args){

}


static PyObject *OSQP_update_verbose(OSQP *self, PyObject *args){
c_int verbose_new;

Expand Down
3 changes: 3 additions & 0 deletions interfaces/python/modulepurepy/_osqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class settings(object):
warm_start [False] - Reuse solution from previous solve
polish [True] - Solution polish
pol_refine_iter [3] - Number of iterative refinement iterations
auto_rho [True] - Automatic rho computation
"""

def __init__(self, **kwargs):
Expand All @@ -149,6 +150,8 @@ def __init__(self, **kwargs):
self.warm_start = kwargs.pop('warm_start', False)
self.polish = kwargs.pop('polish', True)
self.pol_refine_iter = kwargs.pop('pol_refine_iter', 3)
self.auto_rho = kwargs.pop('auto_rho', True)



class scaling(object):
Expand Down
6 changes: 4 additions & 2 deletions interfaces/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from shutil import copyfile
from numpy import get_include
from glob import glob
import shutil as sh
from subprocess import call
from platform import system
import os
Expand Down Expand Up @@ -134,8 +135,9 @@ def build_extensions(self):
# Compile OSQP using CMake

# Create build directory
if not os.path.exists(osqp_build_dir):
os.makedirs(osqp_build_dir)
if os.path.exists(osqp_build_dir):
sh.rmtree(osqp_build_dir)
os.makedirs(osqp_build_dir)
os.chdir(osqp_build_dir)

# Compile static library with CMake
Expand Down
129 changes: 0 additions & 129 deletions interfaces/python/tests/qp_problems/analyze_examples.py

This file was deleted.

Binary file added interfaces/python/tests/qp_problems/behavior.pdf
Binary file not shown.
Loading

0 comments on commit 9036153

Please sign in to comment.