#---- Making the Graph --------------------------------------------- # This initializes the graph, just basic things (its in the SparseGraph Ex) numFeatures=0 numVertices=(rowLength-1)*(colLength-1) vList=GeneralVertexList(numVertices) weightMatrix = scipy.sparse.lil_matrix((numVertices, numVertices)) graph = SparseGraph(vList,True, W=weightMatrix) # HERE IS YOUR GRAPH! #-- This assigns to each vertex an array as a value. In the array, the first value is the x location, and then y (row), and 1 implies the vertex is unexplored. 0 will mean it is closed. The fourth value determines whether the vertex is in the fringe (1) or not (0) #-- 5th value-g(A*), h(A*), f(A*), g(Theta*), h(Theta*), f(Theta*) row=1 for i in range (graph.getNumVertices()): if(i%(colLength-1)==0 and i!=0): row=row+1 graph.setVertex(i, [(i%(colLength-1))+1,row, 1, 0,100000000000.0,0.0, 100000000000.0,100000000000.0, 0.0, 100000000000.0]) #----- Connect vertices # This just runs through and connects the vertices # This is pretty complicated, and you don't need to worry about it. The code here should be right becuase the red edges are draen correctly edgeCheck=[] for row in range((rowLength-1)): for column in range(colLength-1): x=column+1 y=row+1 vertex1=(((colLength-1)*row)+column) vertex2=(((colLength-1)*row)+column)+1 if((((colLength-1)*row)+column)<numVertices and edgeCheck.count([vertex2,vertex1])==0 and vertex1%(colLength-1)<(colLength-2)):
#---- Making the Graph --------------------------------------------- # This initializes the graph, just basic things (its in the SparseGraph Ex) numFeatures=0 numVertices=(rowLength-1)*(colLength-1) vList=GeneralVertexList(numVertices) weightMatrix = scipy.sparse.lil_matrix((numVertices, numVertices)) graph = SparseGraph(vList,True, W=weightMatrix) # HERE IS YOUR GRAPH! #-- This assigns to each vertex an array as a value. In the array, the first value is the x location, and then y (row), and 1 implies the vertex is unexplored. 0 will mean it is closed. The fourth value determines whether the vertex is in the fringe (1) or not (0) #-- 5th value-g(A*), h(A*), f(A*), g(Theta*), h(Theta*), f(Theta*) row=1 for i in range (graph.getNumVertices()): if(i%(colLength-1)==0 and i!=0): row=row+1 graph.setVertex(i, [(i%(colLength-1))+1,row, 1, 0,100000000000.0,0.0, 100000000000.0,100000000000.0, 0.0, 100000000000.0]) """ check the vertex values for i in range (graph.getNumVertices()): print "vertexVal: "+str(i)+ " " + str(graph.getVertex(i)) """ #----- Connect vertices # This just runs through and connects the vertices # This is pretty complicated, and you don't need to worry about it. The code here should be right becuase the red edges are draen correctly edgeCheck=[] for row in range((rowLength-1)): for column in range(colLength-1): x=column+1 y=row+1 vertex1=(((colLength-1)*row)+column)
""" 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)