LP
Simple C/C++ interface to COIN-OR CBC, CPLEX, GLPK and GUROBI, with some interesting features
Functions
Problem creation and modification functions

Functions

LinearProgramlp_create ()
 Creates an empty problem. More...
 
LinearProgramlp_clone (LinearProgram *lp)
 Clones the problem in lp.
 
void lp_read (LinearProgram *lp, const char *fileName)
 Reads a .lp or .mps file in fileName to object lp.
 
void lp_write_lp (LinearProgram *lp, const char *fileName)
 saves the problem in lp to file fileName. Use extension .lp or .mps to define file format.
 
void lp_add_col (LinearProgram *lp, double obj, double lb, double ub, char integer, char *name, int nz, int *rowIdx, double *rowCoef)
 adds a new column (variable) More...
 
void lp_add_cols (LinearProgram *lp, const int count, double *obj, double *lb, double *ub, char *integer, char **name)
 adds new columns (variables) More...
 
void lp_add_cols_same_bound (LinearProgram *lp, const int count, double *obj, double lb, double ub, char *integer, char **name)
 adds set of columns with the same bounds More...
 
void lp_add_bin_cols (LinearProgram *lp, const int count, double *obj, char **name)
 adds a set of binary variables More...
 
void lp_add_row (LinearProgram *lp, const int nz, int *indexes, double *coefs, const char *name, char sense, const double rhs)
 
void lp_add_rows (LinearProgram *lp, int nRows, int *starts, int *idx, double *coef, char *sense, double *rhs, const char **names)
 
void lp_remove_row (LinearProgram *lp, int idxRow)
 Removes a row from lp. More...
 
void lp_remove_rows (LinearProgram *lp, int nRows, int *rows)
 Removes a set of rows from lp Removes a set of rows from lp, calling this function is usually faster than to remove rows one-by-one. More...
 
void lp_set_direction (LinearProgram *lp, const char direction)
 sets optimization direction, maximization or minimization More...
 
int lp_get_direction (LinearProgram *lp)
 returns optimization direction, minimization (LP_MIN) or maximization (LP_MAX) More...
 
void lp_set_obj (LinearProgram *lp, double obj[])
 sets objective function coefficients More...
 
void lp_chg_obj (LinearProgram *lp, int count, int idx[], double obj[])
 changes a set of objective function coefficients More...
 
void lp_set_rhs (LinearProgram *lp, int row, double rhs)
 modifies the right-hand-side of a constraint More...
 
void lp_set_col_bounds (LinearProgram *lp, int col, const double lb, const double ub)
 changes lower and upper bound of a column More...
 
void lp_fix_col (LinearProgram *lp, int col, double val)
 fixed a column to a value More...
 
void lp_set_integer (LinearProgram *lp, int nCols, int cols[])
 sets the type of some variables to integer More...
 
void lp_write_sol (LinearProgram *lp, const char *fileName)
 Saves the incumbent solution in for lp in fileName. More...
 
void lp_load_mip_start (LinearProgram *lp, int count, const char **colNames, const double *colValues)
 Enters a initial feasible solution for the problem. Variables are referenced by their names. Only the main decision variables need to be informed. More...
 
void lp_load_mip_starti (LinearProgram *lp, int count, const int *colIndexes, const double *colValues)
 Enters a initial feasible solution for the problem using column indexes. Only the main decision variables need to be informed. More...
 
int lp_read_mip_start (LinearProgram *lp, const char *fileName)
 Loads from fileName an initial feasible solution. More...
 
void lp_save_mip_start (LinearProgram *lp, const char *fileName)
 saves the solution entered as MIPStart More...
 
void lp_mipstart_debug (LinearProgram *lp)
 tries to discover the source of infeasibility in MIPStart More...
 
void lp_fix_mipstart (LinearProgram *lp)
 For debugging purposes: fixes mipstart variables one by one and optimizes (if initial solution is invalid at some point an infeasible LP will appear) More...
 
void lp_free (LinearProgramPtr *lp)
 releases from memory the problem stored in lp More...
 
void lp_close_env ()
 frees environment static memory at the end of the program More...
 

Detailed Description

These are the functions that can be used to create and modify Mixed Integer Linear Programs

Function Documentation

◆ lp_add_bin_cols()

