public KnapsackAlgorithmInputs(KnapsackAlgorithmInputs inputs)
 {
     Inputs = new List <KnapsackAlgorithmInput>();
     foreach (KnapsackAlgorithmInput input in inputs.Inputs)
     {
         Inputs.Add(new KnapsackAlgorithmInput(input));
     }
 }
Exemple #2
0
 private void LoadInputBtn_Click(object sender, RoutedEventArgs e)
 {
     if (modeBtn.Content.ToString() == "Off")
     {
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.Filter = "Text file (*.kip)|*.kip";
         if (openFileDialog.ShowDialog() == true)
         {
             BinaryFormatter formatter = new BinaryFormatter();
             try
             {
                 using (FileStream fs = new FileStream(openFileDialog.FileName,
                                                       FileMode.OpenOrCreate))
                 {
                     input           = (KnapsackAlgorithmInput)formatter.Deserialize(fs);
                     textField.Text += input;
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Looks like this is not a real input file", "Error",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
     else
     {
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.Filter = "Text file (*.kips)|*.kips";
         if (openFileDialog.ShowDialog() == true)
         {
             BinaryFormatter formatter = new BinaryFormatter();
             try
             {
                 using (FileStream fs = new FileStream(openFileDialog.FileName,
                                                       FileMode.OpenOrCreate))
                 {
                     inputs          = (KnapsackAlgorithmInputs)formatter.Deserialize(fs);
                     textField.Text += inputs;
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Looks like this is not a real inputs file", "Error",
                                 MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
 }
Exemple #3
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);
                    }
                }
            }
        }