def createModelBatteries(self): modelBatteries = [] for i in range (0, len(self.batteries)): modelBatteries.append(Model.Battery(i+1)) return modelBatteries
def randomize(env): modelBatteries = [] # create the array of batteries with the id starting at 1 for i in range(0, len(env.batteries)): maxCap = env.batteries[i].maxCapacity battery = Model.Battery(i + 1) modelBatteries.append(battery) # assign every house to a random battery of which the capacity is still sufficient listOfHouses = env.houses random.shuffle(listOfHouses) # assign random battery to every house for house in listOfHouses: batIndexes = [] for i in range(0, len(env.batteries)): batIndexes.append(i) assignToRandomBattery(batIndexes, env.batteries, house, modelBatteries) # check if every house is connected totalHouses = 0 for battery in modelBatteries: totalHouses += len(battery.houses) if totalHouses == len(env.houses): # assign all the values into a model model = Model(modelBatteries) # calculate the costs of this option model.calculateCosts(env.distanceTable) return model else: return False
def genomeToModel(genome, env): # create the array of batteries with the id starting at 1 modelBatteries = [] for i in range(0, len(env.batteries)): battery = Model.Battery(i + 1) modelBatteries.append(battery) # create child model newModel = Model(modelBatteries) for battery in newModel.modelBatteries: battery.setMaxCapacity(env) # fill list of houses belonging to battery in new model according to genome for gene in genome: for house in env.houses: if house.idHouse == (gene[0]): corHouse = house newModel.modelBatteries[gene[1] - 1].houses.append(corHouse) newModel.calculateCosts(env.distanceTable) return newModel