void lp_add_bin_cols ( LinearProgram lp,
const int  count,
double *  obj,
char **  name 
)

adds a set of binary variables

Parameters
lpthe (integer) linear program
countnumber of columns
objvector with objective function coefficients of these variables
objvector variable names

◆ lp_add_col()

void lp_add_col ( LinearProgram lp,
double  obj,
double  lb,
double  ub,
char  integer,
char *  name,
int  nz,
int *  rowIdx,
double *  rowCoef 
)

adds a new column (variable)

Parameters
lpthe (integer) linear program
objthe objective function coefficient of this variable
lblower bound for this variable
ubupper bound for this variable
integer1 if variable is integer, 0 otherwise
namevariable name
nznumber of non-zero entries of this column in the coefficient matrix
rowIdxindices of rows where this column appears
rowCoefcoefficients that that this variable has in each of its rows

◆ lp_add_cols()

void lp_add_cols ( LinearProgram lp,
const int  count,
double *  obj,
double *  lb,
double *  ub,
char *  integer,
char **  name 
)

adds new columns (variables)

adds new columns to lp, specifying objective function, bounds, integrality and names

Parameters
lpthe (integer) linear program
countnumber of columns
objobjective function coefficients
lblower bounds - if NULL is specified then it is assumed that all variables have lb=0.0
ubupper bounds - if NULL is specified then it is assumed that all variables have ub=infinity
integer- vector of boolean values indicating if each variable is integer, if NULL all variables are assumed to be integral
namesvariable names

◆ lp_add_cols_same_bound()

void lp_add_cols_same_bound ( LinearProgram lp,
const int  count,
double *  obj,
double  lb,
double  ub,
char *  integer,
char **  name 
)

adds set of columns with the same bounds

Parameters
lpthe (integer) linear program
countnumber of columns
objobjective function coefficients
lblower bound for these variables
ubupper bound for these variables
vectorindicating if each variable is integer (1) or continuous (0)

◆ lp_add_row()

void lp_add_row ( LinearProgram lp,
const int  nz,
int *  indexes,
double *  coefs,
const char *  name,
char  sense,
const double  rhs 
)

Adds a new row (linear constraint) to the problem in lp

Parameters
lpthe (integer) linear program
nznumber of non-zero variables in this row
indexesindices of variables
coefscoefficients of variables
namerow name
senseE for equal, L for less-or-equal or G for greter-or-equal
rhsright-hand-side of constraint

◆ lp_add_rows()

void lp_add_rows ( LinearProgram lp,
int  nRows,
int *  starts,
int *  idx,
double *  coef,
char *  sense,
double *  rhs,
const char **  names 
)

Adds new rows (linear constraints) to the problem in lp

Parameters
lpthe (integer) linear program
nRowsnumber of rows
vectorindicating where each row i starts starts[i] and ends (starts[i]+1) in idx and coef
idxcolumn indexes
coefcolumn coefficients
senseE for equal, L for less-or-equal or G for greter-or-equal
rhsright-hand-side of constraint
namesrow names

◆ lp_chg_obj()

void lp_chg_obj ( LinearProgram lp,
int  count,
int  idx[],
double  obj[] 
)

changes a set of objective function coefficients

Parameters
lpthe (integer) linear program
countnumber of variables whose objective function coefficients will change
idxindices of variables whose objective function coefficients will change
coefvector with new coefficients

◆ lp_close_env()

void lp_close_env ( )

frees environment static memory at the end of the program

CPLEX and Gurobi need and environment, which LP creates on demand. Before your program exits, this function should be called to free these data structures.

◆ lp_create()

LinearProgram* lp_create ( )

Creates an empty problem.

Creates an empty problem. Use lp_read to read a problem from a file or API functions (lp_add_cols, lp_add_row) fill the contents of this problem.

◆ lp_fix_col()

void lp_fix_col ( LinearProgram lp,
int  col,
double  val 
)

fixed a column to a value

Parameters
lpthe (integer) linear program
colcolumn index
valvalue

◆ lp_fix_mipstart()

void lp_fix_mipstart ( LinearProgram lp)

For debugging purposes: fixes mipstart variables one by one and optimizes (if initial solution is invalid at some point an infeasible LP will appear)

Parameters
lpthe (integer) linear program

◆ lp_free()

void lp_free ( LinearProgramPtr lp)

releases from memory the problem stored in lp

Parameters
lpthe (integer) linear program, memory is freed and lp is set to NULL

◆ lp_get_direction()

int lp_get_direction ( LinearProgram lp)

returns optimization direction, minimization (LP_MIN) or maximization (LP_MAX)

Parameters
lpthe (integer) linear program
Returns
0 if minimization, 1 if maximization

◆ lp_load_mip_start()

void lp_load_mip_start ( LinearProgram lp,
int  count,
const char **  colNames,
const double *  colValues 
)

Enters a initial feasible solution for the problem. Variables are referenced by their names. Only the main decision variables need to be informed.

Parameters
lpthe (integer) linear program
countnumber of variables whose value will be informed
colNamescolumn names
colValuescolumn values

◆ lp_load_mip_starti()

void lp_load_mip_starti ( LinearProgram lp,
int  count,
const int *  colIndexes,
const double *  colValues 
)

Enters a initial feasible solution for the problem using column indexes. Only the main decision variables need to be informed.

Parameters
lpthe (integer) linear program
countnumber of variables whose value will be informed
colIndexescolumn indexes
colValuescolumn values

◆ lp_mipstart_debug()

void lp_mipstart_debug ( LinearProgram lp)

tries to discover the source of infeasibility in MIPStart

Parameters
lpthe (integer) linear program

◆ lp_read_mip_start()

int lp_read_mip_start ( LinearProgram lp,
const char *  fileName 
)

Loads from fileName an initial feasible solution.

Loads from fileName an initial feasible solution. The solution should be saved in a simple text file as in the example:

Stopped on iterations - objective value 57597.00000000
0 x(1,1,2,2) 1
1 x(3,1,3,2) 1
5 v(5,1) 2
33 x(8,1,5,2) 1
...

The first column (column index) is ignored. The first line is also ignored. Only column names (second column) and column values (third column) need to be informed for non-zero variables.

Parameters
lpthe (integer) linear program
fileNamefile name where the solution is stored

◆ lp_remove_row()

void lp_remove_row ( LinearProgram lp,
int  idxRow 
)

Removes a row from lp.

Parameters
lpthe (integer) linear program
idxRowrow index

◆ lp_remove_rows()

void lp_remove_rows ( LinearProgram lp,
int  nRows,
int *  rows 
)

Removes a set of rows from lp Removes a set of rows from lp, calling this function is usually faster than to remove rows one-by-one.

Parameters
lpthe (integer) linear program
nRowsnumber of rows
rowsrow indices

◆ lp_save_mip_start()

void lp_save_mip_start ( LinearProgram lp,
const char *  fileName 
)

saves the solution entered as MIPStart

Parameters
lpthe (integer) linear program
fileNamefile name where the solution will be stored

◆ lp_set_col_bounds()

void lp_set_col_bounds ( LinearProgram lp,
int  col,
const double  lb,
const double  ub 
)

changes lower and upper bound of a column

Parameters
lpthe (integer) linear program
colcolumn index
lblower bound
ubupper bound

◆ lp_set_direction()

void lp_set_direction ( LinearProgram lp,
const char  direction 
)

sets optimization direction, maximization or minimization

Parameters
lpthe (integer) linear program
directionLP_MIN (0) for minimization (default) or LP_MAX (1) for maximization

◆ lp_set_integer()

void lp_set_integer ( LinearProgram lp,
int  nCols,
int  cols[] 
)

sets the type of some variables to integer

Parameters
lpthe (integer) linear program
nColsnumber of columns
colsvector with column indices

◆ lp_set_obj()

void lp_set_obj ( LinearProgram lp,
double  obj[] 
)

sets objective function coefficients

Parameters
lpthe (integer) linear program
objobjective function coefficients: obj[0] ... obj[n-1], where n is the number of columns

◆ lp_set_rhs()

void lp_set_rhs ( LinearProgram lp,
int  row,
double  rhs 
)

modifies the right-hand-side of a constraint

Parameters
lpthe (integer) linear program
rowthe row index
rhsright-hand-side of constraint

◆ lp_write_sol()

void lp_write_sol ( LinearProgram lp,
const char *  fileName 
)

Saves the incumbent solution in for lp in fileName.

Parameters
lpthe (integer) linear program
fileNamefile name where the solution will be saved