Skip to content

Commit

Permalink
osqp_setup now returns exitflags
Browse files Browse the repository at this point in the history
  • Loading branch information
gbanjac committed Mar 20, 2019
1 parent a46b5f6 commit 78d1135
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 241 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

# General information about the project.
project = 'OSQP'
copyright = '2018, Bartolomeo Stellato, Goran Banjac'
copyright = '2019, Bartolomeo Stellato, Goran Banjac'
author = 'Bartolomeo Stellato, Goran Banjac'

# The version info for the project you're documenting, acts as replacement for
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ C
data->l = l;
data->u = u;
// Define Solver settings as default
osqp_set_default_settings(settings);
settings->alpha = 1.0; // Change alpha parameter
// Setup workspace
work = osqp_setup(data, settings);
osqp_setup(&work, data, settings);
// Solve Problem
osqp_solve(work);
Expand Down
37 changes: 14 additions & 23 deletions examples/osqp_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@

int main(int argc, char **argv) {
// Load problem data
c_float P_x[4] =
{ 4.00000000000000000000, 1.00000000000000000000, 1.00000000000000000000,
2.00000000000000000000, };
c_int P_nnz = 4;
c_int P_i[4] = { 0, 1, 0, 1, };
c_int P_p[3] = { 0, 2, 4, };
c_float q[2] = { 1.00000000000000000000, 1.00000000000000000000, };
c_float A_x[4] =
{ 1.00000000000000000000, 1.00000000000000000000, 1.00000000000000000000,
1.00000000000000000000, };
c_int A_nnz = 4;
c_int A_i[4] = { 0, 1, 0, 2, };
c_int A_p[3] = { 0, 2, 4, };
c_float l[3] =
{ 1.00000000000000000000, 0.00000000000000000000, 0.00000000000000000000, };
c_float u[3] =
{ 1.00000000000000000000, 0.69999999999999995559, 0.69999999999999995559, };
c_float P_x[4] = { 4.0, 1.0, 1.0, 2.0, };
c_int P_nnz = 4;
c_int P_i[4] = { 0, 1, 0, 1, };
c_int P_p[3] = { 0, 2, 4, };
c_float q[2] = { 1.0, 1.0, };
c_float A_x[4] = { 1.0, 1.0, 1.0, 1.0, };
c_int A_nnz = 4;
c_int A_i[4] = { 0, 1, 0, 2, };
c_int A_p[3] = { 0, 2, 4, };
c_float l[3] = { 1.0, 0.0, 0.0, };
c_float u[3] = { 1.0, 0.7, 0.7, };
c_int n = 2;
c_int m = 3;


// Problem settings
OSQPSettings *settings = (OSQPSettings *)c_malloc(sizeof(OSQPSettings));

Expand All @@ -33,7 +26,7 @@ int main(int argc, char **argv) {
OSQPData *data; // OSQPData

// Populate data
data = (OSQPData *)c_malloc(sizeof(OSQPData));
data = (OSQPData *)c_malloc(sizeof(OSQPData));
data->n = n;
data->m = m;
data->P = csc_matrix(data->n, data->n, P_nnz, P_x, P_i, P_p);
Expand All @@ -42,12 +35,11 @@ int main(int argc, char **argv) {
data->l = l;
data->u = u;


// Define Solver settings as default
// Define solver settings as default
osqp_set_default_settings(settings);

// Setup workspace
work = osqp_setup(data, settings);
osqp_setup(&work, data, settings);

// Solve Problem
osqp_solve(work);
Expand All @@ -59,6 +51,5 @@ int main(int argc, char **argv) {
c_free(data);
c_free(settings);


return 0;
}
9 changes: 9 additions & 0 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ extern "C" {
# define OSQP_VERSION ("0.5.0") /* string literals automatically null-terminated
*/

/******************
* Setup Status *
******************/
# define OSQP_DATA_VALIDATION_ERROR (1)
# define OSQP_SETTINGS_VALIDATION_ERROR (2)
# define OSQP_WORKSPACE_ALLOCATION_ERROR (3)
# define OSQP_LOAD_LINSYS_SOLVER_ERROR (4)
# define OSQP_INIT_LINSYS_SOLVER_ERROR (5)


/******************
* Solver Status *
Expand Down
6 changes: 3 additions & 3 deletions include/osqp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ void osqp_set_default_settings(OSQPSettings *settings);
* NB: This is the only function that allocates dynamic memory and is not used
*during code generation
*
* @param work Solver workspace
* @param data Problem data
* @param settings Solver settings
* @return Solver environment
* @return Exitflag for errors (0 if no errors)
*/
OSQPWorkspace* osqp_setup(const OSQPData *data,
OSQPSettings *settings);
c_int osqp_setup(OSQPWorkspace** work, const OSQPData* data, const OSQPSettings* settings);

# endif // #ifndef EMBEDDED

Expand Down
10 changes: 5 additions & 5 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,25 +314,25 @@ typedef struct {
* on the choice
*/
struct linsys_solver {
enum linsys_solver_type type; ///< Linear system solver type (see type.h)
enum linsys_solver_type type; ///< Linear system solver type
// Functions
c_int (*solve)(LinSysSolver *self,
c_float *b,
const OSQPSettings *settings); ///< Solve linear system

# ifndef EMBEDDED
# ifndef EMBEDDED
void (*free)(LinSysSolver *self); ///< Free linear system solver
// (only in desktop version)
# endif // ifndef EMBEDDED
# endif // ifndef EMBEDDED

# if EMBEDDED != 1
# if EMBEDDED != 1
c_int (*update_matrices)(LinSysSolver *self, const csc *P, const csc *A,
const OSQPSettings *settings); ///< Update matrices P
// and A in the solver
c_int (*update_rho_vec)(LinSysSolver *s,
const c_float *rho_vec,
const c_int m); ///< Update rho
# endif // if EMBEDDED != 1
# endif // if EMBEDDED != 1

# ifndef EMBEDDED
c_int nthreads; ///< Number of threads active
Expand Down
8 changes: 4 additions & 4 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const char* osqp_version(void);
* @param settings Settings to be copied
* @return New settings structure
*/
OSQPSettings* copy_settings(OSQPSettings *settings);
OSQPSettings* copy_settings(const OSQPSettings *settings);

# endif // #ifndef EMBEDDED

Expand Down Expand Up @@ -94,9 +94,9 @@ void print_footer(OSQPInfo *info,
// Some R packages clash with elements
// of the windows.h header, so use a
// slimmer version for conflict avoidance
# ifdef R_LANG
#define NOGDI
# endif
# ifdef R_LANG
#define NOGDI
# endif

# include <windows.h>

Expand Down
2 changes: 1 addition & 1 deletion lin_sys/direct/pardiso/pardiso_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct pardiso {
*/
// Attributes
csc *KKT; ///< KKT matrix (in CSR format!)
c_int *KKT_i; ///< KKT column ondeces in 1-indexing for Pardiso
c_int *KKT_i; ///< KKT column indices in 1-indexing for Pardiso
c_int *KKT_p; ///< KKT row pointers in 1-indexing for Pardiso
c_float *bp; ///< workspace memory for solves (rhs)

Expand Down
22 changes: 11 additions & 11 deletions lin_sys/direct/qdldl/qdldl_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ static c_int permute_KKT(csc ** KKT, qdldl_solver * p, c_int Pnz, c_int Anz, c_i

info = (c_float *)c_malloc(AMD_INFO * sizeof(c_float));

// Compute permutation metrix P using AMD
#ifdef DLONG
// Compute permutation matrix P using AMD
#ifdef DLONG
amd_status = amd_l_order((*KKT)->n, (*KKT)->p, (*KKT)->i, p->P, (c_float *)OSQP_NULL, info);
#else
#else
amd_status = amd_order((*KKT)->n, (*KKT)->p, (*KKT)->i, p->P, (c_float *)OSQP_NULL, info);
#endif
#endif
if (amd_status < 0) return (amd_status);


Expand Down Expand Up @@ -247,9 +247,9 @@ qdldl_solver *init_linsys_solver_qdldl(const csc * P, const csc * A, c_float sig

// Check if matrix has been created
if (!KKT_temp){
#ifdef PRINTING
c_eprint("Error forming and permuting KKT matrix");
#endif
#ifdef PRINTING
c_eprint("Error forming and permuting KKT matrix");
#endif
return OSQP_NULL;
}

Expand All @@ -271,14 +271,14 @@ qdldl_solver *init_linsys_solver_qdldl(const csc * P, const csc * A, c_float sig
// Link Functions
p->solve = &solve_linsys_qdldl;

#ifndef EMBEDDED
#ifndef EMBEDDED
p->free = &free_linsys_solver_qdldl;
#endif
#endif

#if EMBEDDED != 1
#if EMBEDDED != 1
p->update_matrices = &update_linsys_solver_matrices_qdldl;
p->update_rho_vec = &update_linsys_solver_rho_vec_qdldl;
#endif
#endif

// Assign type
p->type = QDLDL_SOLVER;
Expand Down
16 changes: 8 additions & 8 deletions lin_sys/direct/qdldl/qdldl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ struct qdldl {
*/
c_int (*solve)(struct qdldl * self, c_float * b, const OSQPSettings * settings);

#ifndef EMBEDDED
#ifndef EMBEDDED
void (*free)(struct qdldl * self); ///< Free workspace (only if desktop)
#endif
#endif

// This used only in non embedded or embedded 2 version
#if EMBEDDED != 1
#if EMBEDDED != 1
c_int (*update_matrices)(struct qdldl * self, const csc *P, const csc *A, const OSQPSettings *settings); ///< Update solver matrices
c_int (*update_rho_vec)(struct qdldl * self, const c_float * rho_vec, const c_int m); ///< Update solver matrices
#endif
#endif

#ifndef EMBEDDED
#ifndef EMBEDDED
c_int nthreads;
#endif
#endif
/** @} */

/**
Expand All @@ -47,7 +47,7 @@ struct qdldl {
c_float *bp; ///< workspace memory for solves


#if EMBEDDED != 1
#if EMBEDDED != 1
// These are required for matrix updates
c_int * Pdiag_idx, Pdiag_n; ///< index and number of diagonal elements in P
csc * KKT; ///< Permuted KKT matrix in sparse form (used to update P and A matrices)
Expand All @@ -60,7 +60,7 @@ struct qdldl {
QDLDL_int *iwork;
QDLDL_bool *bwork;
QDLDL_float *fwork;
#endif
#endif

/** @} */
};
Expand Down

0 comments on commit 78d1135

Please sign in to comment.