Esempio n. 1
0
 def test_get_adjacency_matrix(self):
     json_graph = {"graph": {"A": ["B"], "B": []}}
     graph = Graph(input_graph=json.dumps(json_graph))
     matrix = graph.get_adjacency_matrix()
     answer = np.array([[0, 1], [0, 0]])
     np.testing.assert_equal(matrix, answer)
     self.assertEqual(answer.size, matrix.size)
Esempio n. 2
0
def get_complement(graph: Graph) -> Graph:
    """
    If graph is represented as a matrix, invert that matrix
    :param graph:
    :return: inversion of graph
    """
    adj = graph.get_adjacency_matrix()
    complement = invert(adj)
    return Graph(label=f"{graph.get_label()} complement",
                 input_array=complement)