~ubuntu-branches/ubuntu/feisty/gnumeric/feisty-updates

« back to all changes in this revision

Viewing changes to src/tools/solver/glpk/source/glpmip2.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-11-14 14:02:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114140203-iv3j2aii3vch6isl
Tags: 1.7.2-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* glpmip2.c */
 
2
 
 
3
/*----------------------------------------------------------------------
 
4
-- This code is part of GNU Linear Programming Kit (GLPK).
 
5
--
 
6
-- Copyright (C) 2000, 01, 02, 03, 04, 05, 06 Andrew Makhorin,
 
7
-- Department for Applied Informatics, Moscow Aviation Institute,
 
8
-- Moscow, Russia. All rights reserved. E-mail: <mao@mai2.rcnet.ru>.
 
9
--
 
10
-- GLPK is free software; you can redistribute it and/or modify it
 
11
-- under the terms of the GNU General Public License as published by
 
12
-- the Free Software Foundation; either version 2, or (at your option)
 
13
-- any later version.
 
14
--
 
15
-- GLPK is distributed in the hope that it will be useful, but WITHOUT
 
16
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
17
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 
18
-- License for more details.
 
19
--
 
20
-- You should have received a copy of the GNU General Public License
 
21
-- along with GLPK; see the file COPYING. If not, write to the Free
 
22
-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
23
-- 02110-1301, USA.
 
24
----------------------------------------------------------------------*/
 
25
 
 
26
#include <float.h>
 
27
#include <math.h>
 
28
#include <stdio.h>
 
29
#include "glplib.h"
 
30
#include "glpmip.h"
 
31
 
 
32
/*----------------------------------------------------------------------
 
33
-- show_progress - display progress of the search.
 
34
--
 
35
-- This routine displays some information about progress of the search.
 
36
--
 
37
-- This information includes:
 
38
--
 
39
-- the current number of iterations performed by the simplex solver;
 
40
--
 
41
-- the objective value for the best known integer feasible solution,
 
42
-- which is upper (minimization) or lower (maximization) global bound
 
43
-- for optimal solution of the original mip problem;
 
44
--
 
45
-- the best local bound for active nodes, which is lower (minimization)
 
46
-- or upper (maximization) global bound for optimal solution of the
 
47
-- original mip problem;
 
48
--
 
49
-- the relative mip gap, in percents;
 
50
--
 
51
-- the number of open (active) subproblems;
 
52
--
 
53
-- the number of completely explored subproblems, i.e. whose nodes have
 
54
-- been already removed from the tree. */
 
55
 
 
56
static void show_progress(MIPTREE *tree)
 
57
{     int p;
 
58
      gnm_float temp;
 
59
      char best_mip[50], best_bound[50], *rho, rel_gap[50];
 
60
      /* format the best known integer feasible solution */
 
61
      if (tree->found)
 
62
         sprintf(best_mip, "%17.9e", tree->best);
 
63
      else
 
64
         sprintf(best_mip, "%17s", "not found yet");
 
65
      /* determine reference number of an active subproblem whose local
 
66
         bound is best */
 
67
      p = mip_best_node(tree);
 
68
      /* format the best bound */
 
69
      if (p == 0)
 
70
         sprintf(best_bound, "%17s", "tree is empty");
 
71
      else
 
72
      {  temp = tree->slot[p].node->bound;
 
73
         if (temp == -DBL_MAX)
 
74
            sprintf(best_bound, "%17s", "-inf");
 
75
         else if (temp == +DBL_MAX)
 
76
            sprintf(best_bound, "%17s", "+inf");
 
77
         else
 
78
            sprintf(best_bound, "%17.9e", temp);
 
79
      }
 
80
      /* choose the relation sign between global bounds */
 
81
      switch (tree->dir)
 
82
      {  case LPX_MIN: rho = ">="; break;
 
83
         case LPX_MAX: rho = "<="; break;
 
84
         default: insist(tree != tree);
 
85
      }
 
86
      /* format the relative mip gap */
 
87
      temp = mip_relative_gap(tree);
 
88
      if (temp == 0.0)
 
89
         sprintf(rel_gap, "  0.0%%");
 
90
      else if (temp < 0.001)
 
91
         sprintf(rel_gap, "< 0.1%%");
 
92
      else if (temp <= 9.999)
 
93
         sprintf(rel_gap, "%5.1f%%", 100.0 * temp);
 
94
      else
 
95
         sprintf(rel_gap, "%6s", "");
 
96
      /* display progress of the search */
 
97
      print("+%6d: mip = %s %s %s %s (%d; %d)",
 
98
         lpx_get_int_parm(tree->lp, LPX_K_ITCNT), best_mip, rho,
 
99
         best_bound, rel_gap, tree->a_cnt, tree->t_cnt - tree->n_cnt);
 
100
      tree->tm_lag = utime();
 
101
      return;
 
102
}
 
103
 
 
104
/*----------------------------------------------------------------------
 
105
-- set_local_bound - set local bound for current subproblem.
 
106
--
 
107
-- This routine sets the local bound for integer optimal solution of
 
108
-- the current subproblem, which is optimal solution of LP relaxation.
 
109
-- If the latter is fractional while the objective function is known to
 
110
-- be integral for any integer feasible point, the bound is strengthen
 
111
-- by rounding up (minimization) or down (maximization). */
 
112
 
 
113
static void set_local_bound(MIPTREE *tree)
 
114
{     gnm_float bound;
 
115
      bound = lpx_get_obj_val(tree->lp);
 
116
      if (tree->int_obj)
 
117
      {  /* the objective function is known to be integral */
 
118
         gnm_float temp;
 
119
         temp = gnm_floor(bound + 0.5);
 
120
         if (temp - 1e-5 <= bound && bound <= temp + 1e-5)
 
121
            bound = temp;
 
122
         else
 
123
         {  switch (tree->dir)
 
124
            {  case LPX_MIN:
 
125
                  bound = gnm_ceil(bound); break;
 
126
               case LPX_MAX:
 
127
                  bound = gnm_floor(bound); break;
 
128
               default:
 
129
                  insist(tree != tree);
 
130
            }
 
131
         }
 
132
      }
 
133
      insist(tree->curr != NULL);
 
134
      tree->curr->bound = bound;
 
135
      if (tree->msg_lev >= 3)
 
136
         print("Local bound is %.9e", bound);
 
137
      return;
 
138
}
 
139
 
 
140
/*----------------------------------------------------------------------
 
141
-- is_branch_hopeful - check if specified branch is hopeful.
 
142
--
 
143
-- This routine checks if the specified subproblem can have an integer
 
144
-- optimal solution which is better than the best known one.
 
145
--
 
146
-- The check is based on comparison of the local objective bound stored
 
147
-- in the subproblem descriptor and the incumbent objective value which
 
148
-- is the global objective bound.
 
149
--
 
150
-- If there is a chance that the specified subproblem can have a better
 
151
-- integer optimal solution, the routine returns non-zero. Otherwise, if
 
152
-- the corresponding branch can pruned, zero is returned. */
 
153
 
 
154
static int is_branch_hopeful(MIPTREE *tree, int p)
 
155
{     int ret = 1;
 
156
      if (tree->found)
 
157
      {  gnm_float bound, eps;
 
158
         insist(1 <= p && p <= tree->nslots);
 
159
         insist(tree->slot[p].node != NULL);
 
160
         bound = tree->slot[p].node->bound;
 
161
         eps = tree->tol_obj * (1.0 + gnm_abs(tree->best));
 
162
         switch (tree->dir)
 
163
         {  case LPX_MIN:
 
164
               if (bound >= tree->best - eps) ret = 0;
 
165
               break;
 
166
            case LPX_MAX:
 
167
               if (bound <= tree->best + eps) ret = 0;
 
168
               break;
 
169
            default:
 
170
               insist(tree != tree);
 
171
         }
 
172
      }
 
173
      return ret;
 
174
}
 
175
 
 
176
/*----------------------------------------------------------------------
 
177
-- check_integrality - check integrality of basic solution.
 
178
--
 
179
-- This routine checks if the basic solution of LP relaxation of the
 
180
-- current subproblem satisfies to integrality conditions, i.e. that all
 
181
-- variables of integer kind have integral primal values. (The solution
 
182
-- is assumed to be optimal.)
 
183
--
 
184
-- For each variable of integer kind the routine computes the following
 
185
-- quantity:
 
186
--
 
187
--    ii(x[j]) = min(x[j] - gnm_floor(x[j]), gnm_ceil(x[j]) - x[j]),         (1)
 
188
--
 
189
-- which is a measure of the integer infeasibility (non-integrality) of
 
190
-- x[j] (for example, ii(2.1) = 0.1, ii(3.7) = 0.3, ii(5.0) = 0). It is
 
191
-- understood that 0 <= ii(x[j]) <= 0.5, and variable x[j] is integer
 
192
-- feasible if ii(x[j]) = 0. However, due to floating-point arithmetic
 
193
-- the routine checks less restrictive condition:
 
194
--
 
195
--    ii(x[j]) <= tol_int,                                           (2)
 
196
--
 
197
-- where tol_int is a given tolerance (small positive number) and marks
 
198
-- each variable which does not satisfy to (2) as integer infeasible by
 
199
-- setting its fractionality flag.
 
200
--
 
201
-- In order to characterize integer infeasibility of the basic solution
 
202
-- in the whole the routine computes two parameters: ii_cnt, which is
 
203
-- the number of variables with the fractionality flag set, and ii_sum,
 
204
-- which is the sum of integer infeasibilities (1). */
 
205
 
 
206
static void check_integrality(MIPTREE *tree)
 
207
{     LPX *lp = tree->lp;
 
208
      int j, type, ii_cnt = 0;
 
209
      gnm_float lb, ub, x, temp1, temp2, ii_sum = 0.0;
 
210
      /* walk through the set of columns (structural variables) */
 
211
      for (j = 1; j <= tree->n; j++)
 
212
      {  tree->non_int[j] = 0;
 
213
         /* if the column is continuous, skip it */
 
214
         if (!tree->int_col[j]) continue;
 
215
         /* if the column is non-basic, it is integer feasible */
 
216
         if (lpx_get_col_stat(lp, j) != LPX_BS) continue;
 
217
         /* obtain the type and bounds of the column */
 
218
         type = lpx_get_col_type(lp, j);
 
219
         lb = lpx_get_col_lb(lp, j);
 
220
         ub = lpx_get_col_ub(lp, j);
 
221
         /* obtain value of the column in optimal basic solution */
 
222
         x = lpx_get_col_prim(lp, j);
 
223
         /* if the column's primal value is close to the lower bound,
 
224
            the column is integer feasible within given tolerance */
 
225
         if (type == LPX_LO || type == LPX_DB || type == LPX_FX)
 
226
         {  temp1 = lb - tree->tol_int;
 
227
            temp2 = lb + tree->tol_int;
 
228
            if (temp1 <= x && x <= temp2) continue;
 
229
            /* the lower bound must not be violated */
 
230
            insist(x >= lb);
 
231
         }
 
232
         /* if the column's primal value is close to the upper bound,
 
233
            the column is integer feasible within given tolerance */
 
234
         if (type == LPX_UP || type == LPX_DB || type == LPX_FX)
 
235
         {  temp1 = ub - tree->tol_int;
 
236
            temp2 = ub + tree->tol_int;
 
237
            if (temp1 <= x && x <= temp2) continue;
 
238
            /* the upper bound must not be violated */
 
239
            insist(x <= ub);
 
240
         }
 
241
         /* if the column's primal value is close to nearest integer,
 
242
            the column is integer feasible within given tolerance */
 
243
         temp1 = gnm_floor(x + 0.5) - tree->tol_int;
 
244
         temp2 = gnm_floor(x + 0.5) + tree->tol_int;
 
245
         if (temp1 <= x && x <= temp2) continue;
 
246
         /* otherwise the column is integer infeasible */
 
247
         tree->non_int[j] = 1;
 
248
         /* increase the number of fractional-valued columns */
 
249
         ii_cnt++;
 
250
         /* compute the sum of integer infeasibilities */
 
251
         temp1 = x - gnm_floor(x);
 
252
         temp2 = gnm_ceil(x) - x;
 
253
         insist(temp1 > 0.0 && temp2 > 0.0);
 
254
         ii_sum += (temp1 <= temp2 ? temp1 : temp2);
 
255
      }
 
256
      /* store ii_cnt and ii_sum in the current problem descriptor */
 
257
      insist(tree->curr != NULL);
 
258
      tree->curr->ii_cnt = ii_cnt;
 
259
      tree->curr->ii_sum = ii_sum;
 
260
      /* and also display these parameters */
 
261
      if (tree->msg_lev >= 3)
 
262
      {  if (ii_cnt == 0)
 
263
            print("There are no fractional columns");
 
264
         else if (ii_cnt == 1)
 
265
            print("There is one fractional column, integer infeasibilit"
 
266
               "y is %.3e", ii_sum);
 
267
         else
 
268
            print("There are %d fractional columns, integer infeasibili"
 
269
               "ty is %.3e", ii_cnt, ii_sum);
 
270
      }
 
271
      return;
 
272
}
 
273
 
 
274
/*----------------------------------------------------------------------
 
275
-- record_solution - record better integer feasible solution.
 
276
--
 
277
-- This routine records optimal basic solution of LP relaxation of the
 
278
-- current subproblem, which being integer feasible is better than the
 
279
-- best known integer feasible solution. */
 
280
 
 
281
static void record_solution(MIPTREE *tree)
 
282
{     int m = tree->m;
 
283
      int n = tree->n;
 
284
      LPX *lp = tree->lp;
 
285
      int i, j;
 
286
      gnm_float temp;
 
287
      tree->found = 1;
 
288
      tree->best = lpx_get_obj_val(lp);
 
289
      for (i = 1; i <= m; i++)
 
290
      {  temp = lpx_get_row_prim(lp, i);
 
291
         tree->mipx[i] = temp;
 
292
      }
 
293
      for (j = 1; j <= n; j++)
 
294
      {  temp = lpx_get_col_prim(lp, j);
 
295
         /* value of the integer column must be integral */
 
296
         if (tree->int_col[j]) temp = gnm_floor(temp + 0.5);
 
297
         tree->mipx[m+j] = temp;
 
298
      }
 
299
      return;
 
300
}
 
301
 
 
302
/*----------------------------------------------------------------------
 
303
-- fix_by_red_cost - fix non-basic integer columns by reduced costs.
 
304
--
 
305
-- This routine fixes some non-basic integer columns if their reduced
 
306
-- costs indicate that increasing (decreasing) the column at least by
 
307
-- one involves the objective value becoming worse than the incumbent
 
308
-- objective value (i.e. the global bound). */
 
309
 
 
310
static void fix_by_red_cost(MIPTREE *tree)
 
311
{     int n = tree->n;
 
312
      LPX *lp = tree->lp;
 
313
      int j, stat, fixed = 0;
 
314
      gnm_float obj, lb, ub, dj;
 
315
      /* the global bound must exist */
 
316
      insist(tree->found);
 
317
      /* basic solution of LP relaxation must be optimal */
 
318
      insist(lpx_get_status(lp) == LPX_OPT);
 
319
      /* determine the objective function value */
 
320
      obj = lpx_get_obj_val(lp);
 
321
      /* walk through the column list */
 
322
      for (j = 1; j <= n; j++)
 
323
      {  /* if j-th column is not of integer kind, skip it */
 
324
         if (!tree->int_col[j]) continue;
 
325
         /* obtain bounds of j-th column */
 
326
         lb = lpx_get_col_lb(lp, j);
 
327
         ub = lpx_get_col_ub(lp, j);
 
328
         /* and determine its status and reduced cost */
 
329
         stat = lpx_get_col_stat(lp, j);
 
330
         dj = lpx_get_col_dual(lp, j);
 
331
         /* analyze the reduced cost */
 
332
         switch (tree->dir)
 
333
         {  case LPX_MIN:
 
334
               /* minimization */
 
335
               if (stat == LPX_NL)
 
336
               {  /* j-th column is non-basic on its lower bound */
 
337
                  if (dj < 0.0) dj = 0.0;
 
338
                  if (obj + dj >= tree->best)
 
339
                     lpx_set_col_bnds(lp, j, LPX_FX, lb, lb), fixed++;
 
340
               }
 
341
               else if (stat == LPX_NU)
 
342
               {  /* j-th column is non-basic on its upper bound */
 
343
                  if (dj > 0.0) dj = 0.0;
 
344
                  if (obj - dj >= tree->best)
 
345
                     lpx_set_col_bnds(lp, j, LPX_FX, ub, ub), fixed++;
 
346
               }
 
347
               break;
 
348
            case LPX_MAX:
 
349
               /* maximization */
 
350
               if (stat == LPX_NL)
 
351
               {  /* j-th column is non-basic on its lower bound */
 
352
                  if (dj > 0.0) dj = 0.0;
 
353
                  if (obj + dj <= tree->best)
 
354
                     lpx_set_col_bnds(lp, j, LPX_FX, lb, lb), fixed++;
 
355
               }
 
356
               else if (stat == LPX_NU)
 
357
               {  /* j-th column is non-basic on its upper bound */
 
358
                  if (dj < 0.0) dj = 0.0;
 
359
                  if (obj - dj <= tree->best)
 
360
                     lpx_set_col_bnds(lp, j, LPX_FX, ub, ub), fixed++;
 
361
               }
 
362
               break;
 
363
            default:
 
364
               insist(tree != tree);
 
365
         }
 
366
      }
 
367
      if (tree->msg_lev >= 3)
 
368
      {  if (fixed == 0)
 
369
            /* nothing to say */;
 
370
         else if (fixed == 1)
 
371
            print("One column has been fixed by reduced cost");
 
372
         else
 
373
            print("%d columns have been fixed by reduced costs", fixed);
 
374
      }
 
375
      /* fixing non-basic columns on their current bounds does not
 
376
         change the basic solution itself, however, lpx_set_col_bnds
 
377
         resets the primal and dual statuses to undefined state, and
 
378
         therefore we need to restore them */
 
379
      lpx_put_solution(lp, LPX_P_FEAS, LPX_D_FEAS, NULL, NULL, NULL,
 
380
         NULL, NULL, NULL);
 
381
      return;
 
382
}
 
383
 
 
384
/*----------------------------------------------------------------------
 
385
-- branch_on - perform branching on specified column.
 
386
--
 
387
-- This routine performs branching on j-th column (structural variable)
 
388
-- of the current subproblem. The specified column must be of integer
 
389
-- kind and must have a fractional value in optimal basic solution of
 
390
-- LP relaxation of the current subproblem (i.e. only columns for which
 
391
-- the flag non_int[j] is set are valid candidates to branch on).
 
392
--
 
393
-- Let x be j-th structural variable, and beta be its primal fractional
 
394
-- value in the current basic solution. Branching on j-th variable is
 
395
-- dividing the current subproblem into two new subproblems, which are
 
396
-- identical to the current subproblem with the following exception: in
 
397
-- the first subproblem that begins the down-branch x has a new upper
 
398
-- bound x <= gnm_floor(beta), and in the second subproblem that begins the
 
399
-- up-branch x has a new lower bound x >= gnm_ceil(beta).
 
400
--
 
401
-- The parameter next specifies which subproblem should be solved next
 
402
-- to continue the search:
 
403
--
 
404
-- -1 means that one which begins the down-branch;
 
405
-- +1 means that one which begins the up-branch. */
 
406
 
 
407
static void branch_on(MIPTREE *tree, int j, int next)
 
408
{     LPX *lp = tree->lp;
 
409
      int p, type, clone[1+2];
 
410
      gnm_float beta, lb, ub, new_lb, new_ub;
 
411
      /* check input parameters for correctness */
 
412
      insist(1 <= j && j <= tree->n);
 
413
      insist(tree->non_int[j]);
 
414
      insist(next == -1 || next == +1);
 
415
      /* obtain primal value of j-th column in basic solution */
 
416
      beta = lpx_get_col_prim(lp, j);
 
417
      if (tree->msg_lev >= 3)
 
418
         print("Branching on column %d, primal value is %.9e", j, beta);
 
419
      /* determine the reference number of the current subproblem */
 
420
      insist(tree->curr != NULL);
 
421
      p = tree->curr->p;
 
422
      /* freeze the current subproblem */
 
423
      mip_freeze_node(tree);
 
424
      /* create two clones of the current subproblem; the first clone
 
425
         begins the down-branch, the second one begins the up-branch */
 
426
      mip_clone_node(tree, p, 2, clone);
 
427
      if (tree->msg_lev >= 3)
 
428
         print("Node %d begins down branch, node %d begins up branch",
 
429
            clone[1], clone[2]);
 
430
      /* set new upper bound of j-th column in the first subproblem */
 
431
      mip_revive_node(tree, clone[1]);
 
432
      type = lpx_get_col_type(lp, j);
 
433
      lb = lpx_get_col_lb(lp, j);
 
434
      ub = lpx_get_col_ub(lp, j);
 
435
      new_ub = gnm_floor(beta);
 
436
      switch (type)
 
437
      {  case LPX_FR:
 
438
            type = LPX_UP;
 
439
            break;
 
440
         case LPX_LO:
 
441
            insist(lb <= new_ub);
 
442
            type = (lb < new_ub ? LPX_DB : LPX_FX);
 
443
            break;
 
444
         case LPX_UP:
 
445
            insist(new_ub <= ub - 1.0);
 
446
            break;
 
447
         case LPX_DB:
 
448
            insist(lb <= new_ub && new_ub <= ub - 1.0);
 
449
            type = (lb < new_ub ? LPX_DB : LPX_FX);
 
450
            break;
 
451
         default:
 
452
            insist(type != type);
 
453
      }
 
454
      lpx_set_col_bnds(lp, j, type, lb, new_ub);
 
455
      mip_freeze_node(tree);
 
456
      /* set new lower bound of j-th column in the second subproblem */
 
457
      mip_revive_node(tree, clone[2]);
 
458
      type = lpx_get_col_type(lp, j);
 
459
      lb = lpx_get_col_lb(lp, j);
 
460
      ub = lpx_get_col_ub(lp, j);
 
461
      new_lb = gnm_ceil(beta);
 
462
      switch (type)
 
463
      {  case LPX_FR:
 
464
            type = LPX_LO;
 
465
            break;
 
466
         case LPX_LO:
 
467
            insist(lb + 1.0 <= new_lb);
 
468
            break;
 
469
         case LPX_UP:
 
470
            insist(new_lb <= ub);
 
471
            type = (new_lb < ub ? LPX_DB : LPX_FX);
 
472
            break;
 
473
         case LPX_DB:
 
474
            insist(lb + 1.0 <= new_lb && new_lb <= ub);
 
475
            type = (new_lb < ub ? LPX_DB : LPX_FX);
 
476
            break;
 
477
         default:
 
478
            insist(type != type);
 
479
      }
 
480
      lpx_set_col_bnds(lp, j, type, new_lb, ub);
 
481
      mip_freeze_node(tree);
 
482
      /* revive the subproblem to be solved next */
 
483
      mip_revive_node(tree, clone[next < 0 ? 1 : 2]);
 
484
      return;
 
485
}
 
486
 
 
487
/*----------------------------------------------------------------------
 
488
-- branch_first - choose first branching variable.
 
489
--
 
490
-- This routine looks up the list of structural variables and chooses
 
491
-- the first one, which is of integer kind and has fractional value in
 
492
-- optimal solution of the current LP relaxation.
 
493
--
 
494
-- This routine also selects the branch to be solved next where integer
 
495
-- infeasibility of the chosen variable is less than in other one. */
 
496
 
 
497
static void branch_first(MIPTREE *tree)
 
498
{     int n = tree->n;
 
499
      LPX *lp = tree->lp;
 
500
      int j, next;
 
501
      gnm_float beta;
 
502
      /* choose the column to branch on */
 
503
      for (j = 1; j <= n; j++)
 
504
         if (tree->non_int[j]) break;
 
505
      insist(1 <= j && j <= n);
 
506
      /* select the branch to be solved next */
 
507
      beta = lpx_get_col_prim(lp, j);
 
508
      if (beta - gnm_floor(beta) < gnm_ceil(beta) - beta)
 
509
         next = -1; /* down branch */
 
510
      else
 
511
         next = +1; /* up branch */
 
512
      /* perform branching */
 
513
      branch_on(tree, j, next);
 
514
      return;
 
515
}
 
516
 
 
517
/*----------------------------------------------------------------------
 
518
-- branch_last - choose last branching variable.
 
519
--
 
520
-- This routine looks up the list of structural variables and chooses
 
521
-- the last one, which is of integer kind and has fractional value in
 
522
-- optimal solution of the current LP relaxation.
 
523
--
 
524
-- This routine also selects the branch to be solved next where integer
 
525
-- infeasibility of the chosen variable is less than in other one. */
 
526
 
 
527
static void branch_last(MIPTREE *tree)
 
528
{     int n = tree->n;
 
529
      LPX *lp = tree->lp;
 
530
      int j, next;
 
531
      gnm_float beta;
 
532
      /* choose the column to branch on */
 
533
      for (j = n; j >= 1; j--)
 
534
         if (tree->non_int[j]) break;
 
535
      insist(1 <= j && j <= n);
 
536
      /* select the branch to be solved next */
 
537
      beta = lpx_get_col_prim(lp, j);
 
538
      if (beta - gnm_floor(beta) < gnm_ceil(beta) - beta)
 
539
         next = -1; /* down branch */
 
540
      else
 
541
         next = +1; /* up branch */
 
542
      /* perform branching */
 
543
      branch_on(tree, j, next);
 
544
      return;
 
545
}
 
