alpar@1
|
1 |
/* glpapi02.c (problem retrieving routines) */
|
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 |
#include "glpapi.h"
|
alpar@1
|
26 |
|
alpar@1
|
27 |
/***********************************************************************
|
alpar@1
|
28 |
* NAME
|
alpar@1
|
29 |
*
|
alpar@1
|
30 |
* glp_get_prob_name - retrieve problem name
|
alpar@1
|
31 |
*
|
alpar@1
|
32 |
* SYNOPSIS
|
alpar@1
|
33 |
*
|
alpar@1
|
34 |
* const char *glp_get_prob_name(glp_prob *lp);
|
alpar@1
|
35 |
*
|
alpar@1
|
36 |
* RETURNS
|
alpar@1
|
37 |
*
|
alpar@1
|
38 |
* The routine glp_get_prob_name returns a pointer to an internal
|
alpar@1
|
39 |
* buffer, which contains symbolic name of the problem. However, if the
|
alpar@1
|
40 |
* problem has no assigned name, the routine returns NULL. */
|
alpar@1
|
41 |
|
alpar@1
|
42 |
const char *glp_get_prob_name(glp_prob *lp)
|
alpar@1
|
43 |
{ char *name;
|
alpar@1
|
44 |
name = lp->name;
|
alpar@1
|
45 |
return name;
|
alpar@1
|
46 |
}
|
alpar@1
|
47 |
|
alpar@1
|
48 |
/***********************************************************************
|
alpar@1
|
49 |
* NAME
|
alpar@1
|
50 |
*
|
alpar@1
|
51 |
* glp_get_obj_name - retrieve objective function name
|
alpar@1
|
52 |
*
|
alpar@1
|
53 |
* SYNOPSIS
|
alpar@1
|
54 |
*
|
alpar@1
|
55 |
* const char *glp_get_obj_name(glp_prob *lp);
|
alpar@1
|
56 |
*
|
alpar@1
|
57 |
* RETURNS
|
alpar@1
|
58 |
*
|
alpar@1
|
59 |
* The routine glp_get_obj_name returns a pointer to an internal
|
alpar@1
|
60 |
* buffer, which contains a symbolic name of the objective function.
|
alpar@1
|
61 |
* However, if the objective function has no assigned name, the routine
|
alpar@1
|
62 |
* returns NULL. */
|
alpar@1
|
63 |
|
alpar@1
|
64 |
const char *glp_get_obj_name(glp_prob *lp)
|
alpar@1
|
65 |
{ char *name;
|
alpar@1
|
66 |
name = lp->obj;
|
alpar@1
|
67 |
return name;
|
alpar@1
|
68 |
}
|
alpar@1
|
69 |
|
alpar@1
|
70 |
/***********************************************************************
|
alpar@1
|
71 |
* NAME
|
alpar@1
|
72 |
*
|
alpar@1
|
73 |
* glp_get_obj_dir - retrieve optimization direction flag
|
alpar@1
|
74 |
*
|
alpar@1
|
75 |
* SYNOPSIS
|
alpar@1
|
76 |
*
|
alpar@1
|
77 |
* int glp_get_obj_dir(glp_prob *lp);
|
alpar@1
|
78 |
*
|
alpar@1
|
79 |
* RETURNS
|
alpar@1
|
80 |
*
|
alpar@1
|
81 |
* The routine glp_get_obj_dir returns the optimization direction flag
|
alpar@1
|
82 |
* (i.e. "sense" of the objective function):
|
alpar@1
|
83 |
*
|
alpar@1
|
84 |
* GLP_MIN - minimization;
|
alpar@1
|
85 |
* GLP_MAX - maximization. */
|
alpar@1
|
86 |
|
alpar@1
|
87 |
int glp_get_obj_dir(glp_prob *lp)
|
alpar@1
|
88 |
{ int dir = lp->dir;
|
alpar@1
|
89 |
return dir;
|
alpar@1
|
90 |
}
|
alpar@1
|
91 |
|
alpar@1
|
92 |
/***********************************************************************
|
alpar@1
|
93 |
* NAME
|
alpar@1
|
94 |
*
|
alpar@1
|
95 |
* glp_get_num_rows - retrieve number of rows
|
alpar@1
|
96 |
*
|
alpar@1
|
97 |
* SYNOPSIS
|
alpar@1
|
98 |
*
|
alpar@1
|
99 |
* int glp_get_num_rows(glp_prob *lp);
|
alpar@1
|
100 |
*
|
alpar@1
|
101 |
* RETURNS
|
alpar@1
|
102 |
*
|
alpar@1
|
103 |
* The routine glp_get_num_rows returns the current number of rows in
|
alpar@1
|
104 |
* the specified problem object. */
|
alpar@1
|
105 |
|
alpar@1
|
106 |
int glp_get_num_rows(glp_prob *lp)
|
alpar@1
|
107 |
{ int m = lp->m;
|
alpar@1
|
108 |
return m;
|
alpar@1
|
109 |
}
|
alpar@1
|
110 |
|
alpar@1
|
111 |
/***********************************************************************
|
alpar@1
|
112 |
* NAME
|
alpar@1
|
113 |
*
|
alpar@1
|
114 |
* glp_get_num_cols - retrieve number of columns
|
alpar@1
|
115 |
*
|
alpar@1
|
116 |
* SYNOPSIS
|
alpar@1
|
117 |
*
|
alpar@1
|
118 |
* int glp_get_num_cols(glp_prob *lp);
|
alpar@1
|
119 |
*
|
alpar@1
|
120 |
* RETURNS
|
alpar@1
|
121 |
*
|
alpar@1
|
122 |
* The routine glp_get_num_cols returns the current number of columns
|
alpar@1
|
123 |
* in the specified problem object. */
|
alpar@1
|
124 |
|
alpar@1
|
125 |
int glp_get_num_cols(glp_prob *lp)
|
alpar@1
|
126 |
{ int n = lp->n;
|
alpar@1
|
127 |
return n;
|
alpar@1
|
128 |
}
|
alpar@1
|
129 |
|
alpar@1
|
130 |
/***********************************************************************
|
alpar@1
|
131 |
* NAME
|
alpar@1
|
132 |
*
|
alpar@1
|
133 |
* glp_get_row_name - retrieve row name
|
alpar@1
|
134 |
*
|
alpar@1
|
135 |
* SYNOPSIS
|
alpar@1
|
136 |
*
|
alpar@1
|
137 |
* const char *glp_get_row_name(glp_prob *lp, int i);
|
alpar@1
|
138 |
*
|
alpar@1
|
139 |
* RETURNS
|
alpar@1
|
140 |
*
|
alpar@1
|
141 |
* The routine glp_get_row_name returns a pointer to an internal
|
alpar@1
|
142 |
* buffer, which contains symbolic name of i-th row. However, if i-th
|
alpar@1
|
143 |
* row has no assigned name, the routine returns NULL. */
|
alpar@1
|
144 |
|
alpar@1
|
145 |
const char *glp_get_row_name(glp_prob *lp, int i)
|
alpar@1
|
146 |
{ char *name;
|
alpar@1
|
147 |
if (!(1 <= i && i <= lp->m))
|
alpar@1
|
148 |
xerror("glp_get_row_name: i = %d; row number out of range\n",
|
alpar@1
|
149 |
i);
|
alpar@1
|
150 |
name = lp->row[i]->name;
|
alpar@1
|
151 |
return name;
|
alpar@1
|
152 |
}
|
alpar@1
|
153 |
|
alpar@1
|
154 |
/***********************************************************************
|
alpar@1
|
155 |
* NAME
|
alpar@1
|
156 |
*
|
alpar@1
|
157 |
* glp_get_col_name - retrieve column name
|
alpar@1
|
158 |
*
|
alpar@1
|
159 |
* SYNOPSIS
|
alpar@1
|
160 |
*
|
alpar@1
|
161 |
* const char *glp_get_col_name(glp_prob *lp, int j);
|
alpar@1
|
162 |
*
|
alpar@1
|
163 |
* RETURNS
|
alpar@1
|
164 |
*
|
alpar@1
|
165 |
* The routine glp_get_col_name returns a pointer to an internal
|
alpar@1
|
166 |
* buffer, which contains symbolic name of j-th column. However, if j-th
|
alpar@1
|
167 |
* column has no assigned name, the routine returns NULL. */
|
alpar@1
|
168 |
|
alpar@1
|
169 |
const char *glp_get_col_name(glp_prob *lp, int j)
|
alpar@1
|
170 |
{ char *name;
|
alpar@1
|
171 |
if (!(1 <= j && j <= lp->n))
|
alpar@1
|
172 |
xerror("glp_get_col_name: j = %d; column number out of range\n"
|
alpar@1
|
173 |
, j);
|
alpar@1
|
174 |
name = lp->col[j]->name;
|
alpar@1
|
175 |
return name;
|
alpar@1
|
176 |
}
|
alpar@1
|
177 |
|
alpar@1
|
178 |
/***********************************************************************
|
alpar@1
|
179 |
* NAME
|
alpar@1
|
180 |
*
|
alpar@1
|
181 |
* glp_get_row_type - retrieve row type
|
alpar@1
|
182 |
*
|
alpar@1
|
183 |
* SYNOPSIS
|
alpar@1
|
184 |
*
|
alpar@1
|
185 |
* int glp_get_row_type(glp_prob *lp, int i);
|
alpar@1
|
186 |
*
|
alpar@1
|
187 |
* RETURNS
|
alpar@1
|
188 |
*
|
alpar@1
|
189 |
* The routine glp_get_row_type returns the type of i-th row, i.e. the
|
alpar@1
|
190 |
* type of corresponding auxiliary variable, as follows:
|
alpar@1
|
191 |
*
|
alpar@1
|
192 |
* GLP_FR - free (unbounded) variable;
|
alpar@1
|
193 |
* GLP_LO - variable with lower bound;
|
alpar@1
|
194 |
* GLP_UP - variable with upper bound;
|
alpar@1
|
195 |
* GLP_DB - double-bounded variable;
|
alpar@1
|
196 |
* GLP_FX - fixed variable. */
|
alpar@1
|
197 |
|
alpar@1
|
198 |
int glp_get_row_type(glp_prob *lp, int i)
|
alpar@1
|
199 |
{ if (!(1 <= i && i <= lp->m))
|
alpar@1
|
200 |
xerror("glp_get_row_type: i = %d; row number out of range\n",
|
alpar@1
|
201 |
i);
|
alpar@1
|
202 |
return lp->row[i]->type;
|
alpar@1
|
203 |
}
|
alpar@1
|
204 |
|
alpar@1
|
205 |
/***********************************************************************
|
alpar@1
|
206 |
* NAME
|
alpar@1
|
207 |
*
|
alpar@1
|
208 |
* glp_get_row_lb - retrieve row lower bound
|
alpar@1
|
209 |
*
|
alpar@1
|
210 |
* SYNOPSIS
|
alpar@1
|
211 |
*
|
alpar@1
|
212 |
* double glp_get_row_lb(glp_prob *lp, int i);
|
alpar@1
|
213 |
*
|
alpar@1
|
214 |
* RETURNS
|
alpar@1
|
215 |
*
|
alpar@1
|
216 |
* The routine glp_get_row_lb returns the lower bound of i-th row, i.e.
|
alpar@1
|
217 |
* the lower bound of corresponding auxiliary variable. However, if the
|
alpar@1
|
218 |
* row has no lower bound, the routine returns -DBL_MAX. */
|
alpar@1
|
219 |
|
alpar@1
|
220 |
double glp_get_row_lb(glp_prob *lp, int i)
|
alpar@1
|
221 |
{ double lb;
|
alpar@1
|
222 |
if (!(1 <= i && i <= lp->m))
|
alpar@1
|
223 |
xerror("glp_get_row_lb: i = %d; row number out of range\n", i);
|
alpar@1
|
224 |
switch (lp->row[i]->type)
|
alpar@1
|
225 |
{ case GLP_FR:
|
alpar@1
|
226 |
case GLP_UP:
|
alpar@1
|
227 |
lb = -DBL_MAX; break;
|
alpar@1
|
228 |
case GLP_LO:
|
alpar@1
|
229 |
case GLP_DB:
|
alpar@1
|
230 |
case GLP_FX:
|
alpar@1
|
231 |
lb = lp->row[i]->lb; break;
|
alpar@1
|
232 |
default:
|
alpar@1
|
233 |
xassert(lp != lp);
|
alpar@1
|
234 |
}
|
alpar@1
|
235 |
return lb;
|
alpar@1
|
236 |
}
|
alpar@1
|
237 |
|
alpar@1
|
238 |
/***********************************************************************
|
alpar@1
|
239 |
* NAME
|
alpar@1
|
240 |
*
|
alpar@1
|
241 |
* glp_get_row_ub - retrieve row upper bound
|
alpar@1
|
242 |
*
|
alpar@1
|
243 |
* SYNOPSIS
|
alpar@1
|
244 |
*
|
alpar@1
|
245 |
* double glp_get_row_ub(glp_prob *lp, int i);
|
alpar@1
|
246 |
*
|
alpar@1
|
247 |
* RETURNS
|
alpar@1
|
248 |
*
|
alpar@1
|
249 |
* The routine glp_get_row_ub returns the upper bound of i-th row, i.e.
|
alpar@1
|
250 |
* the upper bound of corresponding auxiliary variable. However, if the
|
alpar@1
|
251 |
* row has no upper bound, the routine returns +DBL_MAX. */
|
alpar@1
|
252 |
|
alpar@1
|
253 |
double glp_get_row_ub(glp_prob *lp, int i)
|
alpar@1
|
254 |
{ double ub;
|
alpar@1
|
255 |
if (!(1 <= i && i <= lp->m))
|
alpar@1
|
256 |
xerror("glp_get_row_ub: i = %d; row number out of range\n", i);
|
alpar@1
|
257 |
switch (lp->row[i]->type)
|
alpar@1
|
258 |
{ case GLP_FR:
|
alpar@1
|
259 |
case GLP_LO:
|
alpar@1
|
260 |
ub = +DBL_MAX; break;
|
alpar@1
|
261 |
case GLP_UP:
|
alpar@1
|
262 |
case GLP_DB:
|
alpar@1
|
263 |
case GLP_FX:
|
alpar@1
|
264 |
ub = lp->row[i]->ub; break;
|
alpar@1
|
265 |
default:
|
alpar@1
|
266 |
xassert(lp != lp);
|
alpar@1
|
267 |
}
|
alpar@1
|
268 |
return ub;
|
alpar@1
|
269 |
}
|
alpar@1
|
270 |
|
alpar@1
|
271 |
/***********************************************************************
|
alpar@1
|
272 |
* NAME
|
alpar@1
|
273 |
*
|
alpar@1
|
274 |
* glp_get_col_type - retrieve column type
|
alpar@1
|
275 |
*
|
alpar@1
|
276 |
* SYNOPSIS
|
alpar@1
|
277 |
*
|
alpar@1
|
278 |
* int glp_get_col_type(glp_prob *lp, int j);
|
alpar@1
|
279 |
*
|
alpar@1
|
280 |
* RETURNS
|
alpar@1
|
281 |
*
|
alpar@1
|
282 |
* The routine glp_get_col_type returns the type of j-th column, i.e.
|
alpar@1
|
283 |
* the type of corresponding structural variable, as follows:
|
alpar@1
|
284 |
*
|
alpar@1
|
285 |
* GLP_FR - free (unbounded) variable;
|
alpar@1
|
286 |
* GLP_LO - variable with lower bound;
|
alpar@1
|
287 |
* GLP_UP - variable with upper bound;
|
alpar@1
|
288 |
* GLP_DB - double-bounded variable;
|
alpar@1
|
289 |
* GLP_FX - fixed variable. */
|
alpar@1
|
290 |
|
alpar@1
|
291 |
int glp_get_col_type(glp_prob *lp, int j)
|
alpar@1
|
292 |
{ if (!(1 <= j && j <= lp->n))
|
alpar@1
|
293 |
xerror("glp_get_col_type: j = %d; column number out of range\n"
|
alpar@1
|
294 |
, j);
|
alpar@1
|
295 |
return lp->col[j]->type;
|
alpar@1
|
296 |
}
|
alpar@1
|
297 |
|
alpar@1
|
298 |
/***********************************************************************
|
alpar@1
|
299 |
* NAME
|
alpar@1
|
300 |
*
|
alpar@1
|
301 |
* glp_get_col_lb - retrieve column lower bound
|
alpar@1
|
302 |
*
|
alpar@1
|
303 |
* SYNOPSIS
|
alpar@1
|
304 |
*
|
alpar@1
|
305 |
* double glp_get_col_lb(glp_prob *lp, int j);
|
alpar@1
|
306 |
*
|
alpar@1
|
307 |
* RETURNS
|
alpar@1
|
308 |
*
|
alpar@1
|
309 |
* The routine glp_get_col_lb returns the lower bound of j-th column,
|
alpar@1
|
310 |
* i.e. the lower bound of corresponding structural variable. However,
|
alpar@1
|
311 |
* if the column has no lower bound, the routine returns -DBL_MAX. */
|
alpar@1
|
312 |
|
alpar@1
|
313 |
double glp_get_col_lb(glp_prob *lp, int j)
|
alpar@1
|
314 |
{ double lb;
|
alpar@1
|
315 |
if (!(1 <= j && j <= lp->n))
|
alpar@1
|
316 |
xerror("glp_get_col_lb: j = %d; column number out of range\n",
|
alpar@1
|
317 |
j);
|
alpar@1
|
318 |
switch (lp->col[j]->type)
|
alpar@1
|
319 |
{ case GLP_FR:
|
alpar@1
|
320 |
case GLP_UP:
|
alpar@1
|
321 |
lb = -DBL_MAX; break;
|
alpar@1
|
322 |
case GLP_LO:
|
alpar@1
|
323 |
case GLP_DB:
|
alpar@1
|
324 |
case GLP_FX:
|
alpar@1
|
325 |
lb = lp->col[j]->lb; break;
|
alpar@1
|
326 |
default:
|
alpar@1
|
327 |
xassert(lp != lp);
|
alpar@1
|
328 |
}
|
alpar@1
|
329 |
return lb;
|
alpar@1
|
330 |
}
|
alpar@1
|
331 |
|
alpar@1
|
332 |
/***********************************************************************
|
alpar@1
|
333 |
* NAME
|
alpar@1
|
334 |
*
|
alpar@1
|
335 |
* glp_get_col_ub - retrieve column upper bound
|
alpar@1
|
336 |
*
|
alpar@1
|
337 |
* SYNOPSIS
|
alpar@1
|
338 |
*
|
alpar@1
|
339 |
* double glp_get_col_ub(glp_prob *lp, int j);
|
alpar@1
|
340 |
*
|
alpar@1
|
341 |
* RETURNS
|
alpar@1
|
342 |
*
|
alpar@1
|
343 |
* The routine glp_get_col_ub returns the upper bound of j-th column,
|
alpar@1
|
344 |
* i.e. the upper bound of corresponding structural variable. However,
|
alpar@1
|
345 |
* if the column has no upper bound, the routine returns +DBL_MAX. */
|
alpar@1
|
346 |
|
alpar@1
|
347 |
double glp_get_col_ub(glp_prob *lp, int j)
|
alpar@1
|
348 |
{ double ub;
|
alpar@1
|
349 |
if (!(1 <= j && j <= lp->n))
|
alpar@1
|
350 |
xerror("glp_get_col_ub: j = %d; column number out of range\n",
|
alpar@1
|
351 |
j);
|
alpar@1
|
352 |
switch (lp->col[j]->type)
|
alpar@1
|
353 |
{ case GLP_FR:
|
alpar@1
|
354 |
case GLP_LO:
|
alpar@1
|
355 |
ub = +DBL_MAX; break;
|
alpar@1
|
356 |
case GLP_UP:
|
alpar@1
|
357 |
case GLP_DB:
|
alpar@1
|
358 |
case GLP_FX:
|
alpar@1
|
359 |
ub = lp->col[j]->ub; break;
|
alpar@1
|
360 |
default:
|
alpar@1
|
361 |
xassert(lp != lp);
|
alpar@1
|
362 |
}
|
alpar@1
|
363 |
return ub;
|
alpar@1
|
364 |
}
|
alpar@1
|
365 |
|
alpar@1
|
366 |
/***********************************************************************
|
alpar@1
|
367 |
* NAME
|
alpar@1
|
368 |
*
|
alpar@1
|
369 |
* glp_get_obj_coef - retrieve obj. coefficient or constant term
|
alpar@1
|
370 |
*
|
alpar@1
|
371 |
* SYNOPSIS
|
alpar@1
|
372 |
*
|
alpar@1
|
373 |
* double glp_get_obj_coef(glp_prob *lp, int j);
|
alpar@1
|
374 |
*
|
alpar@1
|
375 |
* RETURNS
|
alpar@1
|
376 |
*
|
alpar@1
|
377 |
* The routine glp_get_obj_coef returns the objective coefficient at
|
alpar@1
|
378 |
* j-th structural variable (column) of the specified problem object.
|
alpar@1
|
379 |
*
|
alpar@1
|
380 |
* If the parameter j is zero, the routine returns the constant term
|
alpar@1
|
381 |
* ("shift") of the objective function. */
|
alpar@1
|
382 |
|
alpar@1
|
383 |
double glp_get_obj_coef(glp_prob *lp, int j)
|
alpar@1
|
384 |
{ if (!(0 <= j && j <= lp->n))
|
alpar@1
|
385 |
xerror("glp_get_obj_coef: j = %d; column number out of range\n"
|
alpar@1
|
386 |
, j);
|
alpar@1
|
387 |
return j == 0 ? lp->c0 : lp->col[j]->coef;
|
alpar@1
|
388 |
}
|
alpar@1
|
389 |
|
alpar@1
|
390 |
/***********************************************************************
|
alpar@1
|
391 |
* NAME
|
alpar@1
|
392 |
*
|
alpar@1
|
393 |
* glp_get_num_nz - retrieve number of constraint coefficients
|
alpar@1
|
394 |
*
|
alpar@1
|
395 |
* SYNOPSIS
|
alpar@1
|
396 |
*
|
alpar@1
|
397 |
* int glp_get_num_nz(glp_prob *lp);
|
alpar@1
|
398 |
*
|
alpar@1
|
399 |
* RETURNS
|
alpar@1
|
400 |
*
|
alpar@1
|
401 |
* The routine glp_get_num_nz returns the number of (non-zero) elements
|
alpar@1
|
402 |
* in the constraint matrix of the specified problem object. */
|
alpar@1
|
403 |
|
alpar@1
|
404 |
int glp_get_num_nz(glp_prob *lp)
|
alpar@1
|
405 |
{ int nnz = lp->nnz;
|
alpar@1
|
406 |
return nnz;
|
alpar@1
|
407 |
}
|
alpar@1
|
408 |
|
alpar@1
|
409 |
/***********************************************************************
|
alpar@1
|
410 |
* NAME
|
alpar@1
|
411 |
*
|
alpar@1
|
412 |
* glp_get_mat_row - retrieve row of the constraint matrix
|
alpar@1
|
413 |
*
|
alpar@1
|
414 |
* SYNOPSIS
|
alpar@1
|
415 |
*
|
alpar@1
|
416 |
* int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[]);
|
alpar@1
|
417 |
*
|
alpar@1
|
418 |
* DESCRIPTION
|
alpar@1
|
419 |
*
|
alpar@1
|
420 |
* The routine glp_get_mat_row scans (non-zero) elements of i-th row
|
alpar@1
|
421 |
* of the constraint matrix of the specified problem object and stores
|
alpar@1
|
422 |
* their column indices and numeric values to locations ind[1], ...,
|
alpar@1
|
423 |
* ind[len] and val[1], ..., val[len], respectively, where 0 <= len <= n
|
alpar@1
|
424 |
* is the number of elements in i-th row, n is the number of columns.
|
alpar@1
|
425 |
*
|
alpar@1
|
426 |
* The parameter ind and/or val can be specified as NULL, in which case
|
alpar@1
|
427 |
* corresponding information is not stored.
|
alpar@1
|
428 |
*
|
alpar@1
|
429 |
* RETURNS
|
alpar@1
|
430 |
*
|
alpar@1
|
431 |
* The routine glp_get_mat_row returns the length len, i.e. the number
|
alpar@1
|
432 |
* of (non-zero) elements in i-th row. */
|
alpar@1
|
433 |
|
alpar@1
|
434 |
int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[])
|
alpar@1
|
435 |
{ GLPAIJ *aij;
|
alpar@1
|
436 |
int len;
|
alpar@1
|
437 |
if (!(1 <= i && i <= lp->m))
|
alpar@1
|
438 |
xerror("glp_get_mat_row: i = %d; row number out of range\n",
|
alpar@1
|
439 |
i);
|
alpar@1
|
440 |
len = 0;
|
alpar@1
|
441 |
for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
|
alpar@1
|
442 |
{ len++;
|
alpar@1
|
443 |
if (ind != NULL) ind[len] = aij->col->j;
|
alpar@1
|
444 |
if (val != NULL) val[len] = aij->val;
|
alpar@1
|
445 |
}
|
alpar@1
|
446 |
xassert(len <= lp->n);
|
alpar@1
|
447 |
return len;
|
alpar@1
|
448 |
}
|
alpar@1
|
449 |
|
alpar@1
|
450 |
/***********************************************************************
|
alpar@1
|
451 |
* NAME
|
alpar@1
|
452 |
*
|
alpar@1
|
453 |
* glp_get_mat_col - retrieve column of the constraint matrix
|
alpar@1
|
454 |
*
|
alpar@1
|
455 |
* SYNOPSIS
|
alpar@1
|
456 |
*
|
alpar@1
|
457 |
* int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[]);
|
alpar@1
|
458 |
*
|
alpar@1
|
459 |
* DESCRIPTION
|
alpar@1
|
460 |
*
|
alpar@1
|
461 |
* The routine glp_get_mat_col scans (non-zero) elements of j-th column
|
alpar@1
|
462 |
* of the constraint matrix of the specified problem object and stores
|
alpar@1
|
463 |
* their row indices and numeric values to locations ind[1], ...,
|
alpar@1
|
464 |
* ind[len] and val[1], ..., val[len], respectively, where 0 <= len <= m
|
alpar@1
|
465 |
* is the number of elements in j-th column, m is the number of rows.
|
alpar@1
|
466 |
*
|
alpar@1
|
467 |
* The parameter ind or/and val can be specified as NULL, in which case
|
alpar@1
|
468 |
* corresponding information is not stored.
|
alpar@1
|
469 |
*
|
alpar@1
|
470 |
* RETURNS
|
alpar@1
|
471 |
*
|
alpar@1
|
472 |
* The routine glp_get_mat_col returns the length len, i.e. the number
|
alpar@1
|
473 |
* of (non-zero) elements in j-th column. */
|
alpar@1
|
474 |
|
alpar@1
|
475 |
int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[])
|
alpar@1
|
476 |
{ GLPAIJ *aij;
|
alpar@1
|
477 |
int len;
|
alpar@1
|
478 |
if (!(1 <= j && j <= lp->n))
|
alpar@1
|
479 |
xerror("glp_get_mat_col: j = %d; column number out of range\n",
|
alpar@1
|
480 |
j);
|
alpar@1
|
481 |
len = 0;
|
alpar@1
|
482 |
for (aij = lp->col[j]->ptr; aij != NULL; aij = aij->c_next)
|
alpar@1
|
483 |
{ len++;
|
alpar@1
|
484 |
if (ind != NULL) ind[len] = aij->row->i;
|
alpar@1
|
485 |
if (val != NULL) val[len] = aij->val;
|
alpar@1
|
486 |
}
|
alpar@1
|
487 |
xassert(len <= lp->m);
|
alpar@1
|
488 |
return len;
|
alpar@1
|
489 |
}
|
alpar@1
|
490 |
|
alpar@1
|
491 |
/* eof */
|