public List <Individual> GenerateGroupInitialPopulation() { List <Individual> initialPopulation = new List <Individual>(); for (int i = 0; i < populationCount; i++) { List <List <Machine> > schedule = new List <List <Machine> >(24); for (int j = 0; j < 24; j++) { schedule.Add(StaticOperations.GenerateMachineTemplate(scale)); } List <int> initialState = StaticOperations.GenerateInitialMachinesState(scale); List <int> hourlyPowerDemand = StaticOperations.GenerateHourlyLoads(scale); maximumHourChanges = StaticOperations.GenerateMaximumHourlyChanges(scale); Group baseGroup = new Group(new List <int> { 0, 1 }); Group intermittentGroup = new Group(new List <int> { 2, 3, 4 }); Group semiPeakGroup = new Group(new List <int> { 5, 6 }); Group peakGroup = new Group(new List <int> { 7, 8, 9 }); List <Group> groups = new List <Group> { baseGroup, intermittentGroup, semiPeakGroup, peakGroup }; List <List <Machine> > scheduleBackup = BackupSchedule(schedule); schedule[0] = RandomMachineHourGrouppedScheduleInitialisation(schedule[0], groups, hourlyPowerDemand[0]); ReviseMachineStatus(schedule[0], initialState); for (int j = 1; j < 24; j++) { schedule[j] = RandomMachineHourGrouppedScheduleInitialisationWithReference(schedule[j], schedule[j - 1], groups, hourlyPowerDemand[j], out bool success); ReviseMachineStatus(schedule[j], schedule[j - 1]); if (success == false) { j = 0; RestoreScheduleFromBackup(schedule, scheduleBackup); schedule[0] = RandomMachineHourGrouppedScheduleInitialisation(schedule[0], groups, hourlyPowerDemand[0]); ReviseMachineStatus(schedule[0], initialState); } } Individual representation = new Individual(schedule) { groups = groups }; initialPopulation.Add(representation); } return(initialPopulation); }
public List <Individual> GenerateInitialPopulation() { List <Individual> initialPopulation = new List <Individual>(); for (int i = 0; i < populationCount; i++) { List <List <Machine> > schedule = new List <List <Machine> >(24); for (int j = 0; j < 24; j++) { schedule.Add(StaticOperations.GenerateMachineTemplate(scale)); } List <int> initialState = StaticOperations.GenerateInitialMachinesState(scale); List <int> hourlyPowerDemand = StaticOperations.GenerateHourlyLoads(scale); List <int> maximumHourlyChanges = StaticOperations.GenerateMaximumHourlyChanges(scale); List <List <Machine> > scheduleBackup = BackupSchedule(schedule); // 1.) Randomly generate first hour schedule schedule[0] = RandomMachineHourScheduleGeneration(schedule[0], hourlyPowerDemand[0]); ReviseMachineStatus(schedule[0], initialState); for (int j = 1; j < 24; j++) { schedule[j] = RandomMachineHourScheduleGenerationWithReference(schedule[j - 1], hourlyPowerDemand[j], out bool success); ReviseMachineStatus(schedule[j], schedule[j - 1]); if (success == false) { j = 0; RestoreScheduleFromBackup(schedule, scheduleBackup); schedule[0] = RandomMachineHourScheduleGeneration(schedule[0], hourlyPowerDemand[0]); double hourPower = schedule[0].Sum(item => item.CurrentOutputPower); ReviseMachineStatus(schedule[0], initialState); } } Individual representation = new Individual(schedule); initialPopulation.Add(representation); Console.WriteLine("Initial population count: " + i); } return(initialPopulation); }