|
3 | 3 | using System.Diagnostics;
|
4 | 4 | using System.Windows;
|
5 | 5 | using System.Windows.Controls;
|
| 6 | +using System.Windows.Documents; |
6 | 7 | using System.Windows.Media;
|
7 | 8 |
|
8 | 9 | namespace OptimizationIssues.Views
|
@@ -31,8 +32,67 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
|
31 | 32 | viewModel.Weights = weights;
|
32 | 33 | viewModel.Values = values;
|
33 | 34 |
|
34 |
| - int result = viewModel.SolveKnapsack(); |
35 |
| - ResultTextBlock.Text = $"Maksymalna wartość: {result}"; |
| 35 | + var (maxValue, selectedItems, usedCapacity) = viewModel.SolveKnapsackWithDetails(); |
| 36 | + ResultTextBlock.Inlines.Clear(); |
| 37 | + |
| 38 | + ResultTextBlock.Inlines.Add(new Run("Maksymalna wartość: ") |
| 39 | + { |
| 40 | + Foreground = new SolidColorBrush(Colors.White) |
| 41 | + }); |
| 42 | + |
| 43 | + ResultTextBlock.Inlines.Add(new Run(maxValue.ToString()) |
| 44 | + { |
| 45 | + Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFD700")) |
| 46 | + }); |
| 47 | + |
| 48 | + ResultTextBlock.Inlines.Add(new Run("\n\nWybrane przedmioty:\n") |
| 49 | + { |
| 50 | + Foreground = new SolidColorBrush(Colors.White) |
| 51 | + }); |
| 52 | + |
| 53 | + foreach (var item in selectedItems) |
| 54 | + { |
| 55 | + ResultTextBlock.Inlines.Add(new Run("Waga: ") |
| 56 | + { |
| 57 | + Foreground = new SolidColorBrush(Colors.White) |
| 58 | + }); |
| 59 | + |
| 60 | + ResultTextBlock.Inlines.Add(new Run(item.Weight.ToString()) |
| 61 | + { |
| 62 | + Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6A8D7")) |
| 63 | + }); |
| 64 | + |
| 65 | + ResultTextBlock.Inlines.Add(new Run(", Wartość: ") |
| 66 | + { |
| 67 | + Foreground = new SolidColorBrush(Colors.White) |
| 68 | + }); |
| 69 | + |
| 70 | + ResultTextBlock.Inlines.Add(new Run(item.Value.ToString()) |
| 71 | + { |
| 72 | + Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ADD8E6")) |
| 73 | + }); |
| 74 | + |
| 75 | + ResultTextBlock.Inlines.Add(new Run("\n") |
| 76 | + { |
| 77 | + Foreground = new SolidColorBrush(Colors.White) |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + ResultTextBlock.Inlines.Add(new Run("\nZużyta pojemność plecaka: ") |
| 82 | + { |
| 83 | + Foreground = new SolidColorBrush(Colors.White) |
| 84 | + }); |
| 85 | + |
| 86 | + if (usedCapacity == capacity) |
| 87 | + ResultTextBlock.Inlines.Add(new Run($"{usedCapacity}/{capacity}") |
| 88 | + { |
| 89 | + Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#98FF98")) |
| 90 | + }); |
| 91 | + else |
| 92 | + ResultTextBlock.Inlines.Add(new Run($"{usedCapacity}/{capacity}") |
| 93 | + { |
| 94 | + Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF9898")) |
| 95 | + }); |
36 | 96 | }
|
37 | 97 | else
|
38 | 98 | ResultTextBlock.Text = "Podano błędne dane. Upewnij się, że wszystkie pola są poprawnie wypełnione.";
|
|
0 commit comments