private void buttonLoadProblem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { string file = openFileDialog1.FileName; try { string text = File.ReadAllText(file); ShuffleProblem temp = JsonConvert.DeserializeObject <ShuffleProblem>(text); CalculationManager.GetInstance().prb = JsonConvert.DeserializeObject <ShuffleProblem>(text); //CalculationManager.GetInstance().alg = new SecondDiplomAlgorithm(4); //CalculationManager.GetInstance().alg.Init(temp); logBox.Text += temp.Print(); temp.SetBestSol(new Solution(temp.solution)); //logBox.Text += "Calculated res: " + temp.Eval(temp.best_solution) + "\n"; CalculationManager.GetInstance().prb = temp; } catch (IOException) { } } }
private void processBatch_button_Click(object sender, EventArgs e) { string[] files = null; using (OpenFileDialog file = new OpenFileDialog()) { //Allow to select multiple files file.Multiselect = true; file.Filter = "Only jsons | *.json"; //Show the Dialog box to select file(s) DialogResult result = file.ShowDialog(); if (result == DialogResult.OK) { //return input file names files = file.FileNames; } else { return; } } if (files != null) { this.logBox.Clear(); string folderName = Path.GetFileName(Path.GetDirectoryName(files[0])); //this.logBox.Text += folderName + "\n"; foreach (var file in files) { this.logBox.Text += Path.GetFileName(file) + "\t"; try { string text = File.ReadAllText(file); ShuffleProblem temp = JsonConvert.DeserializeObject <ShuffleProblem>(text); CalculationManager.GetInstance().prb = JsonConvert.DeserializeObject <ShuffleProblem>(text); logBox.Text += temp.Print(); temp.SetBestSol(new Solution(temp.solution)); CalculationManager.GetInstance().prb = temp; // autocalc buttonAutoCalculate_Click(sender, e); } catch (IOException) { } //this.logBox.Text += "\n"; } { // save logs string logName = Path.GetDirectoryName(Path.GetDirectoryName(files[0])) + "\\" + folderName + ".txt"; using (FileStream stream = File.OpenWrite(logName)) using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(logBox.Text); } } } }
private void buttonAutoCalculate_Click(object sender, EventArgs e) { //CalculationManager.ScrapAndCreateNew(); if (CalculationManager.GetInstance().alg != null) { ShuffleProblem t = CalculationManager.GetInstance().alg.GetProblem() as ShuffleProblem; if (t != null) { t.ClearMemento(); } } var watch = System.Diagnostics.Stopwatch.StartNew(); buttonInitAlg_Click(sender, e); buttonInitList_Click(sender, e); int old_core_count = CalculationManager.GetInstance().alg.GetProblem().GetEvalCount(); int i = 0; for (i = 0; i < 70; i++) { buttonHC_Click(sender, e); buttonMutate_Click(sender, e); if (CalculationManager.GetInstance().alg.GetProblem().GetEvalCount() == old_core_count) { break; } old_core_count = CalculationManager.GetInstance().alg.GetProblem().GetEvalCount(); CalculationManager.GetInstance().pool = CalculationManager.GetInstance().pool.Distinct().ToList(); if (CalculationManager.GetInstance().pool.Count == 1) { break; } } if (i == 70) { this.logBox.Text += "Calc was breaked due to calculation limits.\n"; } watch.Stop(); //{ // this.logBox.Text += "FINAL:\n"; // foreach (ISolution a in CalculationManager.GetInstance().pool) // this.logBox.Text += CalculationManager.GetInstance().alg.GetProblem().SolPrint(a) + "\n"; //} { ISolution ressol = CalculationManager.GetInstance().pool.First(); foreach (ISolution a in CalculationManager.GetInstance().pool) { if (CalculationManager.GetInstance().alg.GetProblem().Eval(a) < CalculationManager.GetInstance().alg.GetProblem().Eval(ressol)) { ressol = a; } } if (ressol != null) { this.logBox.Text += CalculationManager.GetInstance().alg.GetProblem().Eval(ressol) + "\t"; } } this.logBox.Text += CalculationManager.GetInstance().alg.GetProblem().GetEvalCount() + "\t"; this.logBox.Text += watch.ElapsedMilliseconds + "\n"; }