set_column, set_columnex

set a column in the lp.

unsigned char set_column(lprec *lp, int col_no, REAL *column);

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

Return Value

set_column, set_columnex return TRUE (1) if the operation was successful. A return value of FALSE (0) indicates an error.

Parameters

lp

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

col_no

The column number that must be changed.

count

Number of elements in column and rowno.

column

An array with 1+rows (count for set_columnex if rowno is different from NULL) 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.

Remarks

The set_column, set_columnex functions change the values of an existing column in the model at once. Note that add_column, add_columnex, str_add_column add a column to the model, making the number of columns one larger. These functions change an existing column.
Note that for set_column (and set_columnex when rowno is NULL) element 0 of the array is row 0 (the objective function), element 1 is row 1, ...
set_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 set_columnex instead of set_column. set_columnex is always at least as performant as set_column. It is more performant to call these functions than multiple times set_mat. Note that unspecified values by set_columnex are set to zero.

Example

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

int main(void)
{
  lprec *lp;
  REAL column[1+2];

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

  column[0] = 1.0; /* the objective value */
  column[1] = 2.0;
  column[1] = 3.0;
  set_column(lp, 1, column); /* changes the values of existing column 1 */

  delete_lp(lp);
  return(0);
}

lp_solve API reference

See Also make_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_column, add_column, add_columnex, str_add_column, add_constraint, add_constraintex, str_add_constraint, set_row, set_rowex, set_obj_fn, set_obj_fnex, str_set_obj_fn, set_obj, set_add_rowmode, is_add_rowmode, get_constr_type, is_constr_type, del_constraint, add_column, add_columnex, str_add_column, get_column, get_row, get_mat