29 November 2024 07:40:58 PM knapsack_random_test(): C version Test knapsack_random() subset_next_test(): Test subset_next() Generate in order subsets of size 5 0: 0 0 0 0 0 1: 0 0 0 0 1 2: 0 0 0 1 0 3: 0 0 0 1 1 4: 0 0 1 0 0 5: 0 0 1 0 1 6: 0 0 1 1 0 7: 0 0 1 1 1 8: 0 1 0 0 0 9: 0 1 0 0 1 10: 0 1 0 1 0 11: 0 1 0 1 1 12: 0 1 1 0 0 13: 0 1 1 0 1 14: 0 1 1 1 0 15: 0 1 1 1 1 16: 1 0 0 0 0 17: 1 0 0 0 1 18: 1 0 0 1 0 19: 1 0 0 1 1 20: 1 0 1 0 0 21: 1 0 1 0 1 22: 1 0 1 1 0 23: 1 0 1 1 1 24: 1 1 0 0 0 25: 1 1 0 0 1 26: 1 1 0 1 0 27: 1 1 0 1 1 28: 1 1 1 0 0 29: 1 1 1 0 1 30: 1 1 1 1 0 31: 1 1 1 1 1 subset_random_test(): Test subset_random() Subsets will be of size n = 5 23: 1 0 1 1 1 19: 1 0 0 1 1 11: 0 1 0 1 1 0: 0 0 0 0 0 22: 1 0 1 1 0 7: 0 0 1 1 1 17: 1 0 0 0 1 26: 1 1 0 1 0 30: 1 1 1 1 0 18: 1 0 0 1 0 knapsack_random_test01(): knapsack_random() randomly selects a subset of n items and considers it as a solution to a knapsack problem. Maximize profit without exceeding weight limit. Number of items is 5 Value array: 0: 24 1: 13 2: 23 3: 15 4: 16 Weight array: 0: 12 1: 7 2: 11 3: 8 4: 9 Weight limit is 26 Selected items: 0: 1 1: 0 2: 1 3: 0 4: 0 Weight 23 Value 47 Ratio 2.04348 Selected items: 0: 1 1: 0 2: 0 3: 0 4: 1 Weight 21 Value 40 Ratio 1.90476 Selected items: 0: 1 1: 1 2: 0 3: 1 4: 0 Weight 27 exceeds weight limit 26 Selected items: 0: 1 1: 0 2: 1 3: 1 4: 1 Weight 40 exceeds weight limit 26 Selected items: 0: 0 1: 1 2: 0 3: 1 4: 0 Weight 15 Value 28 Ratio 1.86667 Selected items: 0: 1 1: 0 2: 0 3: 1 4: 0 Weight 20 Value 39 Ratio 1.95 Selected items: 0: 1 1: 0 2: 0 3: 0 4: 0 Weight 12 Value 24 Ratio 2 Selected items: 0: 0 1: 1 2: 1 3: 0 4: 1 Weight 27 exceeds weight limit 26 Selected items: 0: 0 1: 0 2: 0 3: 0 4: 1 Weight 9 Value 16 Ratio 1.77778 Selected items: 0: 0 1: 0 2: 0 3: 0 4: 1 Weight 9 Value 16 Ratio 1.77778 knapsack_random_test(): Normal end of execution.