aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/glpk-4.65/src/api/prob2.c
blob: d352db1287ea3affb7a9056c5cf5dd7fee6f6c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
/* prob2.c (problem retrieving routines) */

/***********************************************************************
*  This code is part of GLPK (GNU Linear Programming Kit).
*
*  Copyright (C) 2000-2013 Andrew Makhorin, Department for Applied
*  Informatics, Moscow Aviation Institute, Moscow, Russia. All rights
*  reserved. E-mail: <mao@gnu.org>.
*
*  GLPK is free software: you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  GLPK is distributed in the hope that it will be useful, but WITHOUT
*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
*  License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/

#include "env.h"
#include "prob.h"

/***********************************************************************
*  NAME
*
*  glp_get_prob_name - retrieve problem name
*
*  SYNOPSIS
*
*  const char *glp_get_prob_name(glp_prob *lp);
*
*  RETURNS
*
*  The routine glp_get_prob_name returns a pointer to an internal
*  buffer, which contains symbolic name of the problem. However, if the
*  problem has no assigned name, the routine returns NULL. */

const char *glp_get_prob_name(glp_prob *lp)
{     char *name;
      name = lp->name;
      return name;
}

/***********************************************************************
*  NAME
*
*  glp_get_obj_name - retrieve objective function name
*
*  SYNOPSIS
*
*  const char *glp_get_obj_name(glp_prob *lp);
*
*  RETURNS
*
*  The routine glp_get_obj_name returns a pointer to an internal
*  buffer, which contains a symbolic name of the objective function.
*  However, if the objective function has no assigned name, the routine
*  returns NULL. */

const char *glp_get_obj_name(glp_prob *lp)
{     char *name;
      name = lp->obj;
      return name;
}

/***********************************************************************
*  NAME
*
*  glp_get_obj_dir - retrieve optimization direction flag
*
*  SYNOPSIS
*
*  int glp_get_obj_dir(glp_prob *lp);
*
*  RETURNS
*
*  The routine glp_get_obj_dir returns the optimization direction flag
*  (i.e. "sense" of the objective function):
*
*  GLP_MIN - minimization;
*  GLP_MAX - maximization. */

int glp_get_obj_dir(glp_prob *lp)
{     int dir = lp->dir;
      return dir;
}

/***********************************************************************
*  NAME
*
*  glp_get_num_rows - retrieve number of rows
*
*  SYNOPSIS
*
*  int glp_get_num_rows(glp_prob *lp);
*
*  RETURNS
*
*  The routine glp_get_num_rows returns the current number of rows in
*  the specified problem object. */

int glp_get_num_rows(glp_prob *lp)
{     int m = lp->m;
      return m;
}

/***********************************************************************
*  NAME
*
*  glp_get_num_cols - retrieve number of columns
*
*  SYNOPSIS
*
*  int glp_get_num_cols(glp_prob *lp);
*
*  RETURNS
*
*  The routine glp_get_num_cols returns the current number of columns
*  in the specified problem object. */

int glp_get_num_cols(glp_prob *lp)
{     int n = lp->n;
      return n;
}

/***********************************************************************
*  NAME
*
*  glp_get_row_name - retrieve row name
*
*  SYNOPSIS
*
*  const char *glp_get_row_name(glp_prob *lp, int i);
*
*  RETURNS
*
*  The routine glp_get_row_name returns a pointer to an internal
*  buffer, which contains symbolic name of i-th row. However, if i-th
*  row has no assigned name, the routine returns NULL. */

const char *glp_get_row_name(glp_prob *lp, int i)
{     char *name;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_name: i = %d; row number out of range\n",
            i);
      name = lp->row[i]->name;
      return name;
}

/***********************************************************************
*  NAME
*
*  glp_get_col_name - retrieve column name
*
*  SYNOPSIS
*
*  const char *glp_get_col_name(glp_prob *lp, int j);
*
*  RETURNS
*
*  The routine glp_get_col_name returns a pointer to an internal
*  buffer, which contains symbolic name of j-th column. However, if j-th
*  column has no assigned name, the routine returns NULL. */

const char *glp_get_col_name(glp_prob *lp, int j)
{     char *name;
      if (!(1 <= j && j <= lp->n))
         xerror("glp_get_col_name: j = %d; column number out of range\n"
            , j);
      name = lp->col[j]->name;
      return name;
}

/***********************************************************************
*  NAME
*
*  glp_get_row_type - retrieve row type
*
*  SYNOPSIS
*
*  int glp_get_row_type(glp_prob *lp, int i);
*
*  RETURNS
*
*  The routine glp_get_row_type returns the type of i-th row, i.e. the
*  type of corresponding auxiliary variable, as follows:
*
*  GLP_FR - free (unbounded) variable;
*  GLP_LO - variable with lower bound;
*  GLP_UP - variable with upper bound;
*  GLP_DB - double-bounded variable;
*  GLP_FX - fixed variable. */

int glp_get_row_type(glp_prob *lp, int i)
{     if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_type: i = %d; row number out of range\n",
            i);
      return lp->row[i]->type;
}

/***********************************************************************
*  NAME
*
*  glp_get_row_lb - retrieve row lower bound
*
*  SYNOPSIS
*
*  double glp_get_row_lb(glp_prob *lp, int i);
*
*  RETURNS
*
*  The routine glp_get_row_lb returns the lower bound of i-th row, i.e.
*  the lower bound of corresponding auxiliary variable. However, if the
*  row has no lower bound, the routine returns -DBL_MAX. */

double glp_get_row_lb(glp_prob *lp, int i)
{     double lb;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_lb: i = %d; row number out of range\n", i);
      switch (lp->row[i]->type)
      {  case GLP_FR:
         case GLP_UP:
            lb = -DBL_MAX; break;
         case GLP_LO:
         case GLP_DB:
         case GLP_FX:
            lb = lp->row[i]->lb; break;
         default:
            xassert(lp != lp);
      }
      return lb;
}

/***********************************************************************
*  NAME
*
*  glp_get_row_ub - retrieve row upper bound
*
*  SYNOPSIS
*
*  double glp_get_row_ub(glp_prob *lp, int i);
*
*  RETURNS
*
*  The routine glp_get_row_ub returns the upper bound of i-th row, i.e.
*  the upper bound of corresponding auxiliary variable. However, if the
*  row has no upper bound, the routine returns +DBL_MAX. */

double glp_get_row_ub(glp_prob *lp, int i)
{     double ub;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_row_ub: i = %d; row number out of range\n", i);
      switch (lp->row[i]->type)
      {  case GLP_FR:
         case GLP_LO:
            ub = +DBL_MAX; break;
         case GLP_UP:
         case GLP_DB:
         case GLP_FX:
            ub = lp->row[i]->ub; break;
         default:
            xassert(lp != lp);
      }
      return ub;
}

/***********************************************************************
*  NAME
*
*  glp_get_col_type - retrieve column type
*
*  SYNOPSIS
*
*  int glp_get_col_type(glp_prob *lp, int j);
*
*  RETURNS
*
*  The routine glp_get_col_type returns the type of j-th column, i.e.
*  the type of corresponding structural variable, as follows:
*
*  GLP_FR - free (unbounded) variable;
*  GLP_LO - variable with lower bound;
*  GLP_UP - variable with upper bound;
*  GLP_DB - double-bounded variable;
*  GLP_FX - fixed variable. */

int glp_get_col_type(glp_prob *lp, int j)
{     if (!(1 <= j && j <= lp->n))
         xerror("glp_get_col_type: j = %d; column number out of range\n"
            , j);
      return lp->col[j]->type;
}

/***********************************************************************
*  NAME
*
*  glp_get_col_lb - retrieve column lower bound
*
*  SYNOPSIS
*
*  double glp_get_col_lb(glp_prob *lp, int j);
*
*  RETURNS
*
*  The routine glp_get_col_lb returns the lower bound of j-th column,
*  i.e. the lower bound of corresponding structural variable. However,
*  if the column has no lower bound, the routine returns -DBL_MAX. */

double glp_get_col_lb(glp_prob *lp, int j)
{     double lb;
      if (!(1 <= j && j <= lp->n))
         xerror("glp_get_col_lb: j = %d; column number out of range\n",
            j);
      switch (lp->col[j]->type)
      {  case GLP_FR:
         case GLP_UP:
            lb = -DBL_MAX; break;
         case GLP_LO:
         case GLP_DB:
         case GLP_FX:
            lb = lp->col[j]->lb; break;
         default:
            xassert(lp != lp);
      }
      return lb;
}

/***********************************************************************
*  NAME
*
*  glp_get_col_ub - retrieve column upper bound
*
*  SYNOPSIS
*
*  double glp_get_col_ub(glp_prob *lp, int j);
*
*  RETURNS
*
*  The routine glp_get_col_ub returns the upper bound of j-th column,
*  i.e. the upper bound of corresponding structural variable. However,
*  if the column has no upper bound, the routine returns +DBL_MAX. */

double glp_get_col_ub(glp_prob *lp, int j)
{     double ub;
      if (!(1 <= j && j <= lp->n))
         xerror("glp_get_col_ub: j = %d; column number out of range\n",
            j);
      switch (lp->col[j]->type)
      {  case GLP_FR:
         case GLP_LO:
            ub = +DBL_MAX; break;
         case GLP_UP:
         case GLP_DB:
         case GLP_FX:
            ub = lp->col[j]->ub; break;
         default:
            xassert(lp != lp);
      }
      return ub;
}

/***********************************************************************
*  NAME
*
*  glp_get_obj_coef - retrieve obj. coefficient or constant term
*
*  SYNOPSIS
*
*  double glp_get_obj_coef(glp_prob *lp, int j);
*
*  RETURNS
*
*  The routine glp_get_obj_coef returns the objective coefficient at
*  j-th structural variable (column) of the specified problem object.
*
*  If the parameter j is zero, the routine returns the constant term
*  ("shift") of the objective function. */

double glp_get_obj_coef(glp_prob *lp, int j)
{     if (!(0 <= j && j <= lp->n))
         xerror("glp_get_obj_coef: j = %d; column number out of range\n"
            , j);
      return j == 0 ? lp->c0 : lp->col[j]->coef;
}

/***********************************************************************
*  NAME
*
*  glp_get_num_nz - retrieve number of constraint coefficients
*
*  SYNOPSIS
*
*  int glp_get_num_nz(glp_prob *lp);
*
*  RETURNS
*
*  The routine glp_get_num_nz returns the number of (non-zero) elements
*  in the constraint matrix of the specified problem object. */

int glp_get_num_nz(glp_prob *lp)
{     int nnz = lp->nnz;
      return nnz;
}

/***********************************************************************
*  NAME
*
*  glp_get_mat_row - retrieve row of the constraint matrix
*
*  SYNOPSIS
*
*  int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[]);
*
*  DESCRIPTION
*
*  The routine glp_get_mat_row scans (non-zero) elements of i-th row
*  of the constraint matrix of the specified problem object and stores
*  their column indices and numeric values to locations ind[1], ...,
*  ind[len] and val[1], ..., val[len], respectively, where 0 <= len <= n
*  is the number of elements in i-th row, n is the number of columns.
*
*  The parameter ind and/or val can be specified as NULL, in which case
*  corresponding information is not stored.
*
*  RETURNS
*
*  The routine glp_get_mat_row returns the length len, i.e. the number
*  of (non-zero) elements in i-th row. */

int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[])
{     GLPAIJ *aij;
      int len;
      if (!(1 <= i && i <= lp->m))
         xerror("glp_get_mat_row: i = %d; row number out of range\n",
            i);
      len = 0;
      for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
      {  len++;
         if (ind != NULL) ind[len] = aij->col->j;
         if (val != NULL) val[len] = aij->val;
      }
      xassert(len <= lp->n);
      return len;
}

/***********************************************************************
*  NAME
*
*  glp_get_mat_col - retrieve column of the constraint matrix
*
*  SYNOPSIS
*
*  int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[]);
*
*  DESCRIPTION
*
*  The routine glp_get_mat_col scans (non-zero) elements of j-th column
*  of the constraint matrix of the specified problem object and stores
*  their row indices and numeric values to locations ind[1], ...,
*  ind[len] and val[1], ..., val[len], respectively, where 0 <= len <= m
*  is the number of elements in j-th column, m is the number of rows.
*
*  The parameter ind or/and val can be specified as NULL, in which case
*  corresponding information is not stored.
*
*  RETURNS
*
*  The routine glp_get_mat_col returns the length len, i.e. the number
*  of (non-zero) elements in j-th column. */

int glp_get_mat_col(glp_prob *lp, int j, int ind[], double val[])
{     GLPAIJ *aij;
      int len;
      if (!(1 <= j && j <= lp->n))
         xerror("glp_get_mat_col: j = %d; column number out of range\n",
            j);
      len = 0;
      for (aij = lp->col[j]->ptr; aij != NULL; aij = aij->c_next)
      {  len++;
         if (ind != NULL) ind[len] = aij->row->i;
         if (val != NULL) val[len] = aij->val;
      }
      xassert(len <= lp->m);
      return len;
}

/* eof */