Documentation |
Transfers a squared matrix into a directed graph
This functionality does not run in MATLAB.
Graph::createGraphFromMatrix(M)
Graph::createGraphFromMatrix(M) generates a directed Graph where each m_{i, j} in the matrix defines an edge fromi to j. The value of the cell defines the weight of the resulting edge.
The vertices of the generated graph are labeled with the numbers 1 to n, where n defines the column/row-dimension of the matrix. Since the matrix has to be squared, n stays the same.
A matrix is defined and the resulting squared matrix is transfered into a Graph.
a := matrix([[3, 2, 4], [2, 3, 6], [4, 8, 3]]); G := Graph::createGraphFromMatrix(a): Graph::printGraphInformation(G)
Vertices: [1, 2, 3] Edges: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] Vertex weights: no vertex weights. Edge descriptions: no edge descriptions. Edge weights: [1, 1] = 3, [1, 2] = 2, [1, 3] = 4, [2, 1] = 2, [2, 2] = 3, [2, 3] = 6, [3, 1] = 4, [3, 2] = 8, [3, 3] = \ 3 (other existing edges have no weight) Edge costs: no edge costs. Adjacency list (out): 1 = [1, 2, 3], 2 = [1, 2, 3], 3 = [1, 2, 3] Adjacency list (in): 1 = [1, 2, 3], 2 = [1, 2, 3], 3 = [1, 2, 3] Graph is directed.