@@ -13,6 +13,12 @@ namespace OptimizationIssues.Views
13
13
/// </summary>
14
14
public partial class KnapsackView : UserControl
15
15
{
16
+ public class KnapsackItem
17
+ {
18
+ public int Index { get ; set ; }
19
+ public int Weight { get ; set ; }
20
+ public int Value { get ; set ; }
21
+ }
16
22
public KnapsackView ( )
17
23
{
18
24
InitializeComponent ( ) ;
@@ -42,7 +48,7 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
42
48
43
49
ResultTextBlock . Inlines . Add ( new Run ( maxValue . ToString ( ) )
44
50
{
45
- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#FFD700 " ) )
51
+ Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#98FF98 " ) )
46
52
} ) ;
47
53
48
54
ResultTextBlock . Inlines . Add ( new Run ( "\n Zużyta pojemność plecaka: " )
@@ -61,24 +67,32 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
61
67
62
68
ResultTextBlock . Inlines . Add ( new Run ( "\n \n Wybrane przedmioty:\n " )
63
69
{
64
- Foreground = new SolidColorBrush ( Colors . White )
70
+ Foreground = new SolidColorBrush ( Colors . White ) ,
71
+ FontWeight = FontWeights . Bold
65
72
} ) ;
66
73
67
- var sortedItems = selectedItems
68
- . Select ( ( value , index ) => new { value , originalIndex = index + 1 } )
69
- . OrderBy ( item => weights . IndexOf ( item . value . Weight ) )
70
- . ToList ( ) ;
74
+ selectedItems . Reverse ( ) ;
71
75
72
- foreach ( var item in sortedItems )
73
- {
74
- int itemNumber = weights . IndexOf ( item . value . Weight ) + 1 ;
76
+ foreach ( var item in selectedItems )
77
+ {
78
+ int itemNumber = item . Index + 1 ;
79
+
80
+ ResultTextBlock . Inlines . Add ( new Run ( $ "Przedmiot ")
81
+ {
82
+ Foreground = new SolidColorBrush ( Colors . White )
83
+ } ) ;
84
+
85
+ ResultTextBlock . Inlines . Add ( new Run ( $ "{ itemNumber } ")
86
+ {
87
+ Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#FFD700" ) )
88
+ } ) ;
75
89
76
- ResultTextBlock . Inlines . Add ( new Run ( $ "Przedmiot { itemNumber } - Waga: ")
90
+ ResultTextBlock . Inlines . Add ( new Run ( $ " - Waga: ")
77
91
{
78
92
Foreground = new SolidColorBrush ( Colors . White )
79
93
} ) ;
80
94
81
- ResultTextBlock . Inlines . Add ( new Run ( item . value . Weight . ToString ( ) )
95
+ ResultTextBlock . Inlines . Add ( new Run ( item . Weight . ToString ( ) )
82
96
{
83
97
Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E6A8D7" ) )
84
98
} ) ;
@@ -88,7 +102,7 @@ private void SolveButton_Click(object sender, RoutedEventArgs e)
88
102
Foreground = new SolidColorBrush ( Colors . White )
89
103
} ) ;
90
104
91
- ResultTextBlock . Inlines . Add ( new Run ( item . value . Value . ToString ( ) )
105
+ ResultTextBlock . Inlines . Add ( new Run ( item . Value . ToString ( ) )
92
106
{
93
107
Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#ADD8E6" ) )
94
108
} ) ;
0 commit comments