private double CalcFitness(Individual person) { SkyLine = new SkyLineBinPack(MainRectangle.Width, Convert.ToBoolean(CompareCrossOver_Mutation.Default.SkyLineWasteSpace)); SkyLine.ApplySkyLine(person.chromosome); int Out_Module_Area = 0; for (int i = 0; i < person.chromosome.Count; i++) { if (person.chromosome[i].Y + person.chromosome[i].Height > MainRectangle.Height) { Out_Module_Area += person.chromosome[i].Height * person.chromosome[i].Width; } } double _fitness = Out_Module_Area; return(_fitness); }
private double CalcFitness(Individual person) { SkyLine = new SkyLineBinPack(MainForm.MainRectangle.Width, Convert.ToBoolean(ProgramSettings.Default.SkyLineWasteSpace)); SkyLine.ApplySkyLine(person.chromosome); int Out_Module_Area = 0; for (int i = 0; i < person.chromosome.Count; i++) { if (person.chromosome[i].Y + person.chromosome[i].Height > MainForm.MainRectangle.Height && person.chromosome[i].Y <= MainForm.MainRectangle.Height) { Out_Module_Area += ((person.chromosome[i].Y + person.chromosome[i].Height) - MainForm.MainRectangle.Height) * person.chromosome[i].Width; } else if (person.chromosome[i].Y > MainForm.MainRectangle.Height) { Out_Module_Area += person.chromosome[i].Height * person.chromosome[i].Width; } } double _fitness = Out_Module_Area; return(_fitness); }
public void Draw_Packing_ForGridView(Individual Best_Individual) { Individual_To_Draw = Best_Individual; SkyLine = new SkyLineBinPack(MainForm.MainRectangle.Width, Convert.ToBoolean(ProgramSettings.Default.SkyLineWasteSpace)); SkyLine.ApplySkyLine(Best_Individual.chromosome); double Max_YY = 0; for (int i = 0; i < Best_Individual.chromosome.Count; i++) { if (Best_Individual.chromosome[i].Y + Best_Individual.chromosome[i].Height > Max_YY) { Max_YY = Best_Individual.chromosome[i].Y + Best_Individual.chromosome[i].Height; } } double Max_XX = MainRectangle.Width; double num = 0; double num2 = 0; num = double.Parse(((double)paintPanel.Height / Max_YY).ToString()) - 0.05; num2 = double.Parse(((double)paintPanel.Width / Max_XX).ToString()) - 0.05; if (num > num2) { num = num2; } else { num2 = num; } double Max_Y = 0; for (int i = 0; i < Best_Individual.chromosome.Count; i++) { if (Best_Individual.chromosome[i].Y * num + Best_Individual.chromosome[i].Height * num > Max_Y) { Max_Y = Best_Individual.chromosome[i].Y * num + Best_Individual.chromosome[i].Height * num; } } double floorPlanWidth = MainForm.MainRectangle.Width * num2 + 5; double floorPlanHeight = Max_Y; PictureBoxDraw.Width = Convert.ToInt32(floorPlanWidth); if (floorPlanHeight > MainRectangle.Height) { PictureBoxDraw.Height = Convert.ToInt32(floorPlanHeight) + 5; } else { PictureBoxDraw.Height = MainRectangle.Height + 5; } Bitmap bmp = new Bitmap(PictureBoxDraw.Width, PictureBoxDraw.Height); Brush brush = Brushes.Red; Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); bool color_or_not = Convert.ToBoolean(ProgramSettings.Default.ColorOrNot); for (int i = 0; i < Best_Individual.chromosome.Count; i++) { if (color_or_not) { g.FillRectangle((Best_Individual.chromosome[i].brush_color), (float)(Best_Individual.chromosome[i].X * num2), (float)(Best_Individual.chromosome[i].Y * num), (float)(Best_Individual.chromosome[i].Width * num2), (float)(Best_Individual.chromosome[i].Height * num)); } else { g.DrawRectangle(new Pen(Color.Green, 2), (float)(Best_Individual.chromosome[i].X * num2), (float)(Best_Individual.chromosome[i].Y * num), (float)(Best_Individual.chromosome[i].Width * num2), (float)(Best_Individual.chromosome[i].Height * num)); } if (!Convert.ToBoolean(ProgramSettings.Default.HideModuleNames)) { g.DrawString(Best_Individual.chromosome[i].Name, new Font(FontFamily.GenericSerif, 15), brush, new PointF((float)(Best_Individual.chromosome[i].X * num2), (float)(Best_Individual.chromosome[i].Y * num))); } } Rectangle mainRect = new Rectangle((int)(MainRectangle.X * num2), (int)(MainRectangle.Y * num), (int)(MainRectangle.Width * num2), (int)(MainRectangle.Height * num)); g.DrawRectangle(new Pen(Color.Red, 2), mainRect); PictureBoxDraw.Image = bmp; }
private void HideNamesModulecheckBox() { Individual Individual_To_Draw = GeneticAlgorithm.Individual_To_Draw; SkyLine = new SkyLineBinPack(MainForm.MainRectangle.Width, Convert.ToBoolean(ProgramSettings.Default.SkyLineWasteSpace)); SkyLine.ApplySkyLine(Individual_To_Draw.chromosome); double Max_YY = 0; for (int i = 0; i < Individual_To_Draw.chromosome.Count; i++) { if (Individual_To_Draw.chromosome[i].Y + Individual_To_Draw.chromosome[i].Height > Max_YY) { Max_YY = Individual_To_Draw.chromosome[i].Y + Individual_To_Draw.chromosome[i].Height; } } double Max_XX = MainRectangle.Width; double num = 0; double num2 = 0; if (Convert.ToBoolean(ProgramSettings.Default.ShowAllRectangleWhileDrawing)) { num = double.Parse(((double)panelPaint.Height / Max_YY).ToString()) - 0.05; } else { num = double.Parse(((double)panelPaint.Height / MainForm.MainRectangle.Height).ToString()) - 0.05; } if (Convert.ToBoolean(ProgramSettings.Default.ShowAllRectangleWhileDrawing)) { num2 = double.Parse(((double)panelPaint.Width / Max_XX).ToString()) - 0.05; } else { num2 = double.Parse(((double)panelPaint.Width / MainForm.MainRectangle.Width).ToString()) - 0.05; } if (num > num2) { num = num2; } else { num2 = num; } double Max_Y = 0; for (int i = 0; i < Individual_To_Draw.chromosome.Count; i++) { if (Individual_To_Draw.chromosome[i].Y * num + Individual_To_Draw.chromosome[i].Height * num > Max_Y) { Max_Y = Individual_To_Draw.chromosome[i].Y * num + Individual_To_Draw.chromosome[i].Height * num; } } double floorPlanWidth = MainForm.MainRectangle.Width * num2 + 5; double floorPlanHeight = Max_Y; pictureBoxDraw.Width = Convert.ToInt32(floorPlanWidth); if (floorPlanHeight > MainRectangle.Height) { pictureBoxDraw.Height = Convert.ToInt32(floorPlanHeight) + 5; } else { pictureBoxDraw.Height = MainRectangle.Height + 5; } Bitmap bmp = new Bitmap(pictureBoxDraw.Width, pictureBoxDraw.Height); Brush brush = Brushes.Red; Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); bool color_or_not = Convert.ToBoolean(ProgramSettings.Default.ColorOrNot); for (int i = 0; i < Individual_To_Draw.chromosome.Count; i++) { if (!ColorcheckBox.Checked) { g.FillRectangle((Individual_To_Draw.chromosome[i].brush_color), (float)(Individual_To_Draw.chromosome[i].X * num2), (float)(Individual_To_Draw.chromosome[i].Y * num), (float)(Individual_To_Draw.chromosome[i].Width * num2), (float)(Individual_To_Draw.chromosome[i].Height * num)); } else { g.DrawRectangle(new Pen(Color.Green, 2), (float)(Individual_To_Draw.chromosome[i].X * num2), (float)(Individual_To_Draw.chromosome[i].Y * num), (float)(Individual_To_Draw.chromosome[i].Width * num2), (float)(Individual_To_Draw.chromosome[i].Height * num)); } if (!HideNamescheckBox.Checked) { g.DrawString(Individual_To_Draw.chromosome[i].Name, new Font(FontFamily.GenericSerif, 15), brush, new PointF((float)(Individual_To_Draw.chromosome[i].X * num2), (float)(Individual_To_Draw.chromosome[i].Y * num))); } } Rectangle mainRect = new Rectangle((int)(MainRectangle.X * num2), (int)(MainRectangle.Y * num), (int)(MainRectangle.Width * num2), (int)(MainRectangle.Height * num)); g.DrawRectangle(new Pen(Color.Red, 2), mainRect); pictureBoxDraw.Image = bmp; }