add_constraint, str_add_constraint

Add a constraint to the lp.

int add_constraint(lprec *lp, REAL *row, short constr_type, REAL rh);

int str_add_constraint(lprec *lp, char *str_row, short constr_type, REAL rh);

Return Value

add_constraint and str_add_constraint return TRUE (1) if the operation was successful. A return value of FALSE (0) indicates an error.
lp->spx_status specifies what error occurred.

Parameters

lp

Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_lp_file, read_LP, read_mps, read_MPS

row

An array with column elements that contains the values of the row.

str_row

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

constr_type

The type of the constraint. Can by any of the following values:

LE (0) Less than or equal (<=)
EQ (1) Equal (=)
GE (2) Greater than or equal (>=)

rh

The value of the right hand side (RHS).

Remarks

The add_constraint, str_add_constraint functions adds a row to the model (at the end) and sets all values of the row at once.
Note that element 0 of the array is not considered (i.e. ignored). Column 1 is element 1, column 2 is element 2, ...

Example

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

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

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

  row[1] = 1.0;
  row[2] = 2.0;
  add_constraint(lp, row, GE, 3.0); /* constructs the row: +v_1 +2 v_2 >= 3 */

  delete_lp(lp);
  return(0);
}

lp_solve API reference

See Also make_lp, copy_lp, read_lp, read_lp_file, read_LP, read_mps, read_MPS, set_obj_fn, str_set_obj_fn, get_constr_type, del_constraint, add_column, str_add_column, get_column, get_row, get_mat, mat_elm