// For brute force we evaluate every possible combination of N Items (in ALL K Slots) // Possible Solutions = 2^N (when including all possible values for K) // 1234 == 00,1,2,3,4,12,13,14,23,24,34,123,124,134,234 // 24 / (24 * // N! / (K! * (N -K)!) // 123 == 321 == 132 == 321 ETC (order does not matter) // 1234 (N=4, K=2) 12,13,14,23,24,34, // 4! / (2! * (4-2)!) == 24 / ( 2 * 2) == 24/4 == 6 private void HandleSolution(KSItem[] solution) { SolutionCount++; KnapsackSolution curSolution = new KnapsackSolution(TM); for (int s = 0; s < solution.Length; s++) { curSolution.TryAddItem(solution[s]); } if (OptimalSolution == null || curSolution.Result.Value > OptimalSolution.Result.Value) { OptimalSolution = curSolution; } }
private void HandleSolution(KSItem[] items) { SolutionCount++; KnapsackSolution curSolution = new KnapsackSolution(TM); //in the permutation scenario the order the items are added to the knapsack are important (the constraints maybe violated) for (int s = 0; s < items.Length; s++) { curSolution.TryAddItem(items[s]); } if (OptimalSolution == null || curSolution.Result.Value > OptimalSolution.Result.Value) { OptimalSolution = curSolution; } return; }