diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:16:34 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:16:34 -0700 |
| commit | 81ba9eb66f8284d8760012973f84cdbe617ceb94 (patch) | |
| tree | 466432644e9e3fd66ee183ec53a1f10abb1b7faa /p2/P2_GeneratePermutations/Client.java | |
Diffstat (limited to 'p2/P2_GeneratePermutations/Client.java')
| -rw-r--r-- | p2/P2_GeneratePermutations/Client.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/p2/P2_GeneratePermutations/Client.java b/p2/P2_GeneratePermutations/Client.java new file mode 100644 index 0000000..de00dc5 --- /dev/null +++ b/p2/P2_GeneratePermutations/Client.java @@ -0,0 +1,73 @@ +import java.util.*; + +public class Client { + private static Random rand = new Random(); + + public static void main(String[] args) throws Exception { + // List<Region> scenario = createRandomScenario(10, 10, 100, 1000, 100000); + List<Region> scenario = createSimpleScenario(); + System.out.println(scenario); + + double budget = 2000; + Set<Allocation> allocations = generateOptions(budget, scenario); + printAllocations(allocations); + } + + public static Set<Allocation> generateOptions(double budget, List<Region> sites) { + Set<Allocation> allocations = new HashSet<>(); + return generateOptions(budget, sites, allocations); + } + + private static Set<Allocation> generateOptions(double budget, List<Region> sites, + Set<Allocation> allocations) { + if (sites.isEmpty()) { + return allocations; + } + + Region temp = sites.remove(); + if (budget >= temp.baseCost) { + budget -= temp.baseCost; + } + } + + + /////////////////////////////////////////////////////////////////////////// + // PROVIDED HELPER METHODS - **DO NOT MODIFY ANYTHING BELOW THIS LINE!** // + /////////////////////////////////////////////////////////////////////////// + + public static void printAllocations(Set<Allocation> allocations) { + System.out.println("All Allocations:"); + for (Allocation a : allocations) { + System.out.println(" " + a); + } + } + + public static List<Region> createRandomScenario(int numLocs, int minPop, int maxPop, + double minCostPer, double maxCostPer) { + List<Region> result = new ArrayList<>(); + + for (int i = 0; i < numLocs; i++) { + int pop = rand.nextInt(minPop, maxPop + 1); + double cost = rand.nextDouble(minCostPer, maxCostPer) * pop; + result.add(new Region("Region #" + i, pop, round2(cost))); + } + + return result; + } + + public static List<Region> createSimpleScenario() { + List<Region> result = new ArrayList<>(); + + result.add(new Region("Region #1", 50, 500)); + result.add(new Region("Region #2", 100, 700)); + result.add(new Region("Region #3", 60, 1000)); + result.add(new Region("Region #4", 20, 1000)); + result.add(new Region("Region #5", 200, 900)); + + return result; + } + + private static double round2(double num) { + return Math.round(num * 100) / 100.0; + } +} |
