-
Notifications
You must be signed in to change notification settings - Fork 0
/
lp.h
219 lines (192 loc) · 9.08 KB
/
lp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#ifdef __cplusplus
extern "C" {
#endif
#ifndef LP_HEADER
#define LP_HEADER
#define LP_ME_DEFAULT 0
#define LP_ME_OPTIMALITY 1
#define LP_ME_FEASIBILITY 2
/* Optimization direction */
#define LP_MIN 0
#define LP_MAX 1
/* Optimization result: */
#define LP_OPTIMAL 0
#define LP_INFEASIBLE 1
#define LP_UNBOUNDED 2
#define LP_FEASIBLE 3
#define LP_INTINFEASIBLE 4
#define LP_NO_SOL_FOUND 5
#define LP_ERROR 6
/* types of cut generators */
#define LP_CUT_TYPES 8
#define LPC_GOMORY 0
#define LPC_REDUCE 1
#define LPC_MIR 2
#define LPC_TWO_MIR 3
#define LPC_L_AND_P 4
#define LPC_ZERO_HALF 5
#define LPC_KNAPSACK 6
#define LPC_FLOW 7
/* constraint types, used when querying model */
#define CONS_PARTITIONING 0
#define CONS_PACKING 1
#define CONS_COVERING 2
#define CONS_CARDINALITY 3
#define CONS_KNAPSACK 4
#define CONS_INV_KNAPSACK 5
#define CONS_FLOW_BIN 6
#define CONS_FLOW_INT 7
#define CONS_FLOW_MX 8
#define CONS_VBOUND 9
#define CONS_OTHER 10
#define CONS_NUMBER 11 /* number of types */
/* LP Callback step */
#define LPCB_CUTS 0
#define LPCB_HEUR 1
typedef struct _LinearProgram LinearProgram;
typedef LinearProgram * LinearProgramPtr;
/* Model input & output */
void lp_read( LinearProgram *lp, const char *fileName );
void lp_write_lp( LinearProgram *lp, const char *fileName );
void lp_write_sol( LinearProgram *lp, const char *fileName );
void lp_load_mip_start(LinearProgram *lp, int count, const char **colNames, const double *colValues);
/* uses indices */
void lp_load_mip_starti( LinearProgram *lp, int count, const int *colIndexes, const double *colValues );
int lp_read_mip_start( LinearProgram *lp, const char *fileName );
void lp_save_mip_start( LinearProgram *lp, const char *fileName );
/* tries to discover the source of infeasibility of a MIPStart */
void lp_mipstart_debug( 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) */
void lp_fix_mipstart( LinearProgram *lp );
/* Model creation, modification and destruction */
LinearProgram *lp_create();
LinearProgram *lp_clone( LinearProgram *lp );
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 **name );
void lp_remove_row( LinearProgram *lp, int idxRow );
void lp_remove_rows( LinearProgram *lp, int nRows, int *rows );
/** @brief adds new columns
*
* adds new columns to lp, specifying objective function, bounds, integrality and names
*
* @param count number of columns
* @param obj objective function coefficients
* @param lb lower bounds - if NULL is specified then it is assumed that all variables have lb=0.0
* @param ub upper bounds - if NULL is specified then it is assumed that all variables have ub=infinity
* @param integer - vector of boolean values indicating if each variable is integer, if NULL all variables
* are assumed to be integral
* @param names variable names
*/
void lp_add_col( LinearProgram *lp, double obj, double lb, double ub, char integer, char *name, int nz, int *rowIdx, double *rowCoef );
void lp_add_cols( LinearProgram *lp, const int count, double *obj, double *lb, double *ub, char *integer, char **name );
void lp_add_cols_same_bound( LinearProgram *lp, const int count, double *obj, double lb, double ub, char *integer, char **name );
void lp_add_bin_cols( LinearProgram *lp, const int count, double *obj, char **name );
void lp_free( LinearProgramPtr *lp );
void lp_set_direction( LinearProgram *lp, const char direction );
int lp_get_direction( LinearProgram *lp );
void lp_set_obj( LinearProgram *lp, double *obj );
void lp_chg_obj(LinearProgram *lp, int count, int idx[], double obj[] );
void lp_set_rhs( LinearProgram *lp, int row, double rhs );
void lp_set_col_bounds( LinearProgram *lp, int col, const double lb, const double ub );
void lp_fix_col( LinearProgram *lp, int col, double val );
void lp_set_integer( LinearProgram *lp, int nCols, int cols[] );
LinearProgram *lp_pre_process( LinearProgram *lp );
// sets cutoff for MIP optimization, optionally also adds constraint */
void lp_add_cutoff( LinearProgram *lp, double cutoff, char addConstraint );
// higher values indicate that these fractional variables will be branched first
void lp_set_branching_priorities( LinearProgram *lp, int *priorities );
// 1: always chose up first, -1: always chose down first 0: automatic
void lp_set_branching_direction( LinearProgram *lp, int direction );
/* frees some static memory, must be called at the end of the program */
void lp_close_env();
/* Model optimization, results query
and solution methods parameters */
void lp_set_mip_emphasis( LinearProgram *lp, const int mipEmphasis );
int lp_get_mip_emphasis( LinearProgram *lp );
int lp_optimize( LinearProgram *lp );
char *lp_status_str( int status, char *statusStr );
double lp_solution_time( LinearProgram *lp );
/* if it is a mip, optimizes as a continuous problem */
int lp_optimize_as_continuous( LinearProgram *lp );
/* add cuts over LP relaxation
* maxRoundsCuts[] is a vector of integers
* 0...LP_CUT_TYPES-1 where for each cut one
* must indicate the maximum number of rounds
* where this cut is separated */
int lp_strengthen_with_cuts( LinearProgram *lp, const int maxRoundsCuts[] );
/* add some cut manually
* or when using the callback */
void lp_add_cut( LinearProgram *lp, int nz, int *cutIdx, double *cutCoef, const char *name, char sense, double rhs );
/* primal and dual solution */
double lp_obj_value(LinearProgram *lp); /* obj value of best solution found */
double lp_best_bound(LinearProgram *lp); /* best valid bound for the optimal solution obj value found */
/* soluton */
double *lp_x( LinearProgram *lp );
/* dual varibles, price for rows - only available when solving continous models */
double *lp_row_price( LinearProgram *lp );
/* slack for rows, i.e. active (tight) rows have slack = 0 */
double *lp_row_slack( LinearProgram *lp );
/* reduced cost for columns - only available when solving continous models */
double *lp_reduced_cost( LinearProgram *lp );
/* multiple solutions (if available) */
int lp_num_saved_sols( LinearProgram *lp );
double lp_saved_sol_obj( LinearProgram *lp, int isol );
double *lp_saved_sol_x( LinearProgram *lp, int isol );
/* command line options */
void lp_parse_options( LinearProgram *lp, int argc, const char **argv );
void lp_help_options( );
/* parameters - input/output */
void lp_set_sol_out_file_name( LinearProgram *lp, const char *sfn );
void lp_set_sol_in_file_name( LinearProgram *lp, const char *sfn );
/* parameters - heuristics */
void lp_set_heur_proximity( LinearProgram *lp, char onOff );
void lp_set_heur_fp_passes( LinearProgram *lp, int passes );
/* parameters - cuts */
void lp_set_cuts( LinearProgram *lp, char onOff );
/* parameters - input/output */
void lp_set_print_messages( LinearProgram *lp, char onOff );
/* parameters - limits */
void lp_set_max_seconds( LinearProgram *lp, int _max );
void lp_set_max_solutions( LinearProgram *lp, int _max );
void lp_set_max_nodes( LinearProgram *lp, int _max );
void lp_set_max_saved_sols( LinearProgram *lp, int _max );
void lp_set_abs_mip_gap( LinearProgram *lp, const double _value );
void lp_set_rel_mip_gap( LinearProgram *lp, const double _value );
/* parameters - parallel */
void lp_set_parallel( LinearProgram *lp, char onOff );
/* Model query */
char lp_is_mip( LinearProgram *lp );
char lp_is_integer( LinearProgram *lp, const int j );
char lp_is_binary( LinearProgram *lp, const int j );
void lp_cols_by_type( LinearProgram *lp, int *binaries, int *integers, int *continuous );
int lp_cols( LinearProgram *lp );
int lp_rows( LinearProgram *lp );
int lp_nz( LinearProgram *lp );
int lp_row( LinearProgram *lp, int row, int *idx, double *coef );
int lp_col( LinearProgram *lp, int col, int *idx, double *coef );
double lp_rhs( LinearProgram *lp, int row );
char lp_sense( LinearProgram *lp, int row );
char *lp_row_name( LinearProgram *lp, int row, char *dest );
char *lp_col_name( LinearProgram *lp, int col, char *dest );
double lp_col_lb( LinearProgram *lp, int col );
double lp_col_ub( LinearProgram *lp, int col );
// returns the index of a variable or -1 if name not found
int lp_col_index( LinearProgram *lp, const char *name );
// returns the index of a constraint or -1 if name not found
int lp_row_index( LinearProgram *lp, const char *name );
const double *lp_obj_coef( LinearProgram *lp );
int lp_row_type( LinearProgram *lp, const int row );
void lp_rows_by_type( LinearProgram *lp, int rtype[] );
int *lp_original_colummns( LinearProgram *lp );
/* callback function prototype */
typedef int (*lp_cb)( LinearProgram *lp, int whereFrom, const int *origCols, LinearProgram *origLP, void *data );
/* enter callback info */
void lp_set_callback( LinearProgram *lp, lp_cb callback, void *data );
// global flag indicating if variable/row names will be stored, can save some memory when off
void lp_set_store_names( char store );
#endif
#ifdef __cplusplus
}
#endif