546
 
 
547
/*----------------------------------------------------------------------
 
548
-- branch_drtom - choose branching variable with Driebeck-Tomlin heur.
 
549
--
 
550
-- This routine chooses a structural variable, which is required to be
 
551
-- integral and has fractional value in optimal solution of the current
 
552
-- LP relaxation, using a heuristic proposed by Driebeck and Tomlin.
 
553
--
 
554
-- The routine also selects the branch to be solved next, again due to
 
555
-- Driebeck and Tomlin.
 
556
--
 
557
-- This routine is based on the heuristic proposed in:
 
558
--
 
559
-- Driebeck N.J. An algorithm for the solution of mixed-integer
 
560
-- programming problems, Management Science, 12: 576-87 (1966)
 
561
--
 
562
-- and improved in:
 
563
--
 
564
-- Tomlin J.A. Branch and bound methods for integer and non-convex
 
565
-- programming, in J.Abadie (ed.), Integer and Nonlinear Programming,
 
566
-- North-Holland, Amsterdam, pp. 437-50 (1970).
 
567
--
 
568
-- Must note that this heuristic is time-expensive, because computing
 
569
-- one-step degradation (see the routine below) requires one BTRAN for
 
570
-- every fractional-valued structural variable. */
 
571
 
 
572
static void branch_drtom(MIPTREE *tree)
 
573
{     int m = tree->m;
 
574
      int n = tree->n;
 
575
      LPX *lp = tree->lp;
 
576
      int j, jj, k, t, next, kase, len, stat, *ind;
 
577
      gnm_float x, dk, alfa, delta_j, delta_k, delta_z, dz_dn, dz_up,
 
578
         dd_dn, dd_up, degrad, *val;
 
579
      /* basic solution of LP relaxation must be optimal */
 
580
      insist(lpx_get_status(lp) == LPX_OPT);
 
581
      /* allocate working arrays */
 
582
      ind = ucalloc(1+n, sizeof(int));
 
583
      val = ucalloc(1+n, sizeof(gnm_float));
 
584
      /* nothing has been chosen so far */
 
585
      jj = 0, degrad = -1.0;
 
586
      /* walk through the list of columns (structural variables) */
 
587
      for (j = 1; j <= n; j++)
 
588
      {  /* if j-th column is not marked as fractional, skip it */
 
589
         if (!tree->non_int[j]) continue;
 
590
         /* obtain (fractional) value of j-th column in basic solution
 
591
            of LP relaxation */
 
592
         x = lpx_get_col_prim(lp, j);
 
593
         /* since the value of j-th column is fractional, the column is
 
594
            basic; compute corresponding row of the simplex table */
 
595
         len = lpx_eval_tab_row(lp, m+j, ind, val);
 
596
         /* the following fragment computes a change in the objective
 
597
            function: delta Z = new Z - old Z, where old Z is the
 
598
            objective value in the current optimal basis, and new Z is
 
599
            the objective value in the adjacent basis, for two cases:
 
600
            1) if new upper bound ub' = gnm_floor(x[j]) is introduced for
 
601
               j-th column (down branch);
 
602
            2) if new lower bound lb' = gnm_ceil(x[j]) is introduced for
 
603
               j-th column (up branch);
 
604
            since in both cases the solution remaining dual feasible
 
605
            becomes primal infeasible, one implicit simplex iteration
 
606
            is performed to determine the change delta Z;
 
607
            it is obvious that new Z, which is never better than old Z,
 
608
            is a lower (minimization) or upper (maximization) bound of
 
609
            the objective function for down- and up-branches. */
 
610
         for (kase = -1; kase <= +1; kase += 2)
 
611
         {  /* if kase < 0, the new upper bound of x[j] is introduced;
 
612
               in this case x[j] should decrease in order to leave the
 
613
               basis and go to its new upper bound */
 
614
            /* if kase > 0, the new lower bound of x[j] is introduced;
 
615
               in this case x[j] should increase in order to leave the
 
616
               basis and go to its new lower bound */
 
617
            /* apply the dual ratio test in order to determine which
 
618
               auxiliary or structural variable should enter the basis
 
619
               to keep dual feasibility */
 
620
            k = lpx_dual_ratio_test(lp, len, ind, val, kase, 1e-8);
 
621
            /* if no non-basic variable has been chosen, LP relaxation
 
622
               of corresponding branch being primal infeasible and dual
 
623
               unbounded has no primal feasible solution; in this case
 
624
               the change delta Z is formally set to infinity */
 
625
            if (k == 0)
 
626
            {  delta_z = (tree->dir == LPX_MIN ? +DBL_MAX : -DBL_MAX);
 
627
               goto skip;
 
628
            }
 
629
            /* row of the simplex table that corresponds to non-basic
 
630
               variable x[k] choosen by the dual ratio test is:
 
631
                  x[j] = ... + alfa * x[k] + ...
 
632
               where alfa is the influence coefficient (an element of
 
633
               the simplex table row) */
 
634
            /* determine the coefficient alfa */
 
635
            for (t = 1; t <= len; t++) if (ind[t] == k) break;
 
636
            insist(1 <= t && t <= len);
 
637
            alfa = val[t];
 
638
            /* since in the adjacent basis the variable x[j] becomes
 
639
               non-basic, knowing its value in the current basis we can
 
640
               determine its change delta x[j] = new x[j] - old x[j] */
 
641
            delta_j = (kase < 0 ? gnm_floor(x) : gnm_ceil(x)) - x;
 
642
            /* and knowing the coefficient alfa we can determine the
 
643
               corresponding change delta x[k] = new x[k] - old x[k],
 
644
               where old x[k] is a value of x[k] in the current basis,
 
645
               and new x[k] is a value of x[k] in the adjacent basis */
 
646
            delta_k = delta_j / alfa;
 
647
            /* Tomlin noticed that if the variable x[k] is of integer
 
648
               kind, its change cannot be less (eventually) than one in
 
649
               the magnitude */
 
650
            if (k > m && tree->int_col[k-m])
 
651
            {  /* x[k] is structural integer variable */
 
652
               if (gnm_abs(delta_k - gnm_floor(delta_k + 0.5)) > 1e-3)
 
653
               {  if (delta_k > 0.0)
 
654
                     delta_k = gnm_ceil(delta_k);  /* +3.14 -> +4 */
 
655
                  else
 
656
                     delta_k = gnm_floor(delta_k); /* -3.14 -> -4 */
 
657
               }
 
658
            }
 
659
            /* now determine the status and reduced cost of x[k] in the
 
660
               current basis */
 
661
            if (k <= m)
 
662
            {  stat = lpx_get_row_stat(lp, k);
 
663
               dk = lpx_get_row_dual(lp, k);
 
664
            }
 
665
            else
 
666
            {  stat = lpx_get_col_stat(lp, k-m);
 
667
               dk = lpx_get_col_dual(lp, k-m);
 
668
            }
 
669
            /* if the current basis is dual degenerative, some reduced
 
670
               costs which are close to zero may have wrong sign due to
 
671
               round-off errors, so correct the sign of d[k] */
 
672
            switch (tree->dir)
 
673
            {  case LPX_MIN:
 
674
                  if (stat == LPX_NL && dk < 0.0 ||
 
675
                      stat == LPX_NU && dk > 0.0 ||
 
676
                      stat == LPX_NF) dk = 0.0;
 
677
                  break;
 
678
               case LPX_MAX:
 
679
                  if (stat == LPX_NL && dk > 0.0 ||
 
680
                      stat == LPX_NU && dk < 0.0 ||
 
681
                      stat == LPX_NF) dk = 0.0;
 
682
                  break;
 
683
               default:
 
684
                  insist(tree != tree);
 
685
            }
 
686
            /* now knowing the change of x[k] and its reduced cost d[k]
 
687
               we can compute the corresponding change in the objective
 
688
               function delta Z = new Z - old Z = d[k] * delta x[k];
 
689
               note that due to Tomlin's modification new Z can be even
 
690
               worse than in the adjacent basis */
 
691
            delta_z = dk * delta_k;
 
692
skip:       /* new Z is never better than old Z, therefore the change
 
693
               delta Z is always non-negative (in case of minimization)
 
694
               or non-positive (in case of maximization) */
 
695
            switch (tree->dir)
 
696
            {  case LPX_MIN: insist(delta_z >= 0.0); break;
 
697
               case LPX_MAX: insist(delta_z <= 0.0); break;
 
698
               default: insist(tree != tree);
 
699
            }
 
700
            /* save the change in the objective fnction for down- and
 
701
               up-branches, respectively */
 
702
            if (kase < 0) dz_dn = delta_z; else dz_up = delta_z;
 
703
         }
 
704
         /* thus, in down-branch no integer feasible solution can be
 
705
            better than Z + dz_dn, and in up-branch no integer feasible
 
706
            solution can be better than Z + dz_up, where Z is value of
 
707
            the objective function in the current basis */
 
708
         /* following the heuristic by Driebeck and Tomlin we choose a
 
709
            column (i.e. structural variable) which provides largest
 
710
            degradation of the objective function in some of branches;
 
711
            besides, we select the branch with smaller degradation to
 
712
            be solved next and keep other branch with larger degradation
 
713
            in the active list hoping to minimize the number of further
 
714
            backtrackings */
 
715
         if (degrad < gnm_abs(dz_dn) || degrad < gnm_abs(dz_up))
 
716
         {  jj = j;
 
717
            if (gnm_abs(dz_dn) < gnm_abs(dz_up))
 
718
            {  /* select down branch to be solved next */
 
719
               next = -1;
 
720
               degrad = gnm_abs(dz_up);
 
721
            }
 
722
            else
 
723
            {  /* select up branch to be solved next */
 
724
               next = +1;
 
725
               degrad = gnm_abs(dz_dn);
 
726
            }
 
727
            /* save the objective changes for printing */
 
728
            dd_dn = dz_dn, dd_up = dz_up;
 
729
            /* if down- or up-branch has no feasible solution, we does
 
730
               not need to consider other candidates (in principle, the
 
731
               corresponding branch could be pruned right now) */
 
732
            if (degrad == DBL_MAX) break;
 
733
         }
 
734
      }
 
735
      /* free working arrays */
 
736
      ufree(ind);
 
737
      ufree(val);
 
738
      /* something must be chosen */
 
739
      insist(1 <= jj && jj <= n);
 
740
      if (tree->msg_lev >= 3)
 
741
      {  print("branch_drtom: column %d chosen to branch on", jj);
 
742
         if (gnm_abs(dd_dn) == DBL_MAX)
 
743
            print("branch_drtom: down-branch is infeasible");
 
744
         else
 
745
            print("branch_drtom: down-branch bound is %.9e",
 
746
               lpx_get_obj_val(lp) + dd_dn);
 
747
         if (gnm_abs(dd_up) == DBL_MAX)
 
748
            print("branch_drtom: up-branch   is infeasible");
 
749
         else
 
750
            print("branch_drtom: up-branch   bound is %.9e",
 
751
               lpx_get_obj_val(lp) + dd_up);
 
752
      }
 
753
      /* perform branching */
 
754
      branch_on(tree, jj, next);
 
755
      return;
 
756
}
 
