glpapi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* glpapi.h (application program interface) */
  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 GLPAPI_H
  24. #define GLPAPI_H
  25. #define GLP_PROB_DEFINED
  26. typedef struct glp_prob glp_prob;
  27. #include "glpk.h"
  28. #include "glpavl.h"
  29. #include "glpbfd.h"
  30. typedef struct GLPROW GLPROW;
  31. typedef struct GLPCOL GLPCOL;
  32. typedef struct GLPAIJ GLPAIJ;
  33. #define GLP_PROB_MAGIC 0xD7D9D6C2
  34. struct glp_prob
  35. { /* LP/MIP problem object */
  36. int magic;
  37. /* magic value used for debugging */
  38. DMP *pool;
  39. /* memory pool to store problem object components */
  40. glp_tree *tree;
  41. /* pointer to the search tree; set by the MIP solver when this
  42. object is used in the tree as a core MIP object */
  43. void *parms;
  44. /* reserved for backward compatibility */
  45. /*--------------------------------------------------------------*/
  46. /* LP/MIP data */
  47. char *name;
  48. /* problem name (1 to 255 chars); NULL means no name is assigned
  49. to the problem */
  50. char *obj;
  51. /* objective function name (1 to 255 chars); NULL means no name
  52. is assigned to the objective function */
  53. int dir;
  54. /* optimization direction flag (objective "sense"):
  55. GLP_MIN - minimization
  56. GLP_MAX - maximization */
  57. double c0;
  58. /* constant term of the objective function ("shift") */
  59. int m_max;
  60. /* length of the array of rows (enlarged automatically) */
  61. int n_max;
  62. /* length of the array of columns (enlarged automatically) */
  63. int m;
  64. /* number of rows, 0 <= m <= m_max */
  65. int n;
  66. /* number of columns, 0 <= n <= n_max */
  67. int nnz;
  68. /* number of non-zero constraint coefficients, nnz >= 0 */
  69. GLPROW **row; /* GLPROW *row[1+m_max]; */
  70. /* row[i], 1 <= i <= m, is a pointer to i-th row */
  71. GLPCOL **col; /* GLPCOL *col[1+n_max]; */
  72. /* col[j], 1 <= j <= n, is a pointer to j-th column */
  73. AVL *r_tree;
  74. /* row index to find rows by their names; NULL means this index
  75. does not exist */
  76. AVL *c_tree;
  77. /* column index to find columns by their names; NULL means this
  78. index does not exist */
  79. /*--------------------------------------------------------------*/
  80. /* basis factorization (LP) */
  81. int valid;
  82. /* the factorization is valid only if this flag is set */
  83. int *head; /* int head[1+m_max]; */
  84. /* basis header (valid only if the factorization is valid);
  85. head[i] = k is the ordinal number of auxiliary (1 <= k <= m)
  86. or structural (m+1 <= k <= m+n) variable which corresponds to
  87. i-th basic variable xB[i], 1 <= i <= m */
  88. glp_bfcp *bfcp;
  89. /* basis factorization control parameters; may be NULL */
  90. BFD *bfd; /* BFD bfd[1:m,1:m]; */
  91. /* basis factorization driver; may be NULL */
  92. /*--------------------------------------------------------------*/
  93. /* basic solution (LP) */
  94. int pbs_stat;
  95. /* primal basic solution status:
  96. GLP_UNDEF - primal solution is undefined
  97. GLP_FEAS - primal solution is feasible
  98. GLP_INFEAS - primal solution is infeasible
  99. GLP_NOFEAS - no primal feasible solution exists */
  100. int dbs_stat;
  101. /* dual basic solution status:
  102. GLP_UNDEF - dual solution is undefined
  103. GLP_FEAS - dual solution is feasible
  104. GLP_INFEAS - dual solution is infeasible
  105. GLP_NOFEAS - no dual feasible solution exists */
  106. double obj_val;
  107. /* objective function value */
  108. int it_cnt;
  109. /* simplex method iteration count; increased by one on performing
  110. one simplex iteration */
  111. int some;
  112. /* ordinal number of some auxiliary or structural variable having
  113. certain property, 0 <= some <= m+n */
  114. /*--------------------------------------------------------------*/
  115. /* interior-point solution (LP) */
  116. int ipt_stat;
  117. /* interior-point solution status:
  118. GLP_UNDEF - interior solution is undefined
  119. GLP_OPT - interior solution is optimal
  120. GLP_INFEAS - interior solution is infeasible
  121. GLP_NOFEAS - no feasible solution exists */
  122. double ipt_obj;
  123. /* objective function value */
  124. /*--------------------------------------------------------------*/
  125. /* integer solution (MIP) */
  126. int mip_stat;
  127. /* integer solution status:
  128. GLP_UNDEF - integer solution is undefined
  129. GLP_OPT - integer solution is optimal
  130. GLP_FEAS - integer solution is feasible
  131. GLP_NOFEAS - no integer solution exists */
  132. double mip_obj;
  133. /* objective function value */
  134. };
  135. struct GLPROW
  136. { /* LP/MIP row (auxiliary variable) */
  137. int i;
  138. /* ordinal number (1 to m) assigned to this row */
  139. char *name;
  140. /* row name (1 to 255 chars); NULL means no name is assigned to
  141. this row */
  142. AVLNODE *node;
  143. /* pointer to corresponding node in the row index; NULL means
  144. that either the row index does not exist or this row has no
  145. name assigned */
  146. #if 1 /* 20/IX-2008 */
  147. int level;
  148. unsigned char origin;
  149. unsigned char klass;
  150. #endif
  151. int type;
  152. /* type of the auxiliary variable:
  153. GLP_FR - free variable
  154. GLP_LO - variable with lower bound
  155. GLP_UP - variable with upper bound
  156. GLP_DB - double-bounded variable
  157. GLP_FX - fixed variable */
  158. double lb; /* non-scaled */
  159. /* lower bound; if the row has no lower bound, lb is zero */
  160. double ub; /* non-scaled */
  161. /* upper bound; if the row has no upper bound, ub is zero */
  162. /* if the row type is GLP_FX, ub is equal to lb */
  163. GLPAIJ *ptr; /* non-scaled */
  164. /* pointer to doubly linked list of constraint coefficients which
  165. are placed in this row */
  166. double rii;
  167. /* diagonal element r[i,i] of scaling matrix R for this row;
  168. if the scaling is not used, r[i,i] is 1 */
  169. int stat;
  170. /* status of the auxiliary variable:
  171. GLP_BS - basic variable
  172. GLP_NL - non-basic variable on lower bound
  173. GLP_NU - non-basic variable on upper bound
  174. GLP_NF - non-basic free variable
  175. GLP_NS - non-basic fixed variable */
  176. int bind;
  177. /* if the auxiliary variable is basic, head[bind] refers to this
  178. row, otherwise, bind is 0; this attribute is valid only if the
  179. basis factorization is valid */
  180. double prim; /* non-scaled */
  181. /* primal value of the auxiliary variable in basic solution */
  182. double dual; /* non-scaled */
  183. /* dual value of the auxiliary variable in basic solution */
  184. double pval; /* non-scaled */
  185. /* primal value of the auxiliary variable in interior solution */
  186. double dval; /* non-scaled */
  187. /* dual value of the auxiliary variable in interior solution */
  188. double mipx; /* non-scaled */
  189. /* primal value of the auxiliary variable in integer solution */
  190. };
  191. struct GLPCOL
  192. { /* LP/MIP column (structural variable) */
  193. int j;
  194. /* ordinal number (1 to n) assigned to this column */
  195. char *name;
  196. /* column name (1 to 255 chars); NULL means no name is assigned
  197. to this column */
  198. AVLNODE *node;
  199. /* pointer to corresponding node in the column index; NULL means
  200. that either the column index does not exist or the column has
  201. no name assigned */
  202. int kind;
  203. /* kind of the structural variable:
  204. GLP_CV - continuous variable
  205. GLP_IV - integer or binary variable */
  206. int type;
  207. /* type of the structural variable:
  208. GLP_FR - free variable
  209. GLP_LO - variable with lower bound
  210. GLP_UP - variable with upper bound
  211. GLP_DB - double-bounded variable
  212. GLP_FX - fixed variable */
  213. double lb; /* non-scaled */
  214. /* lower bound; if the column has no lower bound, lb is zero */
  215. double ub; /* non-scaled */
  216. /* upper bound; if the column has no upper bound, ub is zero */
  217. /* if the column type is GLP_FX, ub is equal to lb */
  218. double coef; /* non-scaled */
  219. /* objective coefficient at the structural variable */
  220. GLPAIJ *ptr; /* non-scaled */
  221. /* pointer to doubly linked list of constraint coefficients which
  222. are placed in this column */
  223. double sjj;
  224. /* diagonal element s[j,j] of scaling matrix S for this column;
  225. if the scaling is not used, s[j,j] is 1 */
  226. int stat;
  227. /* status of the structural variable:
  228. GLP_BS - basic variable
  229. GLP_NL - non-basic variable on lower bound
  230. GLP_NU - non-basic variable on upper bound
  231. GLP_NF - non-basic free variable
  232. GLP_NS - non-basic fixed variable */
  233. int bind;
  234. /* if the structural variable is basic, head[bind] refers to
  235. this column; otherwise, bind is 0; this attribute is valid only
  236. if the basis factorization is valid */
  237. double prim; /* non-scaled */
  238. /* primal value of the structural variable in basic solution */
  239. double dual; /* non-scaled */
  240. /* dual value of the structural variable in basic solution */
  241. double pval; /* non-scaled */
  242. /* primal value of the structural variable in interior solution */
  243. double dval; /* non-scaled */
  244. /* dual value of the structural variable in interior solution */
  245. double mipx; /* non-scaled */
  246. /* primal value of the structural variable in integer solution */
  247. };
  248. struct GLPAIJ
  249. { /* constraint coefficient a[i,j] */
  250. GLPROW *row;
  251. /* pointer to row, where this coefficient is placed */
  252. GLPCOL *col;
  253. /* pointer to column, where this coefficient is placed */
  254. double val;
  255. /* numeric (non-zero) value of this coefficient */
  256. GLPAIJ *r_prev;
  257. /* pointer to previous coefficient in the same row */
  258. GLPAIJ *r_next;
  259. /* pointer to next coefficient in the same row */
  260. GLPAIJ *c_prev;
  261. /* pointer to previous coefficient in the same column */
  262. GLPAIJ *c_next;
  263. /* pointer to next coefficient in the same column */
  264. };
  265. void _glp_check_kkt(glp_prob *P, int sol, int cond, double *ae_max,
  266. int *ae_ind, double *re_max, int *re_ind);
  267. /* check feasibility and optimality conditions */
  268. #define lpx_put_solution _glp_put_solution
  269. void lpx_put_solution(glp_prob *lp, int inval, const int *p_stat,
  270. const int *d_stat, const double *obj_val, const int r_stat[],
  271. const double r_prim[], const double r_dual[], const int c_stat[],
  272. const double c_prim[], const double c_dual[]);
  273. /* store basic solution components */
  274. #define lpx_put_mip_soln _glp_put_mip_soln
  275. void lpx_put_mip_soln(LPX *lp, int i_stat, double row_mipx[],
  276. double col_mipx[]);
  277. /* store mixed integer solution components */
  278. #if 1 /* 28/XI-2009 */
  279. int _glp_analyze_row(glp_prob *P, int len, const int ind[],
  280. const double val[], int type, double rhs, double eps, int *_piv,
  281. double *_x, double *_dx, double *_y, double *_dy, double *_dz);
  282. /* simulate one iteration of dual simplex method */
  283. #endif
  284. #if 1 /* 08/XII-2009 */
  285. void _glp_mpl_init_rand(glp_tran *tran, int seed);
  286. #endif
  287. #define glp_skpgen _glp_skpgen
  288. void glp_skpgen(int n, int r, int type, int v, int s, int a[],
  289. int *b, int c[]);
  290. /* Pisinger's 0-1 single knapsack problem generator */
  291. #if 1 /* 28/V-2010 */
  292. int _glp_intopt1(glp_prob *P, const glp_iocp *parm);
  293. #endif
  294. #endif
  295. /* eof */