1 /* glpapi02.c (problem retrieving routines) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
27 /***********************************************************************
30 * glp_get_prob_name - retrieve problem name
34 * const char *glp_get_prob_name(glp_prob *lp);
38 * The routine glp_get_prob_name returns a pointer to an internal
39 * buffer, which contains symbolic name of the problem. However, if the
40 * problem has no assigned name, the routine returns NULL. */
42 const char *glp_get_prob_name(glp_prob *lp)
48 /***********************************************************************
51 * glp_get_obj_name - retrieve objective function name
55 * const char *glp_get_obj_name(glp_prob *lp);
59 * The routine glp_get_obj_name returns a pointer to an internal
60 * buffer, which contains a symbolic name of the objective function.
61 * However, if the objective function has no assigned name, the routine
64 const char *glp_get_obj_name(glp_prob *lp)
70 /***********************************************************************
73 * glp_get_obj_dir - retrieve optimization direction flag
77 * int glp_get_obj_dir(glp_prob *lp);
81 * The routine glp_get_obj_dir returns the optimization direction flag
82 * (i.e. "sense" of the objective function):
84 * GLP_MIN - minimization;
85 * GLP_MAX - maximization. */
87 int glp_get_obj_dir(glp_prob *lp)
92 /***********************************************************************
95 * glp_get_num_rows - retrieve number of rows
99 * int glp_get_num_rows(glp_prob *lp);
103 * The routine glp_get_num_rows returns the current number of rows in
104 * the specified problem object. */
106 int glp_get_num_rows(glp_prob *lp)
111 /***********************************************************************
114 * glp_get_num_cols - retrieve number of columns
118 * int glp_get_num_cols(glp_prob *lp);
122 * The routine glp_get_num_cols returns the current number of columns
123 * in the specified problem object. */
125 int glp_get_num_cols(glp_prob *lp)
130 /***********************************************************************
133 * glp_get_row_name - retrieve row name
137 * const char *glp_get_row_name(glp_prob *lp, int i);
141 * The routine glp_get_row_name returns a pointer to an internal
142 * buffer, which contains symbolic name of i-th row. However, if i-th
143 * row has no assigned name, the routine returns NULL. */
145 const char *glp_get_row_name(glp_prob *lp, int i)
147 if (!(1 <= i && i <= lp->m))
148 xerror("glp_get_row_name: i = %d; row number out of range\n",
150 name = lp->row[i]->name;
154 /***********************************************************************
157 * glp_get_col_name - retrieve column name
161 * const char *glp_get_col_name(glp_prob *lp, int j);
165 * The routine glp_get_col_name returns a pointer to an internal
166 * buffer, which contains symbolic name of j-th column. However, if j-th
167 * column has no assigned name, the routine returns NULL. */
169 const char *glp_get_col_name(glp_prob *lp, int j)
171 if (!(1 <= j && j <= lp->n))
172 xerror("glp_get_col_name: j = %d; column number out of range\n"
174 name = lp->col[j]->name;
178 /***********************************************************************
181 * glp_get_row_type - retrieve row type
185 * int glp_get_row_type(glp_prob *lp, int i);
189 * The routine glp_get_row_type returns the type of i-th row, i.e. the
190 * type of corresponding auxiliary variable, as follows:
192 * GLP_FR - free (unbounded) variable;
193 * GLP_LO - variable with lower bound;
194 * GLP_UP - variable with upper bound;
195 * GLP_DB - double-bounded variable;
196 * GLP_FX - fixed variable. */
198 int glp_get_row_type(glp_prob *lp, int i)
199 { if (!(1 <= i && i <= lp->m))
200 xerror("glp_get_row_type: i = %d; row number out of range\n",
202 return lp->row[i]->type;
205 /***********************************************************************
208 * glp_get_row_lb - retrieve row lower bound
212 * double glp_get_row_lb(glp_prob *lp, int i);
216 * The routine glp_get_row_lb returns the lower bound of i-th row, i.e.
217 * the lower bound of corresponding auxiliary variable. However, if the
218 * row has no lower bound, the routine returns -DBL_MAX. */
220 double glp_get_row_lb(glp_prob *lp, int i)
222 if (!(1 <= i && i <= lp->m))
223 xerror("glp_get_row_lb: i = %d; row number out of range\n", i);
224 switch (lp->row[i]->type)
227 lb = -DBL_MAX; break;
231 lb = lp->row[i]->lb; break;
238 /***********************************************************************
241 * glp_get_row_ub - retrieve row upper bound
245 * double glp_get_row_ub(glp_prob *lp, int i);
249 * The routine glp_get_row_ub returns the upper bound of i-th row, i.e.
250 * the upper bound of corresponding auxiliary variable. However, if the
251 * row has no upper bound, the routine returns +DBL_MAX. */
253 double glp_get_row_ub(glp_prob *lp, int i)
255 if (!(1 <= i && i <= lp->m))
256 xerror("glp_get_row_ub: i = %d; row number out of range\n", i);
257 switch (lp->row[i]->type)
260 ub = +DBL_MAX; break;
264 ub = lp->row[i]->ub; break;
271 /***********************************************************************
274 * glp_get_col_type - retrieve column type
278 * int glp_get_col_type(glp_prob *lp, int j);
282 * The routine glp_get_col_type returns the type of j-th column, i.e.
283 * the type of corresponding structural variable, as follows:
285 * GLP_FR - free (unbounded) variable;
286 * GLP_LO - variable with lower bound;
287 * GLP_UP - variable with upper bound;
288 * GLP_DB - double-bounded variable;
289 * GLP_FX - fixed variable. */
291 int glp_get_col_type(glp_prob *lp, int j)
292 { if (!(1 <= j && j <= lp->n))
293 xerror("glp_get_col_type: j = %d; column number out of range\n"
295 return lp->col[j]->type;
298 /***********************************************************************
301 * glp_get_col_lb - retrieve column lower bound
305 * double glp_get_col_lb(glp_prob *lp, int j);
309 * The routine glp_get_col_lb returns the lower bound of j-th column,
310 * i.e. the lower bound of corresponding structural variable. However,
311 * if the column has no lower bound, the routine returns -DBL_MAX. */
313 double glp_get_col_lb(glp_prob *lp, int j)
315 if (!(1 <= j && j <= lp->n))
316 xerror("glp_get_col_lb: j = %d; column number out of range\n",
318 switch (lp->col[j]->type)
321 lb = -DBL_MAX; break;
325 lb = lp->col[j]->lb; break;
332 /***********************************************************************
335 * glp_get_col_ub - retrieve column upper bound
339 * double glp_get_col_ub(glp_prob *lp, int j);
343 * The routine glp_get_col_ub returns the upper bound of j-th column,
344 * i.e. the upper bound of corresponding structural variable. However,
345 * if the column has no upper bound, the routine returns +DBL_MAX. */
347 double glp_get_col_ub(glp_prob *lp, int j)
349 if (!(1 <= j && j <= lp->n))
350 xerror("glp_get_col_ub: j = %d; column number out of range\n",
352 switch (lp->col[j]->type)
355 ub = +DBL_MAX; break;
359 ub = lp->col[j]->ub; break;
366 /***********************************************************************
369 * glp_get_obj_coef - retrieve obj. coefficient or constant term
373 * double glp_get_obj_coef(glp_prob *lp, int j);
377 * The routine glp_get_obj_coef returns the objective coefficient at
378 * j-th structural variable (column) of the specified problem object.
380 * If the parameter j is zero, the routine returns the constant term
381 * ("shift") of the objective function. */
383 double glp_get_obj_coef(glp_prob *lp, int j)
384 { if (!(0 <= j && j <= lp->n))
385 xerror("glp_get_obj_coef: j = %d; column number out of range\n"
387 return j == 0 ? lp->c0 : lp->col[j]->coef;
390 /***********************************************************************
393 * glp_get_num_nz - retrieve number of constraint coefficients
397 * int glp_get_num_nz(glp_prob *lp);
401 * The routine glp_get_num_nz returns the number of (non-zero) elements
402 * in the constraint matrix of the specified problem object. */
404 int glp_get_num_nz(glp_prob *lp)
409 /***********************************************************************
412 * glp_get_mat_row - retrieve row of the constraint matrix
416 * int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[]);
420 * The routine glp_get_mat_row scans (non-zero) elements of i-th row
421 * of the constraint matrix of the specified problem object and stores
422 * their column indices and numeric values to locations ind[1], ...,
423 * ind[len] and val[1], ..., val[len], respectively, where 0 <= len <= n
424 * is the number of elements in i-th row, n is the number of columns.
426 * The parameter ind and/or val can be specified as NULL, in which case
427 * corresponding information is not stored.
431 * The routine glp_get_mat_row returns the length len, i.e. the number
432 * of (non-zero) elements in i-th row. */
434 int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[])
437 if (!(1 <= i && i <= lp->m))
438 xerror("glp_get_mat_row: i = %d; row number out of range\n",
441 for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
443 if (ind != NULL) ind[len] = aij->col->j;
444 if (val != NULL) val[len] = aij->val;
446 xassert(len <= lp->n);
450 /***********************************************************************
453 * glp_get_mat_col - retrieve column of the constraint matrix
457 * int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[]);
461 * The routine glp_get_mat_col scans (non-zero) elements of j-th column
462 * of the constraint matrix of the specified problem object and stores
463 * their row indices and numeric values to locations ind[1], ...,
464 * ind[len] and val[1], ..., val[len], respectively, where 0 <= len <= m
465 * is the number of elements in j-th column, m is the number of rows.
467 * The parameter ind or/and val can be specified as NULL, in which case
468 * corresponding information is not stored.
472 * The routine glp_get_mat_col returns the length len, i.e. the number
473 * of (non-zero) elements in j-th column. */
475 int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[])
478 if (!(1 <= j && j <= lp->n))
479 xerror("glp_get_mat_col: j = %d; column number out of range\n",
482 for (aij = lp->col[j]->ptr; aij != NULL; aij = aij->c_next)
484 if (ind != NULL) ind[len] = aij->row->i;
485 if (val != NULL) val[len] = aij->val;
487 xassert(len <= lp->m);