from Graph_tool import multigraph as mg from Graph_tool import direct_multigraph as dmg G = mg(3, 4) G = mg.set_vertex(G, ["1", "2", "3"]) G = mg.set_edge(G, ["12", "23", "22", "33"]) mg.set_adjMatrix(G, 0, 1, 1) mg.set_adjMatrix(G, 1, 2, 1) mg.set_adjMatrix(G, 1, 1, 1) mg.set_adjMatrix(G, 2, 2, 1) mg.set_inMatrix(G, 0, 0, 1) mg.set_inMatrix(G, 1, 1, 1) mg.set_inMatrix(G, 1, 2, 1) mg.set_inMatrix(G, 2, 3, 1) mg.display_vertex(G) mg.display_edge(G) mg.display_adjMatrix(G) mg.display_inMatrix(G) del G G = dmg(3, 4) G = dmg.set_node(G, ["1", "2", "3"]) G = dmg.set_arc(G, ["(1,2)", "(2,1)", "(3,1)", "(3,2)"]) dmg.display_arc(G) dmg.display_node(G) dmg.display_adjMatrix(G) dmg.display_inInMatrix(G) dmg.display_outInMatrix(G) del G
import sys import os import copy import numpy as np from Graph_tool import multigraph as mg; from Graph_tool import direct_multigraph as dmg; Graph_dir=r'C:\Users\Mr Nam\Desktop\TP\Graph' Graph_dir=r'C:\Users\Mr Nam\Desktop\TP\Graph' Graph_1_18_dir=os.path.join(Graph_dir,'Graph_1_18') G_19=mg(6,7) G_19.Vertices=['0', '1', '2', '3', '4', '5'] G_19.Edges=['(0,2)', '(0,4)', '(1,0)', '(2,3)', '(2,4)', '(3,5)', '(4,5)' ] G_19.generate_InMatrix() G_19.generate_adjMatrix() def SPANNINGTREE(Graph): def succ(u): k=0 result=[] for i in Graph.adjMatrix[Graph.Vertices.index(u)]: if i==1:
[0, 0, 0, 0, 1, 0]] G_18.write_Weight(os.path.join(Graph_1_18_dir,'WeightMatrix.txt')) G_29=dmg(6,6) G_29.set_node(["1","2","3","4","5","6"]) G_29.set_arc(["(1,3)","(2,3)","(3,4)","(4,5)","(5,6)","(6,4)"]); G_29.generate_adjMatrix() G_29.generate_in_out_InMatrix() G_29.write_arcs(os.path.join(Graph_1_29_dir,'arcs.txt')) G_29.write_nodes(os.path.join(Graph_1_29_dir,'nodes.txt')) G_29.write_adjMatrix(os.path.join(Graph_1_29_dir,'adjMatrix.txt')) G_29.write_inInMatrix(os.path.join(Graph_1_29_dir,'inInMatrix.txt')) G_29.write_outInMatrix(os.path.join(Graph_1_29_dir,'outInMatrix.txt')) G_33=mg(12,11) G_33.Vertices=['1', '2', '3', '4', '5','6','7','8','9','10','11','12'] G_33.Edges=['(1,2)', '(1,3)', '(2,4)', '(2,5)', '(4,8)', '(4,9)', '(3,7)', '(3,6)', '(6,10)', '(6,11)', '(7,12)'] G_33.generate_adjMatrix() G_33.generate_InMatrix()