def getAllDestinations(self): results = self.destinationDao.getAllSyntheticDestinations(self.distType) for row in results: newDestination = Destination.Destination(row['destinationid'], row['x'], row['y'], row['demand']) newDestination.x = round(newDestination.x, 4) newDestination.y = round(newDestination.y, 4) self.destinations[newDestination.id] = newDestination self.n = len(self.destinations)
def getAllDestinations(self): results = self.destinationDao.getAllSyntheticDestinations(self.distType) for row in results: newDestination = Destination.Destination(row['destinationid'], row['x'], row['y'], row['demand']) self.destinations[newDestination.id] = newDestination newDestination.x = round(newDestination.x, 2) newDestination.y = round(newDestination.y, 2) #print('x = ' + str(newDestination.x)+ ', y = ' + str(newDestination.y)) self.n = len(self.destinations)
def getAllDestinations(self): #results = self.destinationDao.getAllSyntheticDestinations(self.distType) results = self.destinationDao.getAllDestinations() for row in results: newDestination = Destination.Destination(row['destinationid'], row['x'], row['y'], row['demand']) self.destinations[newDestination.id] = newDestination self.n = len(self.destinations)
def getAllDestinations(self): results = self.destinationDao.getAllSyntheticDestinations( self.distType) for row in results: newDestination = Destination.Destination(row['destinationid'], row['x'], row['y'], row['demand']) self.totalDemandInTheRegion += int(row['demand']) self.destinations[newDestination.id] = newDestination self.n = len(self.destinations) print("Number of destintions " + str(self.n))
def findClosestDestination(self, x, y): tempDestination = Destination.Destination(-1, x, y, 0) # print(" FInd closest for " + str(x) + ", " + str(y)) minDistance = sys.maxsize closestDest = None for d in self.destinations: distance = self.util.calculateDistanceBetweenDestinations(self.destinations.get(d), tempDestination) if minDistance > distance: # print("UPDATING MIN DISTANCE " + str(d)) minDistance = distance closestDest = self.destinations.get(d) return closestDest
def getAllDestinations(self): #results = self.destinationDao.getAllSyntheticDestinations(self.distType) results = self.destinationDao.getAllDestinations() index = 0 for row in results: newDestination = Destination.Destination(row['destinationid'], row['x'], row['y'], row['demand']) entry = [] entry.append(row['x']) entry.append(row['y']) self.destinationData.append(entry) self.destinationIds[index] = row['destinationid'] self.totalDemandInTheRegion += int(row['demand']) self.destinations[newDestination.id] = newDestination index += 1 self.n = len(self.destinations)
def createDestinations(self): mu = params['mean'] std = params['std'] assignedCells = [] availableCells = [] destination = Destination.Destination(1, -1, -1, 0) demandToBeAssigned = int(numpy.random.normal(loc=mu, scale=std)) assigned = 0 print("grid size " + str(len(self.pmgrid.grid))) assignedCellIndex = 0 i = self.pmgrid.grid[0] totalPop = 0 for cellIndex in self.pmgrid.grid: cell = self.pmgrid.grid.get(cellIndex) availableCells.append(cell.id) totalPop += cell.pCount print("sum of cellss = " + str(totalPop)) pop = 0 did = 1 minCell = None while assigned < len(self.pmgrid.grid) and len(availableCells) > 0: if len(destination.cells ) == 0 or destination.demand > demandToBeAssigned: # print("Assigned = " + str(assigned)) print("Population till now= " + str(pop)) assigendPop = self.getPopulationFromCellsInArray(assignedCells) remainingPop = self.getPopulationFromCellsInArray( availableCells) print("assigned POP " + str(assigendPop) + ", available pop " + str(remainingPop)) t = assigendPop + remainingPop print("total - " + str(t)) print("\n\n OO Lala New Destination") if destination.demand >= demandToBeAssigned: self.destinations.append(destination) print("assignment status for" + str(i.id) + " is " + str(i.assigned)) if i.id in availableCells: i.assigned = True destination = Destination.Destination(did, -1, -1, 0) did += 1 destination.cells.append(i) availableCells.remove(i.id) assignedCells.append(i.id) destination.x = i.point.x destination.y = i.point.y destination.demand += i.pCount assigned = len(assignedCells) pop += i.pCount demandToBeAssigned = int(numpy.random.normal(loc=mu, scale=std)) print("Demand to be assigned " + str(demandToBeAssigned)) while (destination.demand <= demandToBeAssigned): # print("current demand = " + str(destination.demand)) # print("Total POP assigned " + str(pop) ) if (assigned < len(self.pmgrid.grid) and pop <= totalPop): if (len(availableCells) > 0): # print("Available Cells " + str(len(availableCells))) # print("Assigned gc = " + str(assigned)) median = self.getCurrentMedian(destination) minCell = self.getClosestCell(median, availableCells) # print("assignment status for " + str(minCell) + str(minCell.assigned)) if minCell.id in availableCells: assignedCells.append(minCell.id) availableCells.remove(minCell.id) destination.cells.append(minCell) minCell.assigned = True destination.demand += minCell.pCount pop += minCell.pCount assigned = len(assignedCells) else: print("Blasphemy") print(availableCells) print("Min cell id" + str(minCell.id)) else: break else: break if minCell is not None: if len(availableCells) > 0: i = self.getClosestCell(minCell.point, availableCells) else: break print("Available Cells " + str(len(availableCells))) print("assigned Cells " + str(len(assignedCells))) if pop > totalPop: break print("DID: " + str(did)) print("Len of assigned cells = " + str(len(assignedCells))) print("Len of available cells = " + str(len(availableCells)))