Last active
December 11, 2019 21:46
-
-
Save jbleduigou/4a46a80b5cbeac167931c54fb51dd056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate all possible sub-lists (PowerSet algorithm) | |
Set<List<Item>> subLists = generateAllSubLists(items); | |
// Find best solution for each sub-set | |
SortedSet<Solution> solutions = new TreeSet<>(); | |
for (List<Item> sublist : subLists) { | |
Solution solution = findBestSolution(maxWeight, sublist); | |
solutions.add(solution); | |
} | |
// No need to sort solutions, TreeSet implements SortedSet | |
Solution best = solutions.first(); | |
System.err.println(best); | |
System.out.println(best.getPrice()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment