コード例 #1
0
ファイル: original.py プロジェクト: SajidQ/AI_CS382_Projects
                #print "v1: " + str(vertex1) + "v2: " + str(vertex2)
                graph.addEdge(vertex1,vertex2, edge=1)

        #do the diagonals
        vertex2=(((colLength-1)*row)+column)+(colLength)
        if(obstacles.count([x,y])==0 and (((colLength-1)*row)+column)<numVertices and edgeCheck.count([vertex2,vertex1])==0 and vertex1%(colLength-1)<(colLength-1) and vertex1%(rowLength-1)<(rowLength-1) and vertex2<numVertices and vertex1%(colLength-1)!=(colLength-2)):
            graph.addEdge(vertex1,vertex2, edge=math.sqrt(2))

        vertex1=(((colLength-1)*row)+column)
        vertex2=(((colLength-1)*row)+column)+(colLength-2)
        if((((colLength-1)*row)+column)<numVertices and vertex1%(colLength-1)<(colLength-1) and vertex1%(rowLength-1)<(rowLength-1) and vertex2<numVertices and vertex1%(colLength-1)!=0):
            if(not(obstacles.count([(x-1),y])!=0)):
                graph.addEdge(vertex1,vertex2, edge=math.sqrt(2))


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]