More efficient graph creation

This commit is contained in:
eugenefischer
2025-04-10 14:06:11 -05:00
parent 678ce99424
commit 187401f2d6

View File

@@ -149,22 +149,37 @@ public class Simulator implements GraphModificationFunctions {
betaVertices.forEach(graph::addVertex); betaVertices.forEach(graph::addVertex);
//add edges //add edges
for(Vertex a: alphaVertices) { for(Vertex a: alphaVertices) {
for(Integer well: a.getRecord().getWells()) {
for(Vertex b: betaVertices) { for(Vertex b: betaVertices) {
double weight = 0.0;
for (Integer well: a.getRecord().getWells()) {
if (b.getRecord().isInWell(well)) { if (b.getRecord().isInWell(well)) {
DefaultWeightedEdge edge = graph.getEdge(a, b); weight += 1.0;
if (edge == null) {
edge = graph.addEdge(a, b);
graph.setEdgeWeight(edge, 1.0);
}
else {
double weight = graph.getEdgeWeight(edge);
graph.setEdgeWeight(edge, weight + 1.0);
}
} }
} }
if (weight != 0.0) {
DefaultWeightedEdge edge = graph.addEdge(a, b);
graph.setEdgeWeight(edge, weight);
}
} }
} }
// //add edges
// for(Vertex a: alphaVertices) {
// for(Integer well: a.getRecord().getWells()) {
// for (Vertex b: betaVertices) {
// if (b.getRecord().isInWell(well)) {
// DefaultWeightedEdge edge = graph.getEdge(a, b);
// if (edge == null) {
// edge = graph.addEdge(a, b);
// graph.setEdgeWeight(edge, 1.0);
// }
// else {
// double weight = graph.getEdgeWeight(edge);
// graph.setEdgeWeight(edge, weight + 1.0);
// }
// }
// }
// }
// }
if(verbose){System.out.println("Graph created");} if(verbose){System.out.println("Graph created");}
//stop timing //stop timing
Instant stop = Instant.now(); Instant stop = Instant.now();