add_column, add_columnex, str_add_column

Add a column to the lp.

unsigned char add_column(lprec *lp, REAL *column);

unsigned char add_columnex(lprec *lp, int count, REAL *column, int *rowno);

unsigned char str_add_column(lprec *lp, char *col_string);

Return Value

add_column, add_columnex, and str_add_column return TRUE (1) if the operation was successful. A return value of FALSE (0) indicates an error.



Pointer to previously created lp model. See return value of make_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI


Number of elements in column and rowno.


An array with 1+rows (count for add_columnex if rowno is different from NULL) elements that contains the values of the column.


An array with count elements that contains the row numbers of the column. However this variable can also be NULL. In that case element i in the variable column is row i.


A string with row elements that contains the values of the column. Each element must be separated by space(s).


The add_column, add_columnex, str_add_column functions add a column to the model (at the end) and sets all values of the column at once.
Note that for add_column (and add_columnex when rowno is NULL) element 0 of the array is the value of the objective function for that column. Column 1 is element 1, column 2 is element 2, ...
add_columnex has the possibility to specify only the non-zero elements. In that case rowno specifies the row numbers of the non-zero elements. This will speed up building the model considerably if there are a lot of zero values. In most cases the matrix is sparse and has many zero value. Thus it is almost always better to use add_columnex instead of add_column. add_columnex is always at least as performant as add_column. One important note about add_columnex. str_add_column should only be used in small or demo code since it is not performant and uses more memory.
For add_columnex, column and rowno can both be NULL. In that case an empty column is added.


#include <stdio.h>
#include <stdlib.h>
#include "lp_lib.h"

int main(void)
  lprec *lp;
  REAL column[1+2]; /* must be 1 more then number of rows ! */

  /* Create a new LP model */
  lp = make_lp(2, 0);
  if(lp == NULL) {
    fprintf(stderr, "Unable to create new LP model\n");

  column[0] = 1.0; /* the objective value */
  column[1] = 2.0;
  column[2] = 3.0;
  add_column(lp, column);


lp_solve API reference

See Also make_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_obj_fn, set_obj_fnex, str_set_obj_fn, set_obj, set_column, set_columnex, del_column, set_add_rowmode, is_add_rowmode, add_constraint, add_constraintex, str_add_constraint, set_row, set_rowex, get_column, get_row, get_mat, column_in_lp