set_row, set_rowex

set a constraint in the lp.

unsigned char set_row(lprec *lp, int row_no, REAL *row);

unsigned char set_rowex(lprec *lp, int row_no, int count, REAL *row, int *colno);

Return Value

set_row, set_rowex 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


The row number that must be changed.


Number of elements in row and colno.


An array with 1+column (count for set_rowex if colno is different from NULL) elements that contains the values of the row.


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


The set_row, set_rowex functions change the values of an existing row in the model at once. Note that add_constraint, add_constraintex, str_add_constraint add a row to the model, making the number of rows one larger. These functions change an existing row.
Note that for set_row (and set_rowex when colno is NULL) element 1 of the array is column 1, element 2 is column 2, ... element 0 is not used.
set_rowex has the possibility to specify only the non-zero elements. And in contrary to set_row, set_rowex reads the arrays starting from element 0. However when colno is NULL then set_rowex acts as set_row and then values start at element 1. When colno is provided, then it specifies the column 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_rowex instead of set_row. set_rowex is always at least as performant as set_row. It is more performant to call these functions than multiple times set_mat. Note that unspecified values by set_rowex are set to zero.


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

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

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

  row[1] = 1.0;
  row[2] = 2.0;
  set_row(lp, 1, row); /* changes the values of existing row 1 */


lp_solve API reference

See Also make_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_row, add_constraint, add_constraintex, str_add_constraint, 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, set_column, set_columnex, get_column, get_row, get_mat