Esempio n. 1
0
    def test_metric_closure_no_weight(self):
        M = metric_closure(self.M, weight=None)

        mc = [
            ('A', 'C', {'distance': 2, 'keys': ['k1', 'k3'], 'path': ['A', 'B', 'C']}),
            ('A', 'E', {'distance': 3, 'keys': ['k1', 'k3', 'k7'], 'path': ['A', 'B', 'C', 'E']}),
            ('A', 'F', {'distance': 4, 'keys': ['k1', 'k3', 'k6', 'k8'], 'path': ['A', 'B', 'C', 'D', 'F']}),
            ('A', 'B', {'distance': 1, 'keys': ['k1'], 'path': ['A', 'B']}),
            ('A', 'H', {'distance': 4, 'keys': ['k1', 'k3', 'k7', 'k12'], 'path': ['A', 'B', 'C', 'E', 'H']}),
            ('A', 'D', {'distance': 3, 'keys': ['k1', 'k3', 'k6'], 'path': ['A', 'B', 'C', 'D']}),
            ('C', 'B', {'distance': 1, 'keys': ['k3'], 'path': ['B', 'C']}),
            ('C', 'E', {'distance': 1, 'keys': ['k7'], 'path': ['C', 'E']}),
            ('C', 'F', {'distance': 2, 'keys': ['k6', 'k8'], 'path': ['C', 'D', 'F']}),
            ('C', 'H', {'distance': 2, 'keys': ['k7', 'k12'], 'path': ['C', 'E', 'H']}),
            ('C', 'D', {'distance': 1, 'keys': ['k6'], 'path': ['C', 'D']}),
            ('E', 'B', {'distance': 2, 'keys': ['k3', 'k7'], 'path': ['B', 'C', 'E']}),
            ('E', 'D', {'distance': 2, 'keys': ['k6', 'k7'], 'path': ['D', 'C', 'E']}),
            ('E', 'F', {'distance': 2, 'keys': ['k12', 'k10'], 'path': ['E', 'H', 'F']}),
            ('E', 'H', {'distance': 1, 'keys': ['k12'], 'path': ['E', 'H']}),
            ('F', 'B', {'distance': 3, 'keys': ['k3', 'k6', 'k8'], 'path': ['B', 'C', 'D', 'F']}),
            ('F', 'D', {'distance': 1, 'keys': ['k8'], 'path': ['D', 'F']}),
            ('F', 'H', {'distance': 1, 'keys': ['k10'], 'path': ['F', 'H']}),
            ('B', 'H', {'distance': 3, 'keys': ['k3', 'k7', 'k12'], 'path': ['B', 'C', 'E', 'H']}),
            ('B', 'D', {'distance': 2, 'keys': ['k3', 'k6'], 'path': ['B', 'C', 'D']}),
            ('H', 'D', {'distance': 2, 'keys': ['k8', 'k10'], 'path': ['D', 'F', 'H']})
        ]

        assert_edges_equal(list(M.edges(data=True)), mc)
Esempio n. 2
0
    def test_metric_closure_multigraph(self):
        M = metric_closure(self.M)

        mc = [
            ('A', 'C', {'distance': 4, 'keys': ['k1', 'k4'], 'path': ['A', 'B', 'C']}),
            ('A', 'D', {'distance': 6, 'keys': ['k1', 'k4', 'k6'], 'path': ['A', 'B', 'C', 'D']}),
            ('A', 'B', {'distance': 2, 'keys': ['k1'], 'path': ['A', 'B']}),
            ('A', 'F', {'distance': 8, 'keys': ['k1', 'k4', 'k6', 'k8'], 'path': ['A', 'B', 'C', 'D', 'F']}),
            ('A', 'H', {'distance': 10, 'keys': ['k1', 'k4', 'k6', 'k8', 'k10'], 'path': ['A', 'B', 'C', 'D', 'F', 'H']}),
            ('A', 'E', {'distance': 6, 'keys': ['k1', 'k4', 'k7'], 'path': ['A', 'B', 'C', 'E']}),
            ('C', 'B', {'distance': 2, 'keys': ['k4'], 'path': ['B', 'C']}),
            ('C', 'D', {'distance': 2, 'keys': ['k6'], 'path': ['C', 'D']}),
            ('C', 'F', {'distance': 4, 'keys': ['k6', 'k8'], 'path': ['C', 'D', 'F']}),
            ('C', 'H', {'distance': 6, 'keys': ['k6', 'k8', 'k10'], 'path': ['C', 'D', 'F', 'H']}),
            ('C', 'E', {'distance': 2, 'keys': ['k7'], 'path': ['C', 'E']}),
            ('D', 'B', {'distance': 4, 'keys': ['k4', 'k6'], 'path': ['B', 'C', 'D']}),
            ('D', 'F', {'distance': 2, 'keys': ['k8'], 'path': ['D', 'F']}),
            ('D', 'H', {'distance': 4, 'keys': ['k8', 'k10'], 'path': ['D', 'F', 'H']}),
            ('D', 'E', {'distance': 4, 'keys': ['k6', 'k7'], 'path': ['D', 'C', 'E']}),
            ('B', 'F', {'distance': 6, 'keys': ['k4', 'k6', 'k8'], 'path': ['B', 'C', 'D', 'F']}),
            ('B', 'H', {'distance': 8, 'keys': ['k4', 'k6', 'k8', 'k10'], 'path': ['B', 'C', 'D', 'F', 'H']}),
            ('B', 'E', {'distance': 4, 'keys': ['k4', 'k7'], 'path': ['B', 'C', 'E']}),
            ('F', 'E', {'distance': 6, 'keys': ['k7', 'k6', 'k8'], 'path': ['E', 'C', 'D', 'F']}),
            ('F', 'H', {'distance': 2, 'keys': ['k10'], 'path': ['F', 'H']}),
            ('H', 'E', {'distance': 5, 'keys': ['k12'], 'path': ['E', 'H']})
        ]

        assert_edges_equal(list(M.edges(data=True)), mc)
Esempio n. 3
0
    def test_metric_closure(self):
        M = metric_closure(self.G)
        mc = [(1, 2, {'distance': 10, 'path': [1, 2], 'keys': None, }),
              (1, 3, {'distance': 20, 'path': [1, 2, 3], 'keys': None, }),
              (1, 4, {'distance': 22, 'path': [1, 2, 7, 5, 4], 'keys': None, }),
              (1, 5, {'distance': 12, 'path': [1, 2, 7, 5], 'keys': None, }),
              (1, 6, {'distance': 22, 'path': [1, 2, 7, 5, 6], 'keys': None, }),
              (1, 7, {'distance': 11, 'path': [1, 2, 7], 'keys': None, }),
              (2, 3, {'distance': 10, 'path': [2, 3], 'keys': None, }),
              (2, 4, {'distance': 12, 'path': [2, 7, 5, 4], 'keys': None, }),
              (2, 5, {'distance': 2, 'path': [2, 7, 5], 'keys': None, }),
              (2, 6, {'distance': 12, 'path': [2, 7, 5, 6], 'keys': None, }),
              (2, 7, {'distance': 1, 'path': [2, 7], 'keys': None, }),
              (3, 4, {'distance': 10, 'path': [3, 4], 'keys': None, }),
              (3, 5, {'distance': 12, 'path': [3, 2, 7, 5], 'keys': None, }),
              (3, 6, {'distance': 22, 'path': [3, 2, 7, 5, 6], 'keys': None, }),
              (3, 7, {'distance': 11, 'path': [3, 2, 7], 'keys': None, }),
              (4, 5, {'distance': 10, 'path': [4, 5], 'keys': None, }),
              (4, 6, {'distance': 20, 'path': [4, 5, 6], 'keys': None, }),
              (4, 7, {'distance': 11, 'path': [4, 5, 7], 'keys': None, }),
              (5, 6, {'distance': 10, 'path': [5, 6], 'keys': None, }),
              (5, 7, {'distance': 1, 'path': [5, 7], 'keys': None, }),
              (6, 7, {'distance': 11, 'path': [6, 5, 7], 'keys': None, })]

        assert_edges_equal(list(M.edges(data=True)), mc)
