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); }
private void ReviseMachineStatus(Individual representation) { List <int> initialState = StaticOperations.GenerateInitialMachinesState(scale); // Calculate values of current machine states for (int i = 0; i < representation.Schedule.Count; i++) { List <int> referenceStates = null; if (i == 0) { referenceStates = initialState; } else { referenceStates = representation.Schedule[i - 1].Select(machine => machine.CurrentStatus).ToList(); } for (int j = 0; j < representation.Schedule[i].Count; j++) { Machine current = representation.Schedule[i][j]; if (current.CurrentOutputPower > 0) { // Machine was running in previous hour if (referenceStates[j] > 0) { current.CurrentStatus = referenceStates[j] + 1; } // Machine was turned off in previous hour if (referenceStates[j] < 0) { current.CurrentStatus = 1; } } if (current.CurrentOutputPower == 0) { // Machine was running in previous hour if (referenceStates[j] > 0) { current.CurrentStatus = -1; } if (referenceStates[j] < 0) { current.CurrentStatus = referenceStates[j] - 1; } } } } }
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); }
public Evaluation(int scale) { initialState = StaticOperations.GenerateInitialMachinesState(scale); this.scale = scale; }