Skip to content

Commit

Permalink
If a node already exists, just update its attributes. We were already
Browse files Browse the repository at this point in the history
doing this but we do it neatly now. I fixed a bug in process infeasible
line function. condition_begin and condition_end variables were not
defined, I just removed them from argument list of add or update node
function call.
  • Loading branch information
aykutbulut committed Aug 13, 2016
1 parent eff0559 commit a0ae36d
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/grumpy/BBTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def display(self, item = 'all', basename = 'graph', format='png', count=None):
max_log_cond = max(n.attr['init_log_cond'], max_log_cond)
for n in self.nodes.values():
if 'init_log_cond' in n.attr:
log_begin = n.attr['init_log_cond']
log_begin = n.attr['init_log_cond']
log_end = n.attr['final_log_cond']
normalized_cond = (1-log_begin/max_log_cond)
color = str(hex(int(normalized_cond*256))[2:]) if normalized_cond >= .0625 else '0' + str(hex(int(normalized_cond*256))[2:])
Expand Down Expand Up @@ -490,8 +490,8 @@ def AddOrUpdateNode(self, id, parent_id, branch_direction, status, lp_bound,
#Figure out the color
attrs['init_log_cond'] = math.log(condition_begin, 10)
attrs['final_log_cond'] = math.log(condition_end, 10)
if id==self.root:
print 'id is same as self.root'
if id in self.neighbors:
# node already exists, update attributes
self.set_node_attr(id, 'status', status)
self.set_node_attr(id, 'lp_bound', lp_bound)
self.set_node_attr(id, 'integer_infeasibility_count',
Expand All @@ -510,18 +510,7 @@ def AddOrUpdateNode(self, id, parent_id, branch_direction, status, lp_bound,
integer_infeasibility_sum = integer_infeasibility_sum,
subtree_root = None, **attrs)
elif parent_id is not None:
if id in self.get_node_list():
self.set_node_attr(id, 'status', status)
self.set_node_attr(id, 'lp_bound', lp_bound)
self.set_node_attr(id, 'integer_infeasibility_count',
integer_infeasibility_count)
self.set_node_attr(id, 'integer_infeasibility_sum',
integer_infeasibility_sum)
self.set_node_attr(id, 'subtree_root', None)
if (condition_begin is not None) and (condition_end is not None):
self.set_node_attr(id, 'init_log_cond', math.log(condition_begin, 10))
self.set_node_attr(id, 'final_log_cond', math.log(condition_end, 10))
elif branch_direction == 'L':
if branch_direction == 'L':
self.add_left_child(id, parent_id, status = status,
lp_bound = lp_bound,
integer_infeasibility_count = integer_infeasibility_count,
Expand Down Expand Up @@ -1743,8 +1732,7 @@ def ProcessInfeasibleLine(self, node_id, parent_id, branch_direction,
condition_begin = int(remaining_tokens[0])
condition_end = int(remaining_tokens[1])
self.AddOrUpdateNode(node_id, parent_id, branch_direction, 'infeasible',
lp_bound, ii_count, ii_sum, condition_begin,
condition_end)
lp_bound, ii_count, ii_sum)

def ProcessCandidateLine(self, node_id, parent_id, branch_direction,
remaining_tokens):
Expand Down Expand Up @@ -2080,8 +2068,8 @@ def parse_options():


if __name__ == '__main__':
from BranchAndBound import GenerateRandomMIP, BranchAndBound
from BranchAndBound import GenerateRandomMIP, BranchAndBound

T = BBTree()
#T.set_layout('dot2tex')
#T.set_display_mode('file')
Expand Down

0 comments on commit a0ae36d

Please sign in to comment.