totalDelN = 0 ndKeys = roadAdjList.getVertices() ndKeys = Set(ndKeys) delVnum = 1 while (delVnum>0): roundNum += 1 delVnum = 0 delVertex = Set() for u in ndKeys: nb = roadAdjList.vertList[u].getConnections() if len(nb)==2: vec1 = directionalVec(nb[0], u) vec2 = directionalVec(nb[1], u) prod = innerProduct(vec1, vec2) if abs(prod)>0.9: roadAdjList.removeMiddlePt(u) delVnum += 1 delVertex.add(u) for u in delVertex: ndKeys.remove(u) totalDelN += delVnum print ('{} intermediate nodes removed in round {}').format(delVnum, roundNum) print ('total number of intermediate nodes removed is {}'.format(totalDelN)) roadAdjList.recountVandE() print 'road Adjacency List generated' print 'total number of line segments:' +str(lineNum) print 'with total number of vertices: '+str(roadAdjList.numVertices) print 'with total number of edges: '+str(roadAdjList.numEdges) pickle.dump(roadAdjList, open('CamBosRoadMapFT.p', 'wb'))