Esempio n. 4
0
 def test_metric_closure(self):
     M = metric_closure(self.G)
     mc = [
         (1, 2, {"distance": 10, "path": [1, 2]}),
         (1, 3, {"distance": 20, "path": [1, 2, 3]}),
         (1, 4, {"distance": 22, "path": [1, 2, 7, 5, 4]}),
         (1, 5, {"distance": 12, "path": [1, 2, 7, 5]}),
         (1, 6, {"distance": 22, "path": [1, 2, 7, 5, 6]}),
         (1, 7, {"distance": 11, "path": [1, 2, 7]}),
         (2, 3, {"distance": 10, "path": [2, 3]}),
         (2, 4, {"distance": 12, "path": [2, 7, 5, 4]}),
         (2, 5, {"distance": 2, "path": [2, 7, 5]}),
         (2, 6, {"distance": 12, "path": [2, 7, 5, 6]}),
         (2, 7, {"distance": 1, "path": [2, 7]}),
         (3, 4, {"distance": 10, "path": [3, 4]}),
         (3, 5, {"distance": 12, "path": [3, 2, 7, 5]}),
         (3, 6, {"distance": 22, "path": [3, 2, 7, 5, 6]}),
         (3, 7, {"distance": 11, "path": [3, 2, 7]}),
         (4, 5, {"distance": 10, "path": [4, 5]}),
         (4, 6, {"distance": 20, "path": [4, 5, 6]}),
         (4, 7, {"distance": 11, "path": [4, 5, 7]}),
         (5, 6, {"distance": 10, "path": [5, 6]}),
         (5, 7, {"distance": 1, "path": [5, 7]}),
         (6, 7, {"distance": 11, "path": [6, 5, 7]}),
     ]
     assert_edges_equal(list(M.edges(data=True)), mc)
def calculate_subgraphs_metric_closures(graphs: Collection,
                                        weight: str = None
                                        ) -> typing.List[nx.Graph]:
    metric_closures = []

    for g in graphs:
        metric_closures.append(metric_closure(g, weight=weight))

    return metric_closures
Esempio n. 6
0
 def test_metric_closure(self):
     M = metric_closure(self.G)
     mc = [(1, 2, {'distance': 10, 'path': [1, 2]}),
           (1, 3, {'distance': 20, 'path': [1, 2, 3]}),
           (1, 4, {'distance': 22, 'path': [1, 2, 7, 5, 4]}),
           (1, 5, {'distance': 12, 'path': [1, 2, 7, 5]}),
           (1, 6, {'distance': 22, 'path': [1, 2, 7, 5, 6]}),
           (1, 7, {'distance': 11, 'path': [1, 2, 7]}),
           (2, 3, {'distance': 10, 'path': [2, 3]}),
           (2, 4, {'distance': 12, 'path': [2, 7, 5, 4]}),
           (2, 5, {'distance': 2, 'path': [2, 7, 5]}),
           (2, 6, {'distance': 12, 'path': [2, 7, 5, 6]}),
           (2, 7, {'distance': 1, 'path': [2, 7]}),
           (3, 4, {'distance': 10, 'path': [3, 4]}),
           (3, 5, {'distance': 12, 'path': [3, 2, 7, 5]}),
           (3, 6, {'distance': 22, 'path': [3, 2, 7, 5, 6]}),
           (3, 7, {'distance': 11, 'path': [3, 2, 7]}),
           (4, 5, {'distance': 10, 'path': [4, 5]}),
           (4, 6, {'distance': 20, 'path': [4, 5, 6]}),
           (4, 7, {'distance': 11, 'path': [4, 5, 7]}),
           (5, 6, {'distance': 10, 'path': [5, 6]}),
           (5, 7, {'distance': 1, 'path': [5, 7]}),
           (6, 7, {'distance': 11, 'path': [6, 5, 7]})]
     assert_edges_equal(list(M.edges(data=True)), mc)