Commit fd2a47ea authored by Jan Pöppel's avatar Jan Pöppel
Browse files

added change_node_name method and some first tests for it

parent d491928f
......@@ -89,7 +89,25 @@ class BayesianNetwork(object):
Will have to modify all occurances of the old name.
if oldName in self.node_lookup:
n = self.node_lookup[oldName]
children = list(self.graph.succ[n])
for child in children:
del child.parents[oldName]
child.parents[newName] = n
idx = child.parentOrder.index(oldName)
child.parentOrder[idx] = newName
#Fix nx graph
self.graph.remove_node(n) = newName
del self.node_lookup[oldName]
self.node_lookup[n] = n
for child in children:
self.graph.add_edge(n, self.node_lookup[child])
raise Exception("There is no node with name {} in the network.".format(oldName))
......@@ -80,6 +80,9 @@ class BayesNetTest(unittest.TestCase):
self.assertEqual(str(cm.exception), "There is no node with name Node2 in the BayesianNetwork")
self.assertEqual(n1.parentOrder, ["NewName"])
self.assertTrue(n2 in
self.assertTrue(n2 in
self.assertTrue(n1 in[n2])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment