From 7744586e79da28bf07733515fc0ce278c3337c92 Mon Sep 17 00:00:00 2001 From: eugenefischer <66030419+eugenefischer@users.noreply.github.com> Date: Thu, 10 Apr 2025 20:07:34 -0500 Subject: [PATCH] change frequency of garbage collection requests --- src/main/java/Simulator.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/Simulator.java b/src/main/java/Simulator.java index 7d1e509..2f659bb 100644 --- a/src/main/java/Simulator.java +++ b/src/main/java/Simulator.java @@ -1,3 +1,4 @@ +import org.jgrapht.Graphs; import org.jgrapht.alg.interfaces.MatchingAlgorithm; import org.jgrapht.alg.matching.MaximumWeightBipartiteMatching; import org.jgrapht.graph.DefaultWeightedEdge; @@ -147,15 +148,22 @@ public class Simulator implements GraphModificationFunctions { vertexLabelValue++; } betaVertices.forEach(graph::addVertex); - //add edges + //add edges (best so far) + int edgesAddedCount = 0; for(Vertex a: alphaVertices) { + Set a_wells = a.getRecord().getWells(); for(Vertex b: betaVertices) { - Set sharedWells = new HashSet<>(a.getRecord().getWells()); + Set sharedWells = new HashSet<>(a_wells); sharedWells.retainAll(b.getRecord().getWells()); - double weight = (double) sharedWells.size(); - if (weight != 0.0) { - DefaultWeightedEdge edge = graph.addEdge(a, b); - graph.setEdgeWeight(edge, weight); + if (!sharedWells.isEmpty()) { + Graphs.addEdge(graph, a, b, (double) sharedWells.size()); + } + edgesAddedCount++; + if (edgesAddedCount % 10000000 == 0) { //collect garbage every 10,000,000 edges + System.out.println(edgesAddedCount + " edges added"); + //request garbage collection + System.gc(); + System.out.println("Garbage collection requested"); } } }