74 lines
2.5 KiB
Java
74 lines
2.5 KiB
Java
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;
|
|
}
|
|
}
|