numEdges=graph.getNumEdges() print "\nVertices: " + str(graph.getNumVertices()) print "Edges: " + str(graph.getNumEdges()) #----------------------------------- # Here is where we choose a random start/goal locations. You probably don't need to touch any of this. if(file_provided==False): goal=[] start=[] #---- Get random start ------------------ while start==[]: id=int((i*random.random())%i) vrtx=graph.getVertex(id) if(len(graph.neighbours(id))>1): x=vrtx[0] y=vrtx[1] if(x!=0 and x!=colLength and y!=0 and y!=rowLength): start=[x,y] #---- Get random goal ------------------- while goal==[]: id=int((i*random.random())%i) vrtx=graph.getVertex(id) if(len(graph.neighbours(id))>1): x=vrtx[0] y=vrtx[1] if(start!=[x,y] and x!=0 and x!=colLength and y!=0 and y!=rowLength): goal=[x,y]
""" Name: Generate Graph: Author: Jia_qiu Wang(王佳秋) Data: December, 2016 function: """ from apgl.graph import GeneralVertexList, SparseGraph import numpy numVertices = 5 # 顶点个数 graph = SparseGraph(numVertices) # 具有5个顶点个数的图数据结构 graph[0, 1] = 1 graph[0, 2] = 3 graph[1, 2] = 0.1 graph[3, 4] = 2 graph.setVertex(0, "abc") graph.setVertex(1, 123) print(graph.findConnectedComponents()) # 输出联通分量 print(graph.getWeightMatrix()) # 输出图的邻接矩阵 # print(graph.degreeDistribution()) print(graph.neighbours(0)) print(graph)