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, copy_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+get_Nrows (count for set_columnex, if rowno is different from NULL) elements that contains the values of the column.

rowno

A zero-based 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. And in contrary to set_column, set_columnex reads the arrays starting from element 0. 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+3];     /* must be 1 more than number of rows ! */
  REAL sparsecolumn[2]; /* must be the number of non-zero values */
  int rowno[2];

  /* Create a new LP model */
  lp = make_lp(3, 2);
  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[2] = 0.0;
  column[3] = 3.0;
  set_column(lp, 1, column); /* changes the values of existing column 1 */
  
  rowno[0] = 0; sparsecolumn[0] = 1.0; /* the objective value */
  rowno[1] = 1; sparsecolumn[1] = 2.0;
  rowno[2] = 3; sparsecolumn[2] = 3.0;
  set_columnex(lp, 2, 3, sparsecolumn, rowno); /* changes the values of existing column 2 */

  delete_lp(lp);
  return(0);
}

lp_solve API reference

See Also make_lp, copy_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_column, get_columnex, 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_columnex, get_row, get_rowex, get_mat