Ejemplo n.º 1
0
 private void LoadSolBtn_Click(object sender, RoutedEventArgs e)
 {
     if (modeBtn.Content.ToString() == "Off")
     {
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.Filter = "Text file (*.ksl)|*.ksl";
         if (openFileDialog.ShowDialog() == true)
         {
             BinaryFormatter formatter = new BinaryFormatter();
             try
             {
                 using (FileStream fs = new FileStream(openFileDialog.FileName,
                                                       FileMode.OpenOrCreate))
                 {
                     latestSolution  = (KnapsackSolution)formatter.Deserialize(fs);
                     textField.Text += latestSolution;
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Looks like this is not a real solution file", "Error",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
     else
     {
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.Filter = "Text file (*.ksls)|*.ksls";
         if (openFileDialog.ShowDialog() == true)
         {
             BinaryFormatter formatter = new BinaryFormatter();
             try
             {
                 using (FileStream fs = new FileStream(openFileDialog.FileName,
                                                       FileMode.OpenOrCreate))
                 {
                     latestSolutions = (KnapsackSolutions)formatter.Deserialize(fs);
                     textField.Text += latestSolutions;
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Looks like this is not a real solutions file", "Error",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private async void StartBtn_Click(object sender, RoutedEventArgs e)
        {
            if (input == null && inputs == null)
            {
                MessageBox.Show("Your have no input!", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                if (input != null)
                {
                    if (algorithm != null)
                    {
                        textField.Text        += input;
                        startBtn.IsEnabled     = false;
                        stopBtn.IsEnabled      = true;
                        saveInputBtn.IsEnabled = false;
                        saveSolBtn.IsEnabled   = false;

                        latestSolution = algorithm(input);
                        latestInput    = new KnapsackAlgorithmInput(input);

                        textField.Text        += latestSolution;
                        startBtn.IsEnabled     = true;
                        stopBtn.IsEnabled      = false;
                        saveInputBtn.IsEnabled = true;
                        saveSolBtn.IsEnabled   = true;
                    }
                    else
                    {
                        MessageBox.Show("Your haven't chosen an algorithm!", "Error",
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else if (inputs != null)
                {
                    if (algorithm != null)
                    {
                        textField.Text        += inputs;
                        startBtn.IsEnabled     = false;
                        stopBtn.IsEnabled      = true;
                        saveInputBtn.IsEnabled = false;
                        saveSolBtn.IsEnabled   = false;

                        latestSolutions = Algorithm.BigTest(inputs.Inputs, algorithm);
                        latestInputs    = new KnapsackAlgorithmInputs(inputs);

                        textField.Text        += latestSolutions;
                        startBtn.IsEnabled     = true;
                        stopBtn.IsEnabled      = false;
                        saveInputBtn.IsEnabled = true;
                        saveSolBtn.IsEnabled   = true;
                    }
                    else
                    {
                        MessageBox.Show("Your haven't chosen an algorithm!", "Error",
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }