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