private void tsmiImportAppParams_Click(object sender, EventArgs e) { if (XMLopenFileDialog.ShowDialog() != DialogResult.Cancel) { ImportParams(XMLopenFileDialog.FileName); } }
private void OpenNewXMLtoolStripButton_Click(object sender, EventArgs e) { List <Module> OpenXmlRectangles = new List <Module>(); int Width = -1; int Height = -1; XMLopenFileDialog.Filter = "XML documents (*.xml)|*.xml"; if (XMLopenFileDialog.ShowDialog() == DialogResult.OK && XMLopenFileDialog.FileName != "") { XmlTextReader textReader = new XmlTextReader(XMLopenFileDialog.FileName); OpenXmlRectangles = new List <Module>(); while (textReader.Read()) { XmlNodeType nType = textReader.NodeType; if (nType == XmlNodeType.Element) { if (textReader.Name == "Width" || textReader.Name == "Height") { if (textReader.Name == "Width") { textReader.Read(); Width = Convert.ToInt32(textReader.Value); } if (textReader.Name == "Height") { textReader.Read(); Height = Convert.ToInt32(textReader.Value); } if (Width != -1 && Height != -1) { Module newItem = new Module(); newItem.Width = Width; newItem.Height = Height; OpenXmlRectangles.Add(newItem); Width = -1; Height = -1; } } } } MainRectangle = new Module(); MainRectangle.Width = OpenXmlRectangles[0].Width; MainRectangle.Height = OpenXmlRectangles[0].Height; Rectangles = OpenXmlRectangles.ToList <Module>(); Rectangles.RemoveAt(0); chartImage.Series[0].Points.Clear(); chartImage.Series[1].Points.Clear(); } }
private void BenchMarkToolStripMenuItem_Click(object sender, EventArgs e) { List <Module> OpenXmlRectangles = new List <Module>(); String All_File; string[] rects; XMLopenFileDialog.Filter = "txt documents (*.txt)|*.txt"; if (XMLopenFileDialog.ShowDialog() == DialogResult.OK && XMLopenFileDialog.FileName != "") { StreamReader sr = new StreamReader(XMLopenFileDialog.FileName); All_File = sr.ReadToEnd(); char[] param = { '\n', '\r' }; rects = All_File.Split(param, StringSplitOptions.RemoveEmptyEntries); MainRectangle = new Module(); MainRectangle.Width = Convert.ToInt32(rects[0].Remove(rects[0].Length - 4)); MainRectangle.Height = Convert.ToInt32(rects[1].Remove(rects[1].Length - 4)); string[] line; int width; int height; for (int i = 2; i < rects.Length; i++) { line = rects[i].Split(' '); height = Convert.ToInt32(line[0].Trim().Remove(line[0].Length - 4)); width = Convert.ToInt32(line[1].Trim().Remove(line[1].Length - 4)); Module newItem = new Module(); newItem.Width = width; newItem.Height = height; OpenXmlRectangles.Add(newItem); } Rectangles = OpenXmlRectangles.ToList <Module>(); double sum_rectangles_Area = 0; for (int i = 0; i < Rectangles.Count; i++) { sum_rectangles_Area += (Rectangles[i].Width * Rectangles[i].Height); } double Main_Rectangle_Area = Math.BigMul(MainRectangle.Width, MainRectangle.Height); PopulationSize = Convert.ToInt32(ProgramSettings.Default.PopulationSize); NumberOfGenerations = Convert.ToInt32(ProgramSettings.Default.NumberOfGenerations); NumOfIndividualToUpdate = (Convert.ToInt32(ProgramSettings.Default.PercentOfUpdate) * Convert.ToInt32(ProgramSettings.Default.PopulationSize)) / 100; MaindataGridView.Rows.Clear(); chartImage.Series[0].Points.Clear(); GA = new GeneticAlgorithm(PopulationSize, RateForMutations, RateForCrossover, NumberOfGenerations, NumOfIndividualToUpdate, MainRectangle, Rectangles, MaindataGridView, pictureBoxDraw, NumberGenerationLabel, PlayPausetoolStripButton, toolStripProgressBar1, toolStripStatusLabel1, toolStripDropDownButton1, DrawCharttoolStripButton, BestPolishtoolStripButton, CrossoverMutationtoolStripButton, Compare2toolStripButton, EnterNewIndividualcheckBox, BestFitnesslabel, panelPaint, TimeElapsedlabel); GenerationCollection = GA.GenerationCollection; oThread = new Thread(new ThreadStart(GA.Genetic_Algorithm)); } }
private void OpenXMLToolStripMenuItem_Click(object sender, EventArgs e) { stopWatch.Reset(); TimeElapsedlabel.Text = "Time"; if (GenerationCollection != null) { for (int i = 0; i < GenerationCollection.Count; i++) { for (int j = 0; j < GenerationCollection[i].People.Count; j++) { for (int k = 0; k < GenerationCollection[i].People[j].chromosome.Count; k++) { GenerationCollection[i].People[j].chromosome[k] = null; GenerationCollection[i].People[j].chromosome.RemoveAt(k); k = 0; } GenerationCollection[i].People[j] = null; GenerationCollection[i].People.RemoveAt(j); j = 1; } } GC.Collect(); } List <Module> OpenXmlRectangles = new List <Module>(); int Width = -1; int Height = -1; XMLopenFileDialog.Filter = "XML documents (*.xml)|*.xml"; if (XMLopenFileDialog.ShowDialog() == DialogResult.OK && XMLopenFileDialog.FileName != "") { XmlTextReader textReader = new XmlTextReader(XMLopenFileDialog.FileName); OpenXmlRectangles = new List <Module>(); while (textReader.Read()) { XmlNodeType nType = textReader.NodeType; if (nType == XmlNodeType.Element) { if (textReader.Name == "Width" || textReader.Name == "Height") { if (textReader.Name == "Width") { textReader.Read(); Width = Convert.ToInt32(textReader.Value); } if (textReader.Name == "Height") { textReader.Read(); Height = Convert.ToInt32(textReader.Value); } if (Width != -1 && Height != -1) { Module newItem = new Module(); newItem.Width = Width; newItem.Height = Height; OpenXmlRectangles.Add(newItem); Width = -1; Height = -1; } } } } MainRectangle = new Module(); MainRectangle.Width = OpenXmlRectangles[0].Width; MainRectangle.Height = OpenXmlRectangles[0].Height; Rectangles = OpenXmlRectangles.ToList <Module>(); Rectangles.RemoveAt(0); PopulationSize = Convert.ToInt32(ProgramSettings.Default.PopulationSize); NumberOfGenerations = Convert.ToInt32(ProgramSettings.Default.NumberOfGenerations); NumOfIndividualToUpdate = (Convert.ToInt32(ProgramSettings.Default.PercentOfUpdate) * Convert.ToInt32(ProgramSettings.Default.PopulationSize)) / 100; MaindataGridView.Rows.Clear(); chartImage.Series[0].Points.Clear(); GA = new GeneticAlgorithm(PopulationSize, RateForMutations, RateForCrossover, NumberOfGenerations, NumOfIndividualToUpdate, MainRectangle, Rectangles, MaindataGridView, pictureBoxDraw, NumberGenerationLabel, PlayPausetoolStripButton, toolStripProgressBar1, toolStripStatusLabel1, toolStripDropDownButton1, DrawCharttoolStripButton, BestPolishtoolStripButton, CrossoverMutationtoolStripButton, Compare2toolStripButton, EnterNewIndividualcheckBox, BestFitnesslabel, panelPaint, TimeElapsedlabel); GenerationCollection = GA.GenerationCollection; oThread = new Thread(new ThreadStart(GA.Genetic_Algorithm)); } }