get_basis

Returns the basis of the lp.

unsigned char get_basis(lprec *lp, int *bascolumn, unsigned char nonbasic);

Return Value

get_basis returns TRUE if a basis could be returned, else FALSE.

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

bascolumn

An array with 1+get_Nrows or 1+get_Nrows+get_Ncolumns elements that will contain the basis after the call.

nonbasic

If FALSE, then bascolumn must have 1+get_Nrows elements and only contains the basic variables. If TRUE, then bascolumn must have 1+get_Nrows+get_Ncolumns elements and will also contain the non-basic variables.

Remarks

The get_basis function returns the basis of the lp.
This can only be done after a successful solve. If the model is not successively solved then the function will return FALSE.
The array receives the basic variables and if nonbasic is TRUE, then also the non-basic variables. If an element is less then zero then it means on lower bound, else on upper bound.
Element 0 of the array is set to 0.
The default initial basis is bascolumn[x] = -x.
Each element represents a basis variable. If the absolute value is between 1 and get_Nrows, it represents a slack variable and if it is between get_Nrows+1 and get_Nrows+get_Ncolumns then it represents a regular variable. If the value is negative, then the variable is on its lower bound. If positive it is on its upper bound.
Setting an initial basis can speed up the solver considerably. It is the starting point from where the algorithm continues to find an optimal solution.
When a restart is done, lp_solve continues at the last basis, except if set_basis, default_basis, guess_basis or read_basis is called.

Example


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

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

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

  /* build model
     .
     .
     .
  */

  solve(lp);
  get_basis(lp, bascolumn, FALSE);

  delete_lp(lp);
  return(0);
}

lp_solve API reference

See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_basis, default_basis, read_basis, write_basis, guess_basis, get_basiscrash, set_basiscrash