757
 
 
758
/*----------------------------------------------------------------------
 
759
-- branch_mostf - choose most fractional branching variable.
 
760
--
 
761
-- This routine looks up the list of structural variables and chooses
 
762
-- that one, which is of integer kind and has most fractional value in
 
763
-- optimal solution of the current LP relaxation.
 
764
--
 
765
-- This routine also selects the branch to be solved next where integer
 
766
-- infeasibility of the chosen variable is less than in other one. */
 
767
 
 
768
static void branch_mostf(MIPTREE *tree)
 
769
{     int n = tree->n;
 
770
      LPX *lp = tree->lp;
 
771
      int j, jj, next;
 
772
      gnm_float beta, most, temp;
 
773
      /* choose the column to branch on */
 
774
      jj = 0, most = DBL_MAX;
 
775
      for (j = 1; j <= n; j++)
 
776
      {  if (tree->non_int[j])
 
777
         {  beta = lpx_get_col_prim(lp, j);
 
778
            temp = gnm_floor(beta) + 0.5;
 
779
            if (most > gnm_abs(beta - temp))
 
780
            {  jj = j, most = gnm_abs(beta - temp);
 
781
               if (beta < temp)
 
782
                  next = -1; /* down branch */
 
783
               else
 
784
                  next = +1; /* up branch */
 
785
            }
 
786
         }
 
787
      }
 
788
      /* perform branching */
 
789
      branch_on(tree, jj, next);
 
790
      return;
 
791
}
 
792
 
 
793
/*----------------------------------------------------------------------
 
794
-- cleanup_the_tree - prune hopeless branches from the tree.
 
795
--
 
796
-- This routine walks through the active list and checks the local
 
797
-- bound for every active subproblem. If the local bound indicates that
 
798
-- the subproblem cannot have integer optimal solution better than the
 
799
-- incumbent objective value, the routine deletes such subproblem that,
 
800
-- in turn, involves pruning the corresponding branch of the tree. */
 
801
 
 
802
static void cleanup_the_tree(MIPTREE *tree)
 
803
{     MIPNODE *node, *next_node;
 
804
      int count = 0;
 
805
      /* the global bound must exist */
 
806
      insist(tree->found);
 
807
      /* walk through the list of active subproblems */
 
808
      for (node = tree->head; node != NULL; node = next_node)
 
809
      {  /* deleting some active problem node may involve deleting its
 
810
            parents recursively; however, all its parents being created
 
811
            *before* it are always *precede* it in the node list, so
 
812
            the next problem node is never affected by such deletion */
 
813
         next_node = node->next;
 
814
         /* if the branch is hopeless, prune it */
 
815
         if (!is_branch_hopeful(tree, node->p))
 
816
            mip_delete_node(tree, node->p), count++;
 
817
      }
 
818
      if (tree->msg_lev >= 3)
 
819
      {  if (count == 1)
 
820
            print("One hopeless branch has been pruned");
 
821
         else if (count > 1)
 
822
            print("%d hopeless branches have been pruned", count);
 
823
      }
 
824
      return;
 
825
}
 
