set_bounds

Set the upper and lower bound of a variable.

int set_bounds(lprec *lp, int column, REAL lower, REAL upper);

Return Value

set_bounds returns 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_file, read_LP, read_mps, read_MPS

column

The column number of the variable on which the bounds must be set. It must be between 1 and the number of columns in the lp.

Remarks

The set_bounds function sets a lower and upper bound on the variable identified by column.
Setting a bound on a variable is the way to go instead of adding an extra constraint (row) to the model. Setting a bound doesn't increase the model size that means that the model stays smaller and will be solved faster.
Note that the default lower bound of each variable is 0. So variables will never take negative values if no negative lower bound is set. The default upper bound of a variable is infinity (well not quite. It is 1e24).

Example

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

int main(void)
{
  lprec *lp;

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

  set_bounds(lp, 1, 1.0, 2.0);

  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_lowbo, get_lowbo, set_upbo, get_upbo