def test_returns_correct_branching_for_nielsen_graph(self):
        H = self.nielsenGraph
        ordering = ['s', '1', '2', 't']
        pred = {'s': None, '1': H.get_hyperedge_id({'s'}, {'1'}),
                '2': H.get_hyperedge_id({'s'}, {'2'}),
                't': H.get_hyperedge_id({'2', '1'}, {'t'})}

        branches = ksh._branching_step(H, pred, ordering)
        self.assertEqual(len(branches), 3)
        # branch 1
        b1 = branches[0]
        self.assertEqual(b1.get_node_set(), H.get_node_set())
        hyperedges = b1.get_hyperedge_id_set()
        hyperedgesTuple = [(b1.get_hyperedge_tail(e),
                            b1.get_hyperedge_head(e))
                           for e in hyperedges]
        self.assertEqual(len(hyperedges), 6)
        self.assertIn(({'s'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2', '3'}, {'4'}), hyperedgesTuple)
        self.assertIn(({'1', '2'}, {'t'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'1'}), hyperedgesTuple)
        # branch 2
        b2 = branches[1]
        self.assertEqual(b2.get_node_set(), H.get_node_set())
        hyperedges = b2.get_hyperedge_id_set()
        hyperedgesTuple = [(b2.get_hyperedge_tail(e),
                            b2.get_hyperedge_head(e))
                           for e in hyperedges]
        self.assertEqual(len(hyperedges), 7)
        self.assertIn(({'s'}, {'1'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'1'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'2'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2', '3'}, {'4'}), hyperedgesTuple)
        self.assertIn(({'1', '2'}, {'t'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'1'}), hyperedgesTuple)
        # branch 3
        b3 = branches[2]
        self.assertEqual(b3.get_node_set(), H.get_node_set())
        hyperedges = b3.get_hyperedge_id_set()
        hyperedgesTuple = [(b3.get_hyperedge_tail(e),
                            b3.get_hyperedge_head(e))
                           for e in hyperedges]
        self.assertEqual(len(hyperedges), 8)
        self.assertIn(({'s'}, {'1'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'1'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'2'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2', '3'}, {'4'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'t'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'1'}), hyperedgesTuple)
示例#2
0
    def test_returns_correct_branching_for_nielsen_graph(self):
        H = self.nielsenGraph
        ordering = ['s', '1', '2', 't']
        pred = {
            's': None,
            '1': H.get_hyperedge_id({'s'}, {'1'}),
            '2': H.get_hyperedge_id({'s'}, {'2'}),
            't': H.get_hyperedge_id({'2', '1'}, {'t'})
        }

        branches = ksh._branching_step(H, pred, ordering)
        self.assertEqual(len(branches), 3)
        # branch 1
        b1 = branches[0]
        self.assertEqual(b1.get_node_set(), H.get_node_set())
        hyperedges = b1.get_hyperedge_id_set()
        hyperedgesTuple = [(b1.get_hyperedge_tail(e), b1.get_hyperedge_head(e))
                           for e in hyperedges]
        self.assertEqual(len(hyperedges), 6)
        self.assertIn(({'s'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2', '3'}, {'4'}), hyperedgesTuple)
        self.assertIn(({'1', '2'}, {'t'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'1'}), hyperedgesTuple)
        # branch 2
        b2 = branches[1]
        self.assertEqual(b2.get_node_set(), H.get_node_set())
        hyperedges = b2.get_hyperedge_id_set()
        hyperedgesTuple = [(b2.get_hyperedge_tail(e), b2.get_hyperedge_head(e))
                           for e in hyperedges]
        self.assertEqual(len(hyperedges), 7)
        self.assertIn(({'s'}, {'1'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'1'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'2'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2', '3'}, {'4'}), hyperedgesTuple)
        self.assertIn(({'1', '2'}, {'t'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'1'}), hyperedgesTuple)
        # branch 3
        b3 = branches[2]
        self.assertEqual(b3.get_node_set(), H.get_node_set())
        hyperedges = b3.get_hyperedge_id_set()
        hyperedgesTuple = [(b3.get_hyperedge_tail(e), b3.get_hyperedge_head(e))
                           for e in hyperedges]
        self.assertEqual(len(hyperedges), 8)
        self.assertIn(({'s'}, {'1'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'s'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'1'}, {'2'}), hyperedgesTuple)
        self.assertIn(({'2'}, {'3'}), hyperedgesTuple)
        self.assertIn(({'2', '3'}, {'4'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'t'}), hyperedgesTuple)
        self.assertIn(({'4'}, {'1'}), hyperedgesTuple)
 def test_returns_disconnected_nodes_on_graph_with_two_nodes(self):
     H = DirectedHypergraph()
     s, t = 's', 't'
     H.add_node(s)
     H.add_node(t)
     e1 = H.add_hyperedge({s}, {t})
     predecessor = {s: None, t: e1}
     ordering = [s, t]
     branch = ksh._branching_step(H, predecessor, ordering)[0]
     self.assertEqual(branch.get_hyperedge_id_set(), set([]))
     self.assertEqual(branch.get_node_set(), {'s', 't'})
示例#4
0
 def test_returns_disconnected_nodes_on_graph_with_two_nodes(self):
     H = DirectedHypergraph()
     s, t = 's', 't'
     H.add_node(s)
     H.add_node(t)
     e1 = H.add_hyperedge({s}, {t})
     predecessor = {s: None, t: e1}
     ordering = [s, t]
     branch = ksh._branching_step(H, predecessor, ordering)[0]
     self.assertEqual(branch.get_hyperedge_id_set(), set([]))
     self.assertEqual(branch.get_node_set(), {'s', 't'})