guess_basis

Create a starting base from the provided guess vector.

unsigned char guess_basis(lprec *lp, REAL *guessvector, int *basisvector);

Return Value

guess_basis returns TRUE if a valid base could be termined and FALSE if not.

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

guessvector

A vector that must contain a feasible solution vector. It must contain at least 1+get_Ncolumns elements. Element 0 is not used.

basisvector

When successful, this vector contains a feasible basis corresponding to guessvector. The array must already be dimentioned for at least 1+get_Nrows+get_Ncolumns elements. When the routine returns successful, basisvector is filled with the basis. This array can be provided to set_basis.

Remarks

This routine is ment to find a basis based on provided variable values. This basis can be provided to lp_solve via set_basis. This can result in getting faster to an optimal solution. However the simplex algorithm doesn't guarantee you that.

Example

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

int main(void)
{
  lprec *lp;
  int ret;
  REAL guessvector[1 + 2];
  int basis[1 + 2 + 2];

  /* 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_maxim(lp);
  str_add_constraint(lp, "1 0", LE, 3);
  str_add_constraint(lp, "0 1", LE, 3);

  guessvector[1] = 3;
  guessvector[2] = 3;

  ret = guess_basis(lp, guessvector, basis);
  set_basis(lp, basis, TRUE);
  set_print_sol(lp, TRUE);

  solve(lp); /* notice that the number of iterations is NULL because we provided a base that is immediately optimal */

  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, get_basis, set_basis, default_basis, get_basiscrash set_basiscrash