def printMatrix_CS(CS_placement): ''' function which prints the zones with a charging station ''' print("R:", gv.NRows, "C:", gv.NColumns) matrix = {} for row in range(gv.NRows): matrix[row] = {} for col in range(gv.NColumns, 0, -1): matrix[row][col] = " " for id in zonesMetrics["id"]: couple = sf.zoneIDtoMatrixCoordinates(id) matrix[couple[2]][couple[1]] = '\'' k = 0 for cs in CS_placement: couple = sf.zoneIDtoMatrixCoordinates(cs) matrix[couple[2]][couple[1]] = str(k) k += 1 print("\t") for i in range(gv.NColumns + 1, 0, -1): if i == gv.NColumns + 1: print("\t", end='') else: print(str(i) + "\t", end='') print() for row in range(gv.NRows - 1, -1, -1): print(str(row) + "\t", end='') for col in range(gv.NColumns, 0, -1): print(matrix[row][col] + "\t", end='') print() return
def printMatrix(xynew): ''' function which prints the zones with a charging station ''' print("R:", gv.NRows, "C:", gv.NColumns) matrix = {} for row in range(gv.NRows): matrix[row] = {} for col in range(gv.NColumns, 0, -1): matrix[row][col] = " " for id in zonesMetrics["id"]: couple = sf.zoneIDtoMatrixCoordinates(id) matrix[couple[2]][couple[1]] = '\'' for k in xynew.keys(): couple = xynew[k] matrix[couple[1]][couple[0]] = str(k) print("\t") for i in range(gv.NColumns + 1, 0, -1): if i == gv.NColumns + 1: print("\t", end='') else: print(str(i) + "\t", end='') print() for row in range(gv.NRows - 1, -1, -1): print(str(row) + "\t", end='') for col in range(gv.NColumns, 0, -1): print(matrix[row][col] + "\t", end='') print() return
def exploreNeighbours(): ''' extract a random index to chose which is the station to move :return: logical coordinates of NESW zones, NESW direction, logical index of the zone ''' xynew = {} direction = {} myindex = np.random.randint(len(RechargingStation_Zones), size=1)[0] ID = RechargingStation_Zones[myindex] print('extracted ID', ID) retv = sf.zoneIDtoMatrixCoordinates(ID) xy = [retv[1], retv[2]] max = 2 ## increment to have more choicee i = 0 for dst in range(1, max): xynew[i] = [xy[0] - dst, xy[1]] direction[i] = [0, xy[0] - dst, xy[1]] xynew[i + 1] = [xy[0], xy[1] - dst] direction[i + 1] = [1, xy[0], xy[1] - dst] xynew[i + 2] = [xy[0] + dst, xy[1]] direction[i + 2] = [2, xy[0] + dst, xy[1]] xynew[i + 3] = [xy[0], xy[1] + dst] direction[i + 3] = [3, xy[0], xy[1] + dst] i = i + 4 # print("expNeigh - dir", direction) # print() return xynew, direction, myindex