diff --git a/src/main/java/Simulator.java b/src/main/java/Simulator.java index c477592..5f52f66 100644 --- a/src/main/java/Simulator.java +++ b/src/main/java/Simulator.java @@ -185,47 +185,31 @@ public class Simulator implements GraphModificationFunctions { //Find Maximum Weight Matching if(verbose){System.out.println("Finding maximum weight matching");} //The matching object - MatchingAlgorithm graphMatchingObject; - //The matching weight (have to do this separately, because MatchingAlgorithm interface doesn't have a getMatchingWeight() method) - BigDecimal matchingWeight; + MatchingAlgorithm maxWeightMatching; //Determine algorithm type AlgorithmType algorithm = BiGpairSEQ.getMatchingAlgoritmType(); switch (algorithm) { //Only two options now, but I have room to add more algorithms in the future this way case AUCTION -> { //create a new MaximumIntegerWeightBipartiteAuctionMatching - MaximumIntegerWeightBipartiteAuctionMatching maxWeightMatching = new MaximumIntegerWeightBipartiteAuctionMatching(graph, alphas, betas); - graphMatchingObject = maxWeightMatching; - matchingWeight = maxWeightMatching.getMatchingWeight(); + maxWeightMatching = new MaximumIntegerWeightBipartiteAuctionMatching<>(graph, alphas, betas); } default -> { //HUNGARIAN - //Use JgraphT implementation - MaximumWeightBipartiteMatching maxWeightMatching; //use selected heap type for priority queue HeapType heap = BiGpairSEQ.getPriorityQueueHeapType(); - switch (heap) { - case PAIRING -> { - maxWeightMatching = new MaximumWeightBipartiteMatching(graph, - alphas, - betas, - i -> new PairingHeap(Comparator.naturalOrder())); - } - case FIBONACCI -> { - maxWeightMatching = new MaximumWeightBipartiteMatching(graph, - alphas, - betas, - i -> new FibonacciHeap(Comparator.naturalOrder())); - } - default -> { //I have since learned that the default implementation uses a fibonacci heap. - maxWeightMatching = new MaximumWeightBipartiteMatching(graph, - alphas, - betas); - } + if(HeapType.PAIRING.equals(heap)) { + maxWeightMatching = new MaximumWeightBipartiteMatching(graph, + alphas, + betas, + i -> new PairingHeap(Comparator.naturalOrder())); + } + else {//Fibonacci is the default, and what's used in the JGraphT implementation + maxWeightMatching = new MaximumWeightBipartiteMatching(graph, + alphas, + betas); } - graphMatchingObject = maxWeightMatching; - matchingWeight = maxWeightMatching.getMatchingWeight(); } } - MatchingAlgorithm.Matching matching = graphMatchingObject.getMatching(); + MatchingAlgorithm.Matching matching = maxWeightMatching.getMatching(); if(verbose){System.out.println("Matching completed");} Instant stop = Instant.now(); @@ -295,7 +279,8 @@ public class Simulator implements GraphModificationFunctions { } int min = Math.min(graphAlphaCount, graphBetaCount); - + //matching weight + Double matchingWeight = matching.getWeight(); //rate of attempted matching double attemptRate = (double) (trueCount + falseCount) / min; BigDecimal attemptRateTrunc = new BigDecimal(attemptRate, mc);