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