src/glpios12.c
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 05 Dec 2010 17:35:23 +0100
changeset 2 4c8956a7bdf4
permissions -rw-r--r--
Set up CMAKE build environment
alpar@1
     1
/* glpios12.c (node selection heuristics) */
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 "glpios.h"
alpar@1
    26
alpar@1
    27
/***********************************************************************
alpar@1
    28
*  NAME
alpar@1
    29
*
alpar@1
    30
*  ios_choose_node - select subproblem to continue the search
alpar@1
    31
*
alpar@1
    32
*  SYNOPSIS
alpar@1
    33
*
alpar@1
    34
*  #include "glpios.h"
alpar@1
    35
*  int ios_choose_node(glp_tree *T);
alpar@1
    36
*
alpar@1
    37
*  DESCRIPTION
alpar@1
    38
*
alpar@1
    39
*  The routine ios_choose_node selects a subproblem from the active
alpar@1
    40
*  list to continue the search. The choice depends on the backtracking
alpar@1
    41
*  technique option.
alpar@1
    42
*
alpar@1
    43
*  RETURNS
alpar@1
    44
*
alpar@1
    45
*  The routine ios_choose_node return the reference number of the
alpar@1
    46
*  subproblem selected. */
alpar@1
    47
alpar@1
    48
static int most_feas(glp_tree *T);
alpar@1
    49
static int best_proj(glp_tree *T);
alpar@1
    50
static int best_node(glp_tree *T);
alpar@1
    51
alpar@1
    52
int ios_choose_node(glp_tree *T)
alpar@1
    53
{     int p;
alpar@1
    54
      if (T->parm->bt_tech == GLP_BT_DFS)
alpar@1
    55
      {  /* depth first search */
alpar@1
    56
         xassert(T->tail != NULL);
alpar@1
    57
         p = T->tail->p;
alpar@1
    58
      }
alpar@1
    59
      else if (T->parm->bt_tech == GLP_BT_BFS)
alpar@1
    60
      {  /* breadth first search */
alpar@1
    61
         xassert(T->head != NULL);
alpar@1
    62
         p = T->head->p;
alpar@1
    63
      }
alpar@1
    64
      else if (T->parm->bt_tech == GLP_BT_BLB)
alpar@1
    65
      {  /* select node with best local bound */
alpar@1
    66
         p = best_node(T);
alpar@1
    67
      }
alpar@1
    68
      else if (T->parm->bt_tech == GLP_BT_BPH)
alpar@1
    69
      {  if (T->mip->mip_stat == GLP_UNDEF)
alpar@1
    70
         {  /* "most integer feasible" subproblem */
alpar@1
    71
            p = most_feas(T);
alpar@1
    72
         }
alpar@1
    73
         else
alpar@1
    74
         {  /* best projection heuristic */
alpar@1
    75
            p = best_proj(T);
alpar@1
    76
         }
alpar@1
    77
      }
alpar@1
    78
      else
alpar@1
    79
         xassert(T != T);
alpar@1
    80
      return p;
alpar@1
    81
}
alpar@1
    82
alpar@1
    83
static int most_feas(glp_tree *T)
alpar@1
    84
{     /* select subproblem whose parent has minimal sum of integer
alpar@1
    85
         infeasibilities */
alpar@1
    86
      IOSNPD *node;
alpar@1
    87
      int p;
alpar@1
    88
      double best;
alpar@1
    89
      p = 0, best = DBL_MAX;
alpar@1
    90
      for (node = T->head; node != NULL; node = node->next)
alpar@1
    91
      {  xassert(node->up != NULL);
alpar@1
    92
         if (best > node->up->ii_sum)
alpar@1
    93
            p = node->p, best = node->up->ii_sum;
alpar@1
    94
      }
alpar@1
    95
      return p;
alpar@1
    96
}
alpar@1
    97
alpar@1
    98
