Debian Codegraph @

external/glpk/glpapi02.c

raw symbols SCIP
1 /* glpapi02.c (problem retrieving routines) */cxx . . $ `<file>/external/glpk/glpapi02.c`/
2
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
5 *
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: <[email protected]>.
10 *
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.
15 *
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.
20 *
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 ***********************************************************************/
24
25 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
26
27 /***********************************************************************
28 * NAME
29 *
30 * glp_get_prob_name - retrieve problem name
31 *
32 * SYNOPSIS
33 *
34 * const char *glp_get_prob_name(glp_prob *lp);
35 *
36 * RETURNS
37 *
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. */
41
42 const char *glp_get_prob_namecxx . . $ glp_get_prob_name(b1ad61a3730816ca).(glp_probcxx . . $ glp_prob# *lp)
43 { char *name;
44 name = lp->namecxx . . $ glp_prob#name.;
45 return name;
46 }
47
48 /***********************************************************************
49 * NAME
50 *
51 * glp_get_obj_name - retrieve objective function name
52 *
53 * SYNOPSIS
54 *
55 * const char *glp_get_obj_name(glp_prob *lp);
56 *
57 * RETURNS
58 *
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
62 * returns NULL. */
63
64 const char *glp_get_obj_namecxx . . $ glp_get_obj_name(b1ad61a3730816ca).(glp_probcxx . . $ glp_prob# *lp)
65 { char *name;
66 name = lp->objcxx . . $ glp_prob#obj.;
67 return name;
68 }
69
70 /***********************************************************************
71 * NAME
72 *
73 * glp_get_obj_dir - retrieve optimization direction flag
74 *
75 * SYNOPSIS
76 *
77 * int glp_get_obj_dir(glp_prob *lp);
78 *
79 * RETURNS
80 *
81 * The routine glp_get_obj_dir returns the optimization direction flag
82 * (i.e. "sense" of the objective function):
83 *
84 * GLP_MIN - minimization;
85 * GLP_MAX - maximization. */
86
87 int glp_get_obj_dircxx . . $ glp_get_obj_dir(317ecc1aeadfe2b7).(glp_probcxx . . $ glp_prob# *lp)
88 { int dir = lp->dircxx . . $ glp_prob#dir.;
89 return dir;
90 }
91
92 /***********************************************************************
93 * NAME
94 *
95 * glp_get_num_rows - retrieve number of rows
96 *
97 * SYNOPSIS
98 *
99 * int glp_get_num_rows(glp_prob *lp);
100 *
101 * RETURNS
102 *
103 * The routine glp_get_num_rows returns the current number of rows in
104 * the specified problem object. */
105
106 int glp_get_num_rowscxx . . $ glp_get_num_rows(317ecc1aeadfe2b7).(glp_probcxx . . $ glp_prob# *lp)
107 { int m = lp->mcxx . . $ glp_prob#m.;
108 return m;
109 }
110
111 /***********************************************************************
112 * NAME
113 *
114 * glp_get_num_cols - retrieve number of columns
115 *
116 * SYNOPSIS
117 *
118 * int glp_get_num_cols(glp_prob *lp);
119 *
120 * RETURNS
121 *
122 * The routine glp_get_num_cols returns the current number of columns
123 * in the specified problem object. */
124
125 int glp_get_num_colscxx . . $ glp_get_num_cols(317ecc1aeadfe2b7).(glp_probcxx . . $ glp_prob# *lp)
126 { int n = lp->ncxx . . $ glp_prob#n.;
127 return n;
128 }
129
130 /***********************************************************************
131 * NAME
132 *
133 * glp_get_row_name - retrieve row name
134 *
135 * SYNOPSIS
136 *
137 * const char *glp_get_row_name(glp_prob *lp, int i);
138 *
139 * RETURNS
140 *
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. */
144
145 const char *glp_get_row_namecxx . . $ glp_get_row_name(d11e5f1cd3184808).(glp_probcxx . . $ glp_prob# *lp, int i)
146 { char *name;
147 if (!(1 <= i && i <= lp->mcxx . . $ glp_prob#m.))
148 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_row_name: i = %d; row number out of range\n",
149 i);
150 name = lp->rowcxx . . $ glp_prob#row.[i]->namecxx . . $ GLPROW#name.;
151 return name;
152 }
153
154 /***********************************************************************
155 * NAME
156 *
157 * glp_get_col_name - retrieve column name
158 *
159 * SYNOPSIS
160 *
161 * const char *glp_get_col_name(glp_prob *lp, int j);
162 *
163 * RETURNS
164 *
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. */
168
169 const char *glp_get_col_namecxx . . $ glp_get_col_name(d11e5f1cd3184808).(glp_probcxx . . $ glp_prob# *lp, int j)
170 { char *name;
171 if (!(1 <= j && j <= lp->ncxx . . $ glp_prob#n.))
172 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_col_name: j = %d; column number out of range\n"
173 , j);
174 name = lp->colcxx . . $ glp_prob#col.[j]->namecxx . . $ GLPCOL#name.;
175 return name;
176 }
177
178 /***********************************************************************
179 * NAME
180 *
181 * glp_get_row_type - retrieve row type
182 *
183 * SYNOPSIS
184 *
185 * int glp_get_row_type(glp_prob *lp, int i);
186 *
187 * RETURNS
188 *
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:
191 *
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. */
197
198 int glp_get_row_typecxx . . $ glp_get_row_type(423829e847ef1a83).(glp_probcxx . . $ glp_prob# *lp, int i)
199 { if (!(1 <= i && i <= lp->mcxx . . $ glp_prob#m.))
200 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_row_type: i = %d; row number out of range\n",
201 i);
202 return lp->rowcxx . . $ glp_prob#row.[i]->typecxx . . $ GLPROW#type.;
203 }
204
205 /***********************************************************************
206 * NAME
207 *
208 * glp_get_row_lb - retrieve row lower bound
209 *
210 * SYNOPSIS
211 *
212 * double glp_get_row_lb(glp_prob *lp, int i);
213 *
214 * RETURNS
215 *
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. */
219
220 double glp_get_row_lbcxx . . $ glp_get_row_lb(68c5770eb0f32231).(glp_probcxx . . $ glp_prob# *lp, int i)
221 { double lb;
222 if (!(1 <= i && i <= lp->mcxx . . $ glp_prob#m.))
223 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_row_lb: i = %d; row number out of range\n", i);
224 switch (lp->rowcxx . . $ glp_prob#row.[i]->typecxx . . $ GLPROW#type.)
225 { case GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`!:
226 case GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!:
227 lb = -DBL_MAXcxx . . $ `<external>/18143172452841944454/float.h:105:9`!; break;
228 case GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!:
229 case GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!:
230 case GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!:
231 lb = lp->rowcxx . . $ glp_prob#row.[i]->lbcxx . . $ GLPROW#lb.; break;
232 default:
233 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(lp != lp);
234 }
235 return lb;
236 }
237
238 /***********************************************************************
239 * NAME
240 *
241 * glp_get_row_ub - retrieve row upper bound
242 *
243 * SYNOPSIS
244 *
245 * double glp_get_row_ub(glp_prob *lp, int i);
246 *
247 * RETURNS
248 *
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. */
252
253 double glp_get_row_ubcxx . . $ glp_get_row_ub(68c5770eb0f32231).(glp_probcxx . . $ glp_prob# *lp, int i)
254 { double ub;
255 if (!(1 <= i && i <= lp->mcxx . . $ glp_prob#m.))
256 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_row_ub: i = %d; row number out of range\n", i);
257 switch (lp->rowcxx . . $ glp_prob#row.[i]->typecxx . . $ GLPROW#type.)
258 { case GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`!:
259 case GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!:
260 ub = +DBL_MAXcxx . . $ `<external>/18143172452841944454/float.h:105:9`!; break;
261 case GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!:
262 case GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!:
263 case GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!:
264 ub = lp->rowcxx . . $ glp_prob#row.[i]->ubcxx . . $ GLPROW#ub.; break;
265 default:
266 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(lp != lp);
267 }
268 return ub;
269 }
270
271 /***********************************************************************
272 * NAME
273 *
274 * glp_get_col_type - retrieve column type
275 *
276 * SYNOPSIS
277 *
278 * int glp_get_col_type(glp_prob *lp, int j);
279 *
280 * RETURNS
281 *
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:
284 *
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. */
290
291 int glp_get_col_typecxx . . $ glp_get_col_type(423829e847ef1a83).(glp_probcxx . . $ glp_prob# *lp, int j)
292 { if (!(1 <= j && j <= lp->ncxx . . $ glp_prob#n.))
293 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_col_type: j = %d; column number out of range\n"
294 , j);
295 return lp->colcxx . . $ glp_prob#col.[j]->typecxx . . $ GLPCOL#type.;
296 }
297
298 /***********************************************************************
299 * NAME
300 *
301 * glp_get_col_lb - retrieve column lower bound
302 *
303 * SYNOPSIS
304 *
305 * double glp_get_col_lb(glp_prob *lp, int j);
306 *
307 * RETURNS
308 *
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. */
312
313 double glp_get_col_lbcxx . . $ glp_get_col_lb(68c5770eb0f32231).(glp_probcxx . . $ glp_prob# *lp, int j)
314 { double lb;
315 if (!(1 <= j && j <= lp->ncxx . . $ glp_prob#n.))
316 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_col_lb: j = %d; column number out of range\n",
317 j);
318 switch (lp->colcxx . . $ glp_prob#col.[j]->typecxx . . $ GLPCOL#type.)
319 { case GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`!:
320 case GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!:
321 lb = -DBL_MAXcxx . . $ `<external>/18143172452841944454/float.h:105:9`!; break;
322 case GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!:
323 case GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!:
324 case GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!:
325 lb = lp->colcxx . . $ glp_prob#col.[j]->lbcxx . . $ GLPCOL#lb.; break;
326 default:
327 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(lp != lp);
328 }
329 return lb;
330 }
331
332 /***********************************************************************
333 * NAME
334 *
335 * glp_get_col_ub - retrieve column upper bound
336 *
337 * SYNOPSIS
338 *
339 * double glp_get_col_ub(glp_prob *lp, int j);
340 *
341 * RETURNS
342 *
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. */
346
347 double glp_get_col_ubcxx . . $ glp_get_col_ub(68c5770eb0f32231).(glp_probcxx . . $ glp_prob# *lp, int j)
348 { double ub;
349 if (!(1 <= j && j <= lp->ncxx . . $ glp_prob#n.))
350 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_col_ub: j = %d; column number out of range\n",
351 j);
352 switch (lp->colcxx . . $ glp_prob#col.[j]->typecxx . . $ GLPCOL#type.)
353 { case GLP_FRcxx . . $ `external/glpk/glpk.h:59:9`!:
354 case GLP_LOcxx . . $ `external/glpk/glpk.h:60:9`!:
355 ub = +DBL_MAXcxx . . $ `<external>/18143172452841944454/float.h:105:9`!; break;
356 case GLP_UPcxx . . $ `external/glpk/glpk.h:61:9`!:
357 case GLP_DBcxx . . $ `external/glpk/glpk.h:62:9`!:
358 case GLP_FXcxx . . $ `external/glpk/glpk.h:63:9`!:
359 ub = lp->colcxx . . $ glp_prob#col.[j]->ubcxx . . $ GLPCOL#ub.; break;
360 default:
361 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(lp != lp);
362 }
363 return ub;
364 }
365
366 /***********************************************************************
367 * NAME
368 *
369 * glp_get_obj_coef - retrieve obj. coefficient or constant term
370 *
371 * SYNOPSIS
372 *
373 * double glp_get_obj_coef(glp_prob *lp, int j);
374 *
375 * RETURNS
376 *
377 * The routine glp_get_obj_coef returns the objective coefficient at
378 * j-th structural variable (column) of the specified problem object.
379 *
380 * If the parameter j is zero, the routine returns the constant term
381 * ("shift") of the objective function. */
382
383 double glp_get_obj_coefcxx . . $ glp_get_obj_coef(68c5770eb0f32231).(glp_probcxx . . $ glp_prob# *lp, int j)
384 { if (!(0 <= j && j <= lp->ncxx . . $ glp_prob#n.))
385 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_obj_coef: j = %d; column number out of range\n"
386 , j);
387 return j == 0 ? lp->c0cxx . . $ glp_prob#c0. : lp->colcxx . . $ glp_prob#col.[j]->coefcxx . . $ GLPCOL#coef.;
388 }
389
390 /***********************************************************************
391 * NAME
392 *
393 * glp_get_num_nz - retrieve number of constraint coefficients
394 *
395 * SYNOPSIS
396 *
397 * int glp_get_num_nz(glp_prob *lp);
398 *
399 * RETURNS
400 *
401 * The routine glp_get_num_nz returns the number of (non-zero) elements
402 * in the constraint matrix of the specified problem object. */
403
404 int glp_get_num_nzcxx . . $ glp_get_num_nz(317ecc1aeadfe2b7).(glp_probcxx . . $ glp_prob# *lp)
405 { int nnz = lp->nnzcxx . . $ glp_prob#nnz.;
406 return nnz;
407 }
408
409 /***********************************************************************
410 * NAME
411 *
412 * glp_get_mat_row - retrieve row of the constraint matrix
413 *
414 * SYNOPSIS
415 *
416 * int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[]);
417 *
418 * DESCRIPTION
419 *
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.
425 *
426 * The parameter ind and/or val can be specified as NULL, in which case
427 * corresponding information is not stored.
428 *
429 * RETURNS
430 *
431 * The routine glp_get_mat_row returns the length len, i.e. the number
432 * of (non-zero) elements in i-th row. */
433
434 int glp_get_mat_rowcxx . . $ glp_get_mat_row(223ff0a4a32a5807).(glp_probcxx . . $ glp_prob# *lp, int i, int ind[], double val[])
435 { GLPAIJcxx . . $ GLPAIJ# *aij;
436 int len;
437 if (!(1 <= i && i <= lp->mcxx . . $ glp_prob#m.))
438 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_mat_row: i = %d; row number out of range\n",
439 i);
440 len = 0;
441 for (aij = lp->rowcxx . . $ glp_prob#row.[i]->ptrcxx . . $ GLPROW#ptr.; aij != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; aij = aij->r_nextcxx . . $ GLPAIJ#r_next.)
442 { len++;
443 if (ind != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) ind[len] = aij->colcxx . . $ GLPAIJ#col.->jcxx . . $ GLPCOL#j.;
444 if (val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) val[len] = aij->valcxx . . $ GLPAIJ#val.;
445 }
446 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(len <= lp->n);
447 return len;
448 }
449
450 /***********************************************************************
451 * NAME
452 *
453 * glp_get_mat_col - retrieve column of the constraint matrix
454 *
455 * SYNOPSIS
456 *
457 * int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[]);
458 *
459 * DESCRIPTION
460 *
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.
466 *
467 * The parameter ind or/and val can be specified as NULL, in which case
468 * corresponding information is not stored.
469 *
470 * RETURNS
471 *
472 * The routine glp_get_mat_col returns the length len, i.e. the number
473 * of (non-zero) elements in j-th column. */
474
475 int glp_get_mat_colcxx . . $ glp_get_mat_col(223ff0a4a32a5807).(glp_probcxx . . $ glp_prob# *lp, int j, int ind[], double val[])
476 { GLPAIJcxx . . $ GLPAIJ# *aij;
477 int len;
478 if (!(1 <= j && j <= lp->ncxx . . $ glp_prob#n.))
479 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_get_mat_col: j = %d; column number out of range\n",
480 j);
481 len = 0;
482 for (aij = lp->colcxx . . $ glp_prob#col.[j]->ptrcxx . . $ GLPCOL#ptr.; aij != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; aij = aij->c_nextcxx . . $ GLPAIJ#c_next.)
483 { len++;
484 if (ind != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) ind[len] = aij->rowcxx . . $ GLPAIJ#row.->icxx . . $ GLPROW#i.;
485 if (val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) val[len] = aij->valcxx . . $ GLPAIJ#val.;
486 }
487 xassertcxx . . $ `external/glpk/glpenv.h:162:9`!(len <= lp->m);
488 return len;
489 }
490
491 /* eof */