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. Note that for add_columnex, if rowno is not NULL, that the rows must be in ascending order. If not then it will also return FALSE.

Parameters

lp

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

count

Number of elements in column and rowno.

column

An array with 1+row (count for add_columnex) elements that contains the values of the column.

rowno

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.

col_string

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

Remarks

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. If rowno is not NULL then the row numbers in rowno must be in ascending order. If they are not then add_columnex fails and returns FALSE.
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.

Example

#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");
    return(1);
  }

  column[0] = 1.0;
  column[1] = 2.0;
  column[2] = 3.0;
  add_column(lp, column);

  delete_lp(lp);
  return(0);
}

lp_solve API reference

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