1 /* glpios11.c (process cuts stored in the local cut pool) */
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <mao@gnu.org>.
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
27 /***********************************************************************
30 * ios_process_cuts - process cuts stored in the local cut pool
35 * void ios_process_cuts(glp_tree *T);
39 * The routine ios_process_cuts analyzes each cut currently stored in
40 * the local cut pool, which must be non-empty, and either adds the cut
41 * to the current subproblem or just discards it. All cuts are assumed
42 * to be locally valid. On exit the local cut pool remains unchanged.
46 * 1. E.Balas, S.Ceria, G.Cornuejols, "Mixed 0-1 Programming by
47 * Lift-and-Project in a Branch-and-Cut Framework", Management Sc.,
48 * 42 (1996) 1229-1246.
50 * 2. G.Andreello, A.Caprara, and M.Fischetti, "Embedding Cuts in
51 * a Branch&Cut Framework: a Computational Study with {0,1/2}-Cuts",
52 * Preliminary Draft, October 28, 2003, pp.6-8. */
55 { /* estimated cut efficiency */
57 /* pointer to cut in the cut pool */
59 /* if this flag is set, the cut is included into the current
62 /* cut efficacy (normalized residual) */
64 /* lower bound to objective degradation */
67 static int fcmp(const void *arg1, const void *arg2)
68 { const struct info *info1 = arg1, *info2 = arg2;
69 if (info1->deg == 0.0 && info2->deg == 0.0)
70 { if (info1->eff > info2->eff) return -1;
71 if (info1->eff < info2->eff) return +1;
74 { if (info1->deg > info2->deg) return -1;
75 if (info1->deg < info2->deg) return +1;
80 static double parallel(IOSCUT *a, IOSCUT *b, double work[]);
82 void ios_process_cuts(glp_tree *T)
87 int k, kk, max_cuts, len, ret, *ind;
89 /* the current subproblem must exist */
90 xassert(T->curr != NULL);
91 /* the pool must exist and be non-empty */
93 xassert(pool != NULL);
94 xassert(pool->size > 0);
95 /* allocate working arrays */
96 info = xcalloc(1+pool->size, sizeof(struct info));
97 ind = xcalloc(1+T->n, sizeof(int));
98 val = xcalloc(1+T->n, sizeof(double));
99 work = xcalloc(1+T->n, sizeof(double));
100 for (k = 1; k <= T->n; k++) work[k] = 0.0;
101 /* build the list of cuts stored in the cut pool */
102 for (k = 0, cut = pool->head; cut != NULL; cut = cut->next)
103 k++, info[k].cut = cut, info[k].flag = 0;
104 xassert(k == pool->size);
105 /* estimate efficiency of all cuts in the cut pool */
106 for (k = 1; k <= pool->size; k++)
107 { double temp, dy, dz;
109 /* build the vector of cut coefficients and compute its
112 for (aij = cut->ptr; aij != NULL; aij = aij->next)
113 { xassert(1 <= aij->j && aij->j <= T->n);
114 len++, ind[len] = aij->j, val[len] = aij->val;
115 temp += aij->val * aij->val;
117 if (temp < DBL_EPSILON * DBL_EPSILON) temp = DBL_EPSILON;
118 /* transform the cut to express it only through non-basic
119 (auxiliary and structural) variables */
120 len = glp_transform_row(T->mip, len, ind, val);
121 /* determine change in the cut value and in the objective
122 value for the adjacent basis by simulating one step of the
124 ret = _glp_analyze_row(T->mip, len, ind, val, cut->type,
125 cut->rhs, 1e-9, NULL, NULL, NULL, NULL, &dy, &dz);
126 /* determine normalized residual and lower bound to objective
129 { info[k].eff = fabs(dy) / sqrt(temp);
130 /* if some reduced costs violates (slightly) their zero
131 bounds (i.e. have wrong signs) due to round-off errors,
132 dz also may have wrong sign being close to zero */
133 if (T->mip->dir == GLP_MIN)
134 { if (dz < 0.0) dz = 0.0;
138 { if (dz > 0.0) dz = 0.0;
143 { /* the constraint is not violated at the current point */
144 info[k].eff = info[k].deg = 0.0;
147 { /* no dual feasible adjacent basis exists */
149 info[k].deg = DBL_MAX;
153 /* if the degradation is too small, just ignore it */
154 if (info[k].deg < 0.01) info[k].deg = 0.0;
156 /* sort the list of cuts by decreasing objective degradation and
157 then by decreasing efficacy */
158 qsort(&info[1], pool->size, sizeof(struct info), fcmp);
159 /* only first (most efficient) max_cuts in the list are qualified
160 as candidates to be added to the current subproblem */
161 max_cuts = (T->curr->level == 0 ? 90 : 10);
162 if (max_cuts > pool->size) max_cuts = pool->size;
163 /* add cuts to the current subproblem */
165 xprintf("*** adding cuts ***\n");
167 for (k = 1; k <= max_cuts; k++)
169 /* if this cut seems to be inefficient, skip it */
170 if (info[k].deg < 0.01 && info[k].eff < 0.01) continue;
171 /* if the angle between this cut and every other cut included
172 in the current subproblem is small, skip this cut */
173 for (kk = 1; kk < k; kk++)
175 { if (parallel(info[k].cut, info[kk].cut, work) > 0.90)
179 if (kk < k) continue;
180 /* add this cut to the current subproblem */
182 xprintf("eff = %g; deg = %g\n", info[k].eff, info[k].deg);
184 cut = info[k].cut, info[k].flag = 1;
185 i = glp_add_rows(T->mip, 1);
186 if (cut->name != NULL)
187 glp_set_row_name(T->mip, i, cut->name);
188 xassert(T->mip->row[i]->origin == GLP_RF_CUT);
189 T->mip->row[i]->klass = cut->klass;
191 for (aij = cut->ptr; aij != NULL; aij = aij->next)
192 len++, ind[len] = aij->j, val[len] = aij->val;
193 glp_set_mat_row(T->mip, i, len, ind, val);
194 xassert(cut->type == GLP_LO || cut->type == GLP_UP);
195 glp_set_row_bnds(T->mip, i, cut->type, cut->rhs, cut->rhs);
197 /* free working arrays */
206 /***********************************************************************
207 * Given a cut a * x >= b (<= b) the routine efficacy computes the cut
208 * efficacy as follows:
210 * eff = d * (a * x~ - b) / ||a||,
212 * where d is -1 (in case of '>= b') or +1 (in case of '<= b'), x~ is
213 * the vector of values of structural variables in optimal solution to
214 * LP relaxation of the current subproblem, ||a|| is the Euclidean norm
215 * of the vector of cut coefficients.
217 * If the cut is violated at point x~, the efficacy eff is positive,
218 * and its value is the Euclidean distance between x~ and the cut plane
219 * a * x = b in the space of structural variables.
221 * Following geometrical intuition, it is quite natural to consider
222 * this distance as a first-order measure of the expected efficacy of
223 * the cut: the larger the distance the better the cut [1]. */
225 static double efficacy(glp_tree *T, IOSCUT *cut)
226 { glp_prob *mip = T->mip;
228 double s = 0.0, t = 0.0, temp;
229 for (aij = cut->ptr; aij != NULL; aij = aij->next)
230 { xassert(1 <= aij->j && aij->j <= mip->n);
231 s += aij->val * mip->col[aij->j]->prim;
232 t += aij->val * aij->val;
235 if (temp < DBL_EPSILON) temp = DBL_EPSILON;
236 if (cut->type == GLP_LO)
237 temp = (s >= cut->rhs ? 0.0 : (cut->rhs - s) / temp);
238 else if (cut->type == GLP_UP)
239 temp = (s <= cut->rhs ? 0.0 : (s - cut->rhs) / temp);
246 /***********************************************************************
247 * Given two cuts a1 * x >= b1 (<= b1) and a2 * x >= b2 (<= b2) the
248 * routine parallel computes the cosine of angle between the cut planes
249 * a1 * x = b1 and a2 * x = b2 (which is the acute angle between two
250 * normals to these planes) in the space of structural variables as
253 * cos phi = (a1' * a2) / (||a1|| * ||a2||),
255 * where (a1' * a2) is a dot product of vectors of cut coefficients,
256 * ||a1|| and ||a2|| are Euclidean norms of vectors a1 and a2.
258 * Note that requirement cos phi = 0 forces the cuts to be orthogonal,
259 * i.e. with disjoint support, while requirement cos phi <= 0.999 means
260 * only avoiding duplicate (parallel) cuts [1]. */
262 static double parallel(IOSCUT *a, IOSCUT *b, double work[])
264 double s = 0.0, sa = 0.0, sb = 0.0, temp;
265 for (aij = a->ptr; aij != NULL; aij = aij->next)
266 { work[aij->j] = aij->val;
267 sa += aij->val * aij->val;
269 for (aij = b->ptr; aij != NULL; aij = aij->next)
270 { s += work[aij->j] * aij->val;
271 sb += aij->val * aij->val;
273 for (aij = a->ptr; aij != NULL; aij = aij->next)
275 temp = sqrt(sa) * sqrt(sb);
276 if (temp < DBL_EPSILON * DBL_EPSILON) temp = DBL_EPSILON;