alpar@1
|
1 |
/* glpbfx.c */
|
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 |
typedef struct BFX BFX;
|
alpar@1
|
26 |
#define GLPBFX_DEFINED
|
alpar@1
|
27 |
#include "glpbfx.h"
|
alpar@1
|
28 |
#include "glpenv.h"
|
alpar@1
|
29 |
#include "glplux.h"
|
alpar@1
|
30 |
|
alpar@1
|
31 |
struct BFX
|
alpar@1
|
32 |
{ int valid;
|
alpar@1
|
33 |
LUX *lux;
|
alpar@1
|
34 |
};
|
alpar@1
|
35 |
|
alpar@1
|
36 |
BFX *bfx_create_binv(void)
|
alpar@1
|
37 |
{ /* create factorization of the basis matrix */
|
alpar@1
|
38 |
BFX *bfx;
|
alpar@1
|
39 |
bfx = xmalloc(sizeof(BFX));
|
alpar@1
|
40 |
bfx->valid = 0;
|
alpar@1
|
41 |
bfx->lux = NULL;
|
alpar@1
|
42 |
return bfx;
|
alpar@1
|
43 |
}
|
alpar@1
|
44 |
|
alpar@1
|
45 |
int bfx_factorize(BFX *binv, int m, int (*col)(void *info, int j,
|
alpar@1
|
46 |
int ind[], mpq_t val[]), void *info)
|
alpar@1
|
47 |
{ /* compute factorization of the basis matrix */
|
alpar@1
|
48 |
int ret;
|
alpar@1
|
49 |
xassert(m > 0);
|
alpar@1
|
50 |
if (binv->lux != NULL && binv->lux->n != m)
|
alpar@1
|
51 |
{ lux_delete(binv->lux);
|
alpar@1
|
52 |
binv->lux = NULL;
|
alpar@1
|
53 |
}
|
alpar@1
|
54 |
if (binv->lux == NULL)
|
alpar@1
|
55 |
binv->lux = lux_create(m);
|
alpar@1
|
56 |
ret = lux_decomp(binv->lux, col, info);
|
alpar@1
|
57 |
binv->valid = (ret == 0);
|
alpar@1
|
58 |
return ret;
|
alpar@1
|
59 |
}
|
alpar@1
|
60 |
|
alpar@1
|
61 |
void bfx_ftran(BFX *binv, mpq_t x[], int save)
|
alpar@1
|
62 |
{ /* perform forward transformation (FTRAN) */
|
alpar@1
|
63 |
xassert(binv->valid);
|
alpar@1
|
64 |
lux_solve(binv->lux, 0, x);
|
alpar@1
|
65 |
xassert(save == save);
|
alpar@1
|
66 |
return;
|
alpar@1
|
67 |
}
|
alpar@1
|
68 |
|
alpar@1
|
69 |
void bfx_btran(BFX *binv, mpq_t x[])
|
alpar@1
|
70 |
{ /* perform backward transformation (BTRAN) */
|
alpar@1
|
71 |
xassert(binv->valid);
|
alpar@1
|
72 |
lux_solve(binv->lux, 1, x);
|
alpar@1
|
73 |
return;
|
alpar@1
|
74 |
}
|
alpar@1
|
75 |
|
alpar@1
|
76 |
int bfx_update(BFX *binv, int j)
|
alpar@1
|
77 |
{ /* update factorization of the basis matrix */
|
alpar@1
|
78 |
xassert(binv->valid);
|
alpar@1
|
79 |
xassert(1 <= j && j <= binv->lux->n);
|
alpar@1
|
80 |
return 1;
|
alpar@1
|
81 |
}
|
alpar@1
|
82 |
|
alpar@1
|
83 |
void bfx_delete_binv(BFX *binv)
|
alpar@1
|
84 |
{ /* delete factorization of the basis matrix */
|
alpar@1
|
85 |
if (binv->lux != NULL)
|
alpar@1
|
86 |
lux_delete(binv->lux);
|
alpar@1
|
87 |
xfree(binv);
|
alpar@1
|
88 |
return;
|
alpar@1
|
89 |
}
|
alpar@1
|
90 |
|
alpar@1
|
91 |
/* eof */
|