static int best_proj(glp_tree *T)
alpar@1
    99
{     /* select subproblem using the best projection heuristic */
alpar@1
   100
      IOSNPD *root, *node;
alpar@1
   101
      int p;
alpar@1
   102
      double best, deg, obj;
alpar@1
   103
      /* the global bound must exist */
alpar@1
   104
      xassert(T->mip->mip_stat == GLP_FEAS);
alpar@1
   105
      /* obtain pointer to the root node, which must exist */
alpar@1
   106
      root = T->slot[1].node;
alpar@1
   107
      xassert(root != NULL);
alpar@1
   108
      /* deg estimates degradation of the objective function per unit
alpar@1
   109
         of the sum of integer infeasibilities */
alpar@1
   110
      xassert(root->ii_sum > 0.0);
alpar@1
   111
      deg = (T->mip->mip_obj - root->bound) / root->ii_sum;
alpar@1
   112
      /* nothing has been selected so far */
alpar@1
   113
      p = 0, best = DBL_MAX;
alpar@1
   114
      /* walk through the list of active subproblems */
alpar@1
   115
      for (node = T->head; node != NULL; node = node->next)
alpar@1
   116
      {  xassert(node->up != NULL);
alpar@1
   117
         /* obj estimates optimal objective value if the sum of integer
alpar@1
   118
            infeasibilities were zero */
alpar@1
   119
         obj = node->up->bound + deg * node->up->ii_sum;
alpar@1
   120
         if (T->mip->dir == GLP_MAX) obj = - obj;
alpar@1
   121
         /* select the subproblem which has the best estimated optimal
alpar@1
   122
            objective value */
alpar@1
   123
         if (best > obj) p = node->p, best = obj;
alpar@1
   124
      }
alpar@1
   125
      return p;
alpar@1
   126
}
alpar@1
   127
alpar@1
   128
static int best_node(glp_tree *T)
alpar@1
   129
{     /* select subproblem with best local bound */
alpar@1
   130
      IOSNPD *node, *best = NULL;
alpar@1
   131
      double bound, eps;
alpar@1
   132
      switch (T->mip->dir)
alpar@1
   133
      {  case GLP_MIN:
alpar@1
   134
            bound = +DBL_MAX;
alpar@1
   135
            for (node = T->head; node != NULL; node = node->next)
alpar@1
   136
               if (bound > node->bound) bound = node->bound;
alpar@1
   137
            xassert(bound != +DBL_MAX);
alpar@1
   138
            eps = 0.001 * (1.0 + fabs(bound));
alpar@1
   139
            for (node = T->head; node != NULL; node = node->next)
alpar@1
   140
            {  if (node->bound <= bound + eps)
alpar@1
   141
               {  xassert(node->up != NULL);
alpar@1
   142
                  if (best == NULL ||
alpar@1
   143
#if 1
alpar@1
   144
                  best->up->ii_sum > node->up->ii_sum) best = node;
alpar@1
   145
#else
alpar@1
   146
                  best->lp_obj > node->lp_obj) best = node;
alpar@1
   147
#endif
alpar@1
   148
               }
alpar@1
   149
            }
alpar@1
   150
            break;
alpar@1
   151
         case GLP_MAX:
alpar@1
   152
            bound = -DBL_MAX;
alpar@1
   153
            for (node = T->head; node != NULL; node = node->next)
alpar@1
   154
               if (bound < node->bound) bound = node->bound;
alpar@1
   155
            xassert(bound != -DBL_MAX);
alpar@1
   156
            eps = 0.001 * (1.0 + fabs(bound));
alpar@1
   157
            for (node = T->head; node != NULL; node = node->next)
alpar@1
   158
            {  if (node->bound >= bound - eps)
alpar@1
   159
               {  xassert(node->up != NULL);
alpar@1
   160
                  if (best == NULL ||
alpar@1
   161
#if 1
alpar@1
   162
                  best->up->ii_sum > node->up->ii_sum) best = node;
alpar@1
   163
#else
alpar@1
   164
                  best->lp_obj < node->lp_obj) best = node;
alpar@1
   165
#endif
alpar@1
   166
               }
alpar@1
   167
            }
alpar@1
   168
            break;
alpar@1
   169
         default:
alpar@1
   170
            xassert(T != T);
alpar@1
   171
      }
alpar@1
   172
      xassert(best != NULL);
alpar@1
   173
      return best->p;
alpar@1
   174
}
alpar@1
   175
alpar@1
   176
/* eof */