From 81ba9eb66f8284d8760012973f84cdbe617ceb94 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:16:34 -0700 Subject: init --- p2/P2_GeneratePermutations/Client.java | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 p2/P2_GeneratePermutations/Client.java (limited to 'p2/P2_GeneratePermutations/Client.java') 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 scenario = createRandomScenario(10, 10, 100, 1000, 100000); + List scenario = createSimpleScenario(); + System.out.println(scenario); + + double budget = 2000; + Set allocations = generateOptions(budget, scenario); + printAllocations(allocations); + } + + public static Set generateOptions(double budget, List sites) { + Set allocations = new HashSet<>(); + return generateOptions(budget, sites, allocations); + } + + private static Set generateOptions(double budget, List sites, + Set 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 allocations) { + System.out.println("All Allocations:"); + for (Allocation a : allocations) { + System.out.println(" " + a); + } + } + + public static List createRandomScenario(int numLocs, int minPop, int maxPop, + double minCostPer, double maxCostPer) { + List 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 createSimpleScenario() { + List 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; + } +} -- cgit v1.2.3