Bugfixes and streamlining

This commit is contained in:
eugenefischer
2022-10-22 17:59:01 -05:00
parent 44158d264c
commit 70b08e7c22

View File

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