LP
Simple C/C++ interface to COIN-OR CBC, CPLEX, GLPK and GUROBI, with some interesting features
|
Functions | |
LinearProgram * | lp_create () |
Creates an empty problem. More... | |
LinearProgram * | lp_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... | |
These are the functions that can be used to create and modify Mixed Integer Linear Programs
void lp_add_bin_cols | ( | LinearProgram * | lp, |
const int | count, | ||
double * | obj, | ||
char ** | name | ||
) |
adds a set of binary variables
lp | the (integer) linear program |
count | number of columns |
obj | vector with objective function coefficients of these variables |
obj | vector variable names |
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)
lp | the (integer) linear program |
obj | the objective function coefficient of this variable |
lb | lower bound for this variable |
ub | upper bound for this variable |
integer | 1 if variable is integer, 0 otherwise |
name | variable name |
nz | number of non-zero entries of this column in the coefficient matrix |
rowIdx | indices of rows where this column appears |
rowCoef | coefficients that that this variable has in each of its rows |
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
lp | the (integer) linear program |
count | number of columns |
obj | objective function coefficients |
lb | lower bounds - if NULL is specified then it is assumed that all variables have lb=0.0 |
ub | upper 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 |
names | variable names |
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
lp | the (integer) linear program |
count | number of columns |
obj | objective function coefficients |
lb | lower bound for these variables |
ub | upper bound for these variables |
vector | indicating if each variable is integer (1) or continuous (0) |
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
lp | the (integer) linear program |
nz | number of non-zero variables in this row |
indexes | indices of variables |
coefs | coefficients of variables |
name | row name |
sense | E for equal, L for less-or-equal or G for greter-or-equal |
rhs | right-hand-side of constraint |
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
lp | the (integer) linear program |
nRows | number of rows |
vector | indicating where each row i starts starts[i] and ends (starts[i]+1) in idx and coef |
idx | column indexes |
coef | column coefficients |
sense | E for equal, L for less-or-equal or G for greter-or-equal |
rhs | right-hand-side of constraint |
names | row names |
void lp_chg_obj | ( | LinearProgram * | lp, |
int | count, | ||
int | idx[], | ||
double | obj[] | ||
) |
changes a set of objective function coefficients
lp | the (integer) linear program |
count | number of variables whose objective function coefficients will change |
idx | indices of variables whose objective function coefficients will change |
coef | vector with new coefficients |
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.
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.
void lp_fix_col | ( | LinearProgram * | lp, |
int | col, | ||
double | val | ||
) |
fixed a column to a value
lp | the (integer) linear program |
col | column index |
val | value |
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)
lp | the (integer) linear program |
void lp_free | ( | LinearProgramPtr * | lp | ) |
releases from memory the problem stored in lp
lp | the (integer) linear program, memory is freed and lp is set to NULL |
int lp_get_direction | ( | LinearProgram * | lp | ) |
returns optimization direction, minimization (LP_MIN) or maximization (LP_MAX)
lp | the (integer) linear program |
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.
lp | the (integer) linear program |
count | number of variables whose value will be informed |
colNames | column names |
colValues | column values |
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.
lp | the (integer) linear program |
count | number of variables whose value will be informed |
colIndexes | column indexes |
colValues | column values |
void lp_mipstart_debug | ( | LinearProgram * | lp | ) |
tries to discover the source of infeasibility in MIPStart
lp | the (integer) linear program |
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.
lp | the (integer) linear program |
fileName | file name where the solution is stored |
void lp_remove_row | ( | LinearProgram * | lp, |
int | idxRow | ||
) |
Removes a row from lp.
lp | the (integer) linear program |
idxRow | row index |
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.
lp | the (integer) linear program |
nRows | number of rows |
rows | row indices |
void lp_save_mip_start | ( | LinearProgram * | lp, |
const char * | fileName | ||
) |
saves the solution entered as MIPStart
lp | the (integer) linear program |
fileName | file name where the solution will be stored |
void lp_set_col_bounds | ( | LinearProgram * | lp, |
int | col, | ||
const double | lb, | ||
const double | ub | ||
) |
changes lower and upper bound of a column
lp | the (integer) linear program |
col | column index |
lb | lower bound |
ub | upper bound |
void lp_set_direction | ( | LinearProgram * | lp, |
const char | direction | ||
) |
sets optimization direction, maximization or minimization
lp | the (integer) linear program |
direction | LP_MIN (0) for minimization (default) or LP_MAX (1) for maximization |
void lp_set_integer | ( | LinearProgram * | lp, |
int | nCols, | ||
int | cols[] | ||
) |
sets the type of some variables to integer
lp | the (integer) linear program |
nCols | number of columns |
cols | vector with column indices |
void lp_set_obj | ( | LinearProgram * | lp, |
double | obj[] | ||
) |
sets objective function coefficients
lp | the (integer) linear program |
obj | objective function coefficients: obj[0] ... obj[n-1], where n is the number of columns |
void lp_set_rhs | ( | LinearProgram * | lp, |
int | row, | ||
double | rhs | ||
) |
modifies the right-hand-side of a constraint
lp | the (integer) linear program |
row | the row index |
rhs | right-hand-side of constraint |
void lp_write_sol | ( | LinearProgram * | lp, |
const char * | fileName | ||
) |
Saves the incumbent solution in for lp in fileName.
lp | the (integer) linear program |
fileName | file name where the solution will be saved |