826
 
 
827
/*----------------------------------------------------------------------
 
828
-- btrack_most_feas - select "most integer feasible" subproblem.
 
829
--
 
830
-- This routine selects from the active list a subproblem to be solved
 
831
-- next, whose parent has minimal sum of integer infeasibilities. */
 
832
 
 
833
static void btrack_most_feas(MIPTREE *tree)
 
834
{     MIPNODE *node;
 
835
      int p;
 
836
      gnm_float best;
 
837
      p = 0, best = DBL_MAX;
 
838
      for (node = tree->head; node != NULL; node = node->next)
 
839
      {  insist(node->up != NULL);
 
840
         if (best > node->up->ii_sum)
 
841
            p = node->p, best = node->up->ii_sum;
 
842
      }
 
843
      mip_revive_node(tree, p);
 
844
      return;
 
845
}
 
846
 
 
847
/*----------------------------------------------------------------------
 
848
-- btrack_best_proj - select subproblem with best projection heur.
 
849
--
 
850
-- This routine selects from the active list a subproblem to be solved
 
851
-- next using the best projection heuristic. */
 
852
 
 
853
static void btrack_best_proj(MIPTREE *tree)
 
854
{     MIPNODE *root, *node;
 
855
      int p;
 
856
      gnm_float best, deg, obj;
 
857
      /* the global bound must exist */
 
858
      insist(tree->found);
 
859
      /* obtain pointer to the root node, which must exist */
 
860
      root = tree->slot[1].node;
 
861
      insist(root != NULL);
 
862
      /* deg estimates degradation of the objective function per unit
 
863
         of the sum of integer infeasibilities */
 
864
      insist(root->ii_sum > 0.0);
 
865
      deg = (tree->best - root->bound) / root->ii_sum;
 
866
      /* nothing has been selected so far */
 
867
      p = 0, best = DBL_MAX;
 
868
      /* walk through the list of active subproblems */
 
869
      for (node = tree->head; node != NULL; node = node->next)
 
870
      {  insist(node->up != NULL);
 
871
         /* obj estimates optimal objective value if the sum of integer
 
872
            infeasibilities were zero */
 
873
         obj = node->up->bound + deg * node->up->ii_sum;
 
874
         if (tree->dir == LPX_MAX) obj = - obj;
 
875
         /* select the subproblem which has the best estimated optimal
 
876
            objective value */
 
877
         if (best > obj) p = node->p, best = obj;
 
878
      }
 
879
      mip_revive_node(tree, p);
 
880
      return;
 
881
}
 
882
 
 
883
/*----------------------------------------------------------------------
 
884
-- mip_driver - branch-and-bound driver.
 
885
--
 
886
-- *Synopsis*
 
887
--
 
888
-- #include "glpmip.h"
 
889
-- int mip_driver(MIPTREE *tree);
 
890
--
 
891
-- *Description*
 
892
--
 
893
-- The routine mip_driver is a branch-and-bound driver that manages the
 
894
-- process of solving MIP problem instance.
 
895
--
 
896
-- *Returns*
 
897
--
 
898
-- The routine mip_driver returns one of the following exit codes:
 
899
--
 
900
-- MIP_E_OK       the search is finished;
 
901
--
 
902
-- MIP_E_ITLIM    iterations limit exceeded;
 
903
--
 
904
-- MIP_E_TMLIM    time limit exceeded;
 
905
--
 
906
-- MIP_E_ERROR    an error occurred on solving the LP relaxation of the
 
907
--                current subproblem.
 
908
--
 
909
-- Should note that additional exit codes may appear in future versions
 
910
-- of this routine. */
 
911
 
 
912
int mip_driver(MIPTREE *tree)
 
