Refactor to use selected algorithm type

This commit is contained in:
eugenefischer
2022-10-22 14:58:40 -05:00
parent 3c2ec9002e
commit 0de12a3a12

View File

@@ -183,36 +183,49 @@ public class Simulator implements GraphModificationFunctions {
"removed");}
//Find Maximum Weight Matching
//using jheaps library class PairingHeap for improved efficiency
if(verbose){System.out.println("Finding maximum weight matching");}
//NON-AUCTION ALGORITHM
// MaximumWeightBipartiteMatching maxWeightMatching;
// //Use correct heap type for priority queue
// String heapType = BiGpairSEQ.getPriorityQueueHeapType();
// switch (heapType) {
// 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 -> {
// maxWeightMatching = new MaximumWeightBipartiteMatching(graph,
// alphas,
// betas);
// }
// }
//Auction algorithm version
MaximumWeightBipartiteAuctionMatching maxWeightMatching = new MaximumWeightBipartiteAuctionMatching(graph, alphas, betas);
//get the matching
MatchingAlgorithm.Matching<String, DefaultWeightedEdge> graphMatching = maxWeightMatching.getMatching();
//The matching object
MatchingAlgorithm graphMatchingObject;
//The matching weight (have to do this separately, because MatchingAlgorithm interface doesn't have a getMatchingWeight() method)
BigDecimal matchingWeight;
//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();
}
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);
}
}
graphMatchingObject = maxWeightMatching;
matchingWeight = maxWeightMatching.getMatchingWeight();
}
}
MatchingAlgorithm.Matching<String, DefaultWeightedEdge> matching = graphMatchingObject.getMatching();
if(verbose){System.out.println("Matching completed");}
Instant stop = Instant.now();
@@ -230,7 +243,7 @@ public class Simulator implements GraphModificationFunctions {
List<List<String>> allResults = new ArrayList<>();
NumberFormat nf = NumberFormat.getInstance(Locale.US);
MathContext mc = new MathContext(3);
Iterator<DefaultWeightedEdge> weightIter = graphMatching.iterator();
Iterator<DefaultWeightedEdge> weightIter = matching.iterator();
DefaultWeightedEdge e;
int trueCount = 0;
int falseCount = 0;
@@ -271,11 +284,18 @@ public class Simulator implements GraphModificationFunctions {
}
//Metadata comments for CSV file
// String algoType = "LEDA book with heap: " + heapType;
String algoType = "Basic Auction Algorithm";
String algoType;
switch(algorithm) {
case AUCTION -> {
algoType = "Auction algorithm";
}
default -> { //HUNGARIAN
algoType = "Hungarian algorithm with heap: " + BiGpairSEQ.getPriorityQueueHeapType().name();
}
}
int min = Math.min(graphAlphaCount, graphBetaCount);
//matching weight
BigDecimal totalMatchingWeight = maxWeightMatching.getMatchingWeight();
//rate of attempted matching
double attemptRate = (double) (trueCount + falseCount) / min;
BigDecimal attemptRateTrunc = new BigDecimal(attemptRate, mc);
@@ -314,7 +334,7 @@ public class Simulator implements GraphModificationFunctions {
metadata.put("sequence dropout rate", data.getDropoutRate().toString());
metadata.put("graph filename", dataFilename);
metadata.put("MWM algorithm type", algoType);
metadata.put("matching weight", totalMatchingWeight.toString());
metadata.put("matching weight", matchingWeight.toString());
metadata.put("well populations", wellPopulationsString);
metadata.put("sequence read depth", data.getReadDepth().toString());
metadata.put("sequence read error rate", data.getReadErrorRate().toString());
@@ -352,6 +372,7 @@ public class Simulator implements GraphModificationFunctions {
return output;
}
//Commented out CDR1 matching until it's time to re-implement it
// //Simulated matching of CDR1s to CDR3s. Requires MatchingResult from prior run of matchCDR3s.
// public static MatchingResult[] matchCDR1s(List<Integer[]> distinctCells,