set_basis
Sets an initial basis of the lp.
unsigned char set_basis(lprec *lp, int *bascolumn, unsigned char nonbasic);
Return Value
set_basis returns TRUE if provided basis was set. FALSE if not. If FALSE then provided data was invalid.
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 specifies the basis.
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 nonbasic variables.
Remarks
The set_basis function sets an initial basis of the lp.
The array receives the basic variables and if nonbasic is TRUE, then
also the nonbasic variables. If an element is less then zero then it means on
lower bound, else on upper bound.
Element 0 of the array is unused.
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 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);
}
bascolumn[0] = 0;
bascolumn[1] = 1;
bascolumn[2] = 2;
set_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, get_basis, default_basis, read_basis, write_basis, guess_basis, get_basiscrash, set_basiscrash