913
{     LPX *lp = tree->lp;
 
914
      int p, p_stat, d_stat, ret;
 
915
      /* revive the root subproblem */
 
916
      mip_revive_node(tree, 1);
 
917
loop: /* main loop starts here; at this point some subproblem has been
 
918
         just selected from the active list and made current */
 
919
      insist(tree->curr != NULL);
 
920
      /* determine the reference number of the current subproblem */
 
921
      p = tree->curr->p;
 
922
      if (tree->msg_lev >= 3)
 
923
      {  int level = tree->slot[p].node->level;
 
924
         print("-------------------------------------------------------"
 
925
            "-----------------");
 
926
         print("Processing node %d at level %d", p, level);
 
927
      }
 
928
      /* check if the time limit has been exhausted */
 
929
      if (tree->tm_lim >= 0.0 && tree->tm_lim <= utime() - tree->tm_beg)
 
930
      {  if (tree->msg_lev >= 3)
 
931
            print("Time limit exceeded; search terminated");
 
932
         ret = MIP_E_TMLIM;
 
933
         goto done;
 
934
      }
 
935
      /* display current progress of the search */
 
936
      if (tree->msg_lev >= 3 || tree->msg_lev >= 2 &&
 
937
          utime() - tree->tm_lag >= tree->out_frq - 0.001)
 
938
         show_progress(tree);
 
939
      /* solve LP relaxation of the current subproblem */
 
940
      if (tree->msg_lev >= 3)
 
941
         print("Solving LP relaxation...");
 
942
      ret = mip_solve_node(tree);
 
943
      switch (ret)
 
944
      {  case LPX_E_OK:
 
945
         case LPX_E_OBJLL:
 
946
         case LPX_E_OBJUL:
 
947
            break;
 
948
         case LPX_E_ITLIM:
 
949
            if (tree->msg_lev >= 3)
 
950
               print("Iterations limit exceeded; search terminated");
 
951
            ret = MIP_E_ITLIM;
 
952
            goto done;
 
953
         default:
 
954
            if (tree->msg_lev >= 1)
 
955
               print("mip_driver: cannot solve current LP relaxation");
 
956
            ret = MIP_E_ERROR;
 
957
            goto done;
 
958
      }
 
959
      /* analyze status of the basic solution */
 
960
      p_stat = lpx_get_prim_stat(lp);
 
961
      d_stat = lpx_get_dual_stat(lp);
 
962
      if (p_stat == LPX_P_FEAS && d_stat == LPX_D_FEAS)
 
963
      {  /* LP relaxation has optimal solution */
 
964
         if (tree->msg_lev >= 3)
 
965
            print("Found optimal solution to LP relaxation");
 
966
      }
 
967
      else if (p_stat == LPX_P_FEAS && d_stat == LPX_D_NOFEAS)
 
968
      {  /* LP relaxation has unbounded solution */
 
969
         /* since the current subproblem cannot have a larger feasible
 
970
            region than its parent, there is something wrong */
 
971
         if (tree->msg_lev >= 1)
 
972
            print("mip_driver: current LP relaxation has unbounded solu"
 
973
               "tion");
 
974
         ret = MIP_E_ERROR;
 
975
         goto done;
 
976
      }
 
977
      else if (p_stat == LPX_P_INFEAS && d_stat == LPX_D_FEAS)
 
978
      {  /* LP relaxation has no primal solution which is better than
 
979
            the incumbent objective value */
 
980
         insist(tree->found);
 
981
         if (tree->msg_lev >= 3)
 
982
            print("LP relaxation has no solution better than incumbent "
 
983
               "objective value");
 
984
         /* prune the branch */
 
985
         goto fath;
 
986
      }
 
987
      else if (p_stat == LPX_P_NOFEAS)
 
988
      {  /* LP relaxation has no primal feasible solution */
 
989
         if (tree->msg_lev >= 3)
 
990
            print("LP relaxation has no feasible solution");
 
991
         /* prune the branch */
 
992
         goto fath;
 
993
      }
 
994
      else
 
995
      {  /* other cases cannot appear */
 
996
         insist(lp != lp);
 
997
      }
 
998
      /* at this point basic solution of LP relaxation of the current
 
999
         subproblem is optimal */
 
1000
      insist(p_stat == LPX_P_FEAS && d_stat == LPX_D_FEAS);
 
1001
      /* thus, it defines a local bound for integer optimal solution of
 
1002
         the current subproblem */
 
1003
      set_local_bound(tree);
 
1004
      /* if the local bound indicates that integer optimal solution of
 
1005
         the current subproblem cannot be better than the global bound,
 
1006
         prune the branch */
 
1007
      if (!is_branch_hopeful(tree, p))
 
1008
      {  if (tree->msg_lev >= 3)
 
1009
            print("Current branch is hopeless and can be pruned");
 
1010
         goto fath;
 
1011
      }
 
1012
      /* check integrality of the basic solution */
 
1013
      check_integrality(tree);
 
1014
      /* if the basic solution satisfies to all integrality conditions,
 
1015
         it is a new, better integer feasible solution */
 
1016
      if (tree->curr->ii_cnt == 0)
 
1017
      {  if (tree->msg_lev >= 3)
 
1018
            print("New integer feasible solution found");
 
1019
         record_solution(tree);
 
1020
         if (tree->msg_lev >= 2) show_progress(tree);
 
1021
         /* the current subproblem is fathomed; prune its branch */
 
1022
         goto fath;
 
1023
      }
 
1024
      /* basic solution of LP relaxation of the current subproblem is
 
1025
         integer infeasible */
 
1026
      /* try to fix some non-basic structural variables of integer kind
 
1027
         on their current bounds using reduced costs */
 
1028
      if (tree->found) fix_by_red_cost(tree);
 
1029
      /* perform branching */
 
1030
      switch (tree->branch)
 
1031
      {  case 0:
 
1032
            /* branch on first appropriate variable */
 
1033
            branch_first(tree);
 
1034
            break;
 
1035
         case 1:
 
1036
            /* branch on last appropriate variable */
 
1037
            branch_last(tree);
 
1038
            break;
 
1039
         case 2:
 
1040
            /* branch using the heuristic by Dreebeck and Tomlin */
 
1041
            branch_drtom(tree);
 
1042
            break;
 
1043
         case 3:
 
1044
            /* branch on most fractional variable */
 
1045
            branch_mostf(tree);
 
1046
            break;
 
1047
         default:
 
1048
            insist(tree != tree);
 
1049
      }
 
1050
      /* continue the search from the subproblem which begins down- or
 
1051
         up-branch (it has been revived by branching routine) */
 
1052
      goto loop;
 
1053
fath: /* the current subproblem has been fathomed */
 
1054
      if (tree->msg_lev >= 3)
 
1055
         print("Node %d fathomed", p);
 
1056
      /* freeze the current subproblem */
 
1057
      mip_freeze_node(tree);
 
1058
      /* and prune the corresponding branch of the tree */
 
1059
      mip_delete_node(tree, p);
 
1060
      /* if a new integer feasible solution has just been found, other
 
1061
         branches may become hopeless and therefore should be pruned */
 
1062
      if (tree->found) cleanup_the_tree(tree);
 
1063
      /* if the active list is empty, the search is finished */
 
1064
      if (tree->head == NULL)
 
1065
      {  if (tree->msg_lev >= 3)
 
1066
            print("Active list is empty!");
 
1067
         insist(tree->node_pool->count == 0);
 
1068
         insist(tree->bnds_pool->count == 0);
 
1069
         insist(tree->stat_pool->count == 0);
 
1070
         ret = MIP_E_OK;
 
1071
         goto done;
 
1072
      }
 
1073
      /* perform backtracking */
 
1074
      switch (tree->btrack)
 
1075
      {  case 0:
 
1076
            /* depth first search */
 
1077
            insist(tree->tail != NULL);
 
1078
            mip_revive_node(tree, tree->tail->p);
 
1079
            break;
 
1080
         case 1:
 
1081
            /* breadth first search */
 
1082
            insist(tree->head != NULL);
 
1083
            mip_revive_node(tree, tree->head->p);
 
1084
            break;
 
1085
         case 2:
 
1086
            if (!tree->found)
 
1087
            {  /* "most integer feasible" subproblem */
 
1088
               btrack_most_feas(tree);
 
1089
            }
 
1090
            else
 
1091
            {  /* best projection heuristic */
 
1092
               btrack_best_proj(tree);
 
1093
            }
 
1094
            break;
 
1095
         case 3:
 
1096
            /* select node with best local bound */
 
1097
            mip_revive_node(tree, mip_best_node(tree));
 
1098
            break;
 
1099
         default:
 
1100
            insist(tree != tree);
 
1101
      }
 
1102
      /* continue the search from the subproblem selected */
 
1103
      goto loop;
 
1104
done: /* display status of the search on exit from the solver */
 
1105
      if (tree->msg_lev >= 2) show_progress(tree);
 
1106
      /* decrease the time limit by spent amount of time */
 
1107
      if (tree->tm_lim >= 0.0)
 
1108
      {  tree->tm_lim -= (utime() - tree->tm_beg);
 
1109
         if (tree->tm_lim < 0.0) tree->tm_lim = 0.0;
 
1110
      }
 
1111
      /* return to the calling program */
 
1112
      return ret;
 
1113
}
 
1114
 
 
1115
/* eof */