alpar@1
|
1 |
/* glpspx02.c (dual simplex method) */
|
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 "glpspx.h"
|
alpar@1
|
26 |
|
alpar@1
|
27 |
#define GLP_DEBUG 1
|
alpar@1
|
28 |
|
alpar@1
|
29 |
#if 0
|
alpar@1
|
30 |
#define GLP_LONG_STEP 1
|
alpar@1
|
31 |
#endif
|
alpar@1
|
32 |
|
alpar@1
|
33 |
struct csa
|
alpar@1
|
34 |
{ /* common storage area */
|
alpar@1
|
35 |
/*--------------------------------------------------------------*/
|
alpar@1
|
36 |
/* LP data */
|
alpar@1
|
37 |
int m;
|
alpar@1
|
38 |
/* number of rows (auxiliary variables), m > 0 */
|
alpar@1
|
39 |
int n;
|
alpar@1
|
40 |
/* number of columns (structural variables), n > 0 */
|
alpar@1
|
41 |
char *type; /* char type[1+m+n]; */
|
alpar@1
|
42 |
/* type[0] is not used;
|
alpar@1
|
43 |
type[k], 1 <= k <= m+n, is the type of variable x[k]:
|
alpar@1
|
44 |
GLP_FR - free variable
|
alpar@1
|
45 |
GLP_LO - variable with lower bound
|
alpar@1
|
46 |
GLP_UP - variable with upper bound
|
alpar@1
|
47 |
GLP_DB - double-bounded variable
|
alpar@1
|
48 |
GLP_FX - fixed variable */
|
alpar@1
|
49 |
double *lb; /* double lb[1+m+n]; */
|
alpar@1
|
50 |
/* lb[0] is not used;
|
alpar@1
|
51 |
lb[k], 1 <= k <= m+n, is an lower bound of variable x[k];
|
alpar@1
|
52 |
if x[k] has no lower bound, lb[k] is zero */
|
alpar@1
|
53 |
double *ub; /* double ub[1+m+n]; */
|
alpar@1
|
54 |
/* ub[0] is not used;
|
alpar@1
|
55 |
ub[k], 1 <= k <= m+n, is an upper bound of variable x[k];
|
alpar@1
|
56 |
if x[k] has no upper bound, ub[k] is zero;
|
alpar@1
|
57 |
if x[k] is of fixed type, ub[k] is the same as lb[k] */
|
alpar@1
|
58 |
double *coef; /* double coef[1+m+n]; */
|
alpar@1
|
59 |
/* coef[0] is not used;
|
alpar@1
|
60 |
coef[k], 1 <= k <= m+n, is an objective coefficient at
|
alpar@1
|
61 |
variable x[k] */
|
alpar@1
|
62 |
/*--------------------------------------------------------------*/
|
alpar@1
|
63 |
/* original bounds of variables */
|
alpar@1
|
64 |
char *orig_type; /* char orig_type[1+m+n]; */
|
alpar@1
|
65 |
double *orig_lb; /* double orig_lb[1+m+n]; */
|
alpar@1
|
66 |
double *orig_ub; /* double orig_ub[1+m+n]; */
|
alpar@1
|
67 |
/*--------------------------------------------------------------*/
|
alpar@1
|
68 |
/* original objective function */
|
alpar@1
|
69 |
double *obj; /* double obj[1+n]; */
|
alpar@1
|
70 |
/* obj[0] is a constant term of the original objective function;
|
alpar@1
|
71 |
obj[j], 1 <= j <= n, is an original objective coefficient at
|
alpar@1
|
72 |
structural variable x[m+j] */
|
alpar@1
|
73 |
double zeta;
|
alpar@1
|
74 |
/* factor used to scale original objective coefficients; its
|
alpar@1
|
75 |
sign defines original optimization direction: zeta > 0 means
|
alpar@1
|
76 |
minimization, zeta < 0 means maximization */
|
alpar@1
|
77 |
/*--------------------------------------------------------------*/
|
alpar@1
|
78 |
/* constraint matrix A; it has m rows and n columns and is stored
|
alpar@1
|
79 |
by columns */
|
alpar@1
|
80 |
int *A_ptr; /* int A_ptr[1+n+1]; */
|
alpar@1
|
81 |
/* A_ptr[0] is not used;
|
alpar@1
|
82 |
A_ptr[j], 1 <= j <= n, is starting position of j-th column in
|
alpar@1
|
83 |
arrays A_ind and A_val; note that A_ptr[1] is always 1;
|
alpar@1
|
84 |
A_ptr[n+1] indicates the position after the last element in
|
alpar@1
|
85 |
arrays A_ind and A_val */
|
alpar@1
|
86 |
int *A_ind; /* int A_ind[A_ptr[n+1]]; */
|
alpar@1
|
87 |
/* row indices */
|
alpar@1
|
88 |
double *A_val; /* double A_val[A_ptr[n+1]]; */
|
alpar@1
|
89 |
/* non-zero element values */
|
alpar@1
|
90 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
91 |
/* constraint matrix A stored by rows */
|
alpar@1
|
92 |
int *AT_ptr; /* int AT_ptr[1+m+1];
|
alpar@1
|
93 |
/* AT_ptr[0] is not used;
|
alpar@1
|
94 |
AT_ptr[i], 1 <= i <= m, is starting position of i-th row in
|
alpar@1
|
95 |
arrays AT_ind and AT_val; note that AT_ptr[1] is always 1;
|
alpar@1
|
96 |
AT_ptr[m+1] indicates the position after the last element in
|
alpar@1
|
97 |
arrays AT_ind and AT_val */
|
alpar@1
|
98 |
int *AT_ind; /* int AT_ind[AT_ptr[m+1]]; */
|
alpar@1
|
99 |
/* column indices */
|
alpar@1
|
100 |
double *AT_val; /* double AT_val[AT_ptr[m+1]]; */
|
alpar@1
|
101 |
/* non-zero element values */
|
alpar@1
|
102 |
#endif
|
alpar@1
|
103 |
/*--------------------------------------------------------------*/
|
alpar@1
|
104 |
/* basis header */
|
alpar@1
|
105 |
int *head; /* int head[1+m+n]; */
|
alpar@1
|
106 |
/* head[0] is not used;
|
alpar@1
|
107 |
head[i], 1 <= i <= m, is the ordinal number of basic variable
|
alpar@1
|
108 |
xB[i]; head[i] = k means that xB[i] = x[k] and i-th column of
|
alpar@1
|
109 |
matrix B is k-th column of matrix (I|-A);
|
alpar@1
|
110 |
head[m+j], 1 <= j <= n, is the ordinal number of non-basic
|
alpar@1
|
111 |
variable xN[j]; head[m+j] = k means that xN[j] = x[k] and j-th
|
alpar@1
|
112 |
column of matrix N is k-th column of matrix (I|-A) */
|
alpar@1
|
113 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
114 |
int *bind; /* int bind[1+m+n]; */
|
alpar@1
|
115 |
/* bind[0] is not used;
|
alpar@1
|
116 |
bind[k], 1 <= k <= m+n, is the position of k-th column of the
|
alpar@1
|
117 |
matrix (I|-A) in the matrix (B|N); that is, bind[k] = k' means
|
alpar@1
|
118 |
that head[k'] = k */
|
alpar@1
|
119 |
#endif
|
alpar@1
|
120 |
char *stat; /* char stat[1+n]; */
|
alpar@1
|
121 |
/* stat[0] is not used;
|
alpar@1
|
122 |
stat[j], 1 <= j <= n, is the status of non-basic variable
|
alpar@1
|
123 |
xN[j], which defines its active bound:
|
alpar@1
|
124 |
GLP_NL - lower bound is active
|
alpar@1
|
125 |
GLP_NU - upper bound is active
|
alpar@1
|
126 |
GLP_NF - free variable
|
alpar@1
|
127 |
GLP_NS - fixed variable */
|
alpar@1
|
128 |
/*--------------------------------------------------------------*/
|
alpar@1
|
129 |
/* matrix B is the basis matrix; it is composed from columns of
|
alpar@1
|
130 |
the augmented constraint matrix (I|-A) corresponding to basic
|
alpar@1
|
131 |
variables and stored in a factorized (invertable) form */
|
alpar@1
|
132 |
int valid;
|
alpar@1
|
133 |
/* factorization is valid only if this flag is set */
|
alpar@1
|
134 |
BFD *bfd; /* BFD bfd[1:m,1:m]; */
|
alpar@1
|
135 |
/* factorized (invertable) form of the basis matrix */
|
alpar@1
|
136 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
137 |
/*--------------------------------------------------------------*/
|
alpar@1
|
138 |
/* matrix N is a matrix composed from columns of the augmented
|
alpar@1
|
139 |
constraint matrix (I|-A) corresponding to non-basic variables
|
alpar@1
|
140 |
except fixed ones; it is stored by rows and changes every time
|
alpar@1
|
141 |
the basis changes */
|
alpar@1
|
142 |
int *N_ptr; /* int N_ptr[1+m+1]; */
|
alpar@1
|
143 |
/* N_ptr[0] is not used;
|
alpar@1
|
144 |
N_ptr[i], 1 <= i <= m, is starting position of i-th row in
|
alpar@1
|
145 |
arrays N_ind and N_val; note that N_ptr[1] is always 1;
|
alpar@1
|
146 |
N_ptr[m+1] indicates the position after the last element in
|
alpar@1
|
147 |
arrays N_ind and N_val */
|
alpar@1
|
148 |
int *N_len; /* int N_len[1+m]; */
|
alpar@1
|
149 |
/* N_len[0] is not used;
|
alpar@1
|
150 |
N_len[i], 1 <= i <= m, is length of i-th row (0 to n) */
|
alpar@1
|
151 |
int *N_ind; /* int N_ind[N_ptr[m+1]]; */
|
alpar@1
|
152 |
/* column indices */
|
alpar@1
|
153 |
double *N_val; /* double N_val[N_ptr[m+1]]; */
|
alpar@1
|
154 |
/* non-zero element values */
|
alpar@1
|
155 |
#endif
|
alpar@1
|
156 |
/*--------------------------------------------------------------*/
|
alpar@1
|
157 |
/* working parameters */
|
alpar@1
|
158 |
int phase;
|
alpar@1
|
159 |
/* search phase:
|
alpar@1
|
160 |
0 - not determined yet
|
alpar@1
|
161 |
1 - search for dual feasible solution
|
alpar@1
|
162 |
2 - search for optimal solution */
|
alpar@1
|
163 |
glp_long tm_beg;
|
alpar@1
|
164 |
/* time value at the beginning of the search */
|
alpar@1
|
165 |
int it_beg;
|
alpar@1
|
166 |
/* simplex iteration count at the beginning of the search */
|
alpar@1
|
167 |
int it_cnt;
|
alpar@1
|
168 |
/* simplex iteration count; it increases by one every time the
|
alpar@1
|
169 |
basis changes */
|
alpar@1
|
170 |
int it_dpy;
|
alpar@1
|
171 |
/* simplex iteration count at the most recent display output */
|
alpar@1
|
172 |
/*--------------------------------------------------------------*/
|
alpar@1
|
173 |
/* basic solution components */
|
alpar@1
|
174 |
double *bbar; /* double bbar[1+m]; */
|
alpar@1
|
175 |
/* bbar[0] is not used on phase I; on phase II it is the current
|
alpar@1
|
176 |
value of the original objective function;
|
alpar@1
|
177 |
bbar[i], 1 <= i <= m, is primal value of basic variable xB[i]
|
alpar@1
|
178 |
(if xB[i] is free, its primal value is not updated) */
|
alpar@1
|
179 |
double *cbar; /* double cbar[1+n]; */
|
alpar@1
|
180 |
/* cbar[0] is not used;
|
alpar@1
|
181 |
cbar[j], 1 <= j <= n, is reduced cost of non-basic variable
|
alpar@1
|
182 |
xN[j] (if xN[j] is fixed, its reduced cost is not updated) */
|
alpar@1
|
183 |
/*--------------------------------------------------------------*/
|
alpar@1
|
184 |
/* the following pricing technique options may be used:
|
alpar@1
|
185 |
GLP_PT_STD - standard ("textbook") pricing;
|
alpar@1
|
186 |
GLP_PT_PSE - projected steepest edge;
|
alpar@1
|
187 |
GLP_PT_DVX - Devex pricing (not implemented yet);
|
alpar@1
|
188 |
in case of GLP_PT_STD the reference space is not used, and all
|
alpar@1
|
189 |
steepest edge coefficients are set to 1 */
|
alpar@1
|
190 |
int refct;
|
alpar@1
|
191 |
/* this count is set to an initial value when the reference space
|
alpar@1
|
192 |
is defined and decreases by one every time the basis changes;
|
alpar@1
|
193 |
once this count reaches zero, the reference space is redefined
|
alpar@1
|
194 |
again */
|
alpar@1
|
195 |
char *refsp; /* char refsp[1+m+n]; */
|
alpar@1
|
196 |
/* refsp[0] is not used;
|
alpar@1
|
197 |
refsp[k], 1 <= k <= m+n, is the flag which means that variable
|
alpar@1
|
198 |
x[k] belongs to the current reference space */
|
alpar@1
|
199 |
double *gamma; /* double gamma[1+m]; */
|
alpar@1
|
200 |
/* gamma[0] is not used;
|
alpar@1
|
201 |
gamma[i], 1 <= i <= n, is the steepest edge coefficient for
|
alpar@1
|
202 |
basic variable xB[i]; if xB[i] is free, gamma[i] is not used
|
alpar@1
|
203 |
and just set to 1 */
|
alpar@1
|
204 |
/*--------------------------------------------------------------*/
|
alpar@1
|
205 |
/* basic variable xB[p] chosen to leave the basis */
|
alpar@1
|
206 |
int p;
|
alpar@1
|
207 |
/* index of the basic variable xB[p] chosen, 1 <= p <= m;
|
alpar@1
|
208 |
if the set of eligible basic variables is empty (i.e. if the
|
alpar@1
|
209 |
current basic solution is primal feasible within a tolerance)
|
alpar@1
|
210 |
and thus no variable has been chosen, p is set to 0 */
|
alpar@1
|
211 |
double delta;
|
alpar@1
|
212 |
/* change of xB[p] in the adjacent basis;
|
alpar@1
|
213 |
delta > 0 means that xB[p] violates its lower bound and will
|
alpar@1
|
214 |
increase to achieve it in the adjacent basis;
|
alpar@1
|
215 |
delta < 0 means that xB[p] violates its upper bound and will
|
alpar@1
|
216 |
decrease to achieve it in the adjacent basis */
|
alpar@1
|
217 |
/*--------------------------------------------------------------*/
|
alpar@1
|
218 |
/* pivot row of the simplex table corresponding to basic variable
|
alpar@1
|
219 |
xB[p] chosen is the following vector:
|
alpar@1
|
220 |
T' * e[p] = - N' * inv(B') * e[p] = - N' * rho,
|
alpar@1
|
221 |
where B' is a matrix transposed to the current basis matrix,
|
alpar@1
|
222 |
N' is a matrix, whose rows are columns of the matrix (I|-A)
|
alpar@1
|
223 |
corresponding to non-basic non-fixed variables */
|
alpar@1
|
224 |
int trow_nnz;
|
alpar@1
|
225 |
/* number of non-zero components, 0 <= nnz <= n */
|
alpar@1
|
226 |
int *trow_ind; /* int trow_ind[1+n]; */
|
alpar@1
|
227 |
/* trow_ind[0] is not used;
|
alpar@1
|
228 |
trow_ind[t], 1 <= t <= nnz, is an index of non-zero component,
|
alpar@1
|
229 |
i.e. trow_ind[t] = j means that trow_vec[j] != 0 */
|
alpar@1
|
230 |
double *trow_vec; /* int trow_vec[1+n]; */
|
alpar@1
|
231 |
/* trow_vec[0] is not used;
|
alpar@1
|
232 |
trow_vec[j], 1 <= j <= n, is a numeric value of j-th component
|
alpar@1
|
233 |
of the row */
|
alpar@1
|
234 |
double trow_max;
|
alpar@1
|
235 |
/* infinity (maximum) norm of the row (max |trow_vec[j]|) */
|
alpar@1
|
236 |
int trow_num;
|
alpar@1
|
237 |
/* number of significant non-zero components, which means that:
|
alpar@1
|
238 |
|trow_vec[j]| >= eps for j in trow_ind[1,...,num],
|
alpar@1
|
239 |
|tcol_vec[j]| < eps for j in trow_ind[num+1,...,nnz],
|
alpar@1
|
240 |
where eps is a pivot tolerance */
|
alpar@1
|
241 |
/*--------------------------------------------------------------*/
|
alpar@1
|
242 |
#ifdef GLP_LONG_STEP /* 07/IV-2009 */
|
alpar@1
|
243 |
int nbps;
|
alpar@1
|
244 |
/* number of breakpoints, 0 <= nbps <= n */
|
alpar@1
|
245 |
struct bkpt
|
alpar@1
|
246 |
{ int j;
|
alpar@1
|
247 |
/* index of non-basic variable xN[j], 1 <= j <= n */
|
alpar@1
|
248 |
double t;
|
alpar@1
|
249 |
/* value of dual ray parameter at breakpoint, t >= 0 */
|
alpar@1
|
250 |
double dz;
|
alpar@1
|
251 |
/* dz = zeta(t = t[k]) - zeta(t = 0) */
|
alpar@1
|
252 |
} *bkpt; /* struct bkpt bkpt[1+n]; */
|
alpar@1
|
253 |
/* bkpt[0] is not used;
|
alpar@1
|
254 |
bkpt[k], 1 <= k <= nbps, is k-th breakpoint of the dual
|
alpar@1
|
255 |
objective */
|
alpar@1
|
256 |
#endif
|
alpar@1
|
257 |
/*--------------------------------------------------------------*/
|
alpar@1
|
258 |
/* non-basic variable xN[q] chosen to enter the basis */
|
alpar@1
|
259 |
int q;
|
alpar@1
|
260 |
/* index of the non-basic variable xN[q] chosen, 1 <= q <= n;
|
alpar@1
|
261 |
if no variable has been chosen, q is set to 0 */
|
alpar@1
|
262 |
double new_dq;
|
alpar@1
|
263 |
/* reduced cost of xN[q] in the adjacent basis (it is the change
|
alpar@1
|
264 |
of lambdaB[p]) */
|
alpar@1
|
265 |
/*--------------------------------------------------------------*/
|
alpar@1
|
266 |
/* pivot column of the simplex table corresponding to non-basic
|
alpar@1
|
267 |
variable xN[q] chosen is the following vector:
|
alpar@1
|
268 |
T * e[q] = - inv(B) * N * e[q] = - inv(B) * N[q],
|
alpar@1
|
269 |
where B is the current basis matrix, N[q] is a column of the
|
alpar@1
|
270 |
matrix (I|-A) corresponding to xN[q] */
|
alpar@1
|
271 |
int tcol_nnz;
|
alpar@1
|
272 |
/* number of non-zero components, 0 <= nnz <= m */
|
alpar@1
|
273 |
int *tcol_ind; /* int tcol_ind[1+m]; */
|
alpar@1
|
274 |
/* tcol_ind[0] is not used;
|
alpar@1
|
275 |
tcol_ind[t], 1 <= t <= nnz, is an index of non-zero component,
|
alpar@1
|
276 |
i.e. tcol_ind[t] = i means that tcol_vec[i] != 0 */
|
alpar@1
|
277 |
double *tcol_vec; /* double tcol_vec[1+m]; */
|
alpar@1
|
278 |
/* tcol_vec[0] is not used;
|
alpar@1
|
279 |
tcol_vec[i], 1 <= i <= m, is a numeric value of i-th component
|
alpar@1
|
280 |
of the column */
|
alpar@1
|
281 |
/*--------------------------------------------------------------*/
|
alpar@1
|
282 |
/* working arrays */
|
alpar@1
|
283 |
double *work1; /* double work1[1+m]; */
|
alpar@1
|
284 |
double *work2; /* double work2[1+m]; */
|
alpar@1
|
285 |
double *work3; /* double work3[1+m]; */
|
alpar@1
|
286 |
double *work4; /* double work4[1+m]; */
|
alpar@1
|
287 |
};
|
alpar@1
|
288 |
|
alpar@1
|
289 |
static const double kappa = 0.10;
|
alpar@1
|
290 |
|
alpar@1
|
291 |
/***********************************************************************
|
alpar@1
|
292 |
* alloc_csa - allocate common storage area
|
alpar@1
|
293 |
*
|
alpar@1
|
294 |
* This routine allocates all arrays in the common storage area (CSA)
|
alpar@1
|
295 |
* and returns a pointer to the CSA. */
|
alpar@1
|
296 |
|
alpar@1
|
297 |
static struct csa *alloc_csa(glp_prob *lp)
|
alpar@1
|
298 |
{ struct csa *csa;
|
alpar@1
|
299 |
int m = lp->m;
|
alpar@1
|
300 |
int n = lp->n;
|
alpar@1
|
301 |
int nnz = lp->nnz;
|
alpar@1
|
302 |
csa = xmalloc(sizeof(struct csa));
|
alpar@1
|
303 |
xassert(m > 0 && n > 0);
|
alpar@1
|
304 |
csa->m = m;
|
alpar@1
|
305 |
csa->n = n;
|
alpar@1
|
306 |
csa->type = xcalloc(1+m+n, sizeof(char));
|
alpar@1
|
307 |
csa->lb = xcalloc(1+m+n, sizeof(double));
|
alpar@1
|
308 |
csa->ub = xcalloc(1+m+n, sizeof(double));
|
alpar@1
|
309 |
csa->coef = xcalloc(1+m+n, sizeof(double));
|
alpar@1
|
310 |
csa->orig_type = xcalloc(1+m+n, sizeof(char));
|
alpar@1
|
311 |
csa->orig_lb = xcalloc(1+m+n, sizeof(double));
|
alpar@1
|
312 |
csa->orig_ub = xcalloc(1+m+n, sizeof(double));
|
alpar@1
|
313 |
csa->obj = xcalloc(1+n, sizeof(double));
|
alpar@1
|
314 |
csa->A_ptr = xcalloc(1+n+1, sizeof(int));
|
alpar@1
|
315 |
csa->A_ind = xcalloc(1+nnz, sizeof(int));
|
alpar@1
|
316 |
csa->A_val = xcalloc(1+nnz, sizeof(double));
|
alpar@1
|
317 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
318 |
csa->AT_ptr = xcalloc(1+m+1, sizeof(int));
|
alpar@1
|
319 |
csa->AT_ind = xcalloc(1+nnz, sizeof(int));
|
alpar@1
|
320 |
csa->AT_val = xcalloc(1+nnz, sizeof(double));
|
alpar@1
|
321 |
#endif
|
alpar@1
|
322 |
csa->head = xcalloc(1+m+n, sizeof(int));
|
alpar@1
|
323 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
324 |
csa->bind = xcalloc(1+m+n, sizeof(int));
|
alpar@1
|
325 |
#endif
|
alpar@1
|
326 |
csa->stat = xcalloc(1+n, sizeof(char));
|
alpar@1
|
327 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
328 |
csa->N_ptr = xcalloc(1+m+1, sizeof(int));
|
alpar@1
|
329 |
csa->N_len = xcalloc(1+m, sizeof(int));
|
alpar@1
|
330 |
csa->N_ind = NULL; /* will be allocated later */
|
alpar@1
|
331 |
csa->N_val = NULL; /* will be allocated later */
|
alpar@1
|
332 |
#endif
|
alpar@1
|
333 |
csa->bbar = xcalloc(1+m, sizeof(double));
|
alpar@1
|
334 |
csa->cbar = xcalloc(1+n, sizeof(double));
|
alpar@1
|
335 |
csa->refsp = xcalloc(1+m+n, sizeof(char));
|
alpar@1
|
336 |
csa->gamma = xcalloc(1+m, sizeof(double));
|
alpar@1
|
337 |
csa->trow_ind = xcalloc(1+n, sizeof(int));
|
alpar@1
|
338 |
csa->trow_vec = xcalloc(1+n, sizeof(double));
|
alpar@1
|
339 |
#ifdef GLP_LONG_STEP /* 07/IV-2009 */
|
alpar@1
|
340 |
csa->bkpt = xcalloc(1+n, sizeof(struct bkpt));
|
alpar@1
|
341 |
#endif
|
alpar@1
|
342 |
csa->tcol_ind = xcalloc(1+m, sizeof(int));
|
alpar@1
|
343 |
csa->tcol_vec = xcalloc(1+m, sizeof(double));
|
alpar@1
|
344 |
csa->work1 = xcalloc(1+m, sizeof(double));
|
alpar@1
|
345 |
csa->work2 = xcalloc(1+m, sizeof(double));
|
alpar@1
|
346 |
csa->work3 = xcalloc(1+m, sizeof(double));
|
alpar@1
|
347 |
csa->work4 = xcalloc(1+m, sizeof(double));
|
alpar@1
|
348 |
return csa;
|
alpar@1
|
349 |
}
|
alpar@1
|
350 |
|
alpar@1
|
351 |
/***********************************************************************
|
alpar@1
|
352 |
* init_csa - initialize common storage area
|
alpar@1
|
353 |
*
|
alpar@1
|
354 |
* This routine initializes all data structures in the common storage
|
alpar@1
|
355 |
* area (CSA). */
|
alpar@1
|
356 |
|
alpar@1
|
357 |
static void init_csa(struct csa *csa, glp_prob *lp)
|
alpar@1
|
358 |
{ int m = csa->m;
|
alpar@1
|
359 |
int n = csa->n;
|
alpar@1
|
360 |
char *type = csa->type;
|
alpar@1
|
361 |
double *lb = csa->lb;
|
alpar@1
|
362 |
double *ub = csa->ub;
|
alpar@1
|
363 |
double *coef = csa->coef;
|
alpar@1
|
364 |
char *orig_type = csa->orig_type;
|
alpar@1
|
365 |
double *orig_lb = csa->orig_lb;
|
alpar@1
|
366 |
double *orig_ub = csa->orig_ub;
|
alpar@1
|
367 |
double *obj = csa->obj;
|
alpar@1
|
368 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
369 |
int *A_ind = csa->A_ind;
|
alpar@1
|
370 |
double *A_val = csa->A_val;
|
alpar@1
|
371 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
372 |
int *AT_ptr = csa->AT_ptr;
|
alpar@1
|
373 |
int *AT_ind = csa->AT_ind;
|
alpar@1
|
374 |
double *AT_val = csa->AT_val;
|
alpar@1
|
375 |
#endif
|
alpar@1
|
376 |
int *head = csa->head;
|
alpar@1
|
377 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
378 |
int *bind = csa->bind;
|
alpar@1
|
379 |
#endif
|
alpar@1
|
380 |
char *stat = csa->stat;
|
alpar@1
|
381 |
char *refsp = csa->refsp;
|
alpar@1
|
382 |
double *gamma = csa->gamma;
|
alpar@1
|
383 |
int i, j, k, loc;
|
alpar@1
|
384 |
double cmax;
|
alpar@1
|
385 |
/* auxiliary variables */
|
alpar@1
|
386 |
for (i = 1; i <= m; i++)
|
alpar@1
|
387 |
{ GLPROW *row = lp->row[i];
|
alpar@1
|
388 |
type[i] = (char)row->type;
|
alpar@1
|
389 |
lb[i] = row->lb * row->rii;
|
alpar@1
|
390 |
ub[i] = row->ub * row->rii;
|
alpar@1
|
391 |
coef[i] = 0.0;
|
alpar@1
|
392 |
}
|
alpar@1
|
393 |
/* structural variables */
|
alpar@1
|
394 |
for (j = 1; j <= n; j++)
|
alpar@1
|
395 |
{ GLPCOL *col = lp->col[j];
|
alpar@1
|
396 |
type[m+j] = (char)col->type;
|
alpar@1
|
397 |
lb[m+j] = col->lb / col->sjj;
|
alpar@1
|
398 |
ub[m+j] = col->ub / col->sjj;
|
alpar@1
|
399 |
coef[m+j] = col->coef * col->sjj;
|
alpar@1
|
400 |
}
|
alpar@1
|
401 |
/* original bounds of variables */
|
alpar@1
|
402 |
memcpy(&orig_type[1], &type[1], (m+n) * sizeof(char));
|
alpar@1
|
403 |
memcpy(&orig_lb[1], &lb[1], (m+n) * sizeof(double));
|
alpar@1
|
404 |
memcpy(&orig_ub[1], &ub[1], (m+n) * sizeof(double));
|
alpar@1
|
405 |
/* original objective function */
|
alpar@1
|
406 |
obj[0] = lp->c0;
|
alpar@1
|
407 |
memcpy(&obj[1], &coef[m+1], n * sizeof(double));
|
alpar@1
|
408 |
/* factor used to scale original objective coefficients */
|
alpar@1
|
409 |
cmax = 0.0;
|
alpar@1
|
410 |
for (j = 1; j <= n; j++)
|
alpar@1
|
411 |
if (cmax < fabs(obj[j])) cmax = fabs(obj[j]);
|
alpar@1
|
412 |
if (cmax == 0.0) cmax = 1.0;
|
alpar@1
|
413 |
switch (lp->dir)
|
alpar@1
|
414 |
{ case GLP_MIN:
|
alpar@1
|
415 |
csa->zeta = + 1.0 / cmax;
|
alpar@1
|
416 |
break;
|
alpar@1
|
417 |
case GLP_MAX:
|
alpar@1
|
418 |
csa->zeta = - 1.0 / cmax;
|
alpar@1
|
419 |
break;
|
alpar@1
|
420 |
default:
|
alpar@1
|
421 |
xassert(lp != lp);
|
alpar@1
|
422 |
}
|
alpar@1
|
423 |
#if 1
|
alpar@1
|
424 |
if (fabs(csa->zeta) < 1.0) csa->zeta *= 1000.0;
|
alpar@1
|
425 |
#endif
|
alpar@1
|
426 |
/* scale working objective coefficients */
|
alpar@1
|
427 |
for (j = 1; j <= n; j++) coef[m+j] *= csa->zeta;
|
alpar@1
|
428 |
/* matrix A (by columns) */
|
alpar@1
|
429 |
loc = 1;
|
alpar@1
|
430 |
for (j = 1; j <= n; j++)
|
alpar@1
|
431 |
{ GLPAIJ *aij;
|
alpar@1
|
432 |
A_ptr[j] = loc;
|
alpar@1
|
433 |
for (aij = lp->col[j]->ptr; aij != NULL; aij = aij->c_next)
|
alpar@1
|
434 |
{ A_ind[loc] = aij->row->i;
|
alpar@1
|
435 |
A_val[loc] = aij->row->rii * aij->val * aij->col->sjj;
|
alpar@1
|
436 |
loc++;
|
alpar@1
|
437 |
}
|
alpar@1
|
438 |
}
|
alpar@1
|
439 |
A_ptr[n+1] = loc;
|
alpar@1
|
440 |
xassert(loc-1 == lp->nnz);
|
alpar@1
|
441 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
442 |
/* matrix A (by rows) */
|
alpar@1
|
443 |
loc = 1;
|
alpar@1
|
444 |
for (i = 1; i <= m; i++)
|
alpar@1
|
445 |
{ GLPAIJ *aij;
|
alpar@1
|
446 |
AT_ptr[i] = loc;
|
alpar@1
|
447 |
for (aij = lp->row[i]->ptr; aij != NULL; aij = aij->r_next)
|
alpar@1
|
448 |
{ AT_ind[loc] = aij->col->j;
|
alpar@1
|
449 |
AT_val[loc] = aij->row->rii * aij->val * aij->col->sjj;
|
alpar@1
|
450 |
loc++;
|
alpar@1
|
451 |
}
|
alpar@1
|
452 |
}
|
alpar@1
|
453 |
AT_ptr[m+1] = loc;
|
alpar@1
|
454 |
xassert(loc-1 == lp->nnz);
|
alpar@1
|
455 |
#endif
|
alpar@1
|
456 |
/* basis header */
|
alpar@1
|
457 |
xassert(lp->valid);
|
alpar@1
|
458 |
memcpy(&head[1], &lp->head[1], m * sizeof(int));
|
alpar@1
|
459 |
k = 0;
|
alpar@1
|
460 |
for (i = 1; i <= m; i++)
|
alpar@1
|
461 |
{ GLPROW *row = lp->row[i];
|
alpar@1
|
462 |
if (row->stat != GLP_BS)
|
alpar@1
|
463 |
{ k++;
|
alpar@1
|
464 |
xassert(k <= n);
|
alpar@1
|
465 |
head[m+k] = i;
|
alpar@1
|
466 |
stat[k] = (char)row->stat;
|
alpar@1
|
467 |
}
|
alpar@1
|
468 |
}
|
alpar@1
|
469 |
for (j = 1; j <= n; j++)
|
alpar@1
|
470 |
{ GLPCOL *col = lp->col[j];
|
alpar@1
|
471 |
if (col->stat != GLP_BS)
|
alpar@1
|
472 |
{ k++;
|
alpar@1
|
473 |
xassert(k <= n);
|
alpar@1
|
474 |
head[m+k] = m + j;
|
alpar@1
|
475 |
stat[k] = (char)col->stat;
|
alpar@1
|
476 |
}
|
alpar@1
|
477 |
}
|
alpar@1
|
478 |
xassert(k == n);
|
alpar@1
|
479 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
480 |
for (k = 1; k <= m+n; k++)
|
alpar@1
|
481 |
bind[head[k]] = k;
|
alpar@1
|
482 |
#endif
|
alpar@1
|
483 |
/* factorization of matrix B */
|
alpar@1
|
484 |
csa->valid = 1, lp->valid = 0;
|
alpar@1
|
485 |
csa->bfd = lp->bfd, lp->bfd = NULL;
|
alpar@1
|
486 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
487 |
/* matrix N (by rows) */
|
alpar@1
|
488 |
alloc_N(csa);
|
alpar@1
|
489 |
build_N(csa);
|
alpar@1
|
490 |
#endif
|
alpar@1
|
491 |
/* working parameters */
|
alpar@1
|
492 |
csa->phase = 0;
|
alpar@1
|
493 |
csa->tm_beg = xtime();
|
alpar@1
|
494 |
csa->it_beg = csa->it_cnt = lp->it_cnt;
|
alpar@1
|
495 |
csa->it_dpy = -1;
|
alpar@1
|
496 |
/* reference space and steepest edge coefficients */
|
alpar@1
|
497 |
csa->refct = 0;
|
alpar@1
|
498 |
memset(&refsp[1], 0, (m+n) * sizeof(char));
|
alpar@1
|
499 |
for (i = 1; i <= m; i++) gamma[i] = 1.0;
|
alpar@1
|
500 |
return;
|
alpar@1
|
501 |
}
|
alpar@1
|
502 |
|
alpar@1
|
503 |
#if 1 /* copied from primal */
|
alpar@1
|
504 |
/***********************************************************************
|
alpar@1
|
505 |
* invert_B - compute factorization of the basis matrix
|
alpar@1
|
506 |
*
|
alpar@1
|
507 |
* This routine computes factorization of the current basis matrix B.
|
alpar@1
|
508 |
*
|
alpar@1
|
509 |
* If the operation is successful, the routine returns zero, otherwise
|
alpar@1
|
510 |
* non-zero. */
|
alpar@1
|
511 |
|
alpar@1
|
512 |
static int inv_col(void *info, int i, int ind[], double val[])
|
alpar@1
|
513 |
{ /* this auxiliary routine returns row indices and numeric values
|
alpar@1
|
514 |
of non-zero elements of i-th column of the basis matrix */
|
alpar@1
|
515 |
struct csa *csa = info;
|
alpar@1
|
516 |
int m = csa->m;
|
alpar@1
|
517 |
#ifdef GLP_DEBUG
|
alpar@1
|
518 |
int n = csa->n;
|
alpar@1
|
519 |
#endif
|
alpar@1
|
520 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
521 |
int *A_ind = csa->A_ind;
|
alpar@1
|
522 |
double *A_val = csa->A_val;
|
alpar@1
|
523 |
int *head = csa->head;
|
alpar@1
|
524 |
int k, len, ptr, t;
|
alpar@1
|
525 |
#ifdef GLP_DEBUG
|
alpar@1
|
526 |
xassert(1 <= i && i <= m);
|
alpar@1
|
527 |
#endif
|
alpar@1
|
528 |
k = head[i]; /* B[i] is k-th column of (I|-A) */
|
alpar@1
|
529 |
#ifdef GLP_DEBUG
|
alpar@1
|
530 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
531 |
#endif
|
alpar@1
|
532 |
if (k <= m)
|
alpar@1
|
533 |
{ /* B[i] is k-th column of submatrix I */
|
alpar@1
|
534 |
len = 1;
|
alpar@1
|
535 |
ind[1] = k;
|
alpar@1
|
536 |
val[1] = 1.0;
|
alpar@1
|
537 |
}
|
alpar@1
|
538 |
else
|
alpar@1
|
539 |
{ /* B[i] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
540 |
ptr = A_ptr[k-m];
|
alpar@1
|
541 |
len = A_ptr[k-m+1] - ptr;
|
alpar@1
|
542 |
memcpy(&ind[1], &A_ind[ptr], len * sizeof(int));
|
alpar@1
|
543 |
memcpy(&val[1], &A_val[ptr], len * sizeof(double));
|
alpar@1
|
544 |
for (t = 1; t <= len; t++) val[t] = - val[t];
|
alpar@1
|
545 |
}
|
alpar@1
|
546 |
return len;
|
alpar@1
|
547 |
}
|
alpar@1
|
548 |
|
alpar@1
|
549 |
static int invert_B(struct csa *csa)
|
alpar@1
|
550 |
{ int ret;
|
alpar@1
|
551 |
ret = bfd_factorize(csa->bfd, csa->m, NULL, inv_col, csa);
|
alpar@1
|
552 |
csa->valid = (ret == 0);
|
alpar@1
|
553 |
return ret;
|
alpar@1
|
554 |
}
|
alpar@1
|
555 |
#endif
|
alpar@1
|
556 |
|
alpar@1
|
557 |
#if 1 /* copied from primal */
|
alpar@1
|
558 |
/***********************************************************************
|
alpar@1
|
559 |
* update_B - update factorization of the basis matrix
|
alpar@1
|
560 |
*
|
alpar@1
|
561 |
* This routine replaces i-th column of the basis matrix B by k-th
|
alpar@1
|
562 |
* column of the augmented constraint matrix (I|-A) and then updates
|
alpar@1
|
563 |
* the factorization of B.
|
alpar@1
|
564 |
*
|
alpar@1
|
565 |
* If the factorization has been successfully updated, the routine
|
alpar@1
|
566 |
* returns zero, otherwise non-zero. */
|
alpar@1
|
567 |
|
alpar@1
|
568 |
static int update_B(struct csa *csa, int i, int k)
|
alpar@1
|
569 |
{ int m = csa->m;
|
alpar@1
|
570 |
#ifdef GLP_DEBUG
|
alpar@1
|
571 |
int n = csa->n;
|
alpar@1
|
572 |
#endif
|
alpar@1
|
573 |
int ret;
|
alpar@1
|
574 |
#ifdef GLP_DEBUG
|
alpar@1
|
575 |
xassert(1 <= i && i <= m);
|
alpar@1
|
576 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
577 |
#endif
|
alpar@1
|
578 |
if (k <= m)
|
alpar@1
|
579 |
{ /* new i-th column of B is k-th column of I */
|
alpar@1
|
580 |
int ind[1+1];
|
alpar@1
|
581 |
double val[1+1];
|
alpar@1
|
582 |
ind[1] = k;
|
alpar@1
|
583 |
val[1] = 1.0;
|
alpar@1
|
584 |
xassert(csa->valid);
|
alpar@1
|
585 |
ret = bfd_update_it(csa->bfd, i, 0, 1, ind, val);
|
alpar@1
|
586 |
}
|
alpar@1
|
587 |
else
|
alpar@1
|
588 |
{ /* new i-th column of B is (k-m)-th column of (-A) */
|
alpar@1
|
589 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
590 |
int *A_ind = csa->A_ind;
|
alpar@1
|
591 |
double *A_val = csa->A_val;
|
alpar@1
|
592 |
double *val = csa->work1;
|
alpar@1
|
593 |
int beg, end, ptr, len;
|
alpar@1
|
594 |
beg = A_ptr[k-m];
|
alpar@1
|
595 |
end = A_ptr[k-m+1];
|
alpar@1
|
596 |
len = 0;
|
alpar@1
|
597 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
598 |
val[++len] = - A_val[ptr];
|
alpar@1
|
599 |
xassert(csa->valid);
|
alpar@1
|
600 |
ret = bfd_update_it(csa->bfd, i, 0, len, &A_ind[beg-1], val);
|
alpar@1
|
601 |
}
|
alpar@1
|
602 |
csa->valid = (ret == 0);
|
alpar@1
|
603 |
return ret;
|
alpar@1
|
604 |
}
|
alpar@1
|
605 |
#endif
|
alpar@1
|
606 |
|
alpar@1
|
607 |
#if 1 /* copied from primal */
|
alpar@1
|
608 |
/***********************************************************************
|
alpar@1
|
609 |
* error_ftran - compute residual vector r = h - B * x
|
alpar@1
|
610 |
*
|
alpar@1
|
611 |
* This routine computes the residual vector r = h - B * x, where B is
|
alpar@1
|
612 |
* the current basis matrix, h is the vector of right-hand sides, x is
|
alpar@1
|
613 |
* the solution vector. */
|
alpar@1
|
614 |
|
alpar@1
|
615 |
static void error_ftran(struct csa *csa, double h[], double x[],
|
alpar@1
|
616 |
double r[])
|
alpar@1
|
617 |
{ int m = csa->m;
|
alpar@1
|
618 |
#ifdef GLP_DEBUG
|
alpar@1
|
619 |
int n = csa->n;
|
alpar@1
|
620 |
#endif
|
alpar@1
|
621 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
622 |
int *A_ind = csa->A_ind;
|
alpar@1
|
623 |
double *A_val = csa->A_val;
|
alpar@1
|
624 |
int *head = csa->head;
|
alpar@1
|
625 |
int i, k, beg, end, ptr;
|
alpar@1
|
626 |
double temp;
|
alpar@1
|
627 |
/* compute the residual vector:
|
alpar@1
|
628 |
r = h - B * x = h - B[1] * x[1] - ... - B[m] * x[m],
|
alpar@1
|
629 |
where B[1], ..., B[m] are columns of matrix B */
|
alpar@1
|
630 |
memcpy(&r[1], &h[1], m * sizeof(double));
|
alpar@1
|
631 |
for (i = 1; i <= m; i++)
|
alpar@1
|
632 |
{ temp = x[i];
|
alpar@1
|
633 |
if (temp == 0.0) continue;
|
alpar@1
|
634 |
k = head[i]; /* B[i] is k-th column of (I|-A) */
|
alpar@1
|
635 |
#ifdef GLP_DEBUG
|
alpar@1
|
636 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
637 |
#endif
|
alpar@1
|
638 |
if (k <= m)
|
alpar@1
|
639 |
{ /* B[i] is k-th column of submatrix I */
|
alpar@1
|
640 |
r[k] -= temp;
|
alpar@1
|
641 |
}
|
alpar@1
|
642 |
else
|
alpar@1
|
643 |
{ /* B[i] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
644 |
beg = A_ptr[k-m];
|
alpar@1
|
645 |
end = A_ptr[k-m+1];
|
alpar@1
|
646 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
647 |
r[A_ind[ptr]] += A_val[ptr] * temp;
|
alpar@1
|
648 |
}
|
alpar@1
|
649 |
}
|
alpar@1
|
650 |
return;
|
alpar@1
|
651 |
}
|
alpar@1
|
652 |
#endif
|
alpar@1
|
653 |
|
alpar@1
|
654 |
#if 1 /* copied from primal */
|
alpar@1
|
655 |
/***********************************************************************
|
alpar@1
|
656 |
* refine_ftran - refine solution of B * x = h
|
alpar@1
|
657 |
*
|
alpar@1
|
658 |
* This routine performs one iteration to refine the solution of
|
alpar@1
|
659 |
* the system B * x = h, where B is the current basis matrix, h is the
|
alpar@1
|
660 |
* vector of right-hand sides, x is the solution vector. */
|
alpar@1
|
661 |
|
alpar@1
|
662 |
static void refine_ftran(struct csa *csa, double h[], double x[])
|
alpar@1
|
663 |
{ int m = csa->m;
|
alpar@1
|
664 |
double *r = csa->work1;
|
alpar@1
|
665 |
double *d = csa->work1;
|
alpar@1
|
666 |
int i;
|
alpar@1
|
667 |
/* compute the residual vector r = h - B * x */
|
alpar@1
|
668 |
error_ftran(csa, h, x, r);
|
alpar@1
|
669 |
/* compute the correction vector d = inv(B) * r */
|
alpar@1
|
670 |
xassert(csa->valid);
|
alpar@1
|
671 |
bfd_ftran(csa->bfd, d);
|
alpar@1
|
672 |
/* refine the solution vector (new x) = (old x) + d */
|
alpar@1
|
673 |
for (i = 1; i <= m; i++) x[i] += d[i];
|
alpar@1
|
674 |
return;
|
alpar@1
|
675 |
}
|
alpar@1
|
676 |
#endif
|
alpar@1
|
677 |
|
alpar@1
|
678 |
#if 1 /* copied from primal */
|
alpar@1
|
679 |
/***********************************************************************
|
alpar@1
|
680 |
* error_btran - compute residual vector r = h - B'* x
|
alpar@1
|
681 |
*
|
alpar@1
|
682 |
* This routine computes the residual vector r = h - B'* x, where B'
|
alpar@1
|
683 |
* is a matrix transposed to the current basis matrix, h is the vector
|
alpar@1
|
684 |
* of right-hand sides, x is the solution vector. */
|
alpar@1
|
685 |
|
alpar@1
|
686 |
static void error_btran(struct csa *csa, double h[], double x[],
|
alpar@1
|
687 |
double r[])
|
alpar@1
|
688 |
{ int m = csa->m;
|
alpar@1
|
689 |
#ifdef GLP_DEBUG
|
alpar@1
|
690 |
int n = csa->n;
|
alpar@1
|
691 |
#endif
|
alpar@1
|
692 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
693 |
int *A_ind = csa->A_ind;
|
alpar@1
|
694 |
double *A_val = csa->A_val;
|
alpar@1
|
695 |
int *head = csa->head;
|
alpar@1
|
696 |
int i, k, beg, end, ptr;
|
alpar@1
|
697 |
double temp;
|
alpar@1
|
698 |
/* compute the residual vector r = b - B'* x */
|
alpar@1
|
699 |
for (i = 1; i <= m; i++)
|
alpar@1
|
700 |
{ /* r[i] := b[i] - (i-th column of B)'* x */
|
alpar@1
|
701 |
k = head[i]; /* B[i] is k-th column of (I|-A) */
|
alpar@1
|
702 |
#ifdef GLP_DEBUG
|
alpar@1
|
703 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
704 |
#endif
|
alpar@1
|
705 |
temp = h[i];
|
alpar@1
|
706 |
if (k <= m)
|
alpar@1
|
707 |
{ /* B[i] is k-th column of submatrix I */
|
alpar@1
|
708 |
temp -= x[k];
|
alpar@1
|
709 |
}
|
alpar@1
|
710 |
else
|
alpar@1
|
711 |
{ /* B[i] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
712 |
beg = A_ptr[k-m];
|
alpar@1
|
713 |
end = A_ptr[k-m+1];
|
alpar@1
|
714 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
715 |
temp += A_val[ptr] * x[A_ind[ptr]];
|
alpar@1
|
716 |
}
|
alpar@1
|
717 |
r[i] = temp;
|
alpar@1
|
718 |
}
|
alpar@1
|
719 |
return;
|
alpar@1
|
720 |
}
|
alpar@1
|
721 |
#endif
|
alpar@1
|
722 |
|
alpar@1
|
723 |
#if 1 /* copied from primal */
|
alpar@1
|
724 |
/***********************************************************************
|
alpar@1
|
725 |
* refine_btran - refine solution of B'* x = h
|
alpar@1
|
726 |
*
|
alpar@1
|
727 |
* This routine performs one iteration to refine the solution of the
|
alpar@1
|
728 |
* system B'* x = h, where B' is a matrix transposed to the current
|
alpar@1
|
729 |
* basis matrix, h is the vector of right-hand sides, x is the solution
|
alpar@1
|
730 |
* vector. */
|
alpar@1
|
731 |
|
alpar@1
|
732 |
static void refine_btran(struct csa *csa, double h[], double x[])
|
alpar@1
|
733 |
{ int m = csa->m;
|
alpar@1
|
734 |
double *r = csa->work1;
|
alpar@1
|
735 |
double *d = csa->work1;
|
alpar@1
|
736 |
int i;
|
alpar@1
|
737 |
/* compute the residual vector r = h - B'* x */
|
alpar@1
|
738 |
error_btran(csa, h, x, r);
|
alpar@1
|
739 |
/* compute the correction vector d = inv(B') * r */
|
alpar@1
|
740 |
xassert(csa->valid);
|
alpar@1
|
741 |
bfd_btran(csa->bfd, d);
|
alpar@1
|
742 |
/* refine the solution vector (new x) = (old x) + d */
|
alpar@1
|
743 |
for (i = 1; i <= m; i++) x[i] += d[i];
|
alpar@1
|
744 |
return;
|
alpar@1
|
745 |
}
|
alpar@1
|
746 |
#endif
|
alpar@1
|
747 |
|
alpar@1
|
748 |
#if 1 /* copied from primal */
|
alpar@1
|
749 |
/***********************************************************************
|
alpar@1
|
750 |
* get_xN - determine current value of non-basic variable xN[j]
|
alpar@1
|
751 |
*
|
alpar@1
|
752 |
* This routine returns the current value of non-basic variable xN[j],
|
alpar@1
|
753 |
* which is a value of its active bound. */
|
alpar@1
|
754 |
|
alpar@1
|
755 |
static double get_xN(struct csa *csa, int j)
|
alpar@1
|
756 |
{ int m = csa->m;
|
alpar@1
|
757 |
#ifdef GLP_DEBUG
|
alpar@1
|
758 |
int n = csa->n;
|
alpar@1
|
759 |
#endif
|
alpar@1
|
760 |
double *lb = csa->lb;
|
alpar@1
|
761 |
double *ub = csa->ub;
|
alpar@1
|
762 |
int *head = csa->head;
|
alpar@1
|
763 |
char *stat = csa->stat;
|
alpar@1
|
764 |
int k;
|
alpar@1
|
765 |
double xN;
|
alpar@1
|
766 |
#ifdef GLP_DEBUG
|
alpar@1
|
767 |
xassert(1 <= j && j <= n);
|
alpar@1
|
768 |
#endif
|
alpar@1
|
769 |
k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
770 |
#ifdef GLP_DEBUG
|
alpar@1
|
771 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
772 |
#endif
|
alpar@1
|
773 |
switch (stat[j])
|
alpar@1
|
774 |
{ case GLP_NL:
|
alpar@1
|
775 |
/* x[k] is on its lower bound */
|
alpar@1
|
776 |
xN = lb[k]; break;
|
alpar@1
|
777 |
case GLP_NU:
|
alpar@1
|
778 |
/* x[k] is on its upper bound */
|
alpar@1
|
779 |
xN = ub[k]; break;
|
alpar@1
|
780 |
case GLP_NF:
|
alpar@1
|
781 |
/* x[k] is free non-basic variable */
|
alpar@1
|
782 |
xN = 0.0; break;
|
alpar@1
|
783 |
case GLP_NS:
|
alpar@1
|
784 |
/* x[k] is fixed non-basic variable */
|
alpar@1
|
785 |
xN = lb[k]; break;
|
alpar@1
|
786 |
default:
|
alpar@1
|
787 |
xassert(stat != stat);
|
alpar@1
|
788 |
}
|
alpar@1
|
789 |
return xN;
|
alpar@1
|
790 |
}
|
alpar@1
|
791 |
#endif
|
alpar@1
|
792 |
|
alpar@1
|
793 |
#if 1 /* copied from primal */
|
alpar@1
|
794 |
/***********************************************************************
|
alpar@1
|
795 |
* eval_beta - compute primal values of basic variables
|
alpar@1
|
796 |
*
|
alpar@1
|
797 |
* This routine computes current primal values of all basic variables:
|
alpar@1
|
798 |
*
|
alpar@1
|
799 |
* beta = - inv(B) * N * xN,
|
alpar@1
|
800 |
*
|
alpar@1
|
801 |
* where B is the current basis matrix, N is a matrix built of columns
|
alpar@1
|
802 |
* of matrix (I|-A) corresponding to non-basic variables, and xN is the
|
alpar@1
|
803 |
* vector of current values of non-basic variables. */
|
alpar@1
|
804 |
|
alpar@1
|
805 |
static void eval_beta(struct csa *csa, double beta[])
|
alpar@1
|
806 |
{ int m = csa->m;
|
alpar@1
|
807 |
int n = csa->n;
|
alpar@1
|
808 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
809 |
int *A_ind = csa->A_ind;
|
alpar@1
|
810 |
double *A_val = csa->A_val;
|
alpar@1
|
811 |
int *head = csa->head;
|
alpar@1
|
812 |
double *h = csa->work2;
|
alpar@1
|
813 |
int i, j, k, beg, end, ptr;
|
alpar@1
|
814 |
double xN;
|
alpar@1
|
815 |
/* compute the right-hand side vector:
|
alpar@1
|
816 |
h := - N * xN = - N[1] * xN[1] - ... - N[n] * xN[n],
|
alpar@1
|
817 |
where N[1], ..., N[n] are columns of matrix N */
|
alpar@1
|
818 |
for (i = 1; i <= m; i++)
|
alpar@1
|
819 |
h[i] = 0.0;
|
alpar@1
|
820 |
for (j = 1; j <= n; j++)
|
alpar@1
|
821 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
822 |
#ifdef GLP_DEBUG
|
alpar@1
|
823 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
824 |
#endif
|
alpar@1
|
825 |
/* determine current value of xN[j] */
|
alpar@1
|
826 |
xN = get_xN(csa, j);
|
alpar@1
|
827 |
if (xN == 0.0) continue;
|
alpar@1
|
828 |
if (k <= m)
|
alpar@1
|
829 |
{ /* N[j] is k-th column of submatrix I */
|
alpar@1
|
830 |
h[k] -= xN;
|
alpar@1
|
831 |
}
|
alpar@1
|
832 |
else
|
alpar@1
|
833 |
{ /* N[j] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
834 |
beg = A_ptr[k-m];
|
alpar@1
|
835 |
end = A_ptr[k-m+1];
|
alpar@1
|
836 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
837 |
h[A_ind[ptr]] += xN * A_val[ptr];
|
alpar@1
|
838 |
}
|
alpar@1
|
839 |
}
|
alpar@1
|
840 |
/* solve system B * beta = h */
|
alpar@1
|
841 |
memcpy(&beta[1], &h[1], m * sizeof(double));
|
alpar@1
|
842 |
xassert(csa->valid);
|
alpar@1
|
843 |
bfd_ftran(csa->bfd, beta);
|
alpar@1
|
844 |
/* and refine the solution */
|
alpar@1
|
845 |
refine_ftran(csa, h, beta);
|
alpar@1
|
846 |
return;
|
alpar@1
|
847 |
}
|
alpar@1
|
848 |
#endif
|
alpar@1
|
849 |
|
alpar@1
|
850 |
#if 1 /* copied from primal */
|
alpar@1
|
851 |
/***********************************************************************
|
alpar@1
|
852 |
* eval_pi - compute vector of simplex multipliers
|
alpar@1
|
853 |
*
|
alpar@1
|
854 |
* This routine computes the vector of current simplex multipliers:
|
alpar@1
|
855 |
*
|
alpar@1
|
856 |
* pi = inv(B') * cB,
|
alpar@1
|
857 |
*
|
alpar@1
|
858 |
* where B' is a matrix transposed to the current basis matrix, cB is
|
alpar@1
|
859 |
* a subvector of objective coefficients at basic variables. */
|
alpar@1
|
860 |
|
alpar@1
|
861 |
static void eval_pi(struct csa *csa, double pi[])
|
alpar@1
|
862 |
{ int m = csa->m;
|
alpar@1
|
863 |
double *c = csa->coef;
|
alpar@1
|
864 |
int *head = csa->head;
|
alpar@1
|
865 |
double *cB = csa->work2;
|
alpar@1
|
866 |
int i;
|
alpar@1
|
867 |
/* construct the right-hand side vector cB */
|
alpar@1
|
868 |
for (i = 1; i <= m; i++)
|
alpar@1
|
869 |
cB[i] = c[head[i]];
|
alpar@1
|
870 |
/* solve system B'* pi = cB */
|
alpar@1
|
871 |
memcpy(&pi[1], &cB[1], m * sizeof(double));
|
alpar@1
|
872 |
xassert(csa->valid);
|
alpar@1
|
873 |
bfd_btran(csa->bfd, pi);
|
alpar@1
|
874 |
/* and refine the solution */
|
alpar@1
|
875 |
refine_btran(csa, cB, pi);
|
alpar@1
|
876 |
return;
|
alpar@1
|
877 |
}
|
alpar@1
|
878 |
#endif
|
alpar@1
|
879 |
|
alpar@1
|
880 |
#if 1 /* copied from primal */
|
alpar@1
|
881 |
/***********************************************************************
|
alpar@1
|
882 |
* eval_cost - compute reduced cost of non-basic variable xN[j]
|
alpar@1
|
883 |
*
|
alpar@1
|
884 |
* This routine computes the current reduced cost of non-basic variable
|
alpar@1
|
885 |
* xN[j]:
|
alpar@1
|
886 |
*
|
alpar@1
|
887 |
* d[j] = cN[j] - N'[j] * pi,
|
alpar@1
|
888 |
*
|
alpar@1
|
889 |
* where cN[j] is the objective coefficient at variable xN[j], N[j] is
|
alpar@1
|
890 |
* a column of the augmented constraint matrix (I|-A) corresponding to
|
alpar@1
|
891 |
* xN[j], pi is the vector of simplex multipliers. */
|
alpar@1
|
892 |
|
alpar@1
|
893 |
static double eval_cost(struct csa *csa, double pi[], int j)
|
alpar@1
|
894 |
{ int m = csa->m;
|
alpar@1
|
895 |
#ifdef GLP_DEBUG
|
alpar@1
|
896 |
int n = csa->n;
|
alpar@1
|
897 |
#endif
|
alpar@1
|
898 |
double *coef = csa->coef;
|
alpar@1
|
899 |
int *head = csa->head;
|
alpar@1
|
900 |
int k;
|
alpar@1
|
901 |
double dj;
|
alpar@1
|
902 |
#ifdef GLP_DEBUG
|
alpar@1
|
903 |
xassert(1 <= j && j <= n);
|
alpar@1
|
904 |
#endif
|
alpar@1
|
905 |
k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
906 |
#ifdef GLP_DEBUG
|
alpar@1
|
907 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
908 |
#endif
|
alpar@1
|
909 |
dj = coef[k];
|
alpar@1
|
910 |
if (k <= m)
|
alpar@1
|
911 |
{ /* N[j] is k-th column of submatrix I */
|
alpar@1
|
912 |
dj -= pi[k];
|
alpar@1
|
913 |
}
|
alpar@1
|
914 |
else
|
alpar@1
|
915 |
{ /* N[j] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
916 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
917 |
int *A_ind = csa->A_ind;
|
alpar@1
|
918 |
double *A_val = csa->A_val;
|
alpar@1
|
919 |
int beg, end, ptr;
|
alpar@1
|
920 |
beg = A_ptr[k-m];
|
alpar@1
|
921 |
end = A_ptr[k-m+1];
|
alpar@1
|
922 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
923 |
dj += A_val[ptr] * pi[A_ind[ptr]];
|
alpar@1
|
924 |
}
|
alpar@1
|
925 |
return dj;
|
alpar@1
|
926 |
}
|
alpar@1
|
927 |
#endif
|
alpar@1
|
928 |
|
alpar@1
|
929 |
#if 1 /* copied from primal */
|
alpar@1
|
930 |
/***********************************************************************
|
alpar@1
|
931 |
* eval_bbar - compute and store primal values of basic variables
|
alpar@1
|
932 |
*
|
alpar@1
|
933 |
* This routine computes primal values of all basic variables and then
|
alpar@1
|
934 |
* stores them in the solution array. */
|
alpar@1
|
935 |
|
alpar@1
|
936 |
static void eval_bbar(struct csa *csa)
|
alpar@1
|
937 |
{ eval_beta(csa, csa->bbar);
|
alpar@1
|
938 |
return;
|
alpar@1
|
939 |
}
|
alpar@1
|
940 |
#endif
|
alpar@1
|
941 |
|
alpar@1
|
942 |
#if 1 /* copied from primal */
|
alpar@1
|
943 |
/***********************************************************************
|
alpar@1
|
944 |
* eval_cbar - compute and store reduced costs of non-basic variables
|
alpar@1
|
945 |
*
|
alpar@1
|
946 |
* This routine computes reduced costs of all non-basic variables and
|
alpar@1
|
947 |
* then stores them in the solution array. */
|
alpar@1
|
948 |
|
alpar@1
|
949 |
static void eval_cbar(struct csa *csa)
|
alpar@1
|
950 |
{
|
alpar@1
|
951 |
#ifdef GLP_DEBUG
|
alpar@1
|
952 |
int m = csa->m;
|
alpar@1
|
953 |
#endif
|
alpar@1
|
954 |
int n = csa->n;
|
alpar@1
|
955 |
#ifdef GLP_DEBUG
|
alpar@1
|
956 |
int *head = csa->head;
|
alpar@1
|
957 |
#endif
|
alpar@1
|
958 |
double *cbar = csa->cbar;
|
alpar@1
|
959 |
double *pi = csa->work3;
|
alpar@1
|
960 |
int j;
|
alpar@1
|
961 |
#ifdef GLP_DEBUG
|
alpar@1
|
962 |
int k;
|
alpar@1
|
963 |
#endif
|
alpar@1
|
964 |
/* compute simplex multipliers */
|
alpar@1
|
965 |
eval_pi(csa, pi);
|
alpar@1
|
966 |
/* compute and store reduced costs */
|
alpar@1
|
967 |
for (j = 1; j <= n; j++)
|
alpar@1
|
968 |
{
|
alpar@1
|
969 |
#ifdef GLP_DEBUG
|
alpar@1
|
970 |
k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
971 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
972 |
#endif
|
alpar@1
|
973 |
cbar[j] = eval_cost(csa, pi, j);
|
alpar@1
|
974 |
}
|
alpar@1
|
975 |
return;
|
alpar@1
|
976 |
}
|
alpar@1
|
977 |
#endif
|
alpar@1
|
978 |
|
alpar@1
|
979 |
/***********************************************************************
|
alpar@1
|
980 |
* reset_refsp - reset the reference space
|
alpar@1
|
981 |
*
|
alpar@1
|
982 |
* This routine resets (redefines) the reference space used in the
|
alpar@1
|
983 |
* projected steepest edge pricing algorithm. */
|
alpar@1
|
984 |
|
alpar@1
|
985 |
static void reset_refsp(struct csa *csa)
|
alpar@1
|
986 |
{ int m = csa->m;
|
alpar@1
|
987 |
int n = csa->n;
|
alpar@1
|
988 |
int *head = csa->head;
|
alpar@1
|
989 |
char *refsp = csa->refsp;
|
alpar@1
|
990 |
double *gamma = csa->gamma;
|
alpar@1
|
991 |
int i, k;
|
alpar@1
|
992 |
xassert(csa->refct == 0);
|
alpar@1
|
993 |
csa->refct = 1000;
|
alpar@1
|
994 |
memset(&refsp[1], 0, (m+n) * sizeof(char));
|
alpar@1
|
995 |
for (i = 1; i <= m; i++)
|
alpar@1
|
996 |
{ k = head[i]; /* x[k] = xB[i] */
|
alpar@1
|
997 |
refsp[k] = 1;
|
alpar@1
|
998 |
gamma[i] = 1.0;
|
alpar@1
|
999 |
}
|
alpar@1
|
1000 |
return;
|
alpar@1
|
1001 |
}
|
alpar@1
|
1002 |
|
alpar@1
|
1003 |
/***********************************************************************
|
alpar@1
|
1004 |
* eval_gamma - compute steepest edge coefficients
|
alpar@1
|
1005 |
*
|
alpar@1
|
1006 |
* This routine computes the vector of steepest edge coefficients for
|
alpar@1
|
1007 |
* all basic variables (except free ones) using its direct definition:
|
alpar@1
|
1008 |
*
|
alpar@1
|
1009 |
* gamma[i] = eta[i] + sum alfa[i,j]^2, i = 1,...,m,
|
alpar@1
|
1010 |
* j in C
|
alpar@1
|
1011 |
*
|
alpar@1
|
1012 |
* where eta[i] = 1 means that xB[i] is in the current reference space,
|
alpar@1
|
1013 |
* and 0 otherwise; C is a set of non-basic non-fixed variables xN[j],
|
alpar@1
|
1014 |
* which are in the current reference space; alfa[i,j] are elements of
|
alpar@1
|
1015 |
* the current simplex table.
|
alpar@1
|
1016 |
*
|
alpar@1
|
1017 |
* NOTE: The routine is intended only for debugginig purposes. */
|
alpar@1
|
1018 |
|
alpar@1
|
1019 |
static void eval_gamma(struct csa *csa, double gamma[])
|
alpar@1
|
1020 |
{ int m = csa->m;
|
alpar@1
|
1021 |
int n = csa->n;
|
alpar@1
|
1022 |
char *type = csa->type;
|
alpar@1
|
1023 |
int *head = csa->head;
|
alpar@1
|
1024 |
char *refsp = csa->refsp;
|
alpar@1
|
1025 |
double *alfa = csa->work3;
|
alpar@1
|
1026 |
double *h = csa->work3;
|
alpar@1
|
1027 |
int i, j, k;
|
alpar@1
|
1028 |
/* gamma[i] := eta[i] (or 1, if xB[i] is free) */
|
alpar@1
|
1029 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1030 |
{ k = head[i]; /* x[k] = xB[i] */
|
alpar@1
|
1031 |
#ifdef GLP_DEBUG
|
alpar@1
|
1032 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1033 |
#endif
|
alpar@1
|
1034 |
if (type[k] == GLP_FR)
|
alpar@1
|
1035 |
gamma[i] = 1.0;
|
alpar@1
|
1036 |
else
|
alpar@1
|
1037 |
gamma[i] = (refsp[k] ? 1.0 : 0.0);
|
alpar@1
|
1038 |
}
|
alpar@1
|
1039 |
/* compute columns of the current simplex table */
|
alpar@1
|
1040 |
for (j = 1; j <= n; j++)
|
alpar@1
|
1041 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
1042 |
#ifdef GLP_DEBUG
|
alpar@1
|
1043 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1044 |
#endif
|
alpar@1
|
1045 |
/* skip column, if xN[j] is not in C */
|
alpar@1
|
1046 |
if (!refsp[k]) continue;
|
alpar@1
|
1047 |
#ifdef GLP_DEBUG
|
alpar@1
|
1048 |
/* set C must not contain fixed variables */
|
alpar@1
|
1049 |
xassert(type[k] != GLP_FX);
|
alpar@1
|
1050 |
#endif
|
alpar@1
|
1051 |
/* construct the right-hand side vector h = - N[j] */
|
alpar@1
|
1052 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1053 |
h[i] = 0.0;
|
alpar@1
|
1054 |
if (k <= m)
|
alpar@1
|
1055 |
{ /* N[j] is k-th column of submatrix I */
|
alpar@1
|
1056 |
h[k] = -1.0;
|
alpar@1
|
1057 |
}
|
alpar@1
|
1058 |
else
|
alpar@1
|
1059 |
{ /* N[j] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
1060 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
1061 |
int *A_ind = csa->A_ind;
|
alpar@1
|
1062 |
double *A_val = csa->A_val;
|
alpar@1
|
1063 |
int beg, end, ptr;
|
alpar@1
|
1064 |
beg = A_ptr[k-m];
|
alpar@1
|
1065 |
end = A_ptr[k-m+1];
|
alpar@1
|
1066 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
1067 |
h[A_ind[ptr]] = A_val[ptr];
|
alpar@1
|
1068 |
}
|
alpar@1
|
1069 |
/* solve system B * alfa = h */
|
alpar@1
|
1070 |
xassert(csa->valid);
|
alpar@1
|
1071 |
bfd_ftran(csa->bfd, alfa);
|
alpar@1
|
1072 |
/* gamma[i] := gamma[i] + alfa[i,j]^2 */
|
alpar@1
|
1073 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1074 |
{ k = head[i]; /* x[k] = xB[i] */
|
alpar@1
|
1075 |
if (type[k] != GLP_FR)
|
alpar@1
|
1076 |
gamma[i] += alfa[i] * alfa[i];
|
alpar@1
|
1077 |
}
|
alpar@1
|
1078 |
}
|
alpar@1
|
1079 |
return;
|
alpar@1
|
1080 |
}
|
alpar@1
|
1081 |
|
alpar@1
|
1082 |
/***********************************************************************
|
alpar@1
|
1083 |
* chuzr - choose basic variable (row of the simplex table)
|
alpar@1
|
1084 |
*
|
alpar@1
|
1085 |
* This routine chooses basic variable xB[p] having largest weighted
|
alpar@1
|
1086 |
* bound violation:
|
alpar@1
|
1087 |
*
|
alpar@1
|
1088 |
* |r[p]| / sqrt(gamma[p]) = max |r[i]| / sqrt(gamma[i]),
|
alpar@1
|
1089 |
* i in I
|
alpar@1
|
1090 |
*
|
alpar@1
|
1091 |
* / lB[i] - beta[i], if beta[i] < lB[i]
|
alpar@1
|
1092 |
* |
|
alpar@1
|
1093 |
* r[i] = < 0, if lB[i] <= beta[i] <= uB[i]
|
alpar@1
|
1094 |
* |
|
alpar@1
|
1095 |
* \ uB[i] - beta[i], if beta[i] > uB[i]
|
alpar@1
|
1096 |
*
|
alpar@1
|
1097 |
* where beta[i] is primal value of xB[i] in the current basis, lB[i]
|
alpar@1
|
1098 |
* and uB[i] are lower and upper bounds of xB[i], I is a subset of
|
alpar@1
|
1099 |
* eligible basic variables, which significantly violates their bounds,
|
alpar@1
|
1100 |
* gamma[i] is the steepest edge coefficient.
|
alpar@1
|
1101 |
*
|
alpar@1
|
1102 |
* If |r[i]| is less than a specified tolerance, xB[i] is not included
|
alpar@1
|
1103 |
* in I and therefore ignored.
|
alpar@1
|
1104 |
*
|
alpar@1
|
1105 |
* If I is empty and no variable has been chosen, p is set to 0. */
|
alpar@1
|
1106 |
|
alpar@1
|
1107 |
static void chuzr(struct csa *csa, double tol_bnd)
|
alpar@1
|
1108 |
{ int m = csa->m;
|
alpar@1
|
1109 |
#ifdef GLP_DEBUG
|
alpar@1
|
1110 |
int n = csa->n;
|
alpar@1
|
1111 |
#endif
|
alpar@1
|
1112 |
char *type = csa->type;
|
alpar@1
|
1113 |
double *lb = csa->lb;
|
alpar@1
|
1114 |
double *ub = csa->ub;
|
alpar@1
|
1115 |
int *head = csa->head;
|
alpar@1
|
1116 |
double *bbar = csa->bbar;
|
alpar@1
|
1117 |
double *gamma = csa->gamma;
|
alpar@1
|
1118 |
int i, k, p;
|
alpar@1
|
1119 |
double delta, best, eps, ri, temp;
|
alpar@1
|
1120 |
/* nothing is chosen so far */
|
alpar@1
|
1121 |
p = 0, delta = 0.0, best = 0.0;
|
alpar@1
|
1122 |
/* look through the list of basic variables */
|
alpar@1
|
1123 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1124 |
{ k = head[i]; /* x[k] = xB[i] */
|
alpar@1
|
1125 |
#ifdef GLP_DEBUG
|
alpar@1
|
1126 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1127 |
#endif
|
alpar@1
|
1128 |
/* determine bound violation ri[i] */
|
alpar@1
|
1129 |
ri = 0.0;
|
alpar@1
|
1130 |
if (type[k] == GLP_LO || type[k] == GLP_DB ||
|
alpar@1
|
1131 |
type[k] == GLP_FX)
|
alpar@1
|
1132 |
{ /* xB[i] has lower bound */
|
alpar@1
|
1133 |
eps = tol_bnd * (1.0 + kappa * fabs(lb[k]));
|
alpar@1
|
1134 |
if (bbar[i] < lb[k] - eps)
|
alpar@1
|
1135 |
{ /* and significantly violates it */
|
alpar@1
|
1136 |
ri = lb[k] - bbar[i];
|
alpar@1
|
1137 |
}
|
alpar@1
|
1138 |
}
|
alpar@1
|
1139 |
if (type[k] == GLP_UP || type[k] == GLP_DB ||
|
alpar@1
|
1140 |
type[k] == GLP_FX)
|
alpar@1
|
1141 |
{ /* xB[i] has upper bound */
|
alpar@1
|
1142 |
eps = tol_bnd * (1.0 + kappa * fabs(ub[k]));
|
alpar@1
|
1143 |
if (bbar[i] > ub[k] + eps)
|
alpar@1
|
1144 |
{ /* and significantly violates it */
|
alpar@1
|
1145 |
ri = ub[k] - bbar[i];
|
alpar@1
|
1146 |
}
|
alpar@1
|
1147 |
}
|
alpar@1
|
1148 |
/* if xB[i] is not eligible, skip it */
|
alpar@1
|
1149 |
if (ri == 0.0) continue;
|
alpar@1
|
1150 |
/* xB[i] is eligible basic variable; choose one with largest
|
alpar@1
|
1151 |
weighted bound violation */
|
alpar@1
|
1152 |
#ifdef GLP_DEBUG
|
alpar@1
|
1153 |
xassert(gamma[i] >= 0.0);
|
alpar@1
|
1154 |
#endif
|
alpar@1
|
1155 |
temp = gamma[i];
|
alpar@1
|
1156 |
if (temp < DBL_EPSILON) temp = DBL_EPSILON;
|
alpar@1
|
1157 |
temp = (ri * ri) / temp;
|
alpar@1
|
1158 |
if (best < temp)
|
alpar@1
|
1159 |
p = i, delta = ri, best = temp;
|
alpar@1
|
1160 |
}
|
alpar@1
|
1161 |
/* store the index of basic variable xB[p] chosen and its change
|
alpar@1
|
1162 |
in the adjacent basis */
|
alpar@1
|
1163 |
csa->p = p;
|
alpar@1
|
1164 |
csa->delta = delta;
|
alpar@1
|
1165 |
return;
|
alpar@1
|
1166 |
}
|
alpar@1
|
1167 |
|
alpar@1
|
1168 |
#if 1 /* copied from primal */
|
alpar@1
|
1169 |
/***********************************************************************
|
alpar@1
|
1170 |
* eval_rho - compute pivot row of the inverse
|
alpar@1
|
1171 |
*
|
alpar@1
|
1172 |
* This routine computes the pivot (p-th) row of the inverse inv(B),
|
alpar@1
|
1173 |
* which corresponds to basic variable xB[p] chosen:
|
alpar@1
|
1174 |
*
|
alpar@1
|
1175 |
* rho = inv(B') * e[p],
|
alpar@1
|
1176 |
*
|
alpar@1
|
1177 |
* where B' is a matrix transposed to the current basis matrix, e[p]
|
alpar@1
|
1178 |
* is unity vector. */
|
alpar@1
|
1179 |
|
alpar@1
|
1180 |
static void eval_rho(struct csa *csa, double rho[])
|
alpar@1
|
1181 |
{ int m = csa->m;
|
alpar@1
|
1182 |
int p = csa->p;
|
alpar@1
|
1183 |
double *e = rho;
|
alpar@1
|
1184 |
int i;
|
alpar@1
|
1185 |
#ifdef GLP_DEBUG
|
alpar@1
|
1186 |
xassert(1 <= p && p <= m);
|
alpar@1
|
1187 |
#endif
|
alpar@1
|
1188 |
/* construct the right-hand side vector e[p] */
|
alpar@1
|
1189 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1190 |
e[i] = 0.0;
|
alpar@1
|
1191 |
e[p] = 1.0;
|
alpar@1
|
1192 |
/* solve system B'* rho = e[p] */
|
alpar@1
|
1193 |
xassert(csa->valid);
|
alpar@1
|
1194 |
bfd_btran(csa->bfd, rho);
|
alpar@1
|
1195 |
return;
|
alpar@1
|
1196 |
}
|
alpar@1
|
1197 |
#endif
|
alpar@1
|
1198 |
|
alpar@1
|
1199 |
#if 1 /* copied from primal */
|
alpar@1
|
1200 |
/***********************************************************************
|
alpar@1
|
1201 |
* refine_rho - refine pivot row of the inverse
|
alpar@1
|
1202 |
*
|
alpar@1
|
1203 |
* This routine refines the pivot row of the inverse inv(B) assuming
|
alpar@1
|
1204 |
* that it was previously computed by the routine eval_rho. */
|
alpar@1
|
1205 |
|
alpar@1
|
1206 |
static void refine_rho(struct csa *csa, double rho[])
|
alpar@1
|
1207 |
{ int m = csa->m;
|
alpar@1
|
1208 |
int p = csa->p;
|
alpar@1
|
1209 |
double *e = csa->work3;
|
alpar@1
|
1210 |
int i;
|
alpar@1
|
1211 |
#ifdef GLP_DEBUG
|
alpar@1
|
1212 |
xassert(1 <= p && p <= m);
|
alpar@1
|
1213 |
#endif
|
alpar@1
|
1214 |
/* construct the right-hand side vector e[p] */
|
alpar@1
|
1215 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1216 |
e[i] = 0.0;
|
alpar@1
|
1217 |
e[p] = 1.0;
|
alpar@1
|
1218 |
/* refine solution of B'* rho = e[p] */
|
alpar@1
|
1219 |
refine_btran(csa, e, rho);
|
alpar@1
|
1220 |
return;
|
alpar@1
|
1221 |
}
|
alpar@1
|
1222 |
#endif
|
alpar@1
|
1223 |
|
alpar@1
|
1224 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
1225 |
/***********************************************************************
|
alpar@1
|
1226 |
* eval_trow - compute pivot row of the simplex table
|
alpar@1
|
1227 |
*
|
alpar@1
|
1228 |
* This routine computes the pivot row of the simplex table, which
|
alpar@1
|
1229 |
* corresponds to basic variable xB[p] chosen.
|
alpar@1
|
1230 |
*
|
alpar@1
|
1231 |
* The pivot row is the following vector:
|
alpar@1
|
1232 |
*
|
alpar@1
|
1233 |
* trow = T'* e[p] = - N'* inv(B') * e[p] = - N' * rho,
|
alpar@1
|
1234 |
*
|
alpar@1
|
1235 |
* where rho is the pivot row of the inverse inv(B) previously computed
|
alpar@1
|
1236 |
* by the routine eval_rho.
|
alpar@1
|
1237 |
*
|
alpar@1
|
1238 |
* Note that elements of the pivot row corresponding to fixed non-basic
|
alpar@1
|
1239 |
* variables are not computed.
|
alpar@1
|
1240 |
*
|
alpar@1
|
1241 |
* NOTES
|
alpar@1
|
1242 |
*
|
alpar@1
|
1243 |
* Computing pivot row of the simplex table is one of the most time
|
alpar@1
|
1244 |
* consuming operations, and for some instances it may take more than
|
alpar@1
|
1245 |
* 50% of the total solution time.
|
alpar@1
|
1246 |
*
|
alpar@1
|
1247 |
* In the current implementation there are two routines to compute the
|
alpar@1
|
1248 |
* pivot row. The routine eval_trow1 computes elements of the pivot row
|
alpar@1
|
1249 |
* as inner products of columns of the matrix N and the vector rho; it
|
alpar@1
|
1250 |
* is used when the vector rho is relatively dense. The routine
|
alpar@1
|
1251 |
* eval_trow2 computes the pivot row as a linear combination of rows of
|
alpar@1
|
1252 |
* the matrix N; it is used when the vector rho is relatively sparse. */
|
alpar@1
|
1253 |
|
alpar@1
|
1254 |
static void eval_trow1(struct csa *csa, double rho[])
|
alpar@1
|
1255 |
{ int m = csa->m;
|
alpar@1
|
1256 |
int n = csa->n;
|
alpar@1
|
1257 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
1258 |
int *A_ind = csa->A_ind;
|
alpar@1
|
1259 |
double *A_val = csa->A_val;
|
alpar@1
|
1260 |
int *head = csa->head;
|
alpar@1
|
1261 |
char *stat = csa->stat;
|
alpar@1
|
1262 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1263 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1264 |
int j, k, beg, end, ptr, nnz;
|
alpar@1
|
1265 |
double temp;
|
alpar@1
|
1266 |
/* compute the pivot row as inner products of columns of the
|
alpar@1
|
1267 |
matrix N and vector rho: trow[j] = - rho * N[j] */
|
alpar@1
|
1268 |
nnz = 0;
|
alpar@1
|
1269 |
for (j = 1; j <= n; j++)
|
alpar@1
|
1270 |
{ if (stat[j] == GLP_NS)
|
alpar@1
|
1271 |
{ /* xN[j] is fixed */
|
alpar@1
|
1272 |
trow_vec[j] = 0.0;
|
alpar@1
|
1273 |
continue;
|
alpar@1
|
1274 |
}
|
alpar@1
|
1275 |
k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
1276 |
if (k <= m)
|
alpar@1
|
1277 |
{ /* N[j] is k-th column of submatrix I */
|
alpar@1
|
1278 |
temp = - rho[k];
|
alpar@1
|
1279 |
}
|
alpar@1
|
1280 |
else
|
alpar@1
|
1281 |
{ /* N[j] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
1282 |
beg = A_ptr[k-m], end = A_ptr[k-m+1];
|
alpar@1
|
1283 |
temp = 0.0;
|
alpar@1
|
1284 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
1285 |
temp += rho[A_ind[ptr]] * A_val[ptr];
|
alpar@1
|
1286 |
}
|
alpar@1
|
1287 |
if (temp != 0.0)
|
alpar@1
|
1288 |
trow_ind[++nnz] = j;
|
alpar@1
|
1289 |
trow_vec[j] = temp;
|
alpar@1
|
1290 |
}
|
alpar@1
|
1291 |
csa->trow_nnz = nnz;
|
alpar@1
|
1292 |
return;
|
alpar@1
|
1293 |
}
|
alpar@1
|
1294 |
|
alpar@1
|
1295 |
static void eval_trow2(struct csa *csa, double rho[])
|
alpar@1
|
1296 |
{ int m = csa->m;
|
alpar@1
|
1297 |
int n = csa->n;
|
alpar@1
|
1298 |
int *AT_ptr = csa->AT_ptr;
|
alpar@1
|
1299 |
int *AT_ind = csa->AT_ind;
|
alpar@1
|
1300 |
double *AT_val = csa->AT_val;
|
alpar@1
|
1301 |
int *bind = csa->bind;
|
alpar@1
|
1302 |
char *stat = csa->stat;
|
alpar@1
|
1303 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1304 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1305 |
int i, j, beg, end, ptr, nnz;
|
alpar@1
|
1306 |
double temp;
|
alpar@1
|
1307 |
/* clear the pivot row */
|
alpar@1
|
1308 |
for (j = 1; j <= n; j++)
|
alpar@1
|
1309 |
trow_vec[j] = 0.0;
|
alpar@1
|
1310 |
/* compute the pivot row as a linear combination of rows of the
|
alpar@1
|
1311 |
matrix N: trow = - rho[1] * N'[1] - ... - rho[m] * N'[m] */
|
alpar@1
|
1312 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1313 |
{ temp = rho[i];
|
alpar@1
|
1314 |
if (temp == 0.0) continue;
|
alpar@1
|
1315 |
/* trow := trow - rho[i] * N'[i] */
|
alpar@1
|
1316 |
j = bind[i] - m; /* x[i] = xN[j] */
|
alpar@1
|
1317 |
if (j >= 1 && stat[j] != GLP_NS)
|
alpar@1
|
1318 |
trow_vec[j] -= temp;
|
alpar@1
|
1319 |
beg = AT_ptr[i], end = AT_ptr[i+1];
|
alpar@1
|
1320 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
1321 |
{ j = bind[m + AT_ind[ptr]] - m; /* x[k] = xN[j] */
|
alpar@1
|
1322 |
if (j >= 1 && stat[j] != GLP_NS)
|
alpar@1
|
1323 |
trow_vec[j] += temp * AT_val[ptr];
|
alpar@1
|
1324 |
}
|
alpar@1
|
1325 |
}
|
alpar@1
|
1326 |
/* construct sparse pattern of the pivot row */
|
alpar@1
|
1327 |
nnz = 0;
|
alpar@1
|
1328 |
for (j = 1; j <= n; j++)
|
alpar@1
|
1329 |
{ if (trow_vec[j] != 0.0)
|
alpar@1
|
1330 |
trow_ind[++nnz] = j;
|
alpar@1
|
1331 |
}
|
alpar@1
|
1332 |
csa->trow_nnz = nnz;
|
alpar@1
|
1333 |
return;
|
alpar@1
|
1334 |
}
|
alpar@1
|
1335 |
|
alpar@1
|
1336 |
static void eval_trow(struct csa *csa, double rho[])
|
alpar@1
|
1337 |
{ int m = csa->m;
|
alpar@1
|
1338 |
int i, nnz;
|
alpar@1
|
1339 |
double dens;
|
alpar@1
|
1340 |
/* determine the density of the vector rho */
|
alpar@1
|
1341 |
nnz = 0;
|
alpar@1
|
1342 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1343 |
if (rho[i] != 0.0) nnz++;
|
alpar@1
|
1344 |
dens = (double)nnz / (double)m;
|
alpar@1
|
1345 |
if (dens >= 0.20)
|
alpar@1
|
1346 |
{ /* rho is relatively dense */
|
alpar@1
|
1347 |
eval_trow1(csa, rho);
|
alpar@1
|
1348 |
}
|
alpar@1
|
1349 |
else
|
alpar@1
|
1350 |
{ /* rho is relatively sparse */
|
alpar@1
|
1351 |
eval_trow2(csa, rho);
|
alpar@1
|
1352 |
}
|
alpar@1
|
1353 |
return;
|
alpar@1
|
1354 |
}
|
alpar@1
|
1355 |
#endif
|
alpar@1
|
1356 |
|
alpar@1
|
1357 |
/***********************************************************************
|
alpar@1
|
1358 |
* sort_trow - sort pivot row of the simplex table
|
alpar@1
|
1359 |
*
|
alpar@1
|
1360 |
* This routine reorders the list of non-zero elements of the pivot
|
alpar@1
|
1361 |
* row to put significant elements, whose magnitude is not less than
|
alpar@1
|
1362 |
* a specified tolerance, in front of the list, and stores the number
|
alpar@1
|
1363 |
* of significant elements in trow_num. */
|
alpar@1
|
1364 |
|
alpar@1
|
1365 |
static void sort_trow(struct csa *csa, double tol_piv)
|
alpar@1
|
1366 |
{
|
alpar@1
|
1367 |
#ifdef GLP_DEBUG
|
alpar@1
|
1368 |
int n = csa->n;
|
alpar@1
|
1369 |
char *stat = csa->stat;
|
alpar@1
|
1370 |
#endif
|
alpar@1
|
1371 |
int nnz = csa->trow_nnz;
|
alpar@1
|
1372 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1373 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1374 |
int j, num, pos;
|
alpar@1
|
1375 |
double big, eps, temp;
|
alpar@1
|
1376 |
/* compute infinity (maximum) norm of the row */
|
alpar@1
|
1377 |
big = 0.0;
|
alpar@1
|
1378 |
for (pos = 1; pos <= nnz; pos++)
|
alpar@1
|
1379 |
{
|
alpar@1
|
1380 |
#ifdef GLP_DEBUG
|
alpar@1
|
1381 |
j = trow_ind[pos];
|
alpar@1
|
1382 |
xassert(1 <= j && j <= n);
|
alpar@1
|
1383 |
xassert(stat[j] != GLP_NS);
|
alpar@1
|
1384 |
#endif
|
alpar@1
|
1385 |
temp = fabs(trow_vec[trow_ind[pos]]);
|
alpar@1
|
1386 |
if (big < temp) big = temp;
|
alpar@1
|
1387 |
}
|
alpar@1
|
1388 |
csa->trow_max = big;
|
alpar@1
|
1389 |
/* determine absolute pivot tolerance */
|
alpar@1
|
1390 |
eps = tol_piv * (1.0 + 0.01 * big);
|
alpar@1
|
1391 |
/* move significant row components to the front of the list */
|
alpar@1
|
1392 |
for (num = 0; num < nnz; )
|
alpar@1
|
1393 |
{ j = trow_ind[nnz];
|
alpar@1
|
1394 |
if (fabs(trow_vec[j]) < eps)
|
alpar@1
|
1395 |
nnz--;
|
alpar@1
|
1396 |
else
|
alpar@1
|
1397 |
{ num++;
|
alpar@1
|
1398 |
trow_ind[nnz] = trow_ind[num];
|
alpar@1
|
1399 |
trow_ind[num] = j;
|
alpar@1
|
1400 |
}
|
alpar@1
|
1401 |
}
|
alpar@1
|
1402 |
csa->trow_num = num;
|
alpar@1
|
1403 |
return;
|
alpar@1
|
1404 |
}
|
alpar@1
|
1405 |
|
alpar@1
|
1406 |
#ifdef GLP_LONG_STEP /* 07/IV-2009 */
|
alpar@1
|
1407 |
static int ls_func(const void *p1_, const void *p2_)
|
alpar@1
|
1408 |
{ const struct bkpt *p1 = p1_, *p2 = p2_;
|
alpar@1
|
1409 |
if (p1->t < p2->t) return -1;
|
alpar@1
|
1410 |
if (p1->t > p2->t) return +1;
|
alpar@1
|
1411 |
return 0;
|
alpar@1
|
1412 |
}
|
alpar@1
|
1413 |
|
alpar@1
|
1414 |
static int ls_func1(const void *p1_, const void *p2_)
|
alpar@1
|
1415 |
{ const struct bkpt *p1 = p1_, *p2 = p2_;
|
alpar@1
|
1416 |
if (p1->dz < p2->dz) return -1;
|
alpar@1
|
1417 |
if (p1->dz > p2->dz) return +1;
|
alpar@1
|
1418 |
return 0;
|
alpar@1
|
1419 |
}
|
alpar@1
|
1420 |
|
alpar@1
|
1421 |
static void long_step(struct csa *csa)
|
alpar@1
|
1422 |
{ int m = csa->m;
|
alpar@1
|
1423 |
#ifdef GLP_DEBUG
|
alpar@1
|
1424 |
int n = csa->n;
|
alpar@1
|
1425 |
#endif
|
alpar@1
|
1426 |
char *type = csa->type;
|
alpar@1
|
1427 |
double *lb = csa->lb;
|
alpar@1
|
1428 |
double *ub = csa->ub;
|
alpar@1
|
1429 |
int *head = csa->head;
|
alpar@1
|
1430 |
char *stat = csa->stat;
|
alpar@1
|
1431 |
double *cbar = csa->cbar;
|
alpar@1
|
1432 |
double delta = csa->delta;
|
alpar@1
|
1433 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1434 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1435 |
int trow_num = csa->trow_num;
|
alpar@1
|
1436 |
struct bkpt *bkpt = csa->bkpt;
|
alpar@1
|
1437 |
int j, k, kk, nbps, pos;
|
alpar@1
|
1438 |
double alfa, s, slope, dzmax;
|
alpar@1
|
1439 |
/* delta > 0 means that xB[p] violates its lower bound, so to
|
alpar@1
|
1440 |
increase the dual objective lambdaB[p] must increase;
|
alpar@1
|
1441 |
delta < 0 means that xB[p] violates its upper bound, so to
|
alpar@1
|
1442 |
increase the dual objective lambdaB[p] must decrease */
|
alpar@1
|
1443 |
/* s := sign(delta) */
|
alpar@1
|
1444 |
s = (delta > 0.0 ? +1.0 : -1.0);
|
alpar@1
|
1445 |
/* determine breakpoints of the dual objective */
|
alpar@1
|
1446 |
nbps = 0;
|
alpar@1
|
1447 |
for (pos = 1; pos <= trow_num; pos++)
|
alpar@1
|
1448 |
{ j = trow_ind[pos];
|
alpar@1
|
1449 |
#ifdef GLP_DEBUG
|
alpar@1
|
1450 |
xassert(1 <= j && j <= n);
|
alpar@1
|
1451 |
xassert(stat[j] != GLP_NS);
|
alpar@1
|
1452 |
#endif
|
alpar@1
|
1453 |
/* if there is free non-basic variable, switch to the standard
|
alpar@1
|
1454 |
ratio test */
|
alpar@1
|
1455 |
if (stat[j] == GLP_NF)
|
alpar@1
|
1456 |
{ nbps = 0;
|
alpar@1
|
1457 |
goto done;
|
alpar@1
|
1458 |
}
|
alpar@1
|
1459 |
/* lambdaN[j] = ... - alfa * t - ..., where t = s * lambdaB[i]
|
alpar@1
|
1460 |
is the dual ray parameter, t >= 0 */
|
alpar@1
|
1461 |
alfa = s * trow_vec[j];
|
alpar@1
|
1462 |
#ifdef GLP_DEBUG
|
alpar@1
|
1463 |
xassert(alfa != 0.0);
|
alpar@1
|
1464 |
xassert(stat[j] == GLP_NL || stat[j] == GLP_NU);
|
alpar@1
|
1465 |
#endif
|
alpar@1
|
1466 |
if (alfa > 0.0 && stat[j] == GLP_NL ||
|
alpar@1
|
1467 |
alfa < 0.0 && stat[j] == GLP_NU)
|
alpar@1
|
1468 |
{ /* either lambdaN[j] >= 0 (if stat = GLP_NL) and decreases
|
alpar@1
|
1469 |
or lambdaN[j] <= 0 (if stat = GLP_NU) and increases; in
|
alpar@1
|
1470 |
both cases we have a breakpoint */
|
alpar@1
|
1471 |
nbps++;
|
alpar@1
|
1472 |
#ifdef GLP_DEBUG
|
alpar@1
|
1473 |
xassert(nbps <= n);
|
alpar@1
|
1474 |
#endif
|
alpar@1
|
1475 |
bkpt[nbps].j = j;
|
alpar@1
|
1476 |
bkpt[nbps].t = cbar[j] / alfa;
|
alpar@1
|
1477 |
/*
|
alpar@1
|
1478 |
if (stat[j] == GLP_NL && cbar[j] < 0.0 ||
|
alpar@1
|
1479 |
stat[j] == GLP_NU && cbar[j] > 0.0)
|
alpar@1
|
1480 |
xprintf("%d %g\n", stat[j], cbar[j]);
|
alpar@1
|
1481 |
*/
|
alpar@1
|
1482 |
/* if t is negative, replace it by exact zero (see comments
|
alpar@1
|
1483 |
in the routine chuzc) */
|
alpar@1
|
1484 |
if (bkpt[nbps].t < 0.0) bkpt[nbps].t = 0.0;
|
alpar@1
|
1485 |
}
|
alpar@1
|
1486 |
}
|
alpar@1
|
1487 |
/* if there are less than two breakpoints, switch to the standard
|
alpar@1
|
1488 |
ratio test */
|
alpar@1
|
1489 |
if (nbps < 2)
|
alpar@1
|
1490 |
{ nbps = 0;
|
alpar@1
|
1491 |
goto done;
|
alpar@1
|
1492 |
}
|
alpar@1
|
1493 |
/* sort breakpoints by ascending the dual ray parameter, t */
|
alpar@1
|
1494 |
qsort(&bkpt[1], nbps, sizeof(struct bkpt), ls_func);
|
alpar@1
|
1495 |
/* determine last breakpoint, at which the dual objective still
|
alpar@1
|
1496 |
greater than at t = 0 */
|
alpar@1
|
1497 |
dzmax = 0.0;
|
alpar@1
|
1498 |
slope = fabs(delta); /* initial slope */
|
alpar@1
|
1499 |
for (kk = 1; kk <= nbps; kk++)
|
alpar@1
|
1500 |
{ if (kk == 1)
|
alpar@1
|
1501 |
bkpt[kk].dz =
|
alpar@1
|
1502 |
0.0 + slope * (bkpt[kk].t - 0.0);
|
alpar@1
|
1503 |
else
|
alpar@1
|
1504 |
bkpt[kk].dz =
|
alpar@1
|
1505 |
bkpt[kk-1].dz + slope * (bkpt[kk].t - bkpt[kk-1].t);
|
alpar@1
|
1506 |
if (dzmax < bkpt[kk].dz)
|
alpar@1
|
1507 |
dzmax = bkpt[kk].dz;
|
alpar@1
|
1508 |
else if (bkpt[kk].dz < 0.05 * (1.0 + dzmax))
|
alpar@1
|
1509 |
{ nbps = kk - 1;
|
alpar@1
|
1510 |
break;
|
alpar@1
|
1511 |
}
|
alpar@1
|
1512 |
j = bkpt[kk].j;
|
alpar@1
|
1513 |
k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
1514 |
if (type[k] == GLP_DB)
|
alpar@1
|
1515 |
slope -= fabs(trow_vec[j]) * (ub[k] - lb[k]);
|
alpar@1
|
1516 |
else
|
alpar@1
|
1517 |
{ nbps = kk;
|
alpar@1
|
1518 |
break;
|
alpar@1
|
1519 |
}
|
alpar@1
|
1520 |
}
|
alpar@1
|
1521 |
/* if there are less than two breakpoints, switch to the standard
|
alpar@1
|
1522 |
ratio test */
|
alpar@1
|
1523 |
if (nbps < 2)
|
alpar@1
|
1524 |
{ nbps = 0;
|
alpar@1
|
1525 |
goto done;
|
alpar@1
|
1526 |
}
|
alpar@1
|
1527 |
/* sort breakpoints by ascending the dual change, dz */
|
alpar@1
|
1528 |
qsort(&bkpt[1], nbps, sizeof(struct bkpt), ls_func1);
|
alpar@1
|
1529 |
/*
|
alpar@1
|
1530 |
for (kk = 1; kk <= nbps; kk++)
|
alpar@1
|
1531 |
xprintf("%d; t = %g; dz = %g\n", kk, bkpt[kk].t, bkpt[kk].dz);
|
alpar@1
|
1532 |
*/
|
alpar@1
|
1533 |
done: csa->nbps = nbps;
|
alpar@1
|
1534 |
return;
|
alpar@1
|
1535 |
}
|
alpar@1
|
1536 |
#endif
|
alpar@1
|
1537 |
|
alpar@1
|
1538 |
/***********************************************************************
|
alpar@1
|
1539 |
* chuzc - choose non-basic variable (column of the simplex table)
|
alpar@1
|
1540 |
*
|
alpar@1
|
1541 |
* This routine chooses non-basic variable xN[q], which being entered
|
alpar@1
|
1542 |
* in the basis keeps dual feasibility of the basic solution.
|
alpar@1
|
1543 |
*
|
alpar@1
|
1544 |
* The parameter rtol is a relative tolerance used to relax zero bounds
|
alpar@1
|
1545 |
* of reduced costs of non-basic variables. If rtol = 0, the routine
|
alpar@1
|
1546 |
* implements the standard ratio test. Otherwise, if rtol > 0, the
|
alpar@1
|
1547 |
* routine implements Harris' two-pass ratio test. In the latter case
|
alpar@1
|
1548 |
* rtol should be about three times less than a tolerance used to check
|
alpar@1
|
1549 |
* dual feasibility. */
|
alpar@1
|
1550 |
|
alpar@1
|
1551 |
static void chuzc(struct csa *csa, double rtol)
|
alpar@1
|
1552 |
{
|
alpar@1
|
1553 |
#ifdef GLP_DEBUG
|
alpar@1
|
1554 |
int m = csa->m;
|
alpar@1
|
1555 |
int n = csa->n;
|
alpar@1
|
1556 |
#endif
|
alpar@1
|
1557 |
char *stat = csa->stat;
|
alpar@1
|
1558 |
double *cbar = csa->cbar;
|
alpar@1
|
1559 |
#ifdef GLP_DEBUG
|
alpar@1
|
1560 |
int p = csa->p;
|
alpar@1
|
1561 |
#endif
|
alpar@1
|
1562 |
double delta = csa->delta;
|
alpar@1
|
1563 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1564 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1565 |
int trow_num = csa->trow_num;
|
alpar@1
|
1566 |
int j, pos, q;
|
alpar@1
|
1567 |
double alfa, big, s, t, teta, tmax;
|
alpar@1
|
1568 |
#ifdef GLP_DEBUG
|
alpar@1
|
1569 |
xassert(1 <= p && p <= m);
|
alpar@1
|
1570 |
#endif
|
alpar@1
|
1571 |
/* delta > 0 means that xB[p] violates its lower bound and goes
|
alpar@1
|
1572 |
to it in the adjacent basis, so lambdaB[p] is increasing from
|
alpar@1
|
1573 |
its lower zero bound;
|
alpar@1
|
1574 |
delta < 0 means that xB[p] violates its upper bound and goes
|
alpar@1
|
1575 |
to it in the adjacent basis, so lambdaB[p] is decreasing from
|
alpar@1
|
1576 |
its upper zero bound */
|
alpar@1
|
1577 |
#ifdef GLP_DEBUG
|
alpar@1
|
1578 |
xassert(delta != 0.0);
|
alpar@1
|
1579 |
#endif
|
alpar@1
|
1580 |
/* s := sign(delta) */
|
alpar@1
|
1581 |
s = (delta > 0.0 ? +1.0 : -1.0);
|
alpar@1
|
1582 |
/*** FIRST PASS ***/
|
alpar@1
|
1583 |
/* nothing is chosen so far */
|
alpar@1
|
1584 |
q = 0, teta = DBL_MAX, big = 0.0;
|
alpar@1
|
1585 |
/* walk through significant elements of the pivot row */
|
alpar@1
|
1586 |
for (pos = 1; pos <= trow_num; pos++)
|
alpar@1
|
1587 |
{ j = trow_ind[pos];
|
alpar@1
|
1588 |
#ifdef GLP_DEBUG
|
alpar@1
|
1589 |
xassert(1 <= j && j <= n);
|
alpar@1
|
1590 |
#endif
|
alpar@1
|
1591 |
alfa = s * trow_vec[j];
|
alpar@1
|
1592 |
#ifdef GLP_DEBUG
|
alpar@1
|
1593 |
xassert(alfa != 0.0);
|
alpar@1
|
1594 |
#endif
|
alpar@1
|
1595 |
/* lambdaN[j] = ... - alfa * lambdaB[p] - ..., and due to s we
|
alpar@1
|
1596 |
need to consider only increasing lambdaB[p] */
|
alpar@1
|
1597 |
if (alfa > 0.0)
|
alpar@1
|
1598 |
{ /* lambdaN[j] is decreasing */
|
alpar@1
|
1599 |
if (stat[j] == GLP_NL || stat[j] == GLP_NF)
|
alpar@1
|
1600 |
{ /* lambdaN[j] has zero lower bound */
|
alpar@1
|
1601 |
t = (cbar[j] + rtol) / alfa;
|
alpar@1
|
1602 |
}
|
alpar@1
|
1603 |
else
|
alpar@1
|
1604 |
{ /* lambdaN[j] has no lower bound */
|
alpar@1
|
1605 |
continue;
|
alpar@1
|
1606 |
}
|
alpar@1
|
1607 |
}
|
alpar@1
|
1608 |
else
|
alpar@1
|
1609 |
{ /* lambdaN[j] is increasing */
|
alpar@1
|
1610 |
if (stat[j] == GLP_NU || stat[j] == GLP_NF)
|
alpar@1
|
1611 |
{ /* lambdaN[j] has zero upper bound */
|
alpar@1
|
1612 |
t = (cbar[j] - rtol) / alfa;
|
alpar@1
|
1613 |
}
|
alpar@1
|
1614 |
else
|
alpar@1
|
1615 |
{ /* lambdaN[j] has no upper bound */
|
alpar@1
|
1616 |
continue;
|
alpar@1
|
1617 |
}
|
alpar@1
|
1618 |
}
|
alpar@1
|
1619 |
/* t is a change of lambdaB[p], on which lambdaN[j] reaches
|
alpar@1
|
1620 |
its zero bound (possibly relaxed); since the basic solution
|
alpar@1
|
1621 |
is assumed to be dual feasible, t has to be non-negative by
|
alpar@1
|
1622 |
definition; however, it may happen that lambdaN[j] slightly
|
alpar@1
|
1623 |
(i.e. within a tolerance) violates its zero bound, that
|
alpar@1
|
1624 |
leads to negative t; in the latter case, if xN[j] is chosen,
|
alpar@1
|
1625 |
negative t means that lambdaB[p] changes in wrong direction
|
alpar@1
|
1626 |
that may cause wrong results on updating reduced costs;
|
alpar@1
|
1627 |
thus, if t is negative, we should replace it by exact zero
|
alpar@1
|
1628 |
assuming that lambdaN[j] is exactly on its zero bound, and
|
alpar@1
|
1629 |
violation appears due to round-off errors */
|
alpar@1
|
1630 |
if (t < 0.0) t = 0.0;
|
alpar@1
|
1631 |
/* apply minimal ratio test */
|
alpar@1
|
1632 |
if (teta > t || teta == t && big < fabs(alfa))
|
alpar@1
|
1633 |
q = j, teta = t, big = fabs(alfa);
|
alpar@1
|
1634 |
}
|
alpar@1
|
1635 |
/* the second pass is skipped in the following cases: */
|
alpar@1
|
1636 |
/* if the standard ratio test is used */
|
alpar@1
|
1637 |
if (rtol == 0.0) goto done;
|
alpar@1
|
1638 |
/* if no non-basic variable has been chosen on the first pass */
|
alpar@1
|
1639 |
if (q == 0) goto done;
|
alpar@1
|
1640 |
/* if lambdaN[q] prevents lambdaB[p] from any change */
|
alpar@1
|
1641 |
if (teta == 0.0) goto done;
|
alpar@1
|
1642 |
/*** SECOND PASS ***/
|
alpar@1
|
1643 |
/* here tmax is a maximal change of lambdaB[p], on which the
|
alpar@1
|
1644 |
solution remains dual feasible within a tolerance */
|
alpar@1
|
1645 |
#if 0
|
alpar@1
|
1646 |
tmax = (1.0 + 10.0 * DBL_EPSILON) * teta;
|
alpar@1
|
1647 |
#else
|
alpar@1
|
1648 |
tmax = teta;
|
alpar@1
|
1649 |
#endif
|
alpar@1
|
1650 |
/* nothing is chosen so far */
|
alpar@1
|
1651 |
q = 0, teta = DBL_MAX, big = 0.0;
|
alpar@1
|
1652 |
/* walk through significant elements of the pivot row */
|
alpar@1
|
1653 |
for (pos = 1; pos <= trow_num; pos++)
|
alpar@1
|
1654 |
{ j = trow_ind[pos];
|
alpar@1
|
1655 |
#ifdef GLP_DEBUG
|
alpar@1
|
1656 |
xassert(1 <= j && j <= n);
|
alpar@1
|
1657 |
#endif
|
alpar@1
|
1658 |
alfa = s * trow_vec[j];
|
alpar@1
|
1659 |
#ifdef GLP_DEBUG
|
alpar@1
|
1660 |
xassert(alfa != 0.0);
|
alpar@1
|
1661 |
#endif
|
alpar@1
|
1662 |
/* lambdaN[j] = ... - alfa * lambdaB[p] - ..., and due to s we
|
alpar@1
|
1663 |
need to consider only increasing lambdaB[p] */
|
alpar@1
|
1664 |
if (alfa > 0.0)
|
alpar@1
|
1665 |
{ /* lambdaN[j] is decreasing */
|
alpar@1
|
1666 |
if (stat[j] == GLP_NL || stat[j] == GLP_NF)
|
alpar@1
|
1667 |
{ /* lambdaN[j] has zero lower bound */
|
alpar@1
|
1668 |
t = cbar[j] / alfa;
|
alpar@1
|
1669 |
}
|
alpar@1
|
1670 |
else
|
alpar@1
|
1671 |
{ /* lambdaN[j] has no lower bound */
|
alpar@1
|
1672 |
continue;
|
alpar@1
|
1673 |
}
|
alpar@1
|
1674 |
}
|
alpar@1
|
1675 |
else
|
alpar@1
|
1676 |
{ /* lambdaN[j] is increasing */
|
alpar@1
|
1677 |
if (stat[j] == GLP_NU || stat[j] == GLP_NF)
|
alpar@1
|
1678 |
{ /* lambdaN[j] has zero upper bound */
|
alpar@1
|
1679 |
t = cbar[j] / alfa;
|
alpar@1
|
1680 |
}
|
alpar@1
|
1681 |
else
|
alpar@1
|
1682 |
{ /* lambdaN[j] has no upper bound */
|
alpar@1
|
1683 |
continue;
|
alpar@1
|
1684 |
}
|
alpar@1
|
1685 |
}
|
alpar@1
|
1686 |
/* (see comments for the first pass) */
|
alpar@1
|
1687 |
if (t < 0.0) t = 0.0;
|
alpar@1
|
1688 |
/* t is a change of lambdaB[p], on which lambdaN[j] reaches
|
alpar@1
|
1689 |
its zero (lower or upper) bound; if t <= tmax, all reduced
|
alpar@1
|
1690 |
costs can violate their zero bounds only within relaxation
|
alpar@1
|
1691 |
tolerance rtol, so we can choose non-basic variable having
|
alpar@1
|
1692 |
largest influence coefficient to avoid possible numerical
|
alpar@1
|
1693 |
instability */
|
alpar@1
|
1694 |
if (t <= tmax && big < fabs(alfa))
|
alpar@1
|
1695 |
q = j, teta = t, big = fabs(alfa);
|
alpar@1
|
1696 |
}
|
alpar@1
|
1697 |
/* something must be chosen on the second pass */
|
alpar@1
|
1698 |
xassert(q != 0);
|
alpar@1
|
1699 |
done: /* store the index of non-basic variable xN[q] chosen */
|
alpar@1
|
1700 |
csa->q = q;
|
alpar@1
|
1701 |
/* store reduced cost of xN[q] in the adjacent basis */
|
alpar@1
|
1702 |
csa->new_dq = s * teta;
|
alpar@1
|
1703 |
return;
|
alpar@1
|
1704 |
}
|
alpar@1
|
1705 |
|
alpar@1
|
1706 |
#if 1 /* copied from primal */
|
alpar@1
|
1707 |
/***********************************************************************
|
alpar@1
|
1708 |
* eval_tcol - compute pivot column of the simplex table
|
alpar@1
|
1709 |
*
|
alpar@1
|
1710 |
* This routine computes the pivot column of the simplex table, which
|
alpar@1
|
1711 |
* corresponds to non-basic variable xN[q] chosen.
|
alpar@1
|
1712 |
*
|
alpar@1
|
1713 |
* The pivot column is the following vector:
|
alpar@1
|
1714 |
*
|
alpar@1
|
1715 |
* tcol = T * e[q] = - inv(B) * N * e[q] = - inv(B) * N[q],
|
alpar@1
|
1716 |
*
|
alpar@1
|
1717 |
* where B is the current basis matrix, N[q] is a column of the matrix
|
alpar@1
|
1718 |
* (I|-A) corresponding to variable xN[q]. */
|
alpar@1
|
1719 |
|
alpar@1
|
1720 |
static void eval_tcol(struct csa *csa)
|
alpar@1
|
1721 |
{ int m = csa->m;
|
alpar@1
|
1722 |
#ifdef GLP_DEBUG
|
alpar@1
|
1723 |
int n = csa->n;
|
alpar@1
|
1724 |
#endif
|
alpar@1
|
1725 |
int *head = csa->head;
|
alpar@1
|
1726 |
int q = csa->q;
|
alpar@1
|
1727 |
int *tcol_ind = csa->tcol_ind;
|
alpar@1
|
1728 |
double *tcol_vec = csa->tcol_vec;
|
alpar@1
|
1729 |
double *h = csa->tcol_vec;
|
alpar@1
|
1730 |
int i, k, nnz;
|
alpar@1
|
1731 |
#ifdef GLP_DEBUG
|
alpar@1
|
1732 |
xassert(1 <= q && q <= n);
|
alpar@1
|
1733 |
#endif
|
alpar@1
|
1734 |
k = head[m+q]; /* x[k] = xN[q] */
|
alpar@1
|
1735 |
#ifdef GLP_DEBUG
|
alpar@1
|
1736 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1737 |
#endif
|
alpar@1
|
1738 |
/* construct the right-hand side vector h = - N[q] */
|
alpar@1
|
1739 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1740 |
h[i] = 0.0;
|
alpar@1
|
1741 |
if (k <= m)
|
alpar@1
|
1742 |
{ /* N[q] is k-th column of submatrix I */
|
alpar@1
|
1743 |
h[k] = -1.0;
|
alpar@1
|
1744 |
}
|
alpar@1
|
1745 |
else
|
alpar@1
|
1746 |
{ /* N[q] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
1747 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
1748 |
int *A_ind = csa->A_ind;
|
alpar@1
|
1749 |
double *A_val = csa->A_val;
|
alpar@1
|
1750 |
int beg, end, ptr;
|
alpar@1
|
1751 |
beg = A_ptr[k-m];
|
alpar@1
|
1752 |
end = A_ptr[k-m+1];
|
alpar@1
|
1753 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
1754 |
h[A_ind[ptr]] = A_val[ptr];
|
alpar@1
|
1755 |
}
|
alpar@1
|
1756 |
/* solve system B * tcol = h */
|
alpar@1
|
1757 |
xassert(csa->valid);
|
alpar@1
|
1758 |
bfd_ftran(csa->bfd, tcol_vec);
|
alpar@1
|
1759 |
/* construct sparse pattern of the pivot column */
|
alpar@1
|
1760 |
nnz = 0;
|
alpar@1
|
1761 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1762 |
{ if (tcol_vec[i] != 0.0)
|
alpar@1
|
1763 |
tcol_ind[++nnz] = i;
|
alpar@1
|
1764 |
}
|
alpar@1
|
1765 |
csa->tcol_nnz = nnz;
|
alpar@1
|
1766 |
return;
|
alpar@1
|
1767 |
}
|
alpar@1
|
1768 |
#endif
|
alpar@1
|
1769 |
|
alpar@1
|
1770 |
#if 1 /* copied from primal */
|
alpar@1
|
1771 |
/***********************************************************************
|
alpar@1
|
1772 |
* refine_tcol - refine pivot column of the simplex table
|
alpar@1
|
1773 |
*
|
alpar@1
|
1774 |
* This routine refines the pivot column of the simplex table assuming
|
alpar@1
|
1775 |
* that it was previously computed by the routine eval_tcol. */
|
alpar@1
|
1776 |
|
alpar@1
|
1777 |
static void refine_tcol(struct csa *csa)
|
alpar@1
|
1778 |
{ int m = csa->m;
|
alpar@1
|
1779 |
#ifdef GLP_DEBUG
|
alpar@1
|
1780 |
int n = csa->n;
|
alpar@1
|
1781 |
#endif
|
alpar@1
|
1782 |
int *head = csa->head;
|
alpar@1
|
1783 |
int q = csa->q;
|
alpar@1
|
1784 |
int *tcol_ind = csa->tcol_ind;
|
alpar@1
|
1785 |
double *tcol_vec = csa->tcol_vec;
|
alpar@1
|
1786 |
double *h = csa->work3;
|
alpar@1
|
1787 |
int i, k, nnz;
|
alpar@1
|
1788 |
#ifdef GLP_DEBUG
|
alpar@1
|
1789 |
xassert(1 <= q && q <= n);
|
alpar@1
|
1790 |
#endif
|
alpar@1
|
1791 |
k = head[m+q]; /* x[k] = xN[q] */
|
alpar@1
|
1792 |
#ifdef GLP_DEBUG
|
alpar@1
|
1793 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1794 |
#endif
|
alpar@1
|
1795 |
/* construct the right-hand side vector h = - N[q] */
|
alpar@1
|
1796 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1797 |
h[i] = 0.0;
|
alpar@1
|
1798 |
if (k <= m)
|
alpar@1
|
1799 |
{ /* N[q] is k-th column of submatrix I */
|
alpar@1
|
1800 |
h[k] = -1.0;
|
alpar@1
|
1801 |
}
|
alpar@1
|
1802 |
else
|
alpar@1
|
1803 |
{ /* N[q] is (k-m)-th column of submatrix (-A) */
|
alpar@1
|
1804 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
1805 |
int *A_ind = csa->A_ind;
|
alpar@1
|
1806 |
double *A_val = csa->A_val;
|
alpar@1
|
1807 |
int beg, end, ptr;
|
alpar@1
|
1808 |
beg = A_ptr[k-m];
|
alpar@1
|
1809 |
end = A_ptr[k-m+1];
|
alpar@1
|
1810 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
1811 |
h[A_ind[ptr]] = A_val[ptr];
|
alpar@1
|
1812 |
}
|
alpar@1
|
1813 |
/* refine solution of B * tcol = h */
|
alpar@1
|
1814 |
refine_ftran(csa, h, tcol_vec);
|
alpar@1
|
1815 |
/* construct sparse pattern of the pivot column */
|
alpar@1
|
1816 |
nnz = 0;
|
alpar@1
|
1817 |
for (i = 1; i <= m; i++)
|
alpar@1
|
1818 |
{ if (tcol_vec[i] != 0.0)
|
alpar@1
|
1819 |
tcol_ind[++nnz] = i;
|
alpar@1
|
1820 |
}
|
alpar@1
|
1821 |
csa->tcol_nnz = nnz;
|
alpar@1
|
1822 |
return;
|
alpar@1
|
1823 |
}
|
alpar@1
|
1824 |
#endif
|
alpar@1
|
1825 |
|
alpar@1
|
1826 |
/***********************************************************************
|
alpar@1
|
1827 |
* update_cbar - update reduced costs of non-basic variables
|
alpar@1
|
1828 |
*
|
alpar@1
|
1829 |
* This routine updates reduced costs of all (except fixed) non-basic
|
alpar@1
|
1830 |
* variables for the adjacent basis. */
|
alpar@1
|
1831 |
|
alpar@1
|
1832 |
static void update_cbar(struct csa *csa)
|
alpar@1
|
1833 |
{
|
alpar@1
|
1834 |
#ifdef GLP_DEBUG
|
alpar@1
|
1835 |
int n = csa->n;
|
alpar@1
|
1836 |
#endif
|
alpar@1
|
1837 |
double *cbar = csa->cbar;
|
alpar@1
|
1838 |
int trow_nnz = csa->trow_nnz;
|
alpar@1
|
1839 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1840 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1841 |
int q = csa->q;
|
alpar@1
|
1842 |
double new_dq = csa->new_dq;
|
alpar@1
|
1843 |
int j, pos;
|
alpar@1
|
1844 |
#ifdef GLP_DEBUG
|
alpar@1
|
1845 |
xassert(1 <= q && q <= n);
|
alpar@1
|
1846 |
#endif
|
alpar@1
|
1847 |
/* set new reduced cost of xN[q] */
|
alpar@1
|
1848 |
cbar[q] = new_dq;
|
alpar@1
|
1849 |
/* update reduced costs of other non-basic variables */
|
alpar@1
|
1850 |
if (new_dq == 0.0) goto done;
|
alpar@1
|
1851 |
for (pos = 1; pos <= trow_nnz; pos++)
|
alpar@1
|
1852 |
{ j = trow_ind[pos];
|
alpar@1
|
1853 |
#ifdef GLP_DEBUG
|
alpar@1
|
1854 |
xassert(1 <= j && j <= n);
|
alpar@1
|
1855 |
#endif
|
alpar@1
|
1856 |
if (j != q)
|
alpar@1
|
1857 |
cbar[j] -= trow_vec[j] * new_dq;
|
alpar@1
|
1858 |
}
|
alpar@1
|
1859 |
done: return;
|
alpar@1
|
1860 |
}
|
alpar@1
|
1861 |
|
alpar@1
|
1862 |
/***********************************************************************
|
alpar@1
|
1863 |
* update_bbar - update values of basic variables
|
alpar@1
|
1864 |
*
|
alpar@1
|
1865 |
* This routine updates values of all basic variables for the adjacent
|
alpar@1
|
1866 |
* basis. */
|
alpar@1
|
1867 |
|
alpar@1
|
1868 |
static void update_bbar(struct csa *csa)
|
alpar@1
|
1869 |
{
|
alpar@1
|
1870 |
#ifdef GLP_DEBUG
|
alpar@1
|
1871 |
int m = csa->m;
|
alpar@1
|
1872 |
int n = csa->n;
|
alpar@1
|
1873 |
#endif
|
alpar@1
|
1874 |
double *bbar = csa->bbar;
|
alpar@1
|
1875 |
int p = csa->p;
|
alpar@1
|
1876 |
double delta = csa->delta;
|
alpar@1
|
1877 |
int q = csa->q;
|
alpar@1
|
1878 |
int tcol_nnz = csa->tcol_nnz;
|
alpar@1
|
1879 |
int *tcol_ind = csa->tcol_ind;
|
alpar@1
|
1880 |
double *tcol_vec = csa->tcol_vec;
|
alpar@1
|
1881 |
int i, pos;
|
alpar@1
|
1882 |
double teta;
|
alpar@1
|
1883 |
#ifdef GLP_DEBUG
|
alpar@1
|
1884 |
xassert(1 <= p && p <= m);
|
alpar@1
|
1885 |
xassert(1 <= q && q <= n);
|
alpar@1
|
1886 |
#endif
|
alpar@1
|
1887 |
/* determine the change of xN[q] in the adjacent basis */
|
alpar@1
|
1888 |
#ifdef GLP_DEBUG
|
alpar@1
|
1889 |
xassert(tcol_vec[p] != 0.0);
|
alpar@1
|
1890 |
#endif
|
alpar@1
|
1891 |
teta = delta / tcol_vec[p];
|
alpar@1
|
1892 |
/* set new primal value of xN[q] */
|
alpar@1
|
1893 |
bbar[p] = get_xN(csa, q) + teta;
|
alpar@1
|
1894 |
/* update primal values of other basic variables */
|
alpar@1
|
1895 |
if (teta == 0.0) goto done;
|
alpar@1
|
1896 |
for (pos = 1; pos <= tcol_nnz; pos++)
|
alpar@1
|
1897 |
{ i = tcol_ind[pos];
|
alpar@1
|
1898 |
#ifdef GLP_DEBUG
|
alpar@1
|
1899 |
xassert(1 <= i && i <= m);
|
alpar@1
|
1900 |
#endif
|
alpar@1
|
1901 |
if (i != p)
|
alpar@1
|
1902 |
bbar[i] += tcol_vec[i] * teta;
|
alpar@1
|
1903 |
}
|
alpar@1
|
1904 |
done: return;
|
alpar@1
|
1905 |
}
|
alpar@1
|
1906 |
|
alpar@1
|
1907 |
/***********************************************************************
|
alpar@1
|
1908 |
* update_gamma - update steepest edge coefficients
|
alpar@1
|
1909 |
*
|
alpar@1
|
1910 |
* This routine updates steepest-edge coefficients for the adjacent
|
alpar@1
|
1911 |
* basis. */
|
alpar@1
|
1912 |
|
alpar@1
|
1913 |
static void update_gamma(struct csa *csa)
|
alpar@1
|
1914 |
{ int m = csa->m;
|
alpar@1
|
1915 |
#ifdef GLP_DEBUG
|
alpar@1
|
1916 |
int n = csa->n;
|
alpar@1
|
1917 |
#endif
|
alpar@1
|
1918 |
char *type = csa->type;
|
alpar@1
|
1919 |
int *head = csa->head;
|
alpar@1
|
1920 |
char *refsp = csa->refsp;
|
alpar@1
|
1921 |
double *gamma = csa->gamma;
|
alpar@1
|
1922 |
int p = csa->p;
|
alpar@1
|
1923 |
int trow_nnz = csa->trow_nnz;
|
alpar@1
|
1924 |
int *trow_ind = csa->trow_ind;
|
alpar@1
|
1925 |
double *trow_vec = csa->trow_vec;
|
alpar@1
|
1926 |
int q = csa->q;
|
alpar@1
|
1927 |
int tcol_nnz = csa->tcol_nnz;
|
alpar@1
|
1928 |
int *tcol_ind = csa->tcol_ind;
|
alpar@1
|
1929 |
double *tcol_vec = csa->tcol_vec;
|
alpar@1
|
1930 |
double *u = csa->work3;
|
alpar@1
|
1931 |
int i, j, k,pos;
|
alpar@1
|
1932 |
double gamma_p, eta_p, pivot, t, t1, t2;
|
alpar@1
|
1933 |
#ifdef GLP_DEBUG
|
alpar@1
|
1934 |
xassert(1 <= p && p <= m);
|
alpar@1
|
1935 |
xassert(1 <= q && q <= n);
|
alpar@1
|
1936 |
#endif
|
alpar@1
|
1937 |
/* the basis changes, so decrease the count */
|
alpar@1
|
1938 |
xassert(csa->refct > 0);
|
alpar@1
|
1939 |
csa->refct--;
|
alpar@1
|
1940 |
/* recompute gamma[p] for the current basis more accurately and
|
alpar@1
|
1941 |
compute auxiliary vector u */
|
alpar@1
|
1942 |
#ifdef GLP_DEBUG
|
alpar@1
|
1943 |
xassert(type[head[p]] != GLP_FR);
|
alpar@1
|
1944 |
#endif
|
alpar@1
|
1945 |
gamma_p = eta_p = (refsp[head[p]] ? 1.0 : 0.0);
|
alpar@1
|
1946 |
for (i = 1; i <= m; i++) u[i] = 0.0;
|
alpar@1
|
1947 |
for (pos = 1; pos <= trow_nnz; pos++)
|
alpar@1
|
1948 |
{ j = trow_ind[pos];
|
alpar@1
|
1949 |
#ifdef GLP_DEBUG
|
alpar@1
|
1950 |
xassert(1 <= j && j <= n);
|
alpar@1
|
1951 |
#endif
|
alpar@1
|
1952 |
k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
1953 |
#ifdef GLP_DEBUG
|
alpar@1
|
1954 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1955 |
xassert(type[k] != GLP_FX);
|
alpar@1
|
1956 |
#endif
|
alpar@1
|
1957 |
if (!refsp[k]) continue;
|
alpar@1
|
1958 |
t = trow_vec[j];
|
alpar@1
|
1959 |
gamma_p += t * t;
|
alpar@1
|
1960 |
/* u := u + N[j] * delta[j] * trow[j] */
|
alpar@1
|
1961 |
if (k <= m)
|
alpar@1
|
1962 |
{ /* N[k] = k-j stolbec submatrix I */
|
alpar@1
|
1963 |
u[k] += t;
|
alpar@1
|
1964 |
}
|
alpar@1
|
1965 |
else
|
alpar@1
|
1966 |
{ /* N[k] = k-m-k stolbec (-A) */
|
alpar@1
|
1967 |
int *A_ptr = csa->A_ptr;
|
alpar@1
|
1968 |
int *A_ind = csa->A_ind;
|
alpar@1
|
1969 |
double *A_val = csa->A_val;
|
alpar@1
|
1970 |
int beg, end, ptr;
|
alpar@1
|
1971 |
beg = A_ptr[k-m];
|
alpar@1
|
1972 |
end = A_ptr[k-m+1];
|
alpar@1
|
1973 |
for (ptr = beg; ptr < end; ptr++)
|
alpar@1
|
1974 |
u[A_ind[ptr]] -= t * A_val[ptr];
|
alpar@1
|
1975 |
}
|
alpar@1
|
1976 |
}
|
alpar@1
|
1977 |
xassert(csa->valid);
|
alpar@1
|
1978 |
bfd_ftran(csa->bfd, u);
|
alpar@1
|
1979 |
/* update gamma[i] for other basic variables (except xB[p] and
|
alpar@1
|
1980 |
free variables) */
|
alpar@1
|
1981 |
pivot = tcol_vec[p];
|
alpar@1
|
1982 |
#ifdef GLP_DEBUG
|
alpar@1
|
1983 |
xassert(pivot != 0.0);
|
alpar@1
|
1984 |
#endif
|
alpar@1
|
1985 |
for (pos = 1; pos <= tcol_nnz; pos++)
|
alpar@1
|
1986 |
{ i = tcol_ind[pos];
|
alpar@1
|
1987 |
#ifdef GLP_DEBUG
|
alpar@1
|
1988 |
xassert(1 <= i && i <= m);
|
alpar@1
|
1989 |
#endif
|
alpar@1
|
1990 |
k = head[i];
|
alpar@1
|
1991 |
#ifdef GLP_DEBUG
|
alpar@1
|
1992 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
1993 |
#endif
|
alpar@1
|
1994 |
/* skip xB[p] */
|
alpar@1
|
1995 |
if (i == p) continue;
|
alpar@1
|
1996 |
/* skip free basic variable */
|
alpar@1
|
1997 |
if (type[head[i]] == GLP_FR)
|
alpar@1
|
1998 |
{
|
alpar@1
|
1999 |
#ifdef GLP_DEBUG
|
alpar@1
|
2000 |
xassert(gamma[i] == 1.0);
|
alpar@1
|
2001 |
#endif
|
alpar@1
|
2002 |
continue;
|
alpar@1
|
2003 |
}
|
alpar@1
|
2004 |
/* compute gamma[i] for the adjacent basis */
|
alpar@1
|
2005 |
t = tcol_vec[i] / pivot;
|
alpar@1
|
2006 |
t1 = gamma[i] + t * t * gamma_p + 2.0 * t * u[i];
|
alpar@1
|
2007 |
t2 = (refsp[k] ? 1.0 : 0.0) + eta_p * t * t;
|
alpar@1
|
2008 |
gamma[i] = (t1 >= t2 ? t1 : t2);
|
alpar@1
|
2009 |
/* (though gamma[i] can be exact zero, because the reference
|
alpar@1
|
2010 |
space does not include non-basic fixed variables) */
|
alpar@1
|
2011 |
if (gamma[i] < DBL_EPSILON) gamma[i] = DBL_EPSILON;
|
alpar@1
|
2012 |
}
|
alpar@1
|
2013 |
/* compute gamma[p] for the adjacent basis */
|
alpar@1
|
2014 |
if (type[head[m+q]] == GLP_FR)
|
alpar@1
|
2015 |
gamma[p] = 1.0;
|
alpar@1
|
2016 |
else
|
alpar@1
|
2017 |
{ gamma[p] = gamma_p / (pivot * pivot);
|
alpar@1
|
2018 |
if (gamma[p] < DBL_EPSILON) gamma[p] = DBL_EPSILON;
|
alpar@1
|
2019 |
}
|
alpar@1
|
2020 |
/* if xB[p], which becomes xN[q] in the adjacent basis, is fixed
|
alpar@1
|
2021 |
and belongs to the reference space, remove it from there, and
|
alpar@1
|
2022 |
change all gamma's appropriately */
|
alpar@1
|
2023 |
k = head[p];
|
alpar@1
|
2024 |
if (type[k] == GLP_FX && refsp[k])
|
alpar@1
|
2025 |
{ refsp[k] = 0;
|
alpar@1
|
2026 |
for (pos = 1; pos <= tcol_nnz; pos++)
|
alpar@1
|
2027 |
{ i = tcol_ind[pos];
|
alpar@1
|
2028 |
if (i == p)
|
alpar@1
|
2029 |
{ if (type[head[m+q]] == GLP_FR) continue;
|
alpar@1
|
2030 |
t = 1.0 / tcol_vec[p];
|
alpar@1
|
2031 |
}
|
alpar@1
|
2032 |
else
|
alpar@1
|
2033 |
{ if (type[head[i]] == GLP_FR) continue;
|
alpar@1
|
2034 |
t = tcol_vec[i] / tcol_vec[p];
|
alpar@1
|
2035 |
}
|
alpar@1
|
2036 |
gamma[i] -= t * t;
|
alpar@1
|
2037 |
if (gamma[i] < DBL_EPSILON) gamma[i] = DBL_EPSILON;
|
alpar@1
|
2038 |
}
|
alpar@1
|
2039 |
}
|
alpar@1
|
2040 |
return;
|
alpar@1
|
2041 |
}
|
alpar@1
|
2042 |
|
alpar@1
|
2043 |
#if 1 /* copied from primal */
|
alpar@1
|
2044 |
/***********************************************************************
|
alpar@1
|
2045 |
* err_in_bbar - compute maximal relative error in primal solution
|
alpar@1
|
2046 |
*
|
alpar@1
|
2047 |
* This routine returns maximal relative error:
|
alpar@1
|
2048 |
*
|
alpar@1
|
2049 |
* max |beta[i] - bbar[i]| / (1 + |beta[i]|),
|
alpar@1
|
2050 |
*
|
alpar@1
|
2051 |
* where beta and bbar are, respectively, directly computed and the
|
alpar@1
|
2052 |
* current (updated) values of basic variables.
|
alpar@1
|
2053 |
*
|
alpar@1
|
2054 |
* NOTE: The routine is intended only for debugginig purposes. */
|
alpar@1
|
2055 |
|
alpar@1
|
2056 |
static double err_in_bbar(struct csa *csa)
|
alpar@1
|
2057 |
{ int m = csa->m;
|
alpar@1
|
2058 |
double *bbar = csa->bbar;
|
alpar@1
|
2059 |
int i;
|
alpar@1
|
2060 |
double e, emax, *beta;
|
alpar@1
|
2061 |
beta = xcalloc(1+m, sizeof(double));
|
alpar@1
|
2062 |
eval_beta(csa, beta);
|
alpar@1
|
2063 |
emax = 0.0;
|
alpar@1
|
2064 |
for (i = 1; i <= m; i++)
|
alpar@1
|
2065 |
{ e = fabs(beta[i] - bbar[i]) / (1.0 + fabs(beta[i]));
|
alpar@1
|
2066 |
if (emax < e) emax = e;
|
alpar@1
|
2067 |
}
|
alpar@1
|
2068 |
xfree(beta);
|
alpar@1
|
2069 |
return emax;
|
alpar@1
|
2070 |
}
|
alpar@1
|
2071 |
#endif
|
alpar@1
|
2072 |
|
alpar@1
|
2073 |
#if 1 /* copied from primal */
|
alpar@1
|
2074 |
/***********************************************************************
|
alpar@1
|
2075 |
* err_in_cbar - compute maximal relative error in dual solution
|
alpar@1
|
2076 |
*
|
alpar@1
|
2077 |
* This routine returns maximal relative error:
|
alpar@1
|
2078 |
*
|
alpar@1
|
2079 |
* max |cost[j] - cbar[j]| / (1 + |cost[j]|),
|
alpar@1
|
2080 |
*
|
alpar@1
|
2081 |
* where cost and cbar are, respectively, directly computed and the
|
alpar@1
|
2082 |
* current (updated) reduced costs of non-basic non-fixed variables.
|
alpar@1
|
2083 |
*
|
alpar@1
|
2084 |
* NOTE: The routine is intended only for debugginig purposes. */
|
alpar@1
|
2085 |
|
alpar@1
|
2086 |
static double err_in_cbar(struct csa *csa)
|
alpar@1
|
2087 |
{ int m = csa->m;
|
alpar@1
|
2088 |
int n = csa->n;
|
alpar@1
|
2089 |
char *stat = csa->stat;
|
alpar@1
|
2090 |
double *cbar = csa->cbar;
|
alpar@1
|
2091 |
int j;
|
alpar@1
|
2092 |
double e, emax, cost, *pi;
|
alpar@1
|
2093 |
pi = xcalloc(1+m, sizeof(double));
|
alpar@1
|
2094 |
eval_pi(csa, pi);
|
alpar@1
|
2095 |
emax = 0.0;
|
alpar@1
|
2096 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2097 |
{ if (stat[j] == GLP_NS) continue;
|
alpar@1
|
2098 |
cost = eval_cost(csa, pi, j);
|
alpar@1
|
2099 |
e = fabs(cost - cbar[j]) / (1.0 + fabs(cost));
|
alpar@1
|
2100 |
if (emax < e) emax = e;
|
alpar@1
|
2101 |
}
|
alpar@1
|
2102 |
xfree(pi);
|
alpar@1
|
2103 |
return emax;
|
alpar@1
|
2104 |
}
|
alpar@1
|
2105 |
#endif
|
alpar@1
|
2106 |
|
alpar@1
|
2107 |
/***********************************************************************
|
alpar@1
|
2108 |
* err_in_gamma - compute maximal relative error in steepest edge cff.
|
alpar@1
|
2109 |
*
|
alpar@1
|
2110 |
* This routine returns maximal relative error:
|
alpar@1
|
2111 |
*
|
alpar@1
|
2112 |
* max |gamma'[j] - gamma[j]| / (1 + |gamma'[j]),
|
alpar@1
|
2113 |
*
|
alpar@1
|
2114 |
* where gamma'[j] and gamma[j] are, respectively, directly computed
|
alpar@1
|
2115 |
* and the current (updated) steepest edge coefficients for non-basic
|
alpar@1
|
2116 |
* non-fixed variable x[j].
|
alpar@1
|
2117 |
*
|
alpar@1
|
2118 |
* NOTE: The routine is intended only for debugginig purposes. */
|
alpar@1
|
2119 |
|
alpar@1
|
2120 |
static double err_in_gamma(struct csa *csa)
|
alpar@1
|
2121 |
{ int m = csa->m;
|
alpar@1
|
2122 |
char *type = csa->type;
|
alpar@1
|
2123 |
int *head = csa->head;
|
alpar@1
|
2124 |
double *gamma = csa->gamma;
|
alpar@1
|
2125 |
double *exact = csa->work4;
|
alpar@1
|
2126 |
int i;
|
alpar@1
|
2127 |
double e, emax, temp;
|
alpar@1
|
2128 |
eval_gamma(csa, exact);
|
alpar@1
|
2129 |
emax = 0.0;
|
alpar@1
|
2130 |
for (i = 1; i <= m; i++)
|
alpar@1
|
2131 |
{ if (type[head[i]] == GLP_FR)
|
alpar@1
|
2132 |
{ xassert(gamma[i] == 1.0);
|
alpar@1
|
2133 |
xassert(exact[i] == 1.0);
|
alpar@1
|
2134 |
continue;
|
alpar@1
|
2135 |
}
|
alpar@1
|
2136 |
temp = exact[i];
|
alpar@1
|
2137 |
e = fabs(temp - gamma[i]) / (1.0 + fabs(temp));
|
alpar@1
|
2138 |
if (emax < e) emax = e;
|
alpar@1
|
2139 |
}
|
alpar@1
|
2140 |
return emax;
|
alpar@1
|
2141 |
}
|
alpar@1
|
2142 |
|
alpar@1
|
2143 |
/***********************************************************************
|
alpar@1
|
2144 |
* change_basis - change basis header
|
alpar@1
|
2145 |
*
|
alpar@1
|
2146 |
* This routine changes the basis header to make it corresponding to
|
alpar@1
|
2147 |
* the adjacent basis. */
|
alpar@1
|
2148 |
|
alpar@1
|
2149 |
static void change_basis(struct csa *csa)
|
alpar@1
|
2150 |
{ int m = csa->m;
|
alpar@1
|
2151 |
#ifdef GLP_DEBUG
|
alpar@1
|
2152 |
int n = csa->n;
|
alpar@1
|
2153 |
#endif
|
alpar@1
|
2154 |
char *type = csa->type;
|
alpar@1
|
2155 |
int *head = csa->head;
|
alpar@1
|
2156 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
2157 |
int *bind = csa->bind;
|
alpar@1
|
2158 |
#endif
|
alpar@1
|
2159 |
char *stat = csa->stat;
|
alpar@1
|
2160 |
int p = csa->p;
|
alpar@1
|
2161 |
double delta = csa->delta;
|
alpar@1
|
2162 |
int q = csa->q;
|
alpar@1
|
2163 |
int k;
|
alpar@1
|
2164 |
/* xB[p] leaves the basis, xN[q] enters the basis */
|
alpar@1
|
2165 |
#ifdef GLP_DEBUG
|
alpar@1
|
2166 |
xassert(1 <= p && p <= m);
|
alpar@1
|
2167 |
xassert(1 <= q && q <= n);
|
alpar@1
|
2168 |
#endif
|
alpar@1
|
2169 |
/* xB[p] <-> xN[q] */
|
alpar@1
|
2170 |
k = head[p], head[p] = head[m+q], head[m+q] = k;
|
alpar@1
|
2171 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
2172 |
bind[head[p]] = p, bind[head[m+q]] = m + q;
|
alpar@1
|
2173 |
#endif
|
alpar@1
|
2174 |
if (type[k] == GLP_FX)
|
alpar@1
|
2175 |
stat[q] = GLP_NS;
|
alpar@1
|
2176 |
else if (delta > 0.0)
|
alpar@1
|
2177 |
{
|
alpar@1
|
2178 |
#ifdef GLP_DEBUG
|
alpar@1
|
2179 |
xassert(type[k] == GLP_LO || type[k] == GLP_DB);
|
alpar@1
|
2180 |
#endif
|
alpar@1
|
2181 |
stat[q] = GLP_NL;
|
alpar@1
|
2182 |
}
|
alpar@1
|
2183 |
else /* delta < 0.0 */
|
alpar@1
|
2184 |
{
|
alpar@1
|
2185 |
#ifdef GLP_DEBUG
|
alpar@1
|
2186 |
xassert(type[k] == GLP_UP || type[k] == GLP_DB);
|
alpar@1
|
2187 |
#endif
|
alpar@1
|
2188 |
stat[q] = GLP_NU;
|
alpar@1
|
2189 |
}
|
alpar@1
|
2190 |
return;
|
alpar@1
|
2191 |
}
|
alpar@1
|
2192 |
|
alpar@1
|
2193 |
/***********************************************************************
|
alpar@1
|
2194 |
* check_feas - check dual feasibility of basic solution
|
alpar@1
|
2195 |
*
|
alpar@1
|
2196 |
* If the current basic solution is dual feasible within a tolerance,
|
alpar@1
|
2197 |
* this routine returns zero, otherwise it returns non-zero. */
|
alpar@1
|
2198 |
|
alpar@1
|
2199 |
static int check_feas(struct csa *csa, double tol_dj)
|
alpar@1
|
2200 |
{ int m = csa->m;
|
alpar@1
|
2201 |
int n = csa->n;
|
alpar@1
|
2202 |
char *orig_type = csa->orig_type;
|
alpar@1
|
2203 |
int *head = csa->head;
|
alpar@1
|
2204 |
double *cbar = csa->cbar;
|
alpar@1
|
2205 |
int j, k;
|
alpar@1
|
2206 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2207 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
2208 |
#ifdef GLP_DEBUG
|
alpar@1
|
2209 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2210 |
#endif
|
alpar@1
|
2211 |
if (cbar[j] < - tol_dj)
|
alpar@1
|
2212 |
if (orig_type[k] == GLP_LO || orig_type[k] == GLP_FR)
|
alpar@1
|
2213 |
return 1;
|
alpar@1
|
2214 |
if (cbar[j] > + tol_dj)
|
alpar@1
|
2215 |
if (orig_type[k] == GLP_UP || orig_type[k] == GLP_FR)
|
alpar@1
|
2216 |
return 1;
|
alpar@1
|
2217 |
}
|
alpar@1
|
2218 |
return 0;
|
alpar@1
|
2219 |
}
|
alpar@1
|
2220 |
|
alpar@1
|
2221 |
/***********************************************************************
|
alpar@1
|
2222 |
* set_aux_bnds - assign auxiliary bounds to variables
|
alpar@1
|
2223 |
*
|
alpar@1
|
2224 |
* This routine assigns auxiliary bounds to variables to construct an
|
alpar@1
|
2225 |
* LP problem solved on phase I. */
|
alpar@1
|
2226 |
|
alpar@1
|
2227 |
static void set_aux_bnds(struct csa *csa)
|
alpar@1
|
2228 |
{ int m = csa->m;
|
alpar@1
|
2229 |
int n = csa->n;
|
alpar@1
|
2230 |
char *type = csa->type;
|
alpar@1
|
2231 |
double *lb = csa->lb;
|
alpar@1
|
2232 |
double *ub = csa->ub;
|
alpar@1
|
2233 |
char *orig_type = csa->orig_type;
|
alpar@1
|
2234 |
int *head = csa->head;
|
alpar@1
|
2235 |
char *stat = csa->stat;
|
alpar@1
|
2236 |
double *cbar = csa->cbar;
|
alpar@1
|
2237 |
int j, k;
|
alpar@1
|
2238 |
for (k = 1; k <= m+n; k++)
|
alpar@1
|
2239 |
{ switch (orig_type[k])
|
alpar@1
|
2240 |
{ case GLP_FR:
|
alpar@1
|
2241 |
#if 0
|
alpar@1
|
2242 |
type[k] = GLP_DB, lb[k] = -1.0, ub[k] = +1.0;
|
alpar@1
|
2243 |
#else
|
alpar@1
|
2244 |
/* to force free variables to enter the basis */
|
alpar@1
|
2245 |
type[k] = GLP_DB, lb[k] = -1e3, ub[k] = +1e3;
|
alpar@1
|
2246 |
#endif
|
alpar@1
|
2247 |
break;
|
alpar@1
|
2248 |
case GLP_LO:
|
alpar@1
|
2249 |
type[k] = GLP_DB, lb[k] = 0.0, ub[k] = +1.0;
|
alpar@1
|
2250 |
break;
|
alpar@1
|
2251 |
case GLP_UP:
|
alpar@1
|
2252 |
type[k] = GLP_DB, lb[k] = -1.0, ub[k] = 0.0;
|
alpar@1
|
2253 |
break;
|
alpar@1
|
2254 |
case GLP_DB:
|
alpar@1
|
2255 |
case GLP_FX:
|
alpar@1
|
2256 |
type[k] = GLP_FX, lb[k] = ub[k] = 0.0;
|
alpar@1
|
2257 |
break;
|
alpar@1
|
2258 |
default:
|
alpar@1
|
2259 |
xassert(orig_type != orig_type);
|
alpar@1
|
2260 |
}
|
alpar@1
|
2261 |
}
|
alpar@1
|
2262 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2263 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
2264 |
#ifdef GLP_DEBUG
|
alpar@1
|
2265 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2266 |
#endif
|
alpar@1
|
2267 |
if (type[k] == GLP_FX)
|
alpar@1
|
2268 |
stat[j] = GLP_NS;
|
alpar@1
|
2269 |
else if (cbar[j] >= 0.0)
|
alpar@1
|
2270 |
stat[j] = GLP_NL;
|
alpar@1
|
2271 |
else
|
alpar@1
|
2272 |
stat[j] = GLP_NU;
|
alpar@1
|
2273 |
}
|
alpar@1
|
2274 |
return;
|
alpar@1
|
2275 |
}
|
alpar@1
|
2276 |
|
alpar@1
|
2277 |
/***********************************************************************
|
alpar@1
|
2278 |
* set_orig_bnds - restore original bounds of variables
|
alpar@1
|
2279 |
*
|
alpar@1
|
2280 |
* This routine restores original types and bounds of variables and
|
alpar@1
|
2281 |
* determines statuses of non-basic variables assuming that the current
|
alpar@1
|
2282 |
* basis is dual feasible. */
|
alpar@1
|
2283 |
|
alpar@1
|
2284 |
static void set_orig_bnds(struct csa *csa)
|
alpar@1
|
2285 |
{ int m = csa->m;
|
alpar@1
|
2286 |
int n = csa->n;
|
alpar@1
|
2287 |
char *type = csa->type;
|
alpar@1
|
2288 |
double *lb = csa->lb;
|
alpar@1
|
2289 |
double *ub = csa->ub;
|
alpar@1
|
2290 |
char *orig_type = csa->orig_type;
|
alpar@1
|
2291 |
double *orig_lb = csa->orig_lb;
|
alpar@1
|
2292 |
double *orig_ub = csa->orig_ub;
|
alpar@1
|
2293 |
int *head = csa->head;
|
alpar@1
|
2294 |
char *stat = csa->stat;
|
alpar@1
|
2295 |
double *cbar = csa->cbar;
|
alpar@1
|
2296 |
int j, k;
|
alpar@1
|
2297 |
memcpy(&type[1], &orig_type[1], (m+n) * sizeof(char));
|
alpar@1
|
2298 |
memcpy(&lb[1], &orig_lb[1], (m+n) * sizeof(double));
|
alpar@1
|
2299 |
memcpy(&ub[1], &orig_ub[1], (m+n) * sizeof(double));
|
alpar@1
|
2300 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2301 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
2302 |
#ifdef GLP_DEBUG
|
alpar@1
|
2303 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2304 |
#endif
|
alpar@1
|
2305 |
switch (type[k])
|
alpar@1
|
2306 |
{ case GLP_FR:
|
alpar@1
|
2307 |
stat[j] = GLP_NF;
|
alpar@1
|
2308 |
break;
|
alpar@1
|
2309 |
case GLP_LO:
|
alpar@1
|
2310 |
stat[j] = GLP_NL;
|
alpar@1
|
2311 |
break;
|
alpar@1
|
2312 |
case GLP_UP:
|
alpar@1
|
2313 |
stat[j] = GLP_NU;
|
alpar@1
|
2314 |
break;
|
alpar@1
|
2315 |
case GLP_DB:
|
alpar@1
|
2316 |
if (cbar[j] >= +DBL_EPSILON)
|
alpar@1
|
2317 |
stat[j] = GLP_NL;
|
alpar@1
|
2318 |
else if (cbar[j] <= -DBL_EPSILON)
|
alpar@1
|
2319 |
stat[j] = GLP_NU;
|
alpar@1
|
2320 |
else if (fabs(lb[k]) <= fabs(ub[k]))
|
alpar@1
|
2321 |
stat[j] = GLP_NL;
|
alpar@1
|
2322 |
else
|
alpar@1
|
2323 |
stat[j] = GLP_NU;
|
alpar@1
|
2324 |
break;
|
alpar@1
|
2325 |
case GLP_FX:
|
alpar@1
|
2326 |
stat[j] = GLP_NS;
|
alpar@1
|
2327 |
break;
|
alpar@1
|
2328 |
default:
|
alpar@1
|
2329 |
xassert(type != type);
|
alpar@1
|
2330 |
}
|
alpar@1
|
2331 |
}
|
alpar@1
|
2332 |
return;
|
alpar@1
|
2333 |
}
|
alpar@1
|
2334 |
|
alpar@1
|
2335 |
/***********************************************************************
|
alpar@1
|
2336 |
* check_stab - check numerical stability of basic solution
|
alpar@1
|
2337 |
*
|
alpar@1
|
2338 |
* If the current basic solution is dual feasible within a tolerance,
|
alpar@1
|
2339 |
* this routine returns zero, otherwise it returns non-zero. */
|
alpar@1
|
2340 |
|
alpar@1
|
2341 |
static int check_stab(struct csa *csa, double tol_dj)
|
alpar@1
|
2342 |
{ int n = csa->n;
|
alpar@1
|
2343 |
char *stat = csa->stat;
|
alpar@1
|
2344 |
double *cbar = csa->cbar;
|
alpar@1
|
2345 |
int j;
|
alpar@1
|
2346 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2347 |
{ if (cbar[j] < - tol_dj)
|
alpar@1
|
2348 |
if (stat[j] == GLP_NL || stat[j] == GLP_NF) return 1;
|
alpar@1
|
2349 |
if (cbar[j] > + tol_dj)
|
alpar@1
|
2350 |
if (stat[j] == GLP_NU || stat[j] == GLP_NF) return 1;
|
alpar@1
|
2351 |
}
|
alpar@1
|
2352 |
return 0;
|
alpar@1
|
2353 |
}
|
alpar@1
|
2354 |
|
alpar@1
|
2355 |
#if 1 /* copied from primal */
|
alpar@1
|
2356 |
/***********************************************************************
|
alpar@1
|
2357 |
* eval_obj - compute original objective function
|
alpar@1
|
2358 |
*
|
alpar@1
|
2359 |
* This routine computes the current value of the original objective
|
alpar@1
|
2360 |
* function. */
|
alpar@1
|
2361 |
|
alpar@1
|
2362 |
static double eval_obj(struct csa *csa)
|
alpar@1
|
2363 |
{ int m = csa->m;
|
alpar@1
|
2364 |
int n = csa->n;
|
alpar@1
|
2365 |
double *obj = csa->obj;
|
alpar@1
|
2366 |
int *head = csa->head;
|
alpar@1
|
2367 |
double *bbar = csa->bbar;
|
alpar@1
|
2368 |
int i, j, k;
|
alpar@1
|
2369 |
double sum;
|
alpar@1
|
2370 |
sum = obj[0];
|
alpar@1
|
2371 |
/* walk through the list of basic variables */
|
alpar@1
|
2372 |
for (i = 1; i <= m; i++)
|
alpar@1
|
2373 |
{ k = head[i]; /* x[k] = xB[i] */
|
alpar@1
|
2374 |
#ifdef GLP_DEBUG
|
alpar@1
|
2375 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2376 |
#endif
|
alpar@1
|
2377 |
if (k > m)
|
alpar@1
|
2378 |
sum += obj[k-m] * bbar[i];
|
alpar@1
|
2379 |
}
|
alpar@1
|
2380 |
/* walk through the list of non-basic variables */
|
alpar@1
|
2381 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2382 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
2383 |
#ifdef GLP_DEBUG
|
alpar@1
|
2384 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2385 |
#endif
|
alpar@1
|
2386 |
if (k > m)
|
alpar@1
|
2387 |
sum += obj[k-m] * get_xN(csa, j);
|
alpar@1
|
2388 |
}
|
alpar@1
|
2389 |
return sum;
|
alpar@1
|
2390 |
}
|
alpar@1
|
2391 |
#endif
|
alpar@1
|
2392 |
|
alpar@1
|
2393 |
/***********************************************************************
|
alpar@1
|
2394 |
* display - display the search progress
|
alpar@1
|
2395 |
*
|
alpar@1
|
2396 |
* This routine displays some information about the search progress. */
|
alpar@1
|
2397 |
|
alpar@1
|
2398 |
static void display(struct csa *csa, const glp_smcp *parm, int spec)
|
alpar@1
|
2399 |
{ int m = csa->m;
|
alpar@1
|
2400 |
int n = csa->n;
|
alpar@1
|
2401 |
double *coef = csa->coef;
|
alpar@1
|
2402 |
char *orig_type = csa->orig_type;
|
alpar@1
|
2403 |
int *head = csa->head;
|
alpar@1
|
2404 |
char *stat = csa->stat;
|
alpar@1
|
2405 |
int phase = csa->phase;
|
alpar@1
|
2406 |
double *bbar = csa->bbar;
|
alpar@1
|
2407 |
double *cbar = csa->cbar;
|
alpar@1
|
2408 |
int i, j, cnt;
|
alpar@1
|
2409 |
double sum;
|
alpar@1
|
2410 |
if (parm->msg_lev < GLP_MSG_ON) goto skip;
|
alpar@1
|
2411 |
if (parm->out_dly > 0 &&
|
alpar@1
|
2412 |
1000.0 * xdifftime(xtime(), csa->tm_beg) < parm->out_dly)
|
alpar@1
|
2413 |
goto skip;
|
alpar@1
|
2414 |
if (csa->it_cnt == csa->it_dpy) goto skip;
|
alpar@1
|
2415 |
if (!spec && csa->it_cnt % parm->out_frq != 0) goto skip;
|
alpar@1
|
2416 |
/* compute the sum of dual infeasibilities */
|
alpar@1
|
2417 |
sum = 0.0;
|
alpar@1
|
2418 |
if (phase == 1)
|
alpar@1
|
2419 |
{ for (i = 1; i <= m; i++)
|
alpar@1
|
2420 |
sum -= coef[head[i]] * bbar[i];
|
alpar@1
|
2421 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2422 |
sum -= coef[head[m+j]] * get_xN(csa, j);
|
alpar@1
|
2423 |
}
|
alpar@1
|
2424 |
else
|
alpar@1
|
2425 |
{ for (j = 1; j <= n; j++)
|
alpar@1
|
2426 |
{ if (cbar[j] < 0.0)
|
alpar@1
|
2427 |
if (stat[j] == GLP_NL || stat[j] == GLP_NF)
|
alpar@1
|
2428 |
sum -= cbar[j];
|
alpar@1
|
2429 |
if (cbar[j] > 0.0)
|
alpar@1
|
2430 |
if (stat[j] == GLP_NU || stat[j] == GLP_NF)
|
alpar@1
|
2431 |
sum += cbar[j];
|
alpar@1
|
2432 |
}
|
alpar@1
|
2433 |
}
|
alpar@1
|
2434 |
/* determine the number of basic fixed variables */
|
alpar@1
|
2435 |
cnt = 0;
|
alpar@1
|
2436 |
for (i = 1; i <= m; i++)
|
alpar@1
|
2437 |
if (orig_type[head[i]] == GLP_FX) cnt++;
|
alpar@1
|
2438 |
if (csa->phase == 1)
|
alpar@1
|
2439 |
xprintf(" %6d: %24s infeas = %10.3e (%d)\n",
|
alpar@1
|
2440 |
csa->it_cnt, "", sum, cnt);
|
alpar@1
|
2441 |
else
|
alpar@1
|
2442 |
xprintf("|%6d: obj = %17.9e infeas = %10.3e (%d)\n",
|
alpar@1
|
2443 |
csa->it_cnt, eval_obj(csa), sum, cnt);
|
alpar@1
|
2444 |
csa->it_dpy = csa->it_cnt;
|
alpar@1
|
2445 |
skip: return;
|
alpar@1
|
2446 |
}
|
alpar@1
|
2447 |
|
alpar@1
|
2448 |
#if 1 /* copied from primal */
|
alpar@1
|
2449 |
/***********************************************************************
|
alpar@1
|
2450 |
* store_sol - store basic solution back to the problem object
|
alpar@1
|
2451 |
*
|
alpar@1
|
2452 |
* This routine stores basic solution components back to the problem
|
alpar@1
|
2453 |
* object. */
|
alpar@1
|
2454 |
|
alpar@1
|
2455 |
static void store_sol(struct csa *csa, glp_prob *lp, int p_stat,
|
alpar@1
|
2456 |
int d_stat, int ray)
|
alpar@1
|
2457 |
{ int m = csa->m;
|
alpar@1
|
2458 |
int n = csa->n;
|
alpar@1
|
2459 |
double zeta = csa->zeta;
|
alpar@1
|
2460 |
int *head = csa->head;
|
alpar@1
|
2461 |
char *stat = csa->stat;
|
alpar@1
|
2462 |
double *bbar = csa->bbar;
|
alpar@1
|
2463 |
double *cbar = csa->cbar;
|
alpar@1
|
2464 |
int i, j, k;
|
alpar@1
|
2465 |
#ifdef GLP_DEBUG
|
alpar@1
|
2466 |
xassert(lp->m == m);
|
alpar@1
|
2467 |
xassert(lp->n == n);
|
alpar@1
|
2468 |
#endif
|
alpar@1
|
2469 |
/* basis factorization */
|
alpar@1
|
2470 |
#ifdef GLP_DEBUG
|
alpar@1
|
2471 |
xassert(!lp->valid && lp->bfd == NULL);
|
alpar@1
|
2472 |
xassert(csa->valid && csa->bfd != NULL);
|
alpar@1
|
2473 |
#endif
|
alpar@1
|
2474 |
lp->valid = 1, csa->valid = 0;
|
alpar@1
|
2475 |
lp->bfd = csa->bfd, csa->bfd = NULL;
|
alpar@1
|
2476 |
memcpy(&lp->head[1], &head[1], m * sizeof(int));
|
alpar@1
|
2477 |
/* basic solution status */
|
alpar@1
|
2478 |
lp->pbs_stat = p_stat;
|
alpar@1
|
2479 |
lp->dbs_stat = d_stat;
|
alpar@1
|
2480 |
/* objective function value */
|
alpar@1
|
2481 |
lp->obj_val = eval_obj(csa);
|
alpar@1
|
2482 |
/* simplex iteration count */
|
alpar@1
|
2483 |
lp->it_cnt = csa->it_cnt;
|
alpar@1
|
2484 |
/* unbounded ray */
|
alpar@1
|
2485 |
lp->some = ray;
|
alpar@1
|
2486 |
/* basic variables */
|
alpar@1
|
2487 |
for (i = 1; i <= m; i++)
|
alpar@1
|
2488 |
{ k = head[i]; /* x[k] = xB[i] */
|
alpar@1
|
2489 |
#ifdef GLP_DEBUG
|
alpar@1
|
2490 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2491 |
#endif
|
alpar@1
|
2492 |
if (k <= m)
|
alpar@1
|
2493 |
{ GLPROW *row = lp->row[k];
|
alpar@1
|
2494 |
row->stat = GLP_BS;
|
alpar@1
|
2495 |
row->bind = i;
|
alpar@1
|
2496 |
row->prim = bbar[i] / row->rii;
|
alpar@1
|
2497 |
row->dual = 0.0;
|
alpar@1
|
2498 |
}
|
alpar@1
|
2499 |
else
|
alpar@1
|
2500 |
{ GLPCOL *col = lp->col[k-m];
|
alpar@1
|
2501 |
col->stat = GLP_BS;
|
alpar@1
|
2502 |
col->bind = i;
|
alpar@1
|
2503 |
col->prim = bbar[i] * col->sjj;
|
alpar@1
|
2504 |
col->dual = 0.0;
|
alpar@1
|
2505 |
}
|
alpar@1
|
2506 |
}
|
alpar@1
|
2507 |
/* non-basic variables */
|
alpar@1
|
2508 |
for (j = 1; j <= n; j++)
|
alpar@1
|
2509 |
{ k = head[m+j]; /* x[k] = xN[j] */
|
alpar@1
|
2510 |
#ifdef GLP_DEBUG
|
alpar@1
|
2511 |
xassert(1 <= k && k <= m+n);
|
alpar@1
|
2512 |
#endif
|
alpar@1
|
2513 |
if (k <= m)
|
alpar@1
|
2514 |
{ GLPROW *row = lp->row[k];
|
alpar@1
|
2515 |
row->stat = stat[j];
|
alpar@1
|
2516 |
row->bind = 0;
|
alpar@1
|
2517 |
#if 0
|
alpar@1
|
2518 |
row->prim = get_xN(csa, j) / row->rii;
|
alpar@1
|
2519 |
#else
|
alpar@1
|
2520 |
switch (stat[j])
|
alpar@1
|
2521 |
{ case GLP_NL:
|
alpar@1
|
2522 |
row->prim = row->lb; break;
|
alpar@1
|
2523 |
case GLP_NU:
|
alpar@1
|
2524 |
row->prim = row->ub; break;
|
alpar@1
|
2525 |
case GLP_NF:
|
alpar@1
|
2526 |
row->prim = 0.0; break;
|
alpar@1
|
2527 |
case GLP_NS:
|
alpar@1
|
2528 |
row->prim = row->lb; break;
|
alpar@1
|
2529 |
default:
|
alpar@1
|
2530 |
xassert(stat != stat);
|
alpar@1
|
2531 |
}
|
alpar@1
|
2532 |
#endif
|
alpar@1
|
2533 |
row->dual = (cbar[j] * row->rii) / zeta;
|
alpar@1
|
2534 |
}
|
alpar@1
|
2535 |
else
|
alpar@1
|
2536 |
{ GLPCOL *col = lp->col[k-m];
|
alpar@1
|
2537 |
col->stat = stat[j];
|
alpar@1
|
2538 |
col->bind = 0;
|
alpar@1
|
2539 |
#if 0
|
alpar@1
|
2540 |
col->prim = get_xN(csa, j) * col->sjj;
|
alpar@1
|
2541 |
#else
|
alpar@1
|
2542 |
switch (stat[j])
|
alpar@1
|
2543 |
{ case GLP_NL:
|
alpar@1
|
2544 |
col->prim = col->lb; break;
|
alpar@1
|
2545 |
case GLP_NU:
|
alpar@1
|
2546 |
col->prim = col->ub; break;
|
alpar@1
|
2547 |
case GLP_NF:
|
alpar@1
|
2548 |
col->prim = 0.0; break;
|
alpar@1
|
2549 |
case GLP_NS:
|
alpar@1
|
2550 |
col->prim = col->lb; break;
|
alpar@1
|
2551 |
default:
|
alpar@1
|
2552 |
xassert(stat != stat);
|
alpar@1
|
2553 |
}
|
alpar@1
|
2554 |
#endif
|
alpar@1
|
2555 |
col->dual = (cbar[j] / col->sjj) / zeta;
|
alpar@1
|
2556 |
}
|
alpar@1
|
2557 |
}
|
alpar@1
|
2558 |
return;
|
alpar@1
|
2559 |
}
|
alpar@1
|
2560 |
#endif
|
alpar@1
|
2561 |
|
alpar@1
|
2562 |
/***********************************************************************
|
alpar@1
|
2563 |
* free_csa - deallocate common storage area
|
alpar@1
|
2564 |
*
|
alpar@1
|
2565 |
* This routine frees all the memory allocated to arrays in the common
|
alpar@1
|
2566 |
* storage area (CSA). */
|
alpar@1
|
2567 |
|
alpar@1
|
2568 |
static void free_csa(struct csa *csa)
|
alpar@1
|
2569 |
{ xfree(csa->type);
|
alpar@1
|
2570 |
xfree(csa->lb);
|
alpar@1
|
2571 |
xfree(csa->ub);
|
alpar@1
|
2572 |
xfree(csa->coef);
|
alpar@1
|
2573 |
xfree(csa->orig_type);
|
alpar@1
|
2574 |
xfree(csa->orig_lb);
|
alpar@1
|
2575 |
xfree(csa->orig_ub);
|
alpar@1
|
2576 |
xfree(csa->obj);
|
alpar@1
|
2577 |
xfree(csa->A_ptr);
|
alpar@1
|
2578 |
xfree(csa->A_ind);
|
alpar@1
|
2579 |
xfree(csa->A_val);
|
alpar@1
|
2580 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
2581 |
xfree(csa->AT_ptr);
|
alpar@1
|
2582 |
xfree(csa->AT_ind);
|
alpar@1
|
2583 |
xfree(csa->AT_val);
|
alpar@1
|
2584 |
#endif
|
alpar@1
|
2585 |
xfree(csa->head);
|
alpar@1
|
2586 |
#if 1 /* 06/IV-2009 */
|
alpar@1
|
2587 |
xfree(csa->bind);
|
alpar@1
|
2588 |
#endif
|
alpar@1
|
2589 |
xfree(csa->stat);
|
alpar@1
|
2590 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
2591 |
xfree(csa->N_ptr);
|
alpar@1
|
2592 |
xfree(csa->N_len);
|
alpar@1
|
2593 |
xfree(csa->N_ind);
|
alpar@1
|
2594 |
xfree(csa->N_val);
|
alpar@1
|
2595 |
#endif
|
alpar@1
|
2596 |
xfree(csa->bbar);
|
alpar@1
|
2597 |
xfree(csa->cbar);
|
alpar@1
|
2598 |
xfree(csa->refsp);
|
alpar@1
|
2599 |
xfree(csa->gamma);
|
alpar@1
|
2600 |
xfree(csa->trow_ind);
|
alpar@1
|
2601 |
xfree(csa->trow_vec);
|
alpar@1
|
2602 |
#ifdef GLP_LONG_STEP /* 07/IV-2009 */
|
alpar@1
|
2603 |
xfree(csa->bkpt);
|
alpar@1
|
2604 |
#endif
|
alpar@1
|
2605 |
xfree(csa->tcol_ind);
|
alpar@1
|
2606 |
xfree(csa->tcol_vec);
|
alpar@1
|
2607 |
xfree(csa->work1);
|
alpar@1
|
2608 |
xfree(csa->work2);
|
alpar@1
|
2609 |
xfree(csa->work3);
|
alpar@1
|
2610 |
xfree(csa->work4);
|
alpar@1
|
2611 |
xfree(csa);
|
alpar@1
|
2612 |
return;
|
alpar@1
|
2613 |
}
|
alpar@1
|
2614 |
|
alpar@1
|
2615 |
/***********************************************************************
|
alpar@1
|
2616 |
* spx_dual - core LP solver based on the dual simplex method
|
alpar@1
|
2617 |
*
|
alpar@1
|
2618 |
* SYNOPSIS
|
alpar@1
|
2619 |
*
|
alpar@1
|
2620 |
* #include "glpspx.h"
|
alpar@1
|
2621 |
* int spx_dual(glp_prob *lp, const glp_smcp *parm);
|
alpar@1
|
2622 |
*
|
alpar@1
|
2623 |
* DESCRIPTION
|
alpar@1
|
2624 |
*
|
alpar@1
|
2625 |
* The routine spx_dual is a core LP solver based on the two-phase dual
|
alpar@1
|
2626 |
* simplex method.
|
alpar@1
|
2627 |
*
|
alpar@1
|
2628 |
* RETURNS
|
alpar@1
|
2629 |
*
|
alpar@1
|
2630 |
* 0 LP instance has been successfully solved.
|
alpar@1
|
2631 |
*
|
alpar@1
|
2632 |
* GLP_EOBJLL
|
alpar@1
|
2633 |
* Objective lower limit has been reached (maximization).
|
alpar@1
|
2634 |
*
|
alpar@1
|
2635 |
* GLP_EOBJUL
|
alpar@1
|
2636 |
* Objective upper limit has been reached (minimization).
|
alpar@1
|
2637 |
*
|
alpar@1
|
2638 |
* GLP_EITLIM
|
alpar@1
|
2639 |
* Iteration limit has been exhausted.
|
alpar@1
|
2640 |
*
|
alpar@1
|
2641 |
* GLP_ETMLIM
|
alpar@1
|
2642 |
* Time limit has been exhausted.
|
alpar@1
|
2643 |
*
|
alpar@1
|
2644 |
* GLP_EFAIL
|
alpar@1
|
2645 |
* The solver failed to solve LP instance. */
|
alpar@1
|
2646 |
|
alpar@1
|
2647 |
int spx_dual(glp_prob *lp, const glp_smcp *parm)
|
alpar@1
|
2648 |
{ struct csa *csa;
|
alpar@1
|
2649 |
int binv_st = 2;
|
alpar@1
|
2650 |
/* status of basis matrix factorization:
|
alpar@1
|
2651 |
0 - invalid; 1 - just computed; 2 - updated */
|
alpar@1
|
2652 |
int bbar_st = 0;
|
alpar@1
|
2653 |
/* status of primal values of basic variables:
|
alpar@1
|
2654 |
0 - invalid; 1 - just computed; 2 - updated */
|
alpar@1
|
2655 |
int cbar_st = 0;
|
alpar@1
|
2656 |
/* status of reduced costs of non-basic variables:
|
alpar@1
|
2657 |
0 - invalid; 1 - just computed; 2 - updated */
|
alpar@1
|
2658 |
int rigorous = 0;
|
alpar@1
|
2659 |
/* rigorous mode flag; this flag is used to enable iterative
|
alpar@1
|
2660 |
refinement on computing pivot rows and columns of the simplex
|
alpar@1
|
2661 |
table */
|
alpar@1
|
2662 |
int check = 0;
|
alpar@1
|
2663 |
int p_stat, d_stat, ret;
|
alpar@1
|
2664 |
/* allocate and initialize the common storage area */
|
alpar@1
|
2665 |
csa = alloc_csa(lp);
|
alpar@1
|
2666 |
init_csa(csa, lp);
|
alpar@1
|
2667 |
if (parm->msg_lev >= GLP_MSG_DBG)
|
alpar@1
|
2668 |
xprintf("Objective scale factor = %g\n", csa->zeta);
|
alpar@1
|
2669 |
loop: /* main loop starts here */
|
alpar@1
|
2670 |
/* compute factorization of the basis matrix */
|
alpar@1
|
2671 |
if (binv_st == 0)
|
alpar@1
|
2672 |
{ ret = invert_B(csa);
|
alpar@1
|
2673 |
if (ret != 0)
|
alpar@1
|
2674 |
{ if (parm->msg_lev >= GLP_MSG_ERR)
|
alpar@1
|
2675 |
{ xprintf("Error: unable to factorize the basis matrix (%d"
|
alpar@1
|
2676 |
")\n", ret);
|
alpar@1
|
2677 |
xprintf("Sorry, basis recovery procedure not implemented"
|
alpar@1
|
2678 |
" yet\n");
|
alpar@1
|
2679 |
}
|
alpar@1
|
2680 |
xassert(!lp->valid && lp->bfd == NULL);
|
alpar@1
|
2681 |
lp->bfd = csa->bfd, csa->bfd = NULL;
|
alpar@1
|
2682 |
lp->pbs_stat = lp->dbs_stat = GLP_UNDEF;
|
alpar@1
|
2683 |
lp->obj_val = 0.0;
|
alpar@1
|
2684 |
lp->it_cnt = csa->it_cnt;
|
alpar@1
|
2685 |
lp->some = 0;
|
alpar@1
|
2686 |
ret = GLP_EFAIL;
|
alpar@1
|
2687 |
goto done;
|
alpar@1
|
2688 |
}
|
alpar@1
|
2689 |
csa->valid = 1;
|
alpar@1
|
2690 |
binv_st = 1; /* just computed */
|
alpar@1
|
2691 |
/* invalidate basic solution components */
|
alpar@1
|
2692 |
bbar_st = cbar_st = 0;
|
alpar@1
|
2693 |
}
|
alpar@1
|
2694 |
/* compute reduced costs of non-basic variables */
|
alpar@1
|
2695 |
if (cbar_st == 0)
|
alpar@1
|
2696 |
{ eval_cbar(csa);
|
alpar@1
|
2697 |
cbar_st = 1; /* just computed */
|
alpar@1
|
2698 |
/* determine the search phase, if not determined yet */
|
alpar@1
|
2699 |
if (csa->phase == 0)
|
alpar@1
|
2700 |
{ if (check_feas(csa, 0.90 * parm->tol_dj) != 0)
|
alpar@1
|
2701 |
{ /* current basic solution is dual infeasible */
|
alpar@1
|
2702 |
/* start searching for dual feasible solution */
|
alpar@1
|
2703 |
csa->phase = 1;
|
alpar@1
|
2704 |
set_aux_bnds(csa);
|
alpar@1
|
2705 |
}
|
alpar@1
|
2706 |
else
|
alpar@1
|
2707 |
{ /* current basic solution is dual feasible */
|
alpar@1
|
2708 |
/* start searching for optimal solution */
|
alpar@1
|
2709 |
csa->phase = 2;
|
alpar@1
|
2710 |
set_orig_bnds(csa);
|
alpar@1
|
2711 |
}
|
alpar@1
|
2712 |
xassert(check_stab(csa, parm->tol_dj) == 0);
|
alpar@1
|
2713 |
/* some non-basic double-bounded variables might become
|
alpar@1
|
2714 |
fixed (on phase I) or vice versa (on phase II) */
|
alpar@1
|
2715 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
2716 |
build_N(csa);
|
alpar@1
|
2717 |
#endif
|
alpar@1
|
2718 |
csa->refct = 0;
|
alpar@1
|
2719 |
/* bounds of non-basic variables have been changed, so
|
alpar@1
|
2720 |
invalidate primal values */
|
alpar@1
|
2721 |
bbar_st = 0;
|
alpar@1
|
2722 |
}
|
alpar@1
|
2723 |
/* make sure that the current basic solution remains dual
|
alpar@1
|
2724 |
feasible */
|
alpar@1
|
2725 |
if (check_stab(csa, parm->tol_dj) != 0)
|
alpar@1
|
2726 |
{ if (parm->msg_lev >= GLP_MSG_ERR)
|
alpar@1
|
2727 |
xprintf("Warning: numerical instability (dual simplex, p"
|
alpar@1
|
2728 |
"hase %s)\n", csa->phase == 1 ? "I" : "II");
|
alpar@1
|
2729 |
#if 1
|
alpar@1
|
2730 |
if (parm->meth == GLP_DUALP)
|
alpar@1
|
2731 |
{ store_sol(csa, lp, GLP_UNDEF, GLP_UNDEF, 0);
|
alpar@1
|
2732 |
ret = GLP_EFAIL;
|
alpar@1
|
2733 |
goto done;
|
alpar@1
|
2734 |
}
|
alpar@1
|
2735 |
#endif
|
alpar@1
|
2736 |
/* restart the search */
|
alpar@1
|
2737 |
csa->phase = 0;
|
alpar@1
|
2738 |
binv_st = 0;
|
alpar@1
|
2739 |
rigorous = 5;
|
alpar@1
|
2740 |
goto loop;
|
alpar@1
|
2741 |
}
|
alpar@1
|
2742 |
}
|
alpar@1
|
2743 |
xassert(csa->phase == 1 || csa->phase == 2);
|
alpar@1
|
2744 |
/* on phase I we do not need to wait until the current basic
|
alpar@1
|
2745 |
solution becomes primal feasible; it is sufficient to make
|
alpar@1
|
2746 |
sure that all reduced costs have correct signs */
|
alpar@1
|
2747 |
if (csa->phase == 1 && check_feas(csa, parm->tol_dj) == 0)
|
alpar@1
|
2748 |
{ /* the current basis is dual feasible; switch to phase II */
|
alpar@1
|
2749 |
display(csa, parm, 1);
|
alpar@1
|
2750 |
csa->phase = 2;
|
alpar@1
|
2751 |
if (cbar_st != 1)
|
alpar@1
|
2752 |
{ eval_cbar(csa);
|
alpar@1
|
2753 |
cbar_st = 1;
|
alpar@1
|
2754 |
}
|
alpar@1
|
2755 |
set_orig_bnds(csa);
|
alpar@1
|
2756 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
2757 |
build_N(csa);
|
alpar@1
|
2758 |
#endif
|
alpar@1
|
2759 |
csa->refct = 0;
|
alpar@1
|
2760 |
bbar_st = 0;
|
alpar@1
|
2761 |
}
|
alpar@1
|
2762 |
/* compute primal values of basic variables */
|
alpar@1
|
2763 |
if (bbar_st == 0)
|
alpar@1
|
2764 |
{ eval_bbar(csa);
|
alpar@1
|
2765 |
if (csa->phase == 2)
|
alpar@1
|
2766 |
csa->bbar[0] = eval_obj(csa);
|
alpar@1
|
2767 |
bbar_st = 1; /* just computed */
|
alpar@1
|
2768 |
}
|
alpar@1
|
2769 |
/* redefine the reference space, if required */
|
alpar@1
|
2770 |
switch (parm->pricing)
|
alpar@1
|
2771 |
{ case GLP_PT_STD:
|
alpar@1
|
2772 |
break;
|
alpar@1
|
2773 |
case GLP_PT_PSE:
|
alpar@1
|
2774 |
if (csa->refct == 0) reset_refsp(csa);
|
alpar@1
|
2775 |
break;
|
alpar@1
|
2776 |
default:
|
alpar@1
|
2777 |
xassert(parm != parm);
|
alpar@1
|
2778 |
}
|
alpar@1
|
2779 |
/* at this point the basis factorization and all basic solution
|
alpar@1
|
2780 |
components are valid */
|
alpar@1
|
2781 |
xassert(binv_st && bbar_st && cbar_st);
|
alpar@1
|
2782 |
/* check accuracy of current basic solution components (only for
|
alpar@1
|
2783 |
debugging) */
|
alpar@1
|
2784 |
if (check)
|
alpar@1
|
2785 |
{ double e_bbar = err_in_bbar(csa);
|
alpar@1
|
2786 |
double e_cbar = err_in_cbar(csa);
|
alpar@1
|
2787 |
double e_gamma =
|
alpar@1
|
2788 |
(parm->pricing == GLP_PT_PSE ? err_in_gamma(csa) : 0.0);
|
alpar@1
|
2789 |
xprintf("e_bbar = %10.3e; e_cbar = %10.3e; e_gamma = %10.3e\n",
|
alpar@1
|
2790 |
e_bbar, e_cbar, e_gamma);
|
alpar@1
|
2791 |
xassert(e_bbar <= 1e-5 && e_cbar <= 1e-5 && e_gamma <= 1e-3);
|
alpar@1
|
2792 |
}
|
alpar@1
|
2793 |
/* if the objective has to be maximized, check if it has reached
|
alpar@1
|
2794 |
its lower limit */
|
alpar@1
|
2795 |
if (csa->phase == 2 && csa->zeta < 0.0 &&
|
alpar@1
|
2796 |
parm->obj_ll > -DBL_MAX && csa->bbar[0] <= parm->obj_ll)
|
alpar@1
|
2797 |
{ if (bbar_st != 1 || cbar_st != 1)
|
alpar@1
|
2798 |
{ if (bbar_st != 1) bbar_st = 0;
|
alpar@1
|
2799 |
if (cbar_st != 1) cbar_st = 0;
|
alpar@1
|
2800 |
goto loop;
|
alpar@1
|
2801 |
}
|
alpar@1
|
2802 |
display(csa, parm, 1);
|
alpar@1
|
2803 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2804 |
xprintf("OBJECTIVE LOWER LIMIT REACHED; SEARCH TERMINATED\n"
|
alpar@1
|
2805 |
);
|
alpar@1
|
2806 |
store_sol(csa, lp, GLP_INFEAS, GLP_FEAS, 0);
|
alpar@1
|
2807 |
ret = GLP_EOBJLL;
|
alpar@1
|
2808 |
goto done;
|
alpar@1
|
2809 |
}
|
alpar@1
|
2810 |
/* if the objective has to be minimized, check if it has reached
|
alpar@1
|
2811 |
its upper limit */
|
alpar@1
|
2812 |
if (csa->phase == 2 && csa->zeta > 0.0 &&
|
alpar@1
|
2813 |
parm->obj_ul < +DBL_MAX && csa->bbar[0] >= parm->obj_ul)
|
alpar@1
|
2814 |
{ if (bbar_st != 1 || cbar_st != 1)
|
alpar@1
|
2815 |
{ if (bbar_st != 1) bbar_st = 0;
|
alpar@1
|
2816 |
if (cbar_st != 1) cbar_st = 0;
|
alpar@1
|
2817 |
goto loop;
|
alpar@1
|
2818 |
}
|
alpar@1
|
2819 |
display(csa, parm, 1);
|
alpar@1
|
2820 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2821 |
xprintf("OBJECTIVE UPPER LIMIT REACHED; SEARCH TERMINATED\n"
|
alpar@1
|
2822 |
);
|
alpar@1
|
2823 |
store_sol(csa, lp, GLP_INFEAS, GLP_FEAS, 0);
|
alpar@1
|
2824 |
ret = GLP_EOBJUL;
|
alpar@1
|
2825 |
goto done;
|
alpar@1
|
2826 |
}
|
alpar@1
|
2827 |
/* check if the iteration limit has been exhausted */
|
alpar@1
|
2828 |
if (parm->it_lim < INT_MAX &&
|
alpar@1
|
2829 |
csa->it_cnt - csa->it_beg >= parm->it_lim)
|
alpar@1
|
2830 |
{ if (csa->phase == 2 && bbar_st != 1 || cbar_st != 1)
|
alpar@1
|
2831 |
{ if (csa->phase == 2 && bbar_st != 1) bbar_st = 0;
|
alpar@1
|
2832 |
if (cbar_st != 1) cbar_st = 0;
|
alpar@1
|
2833 |
goto loop;
|
alpar@1
|
2834 |
}
|
alpar@1
|
2835 |
display(csa, parm, 1);
|
alpar@1
|
2836 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2837 |
xprintf("ITERATION LIMIT EXCEEDED; SEARCH TERMINATED\n");
|
alpar@1
|
2838 |
switch (csa->phase)
|
alpar@1
|
2839 |
{ case 1:
|
alpar@1
|
2840 |
d_stat = GLP_INFEAS;
|
alpar@1
|
2841 |
set_orig_bnds(csa);
|
alpar@1
|
2842 |
eval_bbar(csa);
|
alpar@1
|
2843 |
break;
|
alpar@1
|
2844 |
case 2:
|
alpar@1
|
2845 |
d_stat = GLP_FEAS;
|
alpar@1
|
2846 |
break;
|
alpar@1
|
2847 |
default:
|
alpar@1
|
2848 |
xassert(csa != csa);
|
alpar@1
|
2849 |
}
|
alpar@1
|
2850 |
store_sol(csa, lp, GLP_INFEAS, d_stat, 0);
|
alpar@1
|
2851 |
ret = GLP_EITLIM;
|
alpar@1
|
2852 |
goto done;
|
alpar@1
|
2853 |
}
|
alpar@1
|
2854 |
/* check if the time limit has been exhausted */
|
alpar@1
|
2855 |
if (parm->tm_lim < INT_MAX &&
|
alpar@1
|
2856 |
1000.0 * xdifftime(xtime(), csa->tm_beg) >= parm->tm_lim)
|
alpar@1
|
2857 |
{ if (csa->phase == 2 && bbar_st != 1 || cbar_st != 1)
|
alpar@1
|
2858 |
{ if (csa->phase == 2 && bbar_st != 1) bbar_st = 0;
|
alpar@1
|
2859 |
if (cbar_st != 1) cbar_st = 0;
|
alpar@1
|
2860 |
goto loop;
|
alpar@1
|
2861 |
}
|
alpar@1
|
2862 |
display(csa, parm, 1);
|
alpar@1
|
2863 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2864 |
xprintf("TIME LIMIT EXCEEDED; SEARCH TERMINATED\n");
|
alpar@1
|
2865 |
switch (csa->phase)
|
alpar@1
|
2866 |
{ case 1:
|
alpar@1
|
2867 |
d_stat = GLP_INFEAS;
|
alpar@1
|
2868 |
set_orig_bnds(csa);
|
alpar@1
|
2869 |
eval_bbar(csa);
|
alpar@1
|
2870 |
break;
|
alpar@1
|
2871 |
case 2:
|
alpar@1
|
2872 |
d_stat = GLP_FEAS;
|
alpar@1
|
2873 |
break;
|
alpar@1
|
2874 |
default:
|
alpar@1
|
2875 |
xassert(csa != csa);
|
alpar@1
|
2876 |
}
|
alpar@1
|
2877 |
store_sol(csa, lp, GLP_INFEAS, d_stat, 0);
|
alpar@1
|
2878 |
ret = GLP_ETMLIM;
|
alpar@1
|
2879 |
goto done;
|
alpar@1
|
2880 |
}
|
alpar@1
|
2881 |
/* display the search progress */
|
alpar@1
|
2882 |
display(csa, parm, 0);
|
alpar@1
|
2883 |
/* choose basic variable xB[p] */
|
alpar@1
|
2884 |
chuzr(csa, parm->tol_bnd);
|
alpar@1
|
2885 |
if (csa->p == 0)
|
alpar@1
|
2886 |
{ if (bbar_st != 1 || cbar_st != 1)
|
alpar@1
|
2887 |
{ if (bbar_st != 1) bbar_st = 0;
|
alpar@1
|
2888 |
if (cbar_st != 1) cbar_st = 0;
|
alpar@1
|
2889 |
goto loop;
|
alpar@1
|
2890 |
}
|
alpar@1
|
2891 |
display(csa, parm, 1);
|
alpar@1
|
2892 |
switch (csa->phase)
|
alpar@1
|
2893 |
{ case 1:
|
alpar@1
|
2894 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2895 |
xprintf("PROBLEM HAS NO DUAL FEASIBLE SOLUTION\n");
|
alpar@1
|
2896 |
set_orig_bnds(csa);
|
alpar@1
|
2897 |
eval_bbar(csa);
|
alpar@1
|
2898 |
p_stat = GLP_INFEAS, d_stat = GLP_NOFEAS;
|
alpar@1
|
2899 |
break;
|
alpar@1
|
2900 |
case 2:
|
alpar@1
|
2901 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2902 |
xprintf("OPTIMAL SOLUTION FOUND\n");
|
alpar@1
|
2903 |
p_stat = d_stat = GLP_FEAS;
|
alpar@1
|
2904 |
break;
|
alpar@1
|
2905 |
default:
|
alpar@1
|
2906 |
xassert(csa != csa);
|
alpar@1
|
2907 |
}
|
alpar@1
|
2908 |
store_sol(csa, lp, p_stat, d_stat, 0);
|
alpar@1
|
2909 |
ret = 0;
|
alpar@1
|
2910 |
goto done;
|
alpar@1
|
2911 |
}
|
alpar@1
|
2912 |
/* compute pivot row of the simplex table */
|
alpar@1
|
2913 |
{ double *rho = csa->work4;
|
alpar@1
|
2914 |
eval_rho(csa, rho);
|
alpar@1
|
2915 |
if (rigorous) refine_rho(csa, rho);
|
alpar@1
|
2916 |
eval_trow(csa, rho);
|
alpar@1
|
2917 |
sort_trow(csa, parm->tol_bnd);
|
alpar@1
|
2918 |
}
|
alpar@1
|
2919 |
/* unlike primal simplex there is no need to check accuracy of
|
alpar@1
|
2920 |
the primal value of xB[p] (which might be computed using the
|
alpar@1
|
2921 |
pivot row), since bbar is a result of FTRAN */
|
alpar@1
|
2922 |
#ifdef GLP_LONG_STEP /* 07/IV-2009 */
|
alpar@1
|
2923 |
long_step(csa);
|
alpar@1
|
2924 |
if (csa->nbps > 0)
|
alpar@1
|
2925 |
{ csa->q = csa->bkpt[csa->nbps].j;
|
alpar@1
|
2926 |
if (csa->delta > 0.0)
|
alpar@1
|
2927 |
csa->new_dq = + csa->bkpt[csa->nbps].t;
|
alpar@1
|
2928 |
else
|
alpar@1
|
2929 |
csa->new_dq = - csa->bkpt[csa->nbps].t;
|
alpar@1
|
2930 |
}
|
alpar@1
|
2931 |
else
|
alpar@1
|
2932 |
#endif
|
alpar@1
|
2933 |
/* choose non-basic variable xN[q] */
|
alpar@1
|
2934 |
switch (parm->r_test)
|
alpar@1
|
2935 |
{ case GLP_RT_STD:
|
alpar@1
|
2936 |
chuzc(csa, 0.0);
|
alpar@1
|
2937 |
break;
|
alpar@1
|
2938 |
case GLP_RT_HAR:
|
alpar@1
|
2939 |
chuzc(csa, 0.30 * parm->tol_dj);
|
alpar@1
|
2940 |
break;
|
alpar@1
|
2941 |
default:
|
alpar@1
|
2942 |
xassert(parm != parm);
|
alpar@1
|
2943 |
}
|
alpar@1
|
2944 |
if (csa->q == 0)
|
alpar@1
|
2945 |
{ if (bbar_st != 1 || cbar_st != 1 || !rigorous)
|
alpar@1
|
2946 |
{ if (bbar_st != 1) bbar_st = 0;
|
alpar@1
|
2947 |
if (cbar_st != 1) cbar_st = 0;
|
alpar@1
|
2948 |
rigorous = 1;
|
alpar@1
|
2949 |
goto loop;
|
alpar@1
|
2950 |
}
|
alpar@1
|
2951 |
display(csa, parm, 1);
|
alpar@1
|
2952 |
switch (csa->phase)
|
alpar@1
|
2953 |
{ case 1:
|
alpar@1
|
2954 |
if (parm->msg_lev >= GLP_MSG_ERR)
|
alpar@1
|
2955 |
xprintf("Error: unable to choose basic variable on ph"
|
alpar@1
|
2956 |
"ase I\n");
|
alpar@1
|
2957 |
xassert(!lp->valid && lp->bfd == NULL);
|
alpar@1
|
2958 |
lp->bfd = csa->bfd, csa->bfd = NULL;
|
alpar@1
|
2959 |
lp->pbs_stat = lp->dbs_stat = GLP_UNDEF;
|
alpar@1
|
2960 |
lp->obj_val = 0.0;
|
alpar@1
|
2961 |
lp->it_cnt = csa->it_cnt;
|
alpar@1
|
2962 |
lp->some = 0;
|
alpar@1
|
2963 |
ret = GLP_EFAIL;
|
alpar@1
|
2964 |
break;
|
alpar@1
|
2965 |
case 2:
|
alpar@1
|
2966 |
if (parm->msg_lev >= GLP_MSG_ALL)
|
alpar@1
|
2967 |
xprintf("PROBLEM HAS NO FEASIBLE SOLUTION\n");
|
alpar@1
|
2968 |
store_sol(csa, lp, GLP_NOFEAS, GLP_FEAS,
|
alpar@1
|
2969 |
csa->head[csa->p]);
|
alpar@1
|
2970 |
ret = 0;
|
alpar@1
|
2971 |
break;
|
alpar@1
|
2972 |
default:
|
alpar@1
|
2973 |
xassert(csa != csa);
|
alpar@1
|
2974 |
}
|
alpar@1
|
2975 |
goto done;
|
alpar@1
|
2976 |
}
|
alpar@1
|
2977 |
/* check if the pivot element is acceptable */
|
alpar@1
|
2978 |
{ double piv = csa->trow_vec[csa->q];
|
alpar@1
|
2979 |
double eps = 1e-5 * (1.0 + 0.01 * csa->trow_max);
|
alpar@1
|
2980 |
if (fabs(piv) < eps)
|
alpar@1
|
2981 |
{ if (parm->msg_lev >= GLP_MSG_DBG)
|
alpar@1
|
2982 |
xprintf("piv = %.12g; eps = %g\n", piv, eps);
|
alpar@1
|
2983 |
if (!rigorous)
|
alpar@1
|
2984 |
{ rigorous = 5;
|
alpar@1
|
2985 |
goto loop;
|
alpar@1
|
2986 |
}
|
alpar@1
|
2987 |
}
|
alpar@1
|
2988 |
}
|
alpar@1
|
2989 |
/* now xN[q] and xB[p] have been chosen anyhow */
|
alpar@1
|
2990 |
/* compute pivot column of the simplex table */
|
alpar@1
|
2991 |
eval_tcol(csa);
|
alpar@1
|
2992 |
if (rigorous) refine_tcol(csa);
|
alpar@1
|
2993 |
/* accuracy check based on the pivot element */
|
alpar@1
|
2994 |
{ double piv1 = csa->tcol_vec[csa->p]; /* more accurate */
|
alpar@1
|
2995 |
double piv2 = csa->trow_vec[csa->q]; /* less accurate */
|
alpar@1
|
2996 |
xassert(piv1 != 0.0);
|
alpar@1
|
2997 |
if (fabs(piv1 - piv2) > 1e-8 * (1.0 + fabs(piv1)) ||
|
alpar@1
|
2998 |
!(piv1 > 0.0 && piv2 > 0.0 || piv1 < 0.0 && piv2 < 0.0))
|
alpar@1
|
2999 |
{ if (parm->msg_lev >= GLP_MSG_DBG)
|
alpar@1
|
3000 |
xprintf("piv1 = %.12g; piv2 = %.12g\n", piv1, piv2);
|
alpar@1
|
3001 |
if (binv_st != 1 || !rigorous)
|
alpar@1
|
3002 |
{ if (binv_st != 1) binv_st = 0;
|
alpar@1
|
3003 |
rigorous = 5;
|
alpar@1
|
3004 |
goto loop;
|
alpar@1
|
3005 |
}
|
alpar@1
|
3006 |
/* (not a good idea; should be revised later) */
|
alpar@1
|
3007 |
if (csa->tcol_vec[csa->p] == 0.0)
|
alpar@1
|
3008 |
{ csa->tcol_nnz++;
|
alpar@1
|
3009 |
xassert(csa->tcol_nnz <= csa->m);
|
alpar@1
|
3010 |
csa->tcol_ind[csa->tcol_nnz] = csa->p;
|
alpar@1
|
3011 |
}
|
alpar@1
|
3012 |
csa->tcol_vec[csa->p] = piv2;
|
alpar@1
|
3013 |
}
|
alpar@1
|
3014 |
}
|
alpar@1
|
3015 |
/* update primal values of basic variables */
|
alpar@1
|
3016 |
#ifdef GLP_LONG_STEP /* 07/IV-2009 */
|
alpar@1
|
3017 |
if (csa->nbps > 0)
|
alpar@1
|
3018 |
{ int kk, j, k;
|
alpar@1
|
3019 |
for (kk = 1; kk < csa->nbps; kk++)
|
alpar@1
|
3020 |
{ if (csa->bkpt[kk].t >= csa->bkpt[csa->nbps].t) continue;
|
alpar@1
|
3021 |
j = csa->bkpt[kk].j;
|
alpar@1
|
3022 |
k = csa->head[csa->m + j];
|
alpar@1
|
3023 |
xassert(csa->type[k] == GLP_DB);
|
alpar@1
|
3024 |
if (csa->stat[j] == GLP_NL)
|
alpar@1
|
3025 |
csa->stat[j] = GLP_NU;
|
alpar@1
|
3026 |
else
|
alpar@1
|
3027 |
csa->stat[j] = GLP_NL;
|
alpar@1
|
3028 |
}
|
alpar@1
|
3029 |
}
|
alpar@1
|
3030 |
bbar_st = 0;
|
alpar@1
|
3031 |
#else
|
alpar@1
|
3032 |
update_bbar(csa);
|
alpar@1
|
3033 |
if (csa->phase == 2)
|
alpar@1
|
3034 |
csa->bbar[0] += (csa->cbar[csa->q] / csa->zeta) *
|
alpar@1
|
3035 |
(csa->delta / csa->tcol_vec[csa->p]);
|
alpar@1
|
3036 |
bbar_st = 2; /* updated */
|
alpar@1
|
3037 |
#endif
|
alpar@1
|
3038 |
/* update reduced costs of non-basic variables */
|
alpar@1
|
3039 |
update_cbar(csa);
|
alpar@1
|
3040 |
cbar_st = 2; /* updated */
|
alpar@1
|
3041 |
/* update steepest edge coefficients */
|
alpar@1
|
3042 |
switch (parm->pricing)
|
alpar@1
|
3043 |
{ case GLP_PT_STD:
|
alpar@1
|
3044 |
break;
|
alpar@1
|
3045 |
case GLP_PT_PSE:
|
alpar@1
|
3046 |
if (csa->refct > 0) update_gamma(csa);
|
alpar@1
|
3047 |
break;
|
alpar@1
|
3048 |
default:
|
alpar@1
|
3049 |
xassert(parm != parm);
|
alpar@1
|
3050 |
}
|
alpar@1
|
3051 |
/* update factorization of the basis matrix */
|
alpar@1
|
3052 |
ret = update_B(csa, csa->p, csa->head[csa->m+csa->q]);
|
alpar@1
|
3053 |
if (ret == 0)
|
alpar@1
|
3054 |
binv_st = 2; /* updated */
|
alpar@1
|
3055 |
else
|
alpar@1
|
3056 |
{ csa->valid = 0;
|
alpar@1
|
3057 |
binv_st = 0; /* invalid */
|
alpar@1
|
3058 |
}
|
alpar@1
|
3059 |
#if 0 /* 06/IV-2009 */
|
alpar@1
|
3060 |
/* update matrix N */
|
alpar@1
|
3061 |
del_N_col(csa, csa->q, csa->head[csa->m+csa->q]);
|
alpar@1
|
3062 |
if (csa->type[csa->head[csa->p]] != GLP_FX)
|
alpar@1
|
3063 |
add_N_col(csa, csa->q, csa->head[csa->p]);
|
alpar@1
|
3064 |
#endif
|
alpar@1
|
3065 |
/* change the basis header */
|
alpar@1
|
3066 |
change_basis(csa);
|
alpar@1
|
3067 |
/* iteration complete */
|
alpar@1
|
3068 |
csa->it_cnt++;
|
alpar@1
|
3069 |
if (rigorous > 0) rigorous--;
|
alpar@1
|
3070 |
goto loop;
|
alpar@1
|
3071 |
done: /* deallocate the common storage area */
|
alpar@1
|
3072 |
free_csa(csa);
|
alpar@1
|
3073 |
/* return to the calling program */
|
alpar@1
|
3074 |
return ret;
|
alpar@1
|
3075 |
}
|
alpar@1
|
3076 |
|
alpar@1
|
3077 |
/* eof */
|