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