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); }
private void SaveBestIndividualIntoFile(Individual representation) { FileStream memoryStream = new FileStream("riesenie.pdf", FileMode.OpenOrCreate, FileAccess.Write); Document document = new Document(PageSize.A4, 10, 10, 10, 10); PdfWriter writer = PdfWriter.GetInstance(document, memoryStream); document.Open(); PdfPTable table = new PdfPTable(10 * scale + 2) { SpacingBefore = 3, SpacingAfter = 3, HorizontalAlignment = Element.ALIGN_LEFT }; Font font6 = FontFactory.GetFont(FontFactory.TIMES, BaseFont.CP1250, BaseFont.EMBEDDED, 6f); Font boldFont6 = FontFactory.GetFont(FontFactory.TIMES_BOLD, BaseFont.CP1250, BaseFont.EMBEDDED, 6f); List <float> widths = new List <float>(); for (int i = 0; i < scale; i++) { for (int j = 0; j < 10; j++) { widths.Add(60f); } } widths.AddRange(new List <float> { 60f, 60f }); table.SetWidths(widths.ToArray()); // Row 1 PdfPCell cell11 = CreateAlignedCell("S.No", boldFont6); cell11.Rowspan = 2; table.AddCell(cell11); PdfPCell cell12 = CreateAlignedCell("Load \n (MW)", boldFont6); cell12.Rowspan = 2; table.AddCell(cell12); PdfPCell cell13 = CreateAlignedCell("Commitment schedule", font6); cell13.Colspan = 10 * scale; table.AddCell(cell13); // Row 2 for (int i = 1; i < 1 + 10 * scale; i++) { PdfPCell numberCell = CreateAlignedCell(i + "", boldFont6); table.AddCell(numberCell); } // Row 3 - 26 List <int> hourlyLoads = StaticOperations.GenerateHourlyLoads(scale); for (int i = 1; i < 25; i++) { PdfPCell iteratorCell = CreateAlignedCell(i + "", font6); table.AddCell(iteratorCell); PdfPCell loadCell = CreateAlignedCell(hourlyLoads[i - 1] + "", font6); table.AddCell(loadCell); for (int j = 0; j < representation.Schedule[i - 1].Count; j++) { PdfPCell unitCell = CreateAlignedCell( String.Format("{0:0.#}", representation.Schedule[i - 1][j].CurrentOutputPower), font6); table.AddCell(unitCell); } } document.Add(table); Paragraph paragraph = new Paragraph("Total operating cost: " + representation.Fitness + "$.") { SpacingBefore = 3, SpacingAfter = 3, Font = FontFactory.GetFont(FontFactory.TIMES, 9, BaseColor.BLACK), Alignment = 0 }; document.Add(paragraph); if (representation.groups != null) { int counter = 0; foreach (Group group in representation.groups) { counter++; StringBuilder builder = new StringBuilder(); builder.Append("Group " + counter + ": "); foreach (int machine in group.grouppedMachines) { builder.Append((machine + 1) + ", "); } string final = builder.ToString().TrimEnd(' ').TrimEnd(','); Paragraph groupParagraph = new Paragraph(final) { SpacingBefore = 3, SpacingAfter = 3, Font = FontFactory.GetFont(FontFactory.TIMES, 9, BaseColor.BLACK), Alignment = 0 }; document.Add(groupParagraph); } } document.Close(); memoryStream.Close(); }