glpnpp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /* glpnpp.h (LP/MIP preprocessor) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
  7. * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
  8. * E-mail: <mao@gnu.org>.
  9. *
  10. * GLPK is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. * License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************/
  23. #ifndef GLPNPP_H
  24. #define GLPNPP_H
  25. #include "glpapi.h"
  26. typedef struct NPP NPP;
  27. typedef struct NPPROW NPPROW;
  28. typedef struct NPPCOL NPPCOL;
  29. typedef struct NPPAIJ NPPAIJ;
  30. typedef struct NPPTSE NPPTSE;
  31. typedef struct NPPLFE NPPLFE;
  32. struct NPP
  33. { /* LP/MIP preprocessor workspace */
  34. /*--------------------------------------------------------------*/
  35. /* original problem segment */
  36. int orig_dir;
  37. /* optimization direction flag:
  38. GLP_MIN - minimization
  39. GLP_MAX - maximization */
  40. int orig_m;
  41. /* number of rows */
  42. int orig_n;
  43. /* number of columns */
  44. int orig_nnz;
  45. /* number of non-zero constraint coefficients */
  46. /*--------------------------------------------------------------*/
  47. /* transformed problem segment (always minimization) */
  48. DMP *pool;
  49. /* memory pool to store problem components */
  50. char *name;
  51. /* problem name (1 to 255 chars); NULL means no name is assigned
  52. to the problem */
  53. char *obj;
  54. /* objective function name (1 to 255 chars); NULL means no name
  55. is assigned to the objective function */
  56. double c0;
  57. /* constant term of the objective function */
  58. int nrows;
  59. /* number of rows introduced into the problem; this count
  60. increases by one every time a new row is added and never
  61. decreases; thus, actual number of rows may be less than nrows
  62. due to row deletions */
  63. int ncols;
  64. /* number of columns introduced into the problem; this count
  65. increases by one every time a new column is added and never
  66. decreases; thus, actual number of column may be less than
  67. ncols due to column deletions */
  68. NPPROW *r_head;
  69. /* pointer to the beginning of the row list */
  70. NPPROW *r_tail;
  71. /* pointer to the end of the row list */
  72. NPPCOL *c_head;
  73. /* pointer to the beginning of the column list */
  74. NPPCOL *c_tail;
  75. /* pointer to the end of the column list */
  76. /*--------------------------------------------------------------*/
  77. /* transformation history */
  78. DMP *stack;
  79. /* memory pool to store transformation entries */
  80. NPPTSE *top;
  81. /* pointer to most recent transformation entry */
  82. #if 0 /* 16/XII-2009 */
  83. int count[1+25];
  84. /* transformation statistics */
  85. #endif
  86. /*--------------------------------------------------------------*/
  87. /* resultant (preprocessed) problem segment */
  88. int m;
  89. /* number of rows */
  90. int n;
  91. /* number of columns */
  92. int nnz;
  93. /* number of non-zero constraint coefficients */
  94. int *row_ref; /* int row_ref[1+m]; */
  95. /* row_ref[i], 1 <= i <= m, is the reference number assigned to
  96. a row, which is i-th row of the resultant problem */
  97. int *col_ref; /* int col_ref[1+n]; */
  98. /* col_ref[j], 1 <= j <= n, is the reference number assigned to
  99. a column, which is j-th column of the resultant problem */
  100. /*--------------------------------------------------------------*/
  101. /* recovered solution segment */
  102. int sol;
  103. /* solution indicator:
  104. GLP_SOL - basic solution
  105. GLP_IPT - interior-point solution
  106. GLP_MIP - mixed integer solution */
  107. int scaling;
  108. /* scaling option:
  109. GLP_OFF - scaling is disabled
  110. GLP_ON - scaling is enabled */
  111. int p_stat;
  112. /* status of primal basic solution:
  113. GLP_UNDEF - primal solution is undefined
  114. GLP_FEAS - primal solution is feasible
  115. GLP_INFEAS - primal solution is infeasible
  116. GLP_NOFEAS - no primal feasible solution exists */
  117. int d_stat;
  118. /* status of dual basic solution:
  119. GLP_UNDEF - dual solution is undefined
  120. GLP_FEAS - dual solution is feasible
  121. GLP_INFEAS - dual solution is infeasible
  122. GLP_NOFEAS - no dual feasible solution exists */
  123. int t_stat;
  124. /* status of interior-point solution:
  125. GLP_UNDEF - interior solution is undefined
  126. GLP_OPT - interior solution is optimal */
  127. int i_stat;
  128. /* status of mixed integer solution:
  129. GLP_UNDEF - integer solution is undefined
  130. GLP_OPT - integer solution is optimal
  131. GLP_FEAS - integer solution is feasible
  132. GLP_NOFEAS - no integer solution exists */
  133. char *r_stat; /* char r_stat[1+nrows]; */
  134. /* r_stat[i], 1 <= i <= nrows, is status of i-th row:
  135. GLP_BS - inactive constraint
  136. GLP_NL - active constraint on lower bound
  137. GLP_NU - active constraint on upper bound
  138. GLP_NF - active free row
  139. GLP_NS - active equality constraint */
  140. char *c_stat; /* char c_stat[1+nrows]; */
  141. /* c_stat[j], 1 <= j <= nrows, is status of j-th column:
  142. GLP_BS - basic variable
  143. GLP_NL - non-basic variable on lower bound
  144. GLP_NU - non-basic variable on upper bound
  145. GLP_NF - non-basic free variable
  146. GLP_NS - non-basic fixed variable */
  147. double *r_pi; /* double r_pi[1+nrows]; */
  148. /* r_pi[i], 1 <= i <= nrows, is Lagrange multiplier (dual value)
  149. for i-th row (constraint) */
  150. double *c_value; /* double c_value[1+ncols]; */
  151. /* c_value[j], 1 <= j <= ncols, is primal value of j-th column
  152. (structural variable) */
  153. };
  154. struct NPPROW
  155. { /* row (constraint) */
  156. int i;
  157. /* reference number assigned to the row, 1 <= i <= nrows */
  158. char *name;
  159. /* row name (1 to 255 chars); NULL means no name is assigned to
  160. the row */
  161. double lb;
  162. /* lower bound; -DBL_MAX means the row has no lower bound */
  163. double ub;
  164. /* upper bound; +DBL_MAX means the row has no upper bound */
  165. NPPAIJ *ptr;
  166. /* pointer to the linked list of constraint coefficients */
  167. int temp;
  168. /* working field used by preprocessor routines */
  169. NPPROW *prev;
  170. /* pointer to previous row in the row list */
  171. NPPROW *next;
  172. /* pointer to next row in the row list */
  173. };
  174. struct NPPCOL
  175. { /* column (variable) */
  176. int j;
  177. /* reference number assigned to the column, 1 <= j <= ncols */
  178. char *name;
  179. /* column name (1 to 255 chars); NULL means no name is assigned
  180. to the column */
  181. char is_int;
  182. /* 0 means continuous variable; 1 means integer variable */
  183. double lb;
  184. /* lower bound; -DBL_MAX means the column has no lower bound */
  185. double ub;
  186. /* upper bound; +DBL_MAX means the column has no upper bound */
  187. double coef;
  188. /* objective coefficient */
  189. NPPAIJ *ptr;
  190. /* pointer to the linked list of constraint coefficients */
  191. int temp;
  192. /* working field used by preprocessor routines */
  193. #if 1 /* 28/XII-2009 */
  194. union
  195. { double ll;
  196. /* implied column lower bound */
  197. int pos;
  198. /* vertex ordinal number corresponding to this binary column
  199. in the conflict graph (0, if the vertex does not exist) */
  200. } ll;
  201. union
  202. { double uu;
  203. /* implied column upper bound */
  204. int neg;
  205. /* vertex ordinal number corresponding to complement of this
  206. binary column in the conflict graph (0, if the vertex does
  207. not exist) */
  208. } uu;
  209. #endif
  210. NPPCOL *prev;
  211. /* pointer to previous column in the column list */
  212. NPPCOL *next;
  213. /* pointer to next column in the column list */
  214. };
  215. struct NPPAIJ
  216. { /* constraint coefficient */
  217. NPPROW *row;
  218. /* pointer to corresponding row */
  219. NPPCOL *col;
  220. /* pointer to corresponding column */
  221. double val;
  222. /* (non-zero) coefficient value */
  223. NPPAIJ *r_prev;
  224. /* pointer to previous coefficient in the same row */
  225. NPPAIJ *r_next;
  226. /* pointer to next coefficient in the same row */
  227. NPPAIJ *c_prev;
  228. /* pointer to previous coefficient in the same column */
  229. NPPAIJ *c_next;
  230. /* pointer to next coefficient in the same column */
  231. };
  232. struct NPPTSE
  233. { /* transformation stack entry */
  234. int (*func)(NPP *npp, void *info);
  235. /* pointer to routine performing back transformation */
  236. void *info;
  237. /* pointer to specific info (depends on the transformation) */
  238. NPPTSE *link;
  239. /* pointer to another entry created *before* this entry */
  240. };
  241. struct NPPLFE
  242. { /* linear form element */
  243. int ref;
  244. /* row/column reference number */
  245. double val;
  246. /* (non-zero) coefficient value */
  247. NPPLFE *next;
  248. /* pointer to another element */
  249. };
  250. #define npp_create_wksp _glp_npp_create_wksp
  251. NPP *npp_create_wksp(void);
  252. /* create LP/MIP preprocessor workspace */
  253. #define npp_insert_row _glp_npp_insert_row
  254. void npp_insert_row(NPP *npp, NPPROW *row, int where);
  255. /* insert row to the row list */
  256. #define npp_remove_row _glp_npp_remove_row
  257. void npp_remove_row(NPP *npp, NPPROW *row);
  258. /* remove row from the row list */
  259. #define npp_activate_row _glp_npp_activate_row
  260. void npp_activate_row(NPP *npp, NPPROW *row);
  261. /* make row active */
  262. #define npp_deactivate_row _glp_npp_deactivate_row
  263. void npp_deactivate_row(NPP *npp, NPPROW *row);
  264. /* make row inactive */
  265. #define npp_insert_col _glp_npp_insert_col
  266. void npp_insert_col(NPP *npp, NPPCOL *col, int where);
  267. /* insert column to the column list */
  268. #define npp_remove_col _glp_npp_remove_col
  269. void npp_remove_col(NPP *npp, NPPCOL *col);
  270. /* remove column from the column list */
  271. #define npp_activate_col _glp_npp_activate_col
  272. void npp_activate_col(NPP *npp, NPPCOL *col);
  273. /* make column active */
  274. #define npp_deactivate_col _glp_npp_deactivate_col
  275. void npp_deactivate_col(NPP *npp, NPPCOL *col);
  276. /* make column inactive */
  277. #define npp_add_row _glp_npp_add_row
  278. NPPROW *npp_add_row(NPP *npp);
  279. /* add new row to the current problem */
  280. #define npp_add_col _glp_npp_add_col
  281. NPPCOL *npp_add_col(NPP *npp);
  282. /* add new column to the current problem */
  283. #define npp_add_aij _glp_npp_add_aij
  284. NPPAIJ *npp_add_aij(NPP *npp, NPPROW *row, NPPCOL *col, double val);
  285. /* add new element to the constraint matrix */
  286. #define npp_row_nnz _glp_npp_row_nnz
  287. int npp_row_nnz(NPP *npp, NPPROW *row);
  288. /* count number of non-zero coefficients in row */
  289. #define npp_col_nnz _glp_npp_col_nnz
  290. int npp_col_nnz(NPP *npp, NPPCOL *col);
  291. /* count number of non-zero coefficients in column */
  292. #define npp_push_tse _glp_npp_push_tse
  293. void *npp_push_tse(NPP *npp, int (*func)(NPP *npp, void *info),
  294. int size);
  295. /* push new entry to the transformation stack */
  296. #define npp_erase_row _glp_npp_erase_row
  297. void npp_erase_row(NPP *npp, NPPROW *row);
  298. /* erase row content to make it empty */
  299. #define npp_del_row _glp_npp_del_row
  300. void npp_del_row(NPP *npp, NPPROW *row);
  301. /* remove row from the current problem */
  302. #define npp_del_col _glp_npp_del_col
  303. void npp_del_col(NPP *npp, NPPCOL *col);
  304. /* remove column from the current problem */
  305. #define npp_del_aij _glp_npp_del_aij
  306. void npp_del_aij(NPP *npp, NPPAIJ *aij);
  307. /* remove element from the constraint matrix */
  308. #define npp_load_prob _glp_npp_load_prob
  309. void npp_load_prob(NPP *npp, glp_prob *orig, int names, int sol,
  310. int scaling);
  311. /* load original problem into the preprocessor workspace */
  312. #define npp_build_prob _glp_npp_build_prob
  313. void npp_build_prob(NPP *npp, glp_prob *prob);
  314. /* build resultant (preprocessed) problem */
  315. #define npp_postprocess _glp_npp_postprocess
  316. void npp_postprocess(NPP *npp, glp_prob *prob);
  317. /* postprocess solution from the resultant problem */
  318. #define npp_unload_sol _glp_npp_unload_sol
  319. void npp_unload_sol(NPP *npp, glp_prob *orig);
  320. /* store solution to the original problem */
  321. #define npp_delete_wksp _glp_npp_delete_wksp
  322. void npp_delete_wksp(NPP *npp);
  323. /* delete LP/MIP preprocessor workspace */
  324. #define npp_error()
  325. #define npp_free_row _glp_npp_free_row
  326. void npp_free_row(NPP *npp, NPPROW *p);
  327. /* process free (unbounded) row */
  328. #define npp_geq_row _glp_npp_geq_row
  329. void npp_geq_row(NPP *npp, NPPROW *p);
  330. /* process row of 'not less than' type */
  331. #define npp_leq_row _glp_npp_leq_row
  332. void npp_leq_row(NPP *npp, NPPROW *p);
  333. /* process row of 'not greater than' type */
  334. #define npp_free_col _glp_npp_free_col
  335. void npp_free_col(NPP *npp, NPPCOL *q);
  336. /* process free (unbounded) column */
  337. #define npp_lbnd_col _glp_npp_lbnd_col
  338. void npp_lbnd_col(NPP *npp, NPPCOL *q);
  339. /* process column with (non-zero) lower bound */
  340. #define npp_ubnd_col _glp_npp_ubnd_col
  341. void npp_ubnd_col(NPP *npp, NPPCOL *q);
  342. /* process column with upper bound */
  343. #define npp_dbnd_col _glp_npp_dbnd_col
  344. void npp_dbnd_col(NPP *npp, NPPCOL *q);
  345. /* process non-negative column with upper bound */
  346. #define npp_fixed_col _glp_npp_fixed_col
  347. void npp_fixed_col(NPP *npp, NPPCOL *q);
  348. /* process fixed column */
  349. #define npp_make_equality _glp_npp_make_equality
  350. int npp_make_equality(NPP *npp, NPPROW *p);
  351. /* process row with almost identical bounds */
  352. #define npp_make_fixed _glp_npp_make_fixed
  353. int npp_make_fixed(NPP *npp, NPPCOL *q);
  354. /* process column with almost identical bounds */
  355. #define npp_empty_row _glp_npp_empty_row
  356. int npp_empty_row(NPP *npp, NPPROW *p);
  357. /* process empty row */
  358. #define npp_empty_col _glp_npp_empty_col
  359. int npp_empty_col(NPP *npp, NPPCOL *q);
  360. /* process empty column */
  361. #define npp_implied_value _glp_npp_implied_value
  362. int npp_implied_value(NPP *npp, NPPCOL *q, double s);
  363. /* process implied column value */
  364. #define npp_eq_singlet _glp_npp_eq_singlet
  365. int npp_eq_singlet(NPP *npp, NPPROW *p);
  366. /* process row singleton (equality constraint) */
  367. #define npp_implied_lower _glp_npp_implied_lower
  368. int npp_implied_lower(NPP *npp, NPPCOL *q, double l);
  369. /* process implied column lower bound */
  370. #define npp_implied_upper _glp_npp_implied_upper
  371. int npp_implied_upper(NPP *npp, NPPCOL *q, double u);
  372. /* process implied upper bound of column */
  373. #define npp_ineq_singlet _glp_npp_ineq_singlet
  374. int npp_ineq_singlet(NPP *npp, NPPROW *p);
  375. /* process row singleton (inequality constraint) */
  376. #define npp_implied_slack _glp_npp_implied_slack
  377. void npp_implied_slack(NPP *npp, NPPCOL *q);
  378. /* process column singleton (implied slack variable) */
  379. #define npp_implied_free _glp_npp_implied_free
  380. int npp_implied_free(NPP *npp, NPPCOL *q);
  381. /* process column singleton (implied free variable) */
  382. #define npp_eq_doublet _glp_npp_eq_doublet
  383. NPPCOL *npp_eq_doublet(NPP *npp, NPPROW *p);
  384. /* process row doubleton (equality constraint) */
  385. #define npp_forcing_row _glp_npp_forcing_row
  386. int npp_forcing_row(NPP *npp, NPPROW *p, int at);
  387. /* process forcing row */
  388. #define npp_analyze_row _glp_npp_analyze_row
  389. int npp_analyze_row(NPP *npp, NPPROW *p);
  390. /* perform general row analysis */
  391. #define npp_inactive_bound _glp_npp_inactive_bound
  392. void npp_inactive_bound(NPP *npp, NPPROW *p, int which);
  393. /* remove row lower/upper inactive bound */
  394. #define npp_implied_bounds _glp_npp_implied_bounds
  395. void npp_implied_bounds(NPP *npp, NPPROW *p);
  396. /* determine implied column bounds */
  397. #define npp_binarize_prob _glp_npp_binarize_prob
  398. int npp_binarize_prob(NPP *npp);
  399. /* binarize MIP problem */
  400. #define npp_is_packing _glp_npp_is_packing
  401. int npp_is_packing(NPP *npp, NPPROW *row);
  402. /* test if constraint is packing inequality */
  403. #define npp_hidden_packing _glp_npp_hidden_packing
  404. int npp_hidden_packing(NPP *npp, NPPROW *row);
  405. /* identify hidden packing inequality */
  406. #define npp_implied_packing _glp_npp_implied_packing
  407. int npp_implied_packing(NPP *npp, NPPROW *row, int which,
  408. NPPCOL *var[], char set[]);
  409. /* identify implied packing inequality */
  410. #define npp_is_covering _glp_npp_is_covering
  411. int npp_is_covering(NPP *npp, NPPROW *row);
  412. /* test if constraint is covering inequality */
  413. #define npp_hidden_covering _glp_npp_hidden_covering
  414. int npp_hidden_covering(NPP *npp, NPPROW *row);
  415. /* identify hidden covering inequality */
  416. #define npp_is_partitioning _glp_npp_is_partitioning
  417. int npp_is_partitioning(NPP *npp, NPPROW *row);
  418. /* test if constraint is partitioning equality */
  419. #define npp_reduce_ineq_coef _glp_npp_reduce_ineq_coef
  420. int npp_reduce_ineq_coef(NPP *npp, NPPROW *row);
  421. /* reduce inequality constraint coefficients */
  422. #define npp_clean_prob _glp_npp_clean_prob
  423. void npp_clean_prob(NPP *npp);
  424. /* perform initial LP/MIP processing */
  425. #define npp_process_row _glp_npp_process_row
  426. int npp_process_row(NPP *npp, NPPROW *row, int hard);
  427. /* perform basic row processing */
  428. #define npp_improve_bounds _glp_npp_improve_bounds
  429. int npp_improve_bounds(NPP *npp, NPPROW *row, int flag);
  430. /* improve current column bounds */
  431. #define npp_process_col _glp_npp_process_col
  432. int npp_process_col(NPP *npp, NPPCOL *col);
  433. /* perform basic column processing */
  434. #define npp_process_prob _glp_npp_process_prob
  435. int npp_process_prob(NPP *npp, int hard);
  436. /* perform basic LP/MIP processing */
  437. #define npp_simplex _glp_npp_simplex
  438. int npp_simplex(NPP *npp, const glp_smcp *parm);
  439. /* process LP prior to applying primal/dual simplex method */
  440. #define npp_integer _glp_npp_integer
  441. int npp_integer(NPP *npp, const glp_iocp *parm);
  442. /* process MIP prior to applying branch-and-bound method */
  443. #endif
  444. /* eof */