Exemple #1
0
 private void OkBtn_Click(object sender, RoutedEventArgs e)
 {
     if (randBtn.Background == Brushes.Purple)
     {
         Window.input  = KnapsackAlgorithmInput.GenerateFullRandomInput();
         Window.inputs = null;
         Close();
     }
     else if (capBtn.Background == Brushes.Purple)
     {
         int cap;
         if (int.TryParse(capTB.Text, out cap) && cap > 1)
         {
             Window.input  = KnapsackAlgorithmInput.GenerateInputCapacity(cap);
             Window.inputs = null;
             Close();
         }
         else
         {
             MessageBox.Show("Something with your requirements, true again", "Error",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else if (typesBtn.Background == Brushes.Purple)
     {
         Random rand = new Random();
         int    types;
         if (int.TryParse(typeTB.Text, out types) && types > 1)
         {
             Window.input  = KnapsackAlgorithmInput.GenerateInput(rand.Next(1, 100000), rand.Next(1000, 50000), types);
             Window.inputs = null;
             Close();
         }
         else
         {
             MessageBox.Show("Something with your requirements, true again", "Error",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Exemple #2
0
 private void OkBtn_Click(object sender, RoutedEventArgs e)
 {
     if (randBtn.Background == Brushes.Purple)
     {
         int n;
         if (int.TryParse(sizeTB.Text, out n) && n > 0)
         {
             List <KnapsackAlgorithmInput> inputs = new List <KnapsackAlgorithmInput>();
             for (int i = 0; i < n; i++)
             {
                 inputs.Add(KnapsackAlgorithmInput.GenerateFullRandomInput());
             }
             Window.inputs = new KnapsackAlgorithmInputs(inputs);
             Window.input  = null;
             Close();
         }
         else
         {
             MessageBox.Show("Something with your requirements, true again", "Error",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else if (capBtn.Background == Brushes.Purple)
     {
         int cap, size;
         if (int.TryParse(capTB.Text, out cap) && cap > 1 &&
             int.TryParse(sizeTB.Text, out size) && size > 0)
         {
             List <KnapsackAlgorithmInput> inputs = new List <KnapsackAlgorithmInput>();
             for (int i = 0; i < cap; i++)
             {
                 inputs.Add(KnapsackAlgorithmInput.GenerateInputCapacity(cap));
             }
             Window.inputs = new KnapsackAlgorithmInputs(inputs);
             Window.input  = null;
             Close();
         }
         else
         {
             MessageBox.Show("Something with your requirements, true again", "Error",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else if (typesBtn.Background == Brushes.Purple)
     {
         Random rand = new Random();
         int    types, size;
         if (int.TryParse(typeTB.Text, out types) && types > 1 &&
             int.TryParse(sizeTB.Text, out size) && size > 0)
         {
             List <KnapsackAlgorithmInput> inputs = new List <KnapsackAlgorithmInput>();
             for (int i = 0; i < types; i++)
             {
                 inputs.Add(KnapsackAlgorithmInput.GenerateInput(rand.Next(1, 100000), rand.Next(1000, 50000), types));
             }
             Window.inputs = new KnapsackAlgorithmInputs(inputs);
             Window.input  = null;
             Close();
         }
         else
         {
             MessageBox.Show("Something with your requirements, true again", "Error",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }