Пример #1
0
        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)
                {
                }
            }
        }
Пример #2
0
        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);
                        }
                }
            }
        }