15-May-2025 08:18:52 knapsack_greedy_test(): MATLAB/Octave version 6.4.0 Test knapsack_greedy(). knapsack_greedy_test01(): knapsack_greedy() uses a greedy algorithm to estimate a solution of the knapsack problem. Test 1 Knapsack weight capacity is 26 Object weights: 12 7 11 8 9 Object values: 24 13 23 15 16 Object Profit Mass Density 1 23 11 2.09091 2 24 12 2 3 15 8 1.875 4 13 7 1.85714 5 16 9 1.77778 Contents of Knapsack Object Profit Mass Density 1 23 11 2.09091 2 24 12 2 Number of objects = 2 Total weight = 23 Total profit = 47 Total density = 2.04348 Test 2 Knapsack weight capacity is 190 Object weights: 56 59 80 64 75 17 Object values: 50 50 64 46 50 5 Object Profit Mass Density 1 50 56 0.892857 2 50 59 0.847458 3 64 80 0.8 4 46 64 0.71875 5 50 75 0.666667 6 5 17 0.294118 Contents of Knapsack Object Profit Mass Density 1 50 56 0.892857 2 50 59 0.847458 4 46 64 0.71875 Number of objects = 3 Total weight = 179 Total profit = 146 Total density = 0.815642 Test 3 Knapsack weight capacity is 20 Object weights: 10 9 4 2 1 20 Object values: 175 90 20 50 10 200 Object Profit Mass Density 1 50 2 25 2 175 10 17.5 3 90 9 10 4 10 1 10 5 200 20 10 6 20 4 5 Contents of Knapsack Object Profit Mass Density 1 50 2 25 2 175 10 17.5 4 10 1 10 6 20 4 5 Number of objects = 4 Total weight = 17 Total profit = 255 Total density = 15 Test 4 Knapsack weight capacity is 50 Object weights: 31 10 20 19 4 3 6 Object values: 70 20 39 37 7 5 10 Object Profit Mass Density 1 70 31 2.25806 2 20 10 2 3 39 20 1.95 4 37 19 1.94737 5 7 4 1.75 6 5 3 1.66667 7 10 6 1.66667 Contents of Knapsack Object Profit Mass Density 1 70 31 2.25806 2 20 10 2 5 7 4 1.75 6 5 3 1.66667 Number of objects = 4 Total weight = 48 Total profit = 102 Total density = 2.125 Test 5 Knapsack weight capacity is 170 Object weights: 41 50 49 59 55 57 60 Object values: 442 525 511 593 546 564 617 Object Profit Mass Density 1 442 41 10.7805 2 525 50 10.5 3 511 49 10.4286 4 617 60 10.2833 5 593 59 10.0508 6 546 55 9.92727 7 564 57 9.89474 Contents of Knapsack Object Profit Mass Density 1 442 41 10.7805 2 525 50 10.5 3 511 49 10.4286 Number of objects = 3 Total weight = 140 Total profit = 1478 Total density = 10.5571 Test 6 Knapsack weight capacity is 104 Object weights: 25 35 45 5 25 3 2 2 Object values: 350 400 450 20 70 8 5 5 Object Profit Mass Density 1 350 25 14 2 400 35 11.4286 3 450 45 10 4 20 5 4 5 70 25 2.8 6 8 3 2.66667 7 5 2 2.5 8 5 2 2.5 Contents of Knapsack Object Profit Mass Density 1 350 25 14 2 400 35 11.4286 4 20 5 4 5 70 25 2.8 6 8 3 2.66667 7 5 2 2.5 8 5 2 2.5 Number of objects = 7 Total weight = 97 Total profit = 858 Total density = 8.84536 Test 7 Knapsack weight capacity is 67 Object weights: 23 26 20 18 32 27 29 26 30 27 Object values: 505 352 458 220 354 414 498 545 473 543 Object Profit Mass Density 1 458 20 22.9 2 505 23 21.9565 3 545 26 20.9615 4 543 27 20.1111 5 498 29 17.1724 6 473 30 15.7667 7 414 27 15.3333 8 352 26 13.5385 9 220 18 12.2222 10 354 32 11.0625 Contents of Knapsack Object Profit Mass Density 1 458 20 22.9 2 505 23 21.9565 9 220 18 12.2222 Number of objects = 3 Total weight = 61 Total profit = 1183 Total density = 19.3934 Test 8 Knapsack weight capacity is 165 Object weights: 23 31 29 44 53 38 63 85 89 82 Object values: 92 57 49 68 60 43 67 84 87 72 Object Profit Mass Density 1 92 23 4 2 57 31 1.83871 3 49 29 1.68966 4 68 44 1.54545 5 60 53 1.13208 6 43 38 1.13158 7 67 63 1.06349 8 84 85 0.988235 9 87 89 0.977528 10 72 82 0.878049 Contents of Knapsack Object Profit Mass Density 1 92 23 4 2 57 31 1.83871 3 49 29 1.68966 4 68 44 1.54545 6 43 38 1.13158 Number of objects = 5 Total weight = 165 Total profit = 309 Total density = 1.87273 Test 9 Knapsack weight capacity is 750 Object weights: Columns 1 through 13: 70 73 77 80 82 87 90 94 98 106 110 113 115 Columns 14 and 15: 118 120 Object values: Columns 1 through 13: 135 139 149 150 156 163 173 184 192 201 210 214 221 Columns 14 and 15: 229 240 Object Profit Mass Density 1 240 120 2 2 192 98 1.95918 3 184 94 1.95745 4 229 118 1.94068 5 149 77 1.93506 6 135 70 1.92857 7 173 90 1.92222 8 221 115 1.92174 9 210 110 1.90909 10 139 73 1.90411 11 156 82 1.90244 12 201 106 1.89623 13 214 113 1.89381 14 150 80 1.875 15 163 87 1.87356 Contents of Knapsack Object Profit Mass Density 1 240 120 2 2 192 98 1.95918 3 184 94 1.95745 4 229 118 1.94068 5 149 77 1.93506 6 135 70 1.92857 7 173 90 1.92222 10 139 73 1.90411 Number of objects = 8 Total weight = 740 Total profit = 1441 Total density = 1.9473 Test 10 Knapsack weight capacity is 6404180 Object weights: Columns 1 through 8: 382745 799601 909247 729069 467902 44328 34610 698150 Columns 9 through 16: 823460 903959 853665 551830 610856 670702 488960 951111 Columns 17 through 24: 323046 446298 931161 31385 496951 264724 224916 169684 Object values: Columns 1 through 6: 8.2559e+05 1.6770e+06 1.6766e+06 1.5240e+06 9.4397e+05 9.7426e+04 Columns 7 through 12: 6.9666e+04 1.2965e+06 1.6797e+06 1.9030e+06 1.8450e+06 1.0493e+06 Columns 13 through 18: 1.2528e+06 1.3198e+06 9.5328e+05 2.0675e+06 6.7537e+05 8.5366e+05 Columns 19 through 24: 1.8260e+06 6.5731e+04 9.0149e+05 5.7724e+05 4.6626e+05 3.6926e+05 Object Profit Mass Density 1 97426 44328 2.19784 2 577243 264724 2.18055 3 369261 169684 2.17617 4 2067538 951111 2.17381 5 1844992 853665 2.16126 6 825594 382745 2.15703 7 1902996 903959 2.10518 8 1677009 799601 2.09731 9 65731 31385 2.09434 10 675367 323046 2.09062 11 1523970 729069 2.0903 12 466257 224916 2.07303 13 1252836 610856 2.05095 14 1679693 823460 2.0398 15 943972 467902 2.01746 16 69666 34610 2.01289 17 1319836 670702 1.96784 18 1826027 931161 1.96102 19 953277 488960 1.9496 20 853655 446298 1.91275 21 1049289 551830 1.90147 22 1296457 698150 1.85699 23 1676628 909247 1.84397 24 901489 496951 1.81404 Contents of Knapsack Object Profit Mass Density 1 97426 44328 2.19784 2 577243 264724 2.18055 3 369261 169684 2.17617 4 2067538 951111 2.17381 5 1844992 853665 2.16126 6 825594 382745 2.15703 7 1902996 903959 2.10518 8 1677009 799601 2.09731 9 65731 31385 2.09434 10 675367 323046 2.09062 11 1523970 729069 2.0903 12 466257 224916 2.07303 13 1252836 610856 2.05095 16 69666 34610 2.01289 Number of objects = 14 Total weight = 6323699 Total profit = 13415886 Total density = 2.12153 knapsack_greedy_test(): Normal end of execution. 15-May-2025 08:18:52