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
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<Vertex, DefaultWeightedEdge> 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,
if(HeapType.PAIRING.equals(heap)) {
maxWeightMatching = new MaximumWeightBipartiteMatching<Vertex, DefaultWeightedEdge>(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,
else {//Fibonacci is the default, and what's used in the JGraphT implementation
maxWeightMatching = new MaximumWeightBipartiteMatching<Vertex, DefaultWeightedEdge>(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");}
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);