Implement matching using jheaps PairingHeap
This commit is contained in:
10
.idea/libraries/jheaps.xml
generated
Normal file
10
.idea/libraries/jheaps.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="jheaps" type="repository">
|
||||
<properties maven-id="org.jheaps:jheaps:0.14" />
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jheaps/jheaps/0.14/jheaps-0.14.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Binary file not shown.
@@ -51,7 +51,7 @@ public class Plate {
|
||||
//n = Equations.getRandomNumber(0, cells.size());
|
||||
// was testing generating the cell sample file with exponential dist, then sampling flat here
|
||||
//that would be more realistic
|
||||
//But would mess up my
|
||||
//But would mess up other things in the simulation with how I've coded it.
|
||||
if(n > test){
|
||||
test = n;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,18 @@ import org.jgrapht.alg.matching.MaximumWeightBipartiteMatching;
|
||||
import org.jgrapht.generate.SimpleWeightedBipartiteGraphMatrixGenerator;
|
||||
import org.jgrapht.graph.DefaultWeightedEdge;
|
||||
import org.jgrapht.graph.SimpleWeightedGraph;
|
||||
import org.jheaps.AddressableHeap;
|
||||
import org.jheaps.tree.PairingHeap;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.MathContext;
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Simulator {
|
||||
@@ -158,19 +163,26 @@ public class Simulator {
|
||||
Map<Integer, Integer> alphaWellCounts = new HashMap<>();
|
||||
//count how many wells each beta appears in
|
||||
Map<Integer, Integer> betaWellCounts = new HashMap<>();
|
||||
//the adjacency matrix to be used by the graph generator
|
||||
double[][] weights = new double[plateVtoAMap.size()][plateVtoBMap.size()];
|
||||
|
||||
countPeptidesAndFillMatrix(samplePlate, allAlphas, allBetas, plateAtoVMap,
|
||||
plateBtoVMap, alphaIndex, betaIndex, alphaWellCounts, betaWellCounts, weights);
|
||||
if(verbose){System.out.println("matrix created");}
|
||||
|
||||
/**
|
||||
* This is where the bipartite graph is created
|
||||
*/
|
||||
if(verbose){System.out.println("creating graph");}
|
||||
//the graph object
|
||||
SimpleWeightedGraph<Integer, DefaultWeightedEdge> graph =
|
||||
new SimpleWeightedGraph<>(DefaultWeightedEdge.class);
|
||||
//the graph generator
|
||||
SimpleWeightedBipartiteGraphMatrixGenerator graphGenerator = new SimpleWeightedBipartiteGraphMatrixGenerator();
|
||||
//the list of alpha vertices
|
||||
List<Integer> alphaVertices = new ArrayList<>();
|
||||
alphaVertices.addAll(plateVtoAMap.keySet()); //This will work because LinkedHashMap preserves order of entry
|
||||
graphGenerator.first(alphaVertices);
|
||||
//the list of beta vertices
|
||||
List<Integer> betaVertices = new ArrayList<>();
|
||||
betaVertices.addAll(plateVtoBMap.keySet());
|
||||
graphGenerator.second(betaVertices); //This will work because LinkedHashMap preserves order of entry
|
||||
@@ -183,9 +195,24 @@ public class Simulator {
|
||||
if(verbose){System.out.println("Over- and under-weight edges set to 0.0");}
|
||||
|
||||
|
||||
/**
|
||||
* This is where the maximum weighted matching is found
|
||||
*/
|
||||
// if(verbose){System.out.println("Finding maximum weighted matching");}
|
||||
// MaximumWeightBipartiteMatching maxWeightMatching =
|
||||
// new MaximumWeightBipartiteMatching(graph, plateVtoAMap.keySet(), plateVtoBMap.keySet());
|
||||
// MatchingAlgorithm.Matching<String, DefaultWeightedEdge> graphMatching = maxWeightMatching.getMatching();
|
||||
// if(verbose){System.out.println("Matching completed");}
|
||||
// Instant stop = Instant.now();
|
||||
|
||||
//trying with jheaps now
|
||||
if(verbose){System.out.println("Finding maximum weighted matching");}
|
||||
//Attempting to use addressable heap to improve performance
|
||||
MaximumWeightBipartiteMatching maxWeightMatching =
|
||||
new MaximumWeightBipartiteMatching(graph, plateVtoAMap.keySet(), plateVtoBMap.keySet());
|
||||
new MaximumWeightBipartiteMatching(graph,
|
||||
plateVtoAMap.keySet(),
|
||||
plateVtoBMap.keySet(),
|
||||
(i) -> new PairingHeap(Comparator.naturalOrder()));
|
||||
MatchingAlgorithm.Matching<String, DefaultWeightedEdge> graphMatching = maxWeightMatching.getMatching();
|
||||
if(verbose){System.out.println("Matching completed");}
|
||||
Instant stop = Instant.now();
|
||||
@@ -666,4 +693,9 @@ public class Simulator {
|
||||
return inverse;
|
||||
}
|
||||
|
||||
private static int bigDecimalComparator(BigDecimal bd, Integer i) {
|
||||
return bd.compareTo(BigDecimal.valueOf(i));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ public class UserInterface {
|
||||
public static void main(String[] args) {
|
||||
|
||||
if(args.length != 0){
|
||||
//These command line options are a big mess
|
||||
//Really, I don't think command line tools are expected to work in this many different modes
|
||||
//making cells, making plates, and matching are the sort of thing that UNIX philosophy would say
|
||||
//should be three separate programs.
|
||||
//There might be a way to do it with option parameters?
|
||||
|
||||
Options mainOptions = new Options();
|
||||
Option makeCells = Option.builder("cells")
|
||||
.longOpt("make-cells")
|
||||
|
||||
Reference in New Issue
Block a user