Skip to content

Commit

Permalink
We now accept only upper triangular P. Need to fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
gbanjac committed Mar 20, 2019
1 parent fb56f80 commit 06678c7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
16 changes: 8 additions & 8 deletions docs/examples/demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ C
int main(int argc, char **argv) {
// Load problem data
c_float P_x[4] = {4.00, 1.00, 1.00, 2.00, };
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.00, 1.00, };
c_float A_x[4] = {1.00, 1.00, 1.00, 1.00, };
c_float P_x[3] = {4.0, 1.0, 2.0, };
c_int P_nnz = 3;
c_int P_i[3] = {0, 0, 1, };
c_int P_p[3] = {0, 1, 3, };
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.00, 0.00, 0.00, };
c_float u[3] = {1.00, 0.70, 0.70, };
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;
Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/CC++.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Data
.. doxygenstruct:: OSQPData
:members:

The matrices are defined in `Compressed Sparse Column (CSC) format <https://people.sc.fsu.edu/~jburkardt/data/cc/cc.html>`_.
The matrices are defined in `Compressed Sparse Column (CSC) format <https://people.sc.fsu.edu/~jburkardt/data/cc/cc.html>`_ using zero-based indexing.

.. doxygenstruct:: csc
:members:
Expand Down
8 changes: 4 additions & 4 deletions examples/osqp_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

int main(int argc, char **argv) {
// Load problem data
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 P_x[3] = { 4.0, 1.0, 2.0, };
c_int P_nnz = 3;
c_int P_i[3] = { 0, 0, 1, };
c_int P_p[3] = { 0, 1, 3, };
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;
Expand Down
5 changes: 2 additions & 3 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ typedef struct {
typedef struct {
c_int n; ///< number of variables n
c_int m; ///< number of constraints m
csc *P; ///< quadratic part of the cost P in csc format (size n x n). It
/// can be either the full P or only the upper triangular part. The
/// workspace stores only the upper triangular part
csc *P; ///< the upper triangular part of the quadratic cost matrix
/// P in csc format (size n x n).
csc *A; ///< linear constraints matrix A in csc format (size m x n)
c_float *q; ///< dense array for linear part of cost function (size n)
c_float *l; ///< dense array for lower bound (size m)
Expand Down
16 changes: 13 additions & 3 deletions src/auxil.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ c_int check_termination(OSQPWorkspace *work, c_int approximate) {


c_int validate_data(const OSQPData *data) {
c_int j;
c_int j, ptr;

if (!data) {
# ifdef PRINTING
Expand Down Expand Up @@ -827,11 +827,21 @@ c_int validate_data(const OSQPData *data) {
return 1;
}

for (j = 0; j < data->n; j++) { // COLUMN
for (ptr = data->P->p[j]; ptr < data->P->p[j + 1]; ptr++) {
if (data->P->i[ptr] > j) { // if ROW > COLUMN
# ifdef PRINTING
c_eprint("P is not upper triangular");
# endif /* ifdef PRINTING */
return 1;
}
}
}

// Matrix A
if ((data->A->m != data->m) || (data->A->n != data->n)) {
# ifdef PRINTING
c_eprint("A does not have dimension m x n with m = %i and n = %i",
(int)data->m, (int)data->n);
c_eprint("A does not have dimension %i x %i", (int)data->m, (int)data->n);
# endif /* ifdef PRINTING */
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/osqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ c_int osqp_setup(OSQPWorkspace** work, const OSQPData *data, const OSQPSettings
(*work)->data = c_malloc(sizeof(OSQPData));
(*work)->data->n = data->n; // Number of variables
(*work)->data->m = data->m; // Number of linear constraints
(*work)->data->P = csc_to_triu(data->P); // Cost function matrix
(*work)->data->P = copy_csc_mat(data->P); // Cost function matrix
(*work)->data->q = vec_copy(data->q, data->n); // Linear part of cost function
(*work)->data->A = copy_csc_mat(data->A); // Linear constraints matrix
(*work)->data->l = vec_copy(data->l, data->m); // Lower bounds on constraints
Expand Down

0 comments on commit 06678c7

Please sign in to comment.