public void Log(string line) { Helper.ControlInvokeRequired(LogListView, () => { LogListView.Items.Add(new ListViewItem(line)); LogListView.EnsureVisible(LogListView.Items.Count - 1); LogListView.Refresh(); }); }
private void LoadMenuItem_Click(object sender, EventArgs e) { //десериализация состояния программы и восстановление состояния программы if (!isAnimationFinished) { MessageBox.Show(Constants.Strings.ANIMATION_END); return; } OpenFileDialog openFileDialog = new OpenFileDialog(); SerializableContainer container; BinaryFormatter formatter = new BinaryFormatter(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = Constants.Strings.FILE_FORMAT; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { clearChart(); var fs = openFileDialog.OpenFile(); foreach (ListViewItem i in LogListView.Items) { i.Remove(); } container = (SerializableContainer)formatter.Deserialize(fs); this.logType = container.LogType; if (logType == Constants.Integers.LOG_TYPE_BEST) { LogTypeBox.SelectedItem = "Best individual"; } else if (logType == Constants.Integers.LOG_TYPE_AVERAGE) { LogTypeBox.SelectedItem = "Average individual"; } else if (logType == Constants.Integers.LOG_TYPE_WORST) { LogTypeBox.SelectedItem = "Worst individual"; } this.EpochNumeric.Value = container.EpochCount; this.MutationNumeric.Value = container.MutationChance; this.PopulationNumeric.Value = container.PopSize; this.BestIndividualTextBox.Text = container.BestInd; this.bestIndsBackup = container.BestInds; this.averageIndsBackup = container.AverageInds; this.worstIndsBackup = container.WorstInds; for (int i = 0; i < container.BestInds.Count; ++i) { geneticChart.Series[0].Points.Add(new DataPoint((double)container.BestInds[i].Epoch, (double)container.BestInds[i].Fitness)); geneticChart.Series[1].Points.Add(new DataPoint((double)container.AverageInds[i].Epoch, (double)container.AverageInds[i].Fitness)); geneticChart.Series[2].Points.Add(new DataPoint((double)container.WorstInds[i].Epoch, (double)container.WorstInds[i].Fitness)); if (logType == Constants.Integers.LOG_TYPE_BEST) { LogListView.Items.Add("Epoch: " + container.BestInds[i].Epoch + " best: " + container.BestInds[i].GetChromosomeString() + "\n"); } else if (logType == Constants.Integers.LOG_TYPE_AVERAGE) { LogListView.Items.Add("Epoch: " + container.AverageInds[i].Epoch + " average: " + container.AverageInds[i].GetChromosomeString() + "\n"); } else if (logType == Constants.Integers.LOG_TYPE_WORST) { LogListView.Items.Add("Epoch: " + container.WorstInds[i].Epoch + " worst: " + container.WorstInds[i].GetChromosomeString() + "\n"); } } LogListView.Refresh(); } }