BCP_tm_node.cpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #include "BCP_math.hpp"
4 #include "BCP_USER.hpp"
5 #include "BCP_tm.hpp"
6 #include "BCP_tm_user.hpp"
7 #include "BCP_tm_node.hpp"
8 #include "BCP_node_change.hpp"
9 
10 
13 
14 //#############################################################################
15 
17  CoinTreeNode(level),
18  status(BCP_DefaultNode),
19  _index(0),
20  _parent(0),
21  _birth_index(-1),
22  _children(),
23  lp(-1), cg(-1), cp(-1), vg(-1), vp(-1),
24  _processed_leaf_num(0),
25  _pruned_leaf_num(0),
26  _tobepriced_leaf_num(0),
27  _leaf_num(0),
28  _core_storage(-1),
29  _var_storage(-1),
30  _cut_storage(-1),
31  _ws_storage(-1),
32  _locally_stored(true),
33  _data_location(-1),
34  _data(desc)
35 {
37 }
38 
39 //#############################################################################
40 
41 // BCP_tm_node::BCP_tm_node(int level, BCP_node_change* desc,
42 // BCP_tm_node* parent, int index) :
43 // CoinTreeNode(level),
44 // status(BCP_DefaultNode),
45 // _index(0),
46 // _parent(0),
47 // _birth_index(-1),
48 // _children(),
49 // lp(-1), cg(-1), cp(-1), vg(-1), vp(-1),
50 // _processed_leaf_num(0),
51 // _pruned_leaf_num(0),
52 // _tobepriced_leaf_num(0),
53 // _leaf_num(0),
54 // _locally_stored(1),
55 // _data_location(-1),
56 // _data(desc) {}
57 
58 //#############################################################################
59 
60 int
62  int del_num = child_num();
63  if (del_num > 0) {
66  while (child != lastchild) {
67  del_num += (*child)->mark_descendants_for_deletion();
68  (*child)->_index = -1;
69  ++child;
70  }
71  _children.clear();
72  }
73  return del_num;
74 }
75 
76 //#############################################################################
77 
78 void
80 {
81  const int num_children = child_num();
82  int i;
83  for (i = num_children - 1; i >= 0; --i) {
84  if (_children[i] == node)
85  break;
86  }
87  if (i < 0) {
88  throw BCP_fatal_error("BCP_tm_node::remove_child : \
89 Trying to remove nonexistent child.\n");
90  }
91  _children[i] = _children[num_children-1];
93 }
94 
95 //#############################################################################
96 // This member function counts for every serch tree node the number of
97 // descendants and that how many of them are pruned already / currently being
98 // processed. (This includes the node itself.)
99 
100 void
101 BCP_tree::enumerate_leaves(BCP_tm_node* node, const double obj_limit)
102 {
103  if (node->child_num() == 0) {
104  const BCP_tm_node_status st = node->status;
105  node->_leaf_num = 1;
106  node->_processed_leaf_num = st == BCP_ActiveNode ? 1 : 0;
107  const bool is_pruned = ( st == BCP_PrunedNode_OverUB ||
108  st == BCP_PrunedNode_Infeas ||
109  st == BCP_PrunedNode_Discarded );
110  node->_pruned_leaf_num = is_pruned ? 1 : 0;
111  const bool is_next_phase = ( st == BCP_NextPhaseNode_OverUB ||
112  st == BCP_NextPhaseNode_Infeas );
113  node->_tobepriced_leaf_num =
115  node->getTrueLB() > obj_limit) ||
116  is_next_phase ) ? 1 : 0;
117  } else {
118  node->_leaf_num = 0;
119  node->_processed_leaf_num = 0;
120  node->_pruned_leaf_num = 0;
121  node->_tobepriced_leaf_num = 0;
124  node->_children.end();
125  for (child = node->_children.begin(); child != lastchild; ++child) {
126  this->enumerate_leaves(*child, obj_limit);
127  node->_processed_leaf_num += (*child)->_processed_leaf_num;
128  node->_pruned_leaf_num += (*child)->_pruned_leaf_num;
129  node->_tobepriced_leaf_num += (*child)->_tobepriced_leaf_num;
130  node->_leaf_num += (*child)->_leaf_num;
131  }
132  }
133 }
134 
135 //#############################################################################
136 // Find the best lower bound
137 double
139 {
140  double worstlb = BCP_DBL_MAX;
141  if (node->child_num() == 0) {
142  const BCP_tm_node_status st = node->status;
143  if (st == BCP_ActiveNode || st == BCP_CandidateNode)
144  worstlb = node->getTrueLB();
145  } else {
148  for (child = node->_children.begin(); child != lastchild; ++child) {
149  const double childlb = true_lower_bound(*child);
150  if (childlb < worstlb)
151  worstlb = childlb;
152  }
153  }
154  return worstlb;
155 }
int _pruned_leaf_num
Definition: BCP_tm_node.hpp:93
static int num_local_nodes
Definition: BCP_tm_node.hpp:73
void clear()
Delete every entry.
BCP_vec< BCP_tm_node * > _children
Definition: BCP_tm_node.hpp:87
void enumerate_leaves(BCP_tm_node *node, const double obj_limit)
Return the worst true lower bound in the search tree.
BCP_tm_node_status status
Definition: BCP_tm_node.hpp:78
BCP_tm_node(const BCP_tm_node &)
The copy constructor is declared but not defined to disable it.
static int num_remote_nodes
Definition: BCP_tm_node.hpp:74
iterator begin()
Return an iterator to the beginning of the object.
Definition: BCP_vector.hpp:99
int _tobepriced_leaf_num
Definition: BCP_tm_node.hpp:95
#define BCP_DBL_MAX
Definition: BCP_math.hpp:6
int child_num() const
void fint fint fint real fint real real real real real real real real real fint real fint * lp
void pop_back()
Delete the last entry.
BCP_tm_node * child(int ind)
int mark_descendants_for_deletion()
Definition: BCP_tm_node.cpp:61
int _processed_leaf_num
Definition: BCP_tm_node.hpp:91
BCP_tm_node_status
Node status in the Tree Manager.
Definition: BCP_tm_node.hpp:23
void remove_child(BCP_tm_node *node)
Definition: BCP_tm_node.cpp:79
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
double true_lower_bound(const BCP_tm_node *node) const
Return the worst true lower bound in the search tree.
iterator end()
Return an iterator to the end of the object.
Definition: BCP_vector.hpp:104
The class BCP_vec serves the same purpose as the vector class in the standard template library...
Definition: BCP_vector.hpp:24