From b997e9c532e9f92e1ea792ce7d0c6f6951e52893 Mon Sep 17 00:00:00 2001 From: Saurav Bhattacharya Date: Thu, 19 Mar 2026 12:44:24 -0700 Subject: [PATCH] refactor: rename edge class to Edge (Java PascalCase convention) Rename the edge class to Edge to follow Java naming conventions. Update all 197 files with type references (generics, constructors, declarations, casts, array types) across the entire codebase. Closes #89 --- .../src/gvisual/AdjacencyMatrixHeatmap.java | 22 +-- .../gvisual/ArticulationPointAnalyzer.java | 32 +-- Gvisual/src/gvisual/BipartiteAnalyzer.java | 4 +- Gvisual/src/gvisual/ChordalGraphAnalyzer.java | 26 +-- Gvisual/src/gvisual/CircularLayout.java | 16 +- Gvisual/src/gvisual/CliqueAnalyzer.java | 4 +- Gvisual/src/gvisual/CommunityDetector.java | 14 +- .../gvisual/CommunityEvolutionTracker.java | 10 +- Gvisual/src/gvisual/CsvReportExporter.java | 10 +- Gvisual/src/gvisual/CycleAnalyzer.java | 12 +- .../gvisual/DegreeDistributionAnalyzer.java | 10 +- .../src/gvisual/DominatingSetAnalyzer.java | 6 +- Gvisual/src/gvisual/DotExporter.java | 12 +- Gvisual/src/gvisual/{edge.java => Edge.java} | 10 +- .../src/gvisual/EdgePersistenceAnalyzer.java | 28 +-- Gvisual/src/gvisual/EulerianPathAnalyzer.java | 38 ++-- .../gvisual/FeedbackVertexSetAnalyzer.java | 18 +- Gvisual/src/gvisual/ForceDirectedLayout.java | 32 +-- Gvisual/src/gvisual/GexfExporter.java | 28 +-- .../src/gvisual/GraphAlgorithmAnimator.java | 46 ++--- .../src/gvisual/GraphAnnotationManager.java | 2 +- Gvisual/src/gvisual/GraphAnomalyDetector.java | 10 +- Gvisual/src/gvisual/GraphAsciiRenderer.java | 14 +- Gvisual/src/gvisual/GraphBenchmarkSuite.java | 24 +-- .../gvisual/GraphCentralityCorrelator.java | 4 +- .../gvisual/GraphClusterQualityAnalyzer.java | 18 +- .../src/gvisual/GraphColoringAnalyzer.java | 12 +- Gvisual/src/gvisual/GraphCompressor.java | 24 +-- .../src/gvisual/GraphDiameterAnalyzer.java | 6 +- Gvisual/src/gvisual/GraphDiffAnalyzer.java | 12 +- .../src/gvisual/GraphDiffHtmlExporter.java | 6 +- .../gvisual/GraphDistanceDistribution.java | 4 +- Gvisual/src/gvisual/GraphEntropyAnalyzer.java | 10 +- Gvisual/src/gvisual/GraphFileParser.java | 24 +-- Gvisual/src/gvisual/GraphGenerator.java | 40 ++-- .../src/gvisual/GraphIsomorphismAnalyzer.java | 14 +- Gvisual/src/gvisual/GraphLayoutComparer.java | 8 +- Gvisual/src/gvisual/GraphMLExporter.java | 34 ++-- Gvisual/src/gvisual/GraphMerger.java | 74 +++---- Gvisual/src/gvisual/GraphMinorAnalyzer.java | 68 +++---- .../gvisual/GraphNeighborhoodAnalyzer.java | 8 +- Gvisual/src/gvisual/GraphNetworkProfiler.java | 8 +- Gvisual/src/gvisual/GraphPartitioner.java | 10 +- Gvisual/src/gvisual/GraphPathExplorer.java | 8 +- .../src/gvisual/GraphPathExplorerTest.java | 36 ++-- .../src/gvisual/GraphProductCalculator.java | 48 ++--- Gvisual/src/gvisual/GraphQueryEngine.java | 32 +-- Gvisual/src/gvisual/GraphRenderers.java | 30 +-- .../src/gvisual/GraphResilienceAnalyzer.java | 22 +-- Gvisual/src/gvisual/GraphSampler.java | 36 ++-- .../src/gvisual/GraphSimilarityAnalyzer.java | 16 +- .../gvisual/GraphSparsificationAnalyzer.java | 110 +++++------ Gvisual/src/gvisual/GraphStats.java | 26 +-- Gvisual/src/gvisual/GraphSummarizer.java | 36 ++-- .../src/gvisual/GraphSymmetryAnalyzer.java | 14 +- .../src/gvisual/GraphTimelineExporter.java | 8 +- Gvisual/src/gvisual/GraphUtils.java | 62 +++--- Gvisual/src/gvisual/GrowthRateAnalyzer.java | 10 +- Gvisual/src/gvisual/HierarchicalLayout.java | 24 +-- .../src/gvisual/IndependentSetAnalyzer.java | 22 +-- .../src/gvisual/InfluenceSpreadSimulator.java | 16 +- .../src/gvisual/InteractiveHtmlExporter.java | 8 +- Gvisual/src/gvisual/JsonGraphExporter.java | 18 +- Gvisual/src/gvisual/KCoreDecomposition.java | 6 +- Gvisual/src/gvisual/KTrussAnalyzer.java | 78 ++++---- Gvisual/src/gvisual/LaplacianBuilder.java | 12 +- Gvisual/src/gvisual/LineGraphAnalyzer.java | 40 ++-- .../src/gvisual/LinkPredictionAnalyzer.java | 4 +- .../src/gvisual/LouvainCommunityDetector.java | 18 +- Gvisual/src/gvisual/Main.java | 68 +++---- Gvisual/src/gvisual/MaxCutAnalyzer.java | 30 +-- .../src/gvisual/MetricDimensionAnalyzer.java | 4 +- Gvisual/src/gvisual/MinimumSpanningTree.java | 66 +++---- Gvisual/src/gvisual/MotifAnalyzer.java | 8 +- Gvisual/src/gvisual/NetworkFlowAnalyzer.java | 40 ++-- .../src/gvisual/NetworkReportGenerator.java | 36 ++-- .../src/gvisual/NetworkRoleClassifier.java | 4 +- .../src/gvisual/NodeCentralityAnalyzer.java | 8 +- .../src/gvisual/NodeSimilarityAnalyzer.java | 4 +- Gvisual/src/gvisual/PageRankAnalyzer.java | 14 +- Gvisual/src/gvisual/PlanarGraphAnalyzer.java | 30 +-- Gvisual/src/gvisual/RichClubAnalyzer.java | 16 +- Gvisual/src/gvisual/ShortestPathFinder.java | 40 ++-- Gvisual/src/gvisual/SignedGraphAnalyzer.java | 70 +++---- Gvisual/src/gvisual/SmallWorldAnalyzer.java | 6 +- Gvisual/src/gvisual/SpectralAnalyzer.java | 4 +- Gvisual/src/gvisual/SteinerTreeAnalyzer.java | 20 +- .../StronglyConnectedComponentsAnalyzer.java | 32 +-- .../src/gvisual/StructuralHoleAnalyzer.java | 8 +- Gvisual/src/gvisual/SubgraphExtractor.java | 32 +-- .../src/gvisual/SubgraphPatternMatcher.java | 104 +++++----- Gvisual/src/gvisual/SvgExporter.java | 18 +- Gvisual/src/gvisual/TemporalGraph.java | 28 +-- .../src/gvisual/TopologicalSortAnalyzer.java | 20 +- Gvisual/src/gvisual/TournamentAnalyzer.java | 12 +- Gvisual/src/gvisual/TreeAnalyzer.java | 8 +- Gvisual/src/gvisual/TreewidthAnalyzer.java | 12 +- .../gvisual/VertexConnectivityAnalyzer.java | 56 +++--- Gvisual/src/gvisual/VertexCoverAnalyzer.java | 20 +- .../src/test/GraphTimelineExporterTest.java | 8 +- .../src/test/gvisual/CycleAnalyzerTest.java | 66 +++---- .../src/test/gvisual/GraphCompressorTest.java | 6 +- Gvisual/src/test/gvisual/GraphMergerTest.java | 14 +- .../gvisual/GraphProductCalculatorTest.java | 40 ++-- .../test/gvisual/PageRankAnalyzerTest.java | 14 +- .../ArticulationPointAnalyzerTest.java | 10 +- .../test/gvisual/BipartiteAnalyzerTest.java | 12 +- .../gvisual/ChordalGraphAnalyzerTest.java | 28 +-- Gvisual/test/gvisual/CircularLayoutTest.java | 18 +- Gvisual/test/gvisual/CliqueAnalyzerTest.java | 8 +- .../test/gvisual/CommunityDetectorTest.java | 82 ++++---- .../CommunityEvolutionTrackerTest.java | 90 ++++----- .../test/gvisual/CsvReportExporterTest.java | 74 +++---- Gvisual/test/gvisual/CycleAnalyzerTest.java | 106 +++++----- .../DegreeDistributionAnalyzerTest.java | 8 +- .../gvisual/DominatingSetAnalyzerTest.java | 8 +- Gvisual/test/gvisual/DotExporterTest.java | 20 +- .../gvisual/EdgePersistenceAnalyzerTest.java | 36 ++-- Gvisual/test/gvisual/EdgeTest.java | 36 ++-- .../gvisual/EulerianPathAnalyzerTest.java | 82 ++++---- .../FeedbackVertexSetAnalyzerTest.java | 32 +-- .../test/gvisual/ForceDirectedLayoutTest.java | 12 +- Gvisual/test/gvisual/GexfExporterTest.java | 24 +-- .../gvisual/GraphAlgorithmAnimatorTest.java | 34 ++-- .../gvisual/GraphAnnotationManagerTest.java | 12 +- .../gvisual/GraphAnomalyDetectorTest.java | 38 ++-- .../test/gvisual/GraphAsciiRendererTest.java | 22 +-- .../test/gvisual/GraphBenchmarkSuiteTest.java | 10 +- .../GraphCentralityCorrelatorTest.java | 8 +- .../GraphClusterQualityAnalyzerTest.java | 6 +- .../gvisual/GraphColoringAnalyzerTest.java | 10 +- .../gvisual/GraphDiameterAnalyzerTest.java | 30 +-- .../test/gvisual/GraphDiffAnalyzerTest.java | 8 +- .../GraphDistanceDistributionTest.java | 50 ++--- .../gvisual/GraphEntropyAnalyzerTest.java | 80 ++++---- Gvisual/test/gvisual/GraphGeneratorTest.java | 24 +-- .../gvisual/GraphIsomorphismAnalyzerTest.java | 112 +++++------ Gvisual/test/gvisual/GraphMLExporterTest.java | 58 +++--- Gvisual/test/gvisual/GraphMergerTest.java | 34 ++-- .../test/gvisual/GraphMinorAnalyzerTest.java | 70 +++---- .../GraphNeighborhoodAnalyzerTest.java | 6 +- .../gvisual/GraphNetworkProfilerTest.java | 40 ++-- .../test/gvisual/GraphPartitionerTest.java | 10 +- .../test/gvisual/GraphQueryEngineTest.java | 22 +-- .../gvisual/GraphResilienceAnalyzerTest.java | 26 +-- Gvisual/test/gvisual/GraphSamplerTest.java | 8 +- .../gvisual/GraphSimilarityAnalyzerTest.java | 146 +++++++------- .../GraphSparsificationAnalyzerTest.java | 72 +++---- Gvisual/test/gvisual/GraphStatsTest.java | 184 +++++++++--------- Gvisual/test/gvisual/GraphSummarizerTest.java | 68 +++---- .../gvisual/GraphSymmetryAnalyzerTest.java | 10 +- Gvisual/test/gvisual/GraphUtilsTest.java | 52 ++--- .../test/gvisual/GrowthRateAnalyzerTest.java | 144 +++++++------- .../test/gvisual/HamiltonianAnalyzerTest.java | 6 +- .../test/gvisual/HierarchicalLayoutTest.java | 82 ++++---- .../gvisual/IndependentSetAnalyzerTest.java | 86 ++++---- .../gvisual/InfluenceSpreadSimulatorTest.java | 42 ++-- .../gvisual/InteractiveHtmlExporterTest.java | 14 +- .../test/gvisual/JsonGraphExporterTest.java | 50 ++--- .../test/gvisual/KCoreDecompositionTest.java | 8 +- Gvisual/test/gvisual/KTrussAnalyzerTest.java | 16 +- .../test/gvisual/LaplacianBuilderTest.java | 4 +- .../test/gvisual/LineGraphAnalyzerTest.java | 34 ++-- .../gvisual/LinkPredictionAnalyzerTest.java | 148 +++++++------- .../gvisual/LouvainCommunityDetectorTest.java | 8 +- Gvisual/test/gvisual/MaxCutAnalyzerTest.java | 10 +- .../gvisual/MetricDimensionAnalyzerTest.java | 56 +++--- .../test/gvisual/MinimumSpanningTreeTest.java | 138 ++++++------- Gvisual/test/gvisual/MotifAnalyzerTest.java | 10 +- .../test/gvisual/NetworkFlowAnalyzerTest.java | 26 +-- .../gvisual/NetworkReportGeneratorTest.java | 32 +-- .../gvisual/NetworkRoleClassifierTest.java | 72 +++---- .../gvisual/NodeCentralityAnalyzerTest.java | 8 +- .../gvisual/NodeSimilarityAnalyzerTest.java | 6 +- .../test/gvisual/PageRankAnalyzerTest.java | 10 +- .../test/gvisual/PlanarGraphAnalyzerTest.java | 100 +++++----- .../test/gvisual/RandomWalkAnalyzerTest.java | 6 +- .../test/gvisual/RichClubAnalyzerTest.java | 42 ++-- .../test/gvisual/ShortestPathFinderTest.java | 12 +- .../test/gvisual/SignedGraphAnalyzerTest.java | 50 ++--- .../test/gvisual/SmallWorldAnalyzerTest.java | 6 +- .../test/gvisual/SpectralAnalyzerTest.java | 26 +-- .../test/gvisual/SteinerTreeAnalyzerTest.java | 96 ++++----- ...ronglyConnectedComponentsAnalyzerTest.java | 72 +++---- .../gvisual/StructuralHoleAnalyzerTest.java | 88 ++++----- .../test/gvisual/SubgraphExtractorTest.java | 36 ++-- .../gvisual/SubgraphPatternMatcherTest.java | 104 +++++----- Gvisual/test/gvisual/SvgExporterTest.java | 20 +- Gvisual/test/gvisual/TemporalGraphTest.java | 60 +++--- .../gvisual/TopologicalSortAnalyzerTest.java | 96 ++++----- .../test/gvisual/TournamentAnalyzerTest.java | 8 +- Gvisual/test/gvisual/TreeAnalyzerTest.java | 34 ++-- .../test/gvisual/TreewidthAnalyzerTest.java | 6 +- .../VertexConnectivityAnalyzerTest.java | 106 +++++----- .../test/gvisual/VertexCoverAnalyzerTest.java | 8 +- 195 files changed, 3220 insertions(+), 3220 deletions(-) rename Gvisual/src/gvisual/{edge.java => Edge.java} (95%) diff --git a/Gvisual/src/gvisual/AdjacencyMatrixHeatmap.java b/Gvisual/src/gvisual/AdjacencyMatrixHeatmap.java index 8ce1273..c9a51c9 100644 --- a/Gvisual/src/gvisual/AdjacencyMatrixHeatmap.java +++ b/Gvisual/src/gvisual/AdjacencyMatrixHeatmap.java @@ -26,9 +26,9 @@ */ public class AdjacencyMatrixHeatmap extends JPanel { - private final Graph graph; + private final Graph graph; private List nodeOrder; - private final Map> adjacency; + private final Map> adjacency; private int cellSize = 12; private int offsetX = 0; private int offsetY = 0; @@ -49,7 +49,7 @@ public class AdjacencyMatrixHeatmap extends JPanel { private static final Color HIGHLIGHT_COLOR = new Color(255, 255, 255, 40); private static final Color LABEL_COLOR = new Color(200, 200, 200); - public AdjacencyMatrixHeatmap(Graph graph) { + public AdjacencyMatrixHeatmap(Graph graph) { this.graph = graph; this.adjacency = new HashMap<>(); setBackground(BG_COLOR); @@ -62,7 +62,7 @@ public AdjacencyMatrixHeatmap(Graph graph) { private void buildAdjacency() { adjacency.clear(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); adjacency.computeIfAbsent(v1, k -> new HashMap<>()).put(v2, e); @@ -192,9 +192,9 @@ public String getToolTipText(MouseEvent e) { if (hoveredRow.equals(hoveredCol)) { return "Node: " + hoveredRow + " (degree: " + graph.degree(hoveredRow) + ")"; } - Map rowMap = adjacency.get(hoveredRow); + Map rowMap = adjacency.get(hoveredRow); if (rowMap != null && rowMap.containsKey(hoveredCol)) { - edge ed = rowMap.get(hoveredCol); + Edge ed = rowMap.get(hoveredCol); String type = getEdgeTypeName(ed.getType()); String weight = ed.getWeight() != 0 ? ", weight: " + ed.getWeight() : ""; return hoveredRow + " ↔ " + hoveredCol + " [" + type + weight + "]"; @@ -216,7 +216,7 @@ private String getEdgeTypeName(String type) { } } - private Color getEdgeColor(edge e) { + private Color getEdgeColor(Edge e) { if (e == null) return DEFAULT_COLOR; String type = e.getType(); if (type == null) return DEFAULT_COLOR; @@ -269,9 +269,9 @@ protected void paintComponent(Graphics g2) { int brightness = Math.min(255, 40 + deg * 15); g.setColor(new Color(brightness, brightness, brightness)); } else { - Map rowMap = adjacency.get(nodeR); + Map rowMap = adjacency.get(nodeR); if (rowMap != null && rowMap.containsKey(nodeC)) { - edge e = rowMap.get(nodeC); + Edge e = rowMap.get(nodeC); Color base = getEdgeColor(e); float alpha = e.getWeight() > 0 ? Math.min(1f, 0.4f + e.getWeight() * 0.1f) : 0.85f; g.setColor(new Color(base.getRed(), base.getGreen(), base.getBlue(), @@ -347,7 +347,7 @@ protected void paintComponent(Graphics g2) { }; for (int i = 0; i < legend.length; i++) { int ly = legendY + 20 + i * 22; - edge dummy = new edge(legend[i][1], "", ""); + Edge dummy = new Edge(legend[i][1], "", ""); g.setColor(getEdgeColor(dummy)); g.fillRect(legendX, ly - 10, 14, 14); g.setColor(LABEL_COLOR); @@ -366,7 +366,7 @@ protected void paintComponent(Graphics g2) { /** * Creates a dialog window containing the heatmap with controls. */ - public static JDialog createDialog(JFrame parent, Graph graph) { + public static JDialog createDialog(JFrame parent, Graph graph) { JDialog dialog = new JDialog(parent, "Adjacency Matrix Heatmap", false); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); diff --git a/Gvisual/src/gvisual/ArticulationPointAnalyzer.java b/Gvisual/src/gvisual/ArticulationPointAnalyzer.java index 7cdbdfb..80e6215 100644 --- a/Gvisual/src/gvisual/ArticulationPointAnalyzer.java +++ b/Gvisual/src/gvisual/ArticulationPointAnalyzer.java @@ -25,7 +25,7 @@ */ public class ArticulationPointAnalyzer { - private final Graph graph; + private final Graph graph; /** * Create a new analyzer for the given graph. @@ -33,7 +33,7 @@ public class ArticulationPointAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public ArticulationPointAnalyzer(Graph graph) { + public ArticulationPointAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -46,13 +46,13 @@ public ArticulationPointAnalyzer(Graph graph) { * A bridge (cut edge) whose removal disconnects the graph. */ public static class Bridge { - private final edge bridgeEdge; + private final Edge bridgeEdge; private final String endpoint1; private final String endpoint2; private final int componentSizeA; private final int componentSizeB; - public Bridge(edge bridgeEdge, String endpoint1, String endpoint2, + public Bridge(Edge bridgeEdge, String endpoint1, String endpoint2, int componentSizeA, int componentSizeB) { this.bridgeEdge = bridgeEdge; this.endpoint1 = endpoint1; @@ -62,7 +62,7 @@ public Bridge(edge bridgeEdge, String endpoint1, String endpoint2, } /** The bridge edge. */ - public edge getEdge() { return bridgeEdge; } + public Edge getEdge() { return bridgeEdge; } /** One endpoint. */ public String getEndpoint1() { return endpoint1; } /** Other endpoint. */ @@ -227,7 +227,7 @@ public AnalysisResult analyze() { Map parent = new HashMap(); Set visited = new HashSet(); Set articulationPoints = new LinkedHashSet(); - List bridgeEdges = new ArrayList(); + List bridgeEdges = new ArrayList(); int[] timer = {0}; // Run DFS from each unvisited vertex (handles disconnected graphs) @@ -245,7 +245,7 @@ public AnalysisResult analyze() { for (String ap : articulationPoints) { int degree = graph.degree(ap); Map edgeTypeCounts = new HashMap(); - for (edge e : graph.getIncidentEdges(ap)) { + for (Edge e : graph.getIncidentEdges(ap)) { String type = e.getType() != null ? e.getType() : "unknown"; edgeTypeCounts.put(type, edgeTypeCounts.getOrDefault(type, 0) + 1); } @@ -260,7 +260,7 @@ public AnalysisResult analyze() { // Build bridge details with component size estimation List bridges = new ArrayList(); - for (edge e : bridgeEdges) { + for (Edge e : bridgeEdges) { String v1 = e.getVertex1() != null ? e.getVertex1() : findEndpoints(e)[0]; String v2 = e.getVertex2() != null ? e.getVertex2() : findEndpoints(e)[1]; int[] sizes = estimateComponentSizes(v1, v2, e); @@ -284,7 +284,7 @@ private void dfs(String u, Map parent, Set visited, Set articulationPoints, - List bridges, + List bridges, int[] timer) { visited.add(u); disc.put(u, timer[0]); @@ -314,7 +314,7 @@ private void dfs(String u, // Bridge: low[v] > disc[u] if (low.get(v) > disc.get(u)) { - edge bridgeEdge = findEdge(u, v); + Edge bridgeEdge = findEdge(u, v); if (bridgeEdge != null) { bridges.add(bridgeEdge); } @@ -329,8 +329,8 @@ private void dfs(String u, /** * Find the edge connecting two vertices. */ - private edge findEdge(String u, String v) { - for (edge e : graph.getIncidentEdges(u)) { + private Edge findEdge(String u, String v) { + for (Edge e : graph.getIncidentEdges(u)) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); // Also check via JUNG endpoints since vertex1/vertex2 may be null @@ -348,7 +348,7 @@ private edge findEdge(String u, String v) { /** * Find endpoints of an edge via the graph when vertex1/vertex2 may be null. */ - private String[] findEndpoints(edge e) { + private String[] findEndpoints(Edge e) { Collection endpoints = graph.getEndpoints(e); if (endpoints != null && endpoints.size() == 2) { Iterator it = endpoints.iterator(); @@ -396,7 +396,7 @@ private int countBiconnectedComponents(String vertex) { * Estimate the sizes of the two components that would result from * removing a bridge edge. */ - private int[] estimateComponentSizes(String v1, String v2, edge bridgeEdge) { + private int[] estimateComponentSizes(String v1, String v2, Edge bridgeEdge) { // BFS from v1, excluding the bridge edge Set comp1 = bfsExcludingEdge(v1, bridgeEdge); Set comp2 = bfsExcludingEdge(v2, bridgeEdge); @@ -406,7 +406,7 @@ private int[] estimateComponentSizes(String v1, String v2, edge bridgeEdge) { /** * BFS from a start vertex, excluding a specific edge. */ - private Set bfsExcludingEdge(String start, edge excluded) { + private Set bfsExcludingEdge(String start, Edge excluded) { Set visited = new HashSet(); Queue queue = new LinkedList(); queue.add(start); @@ -414,7 +414,7 @@ private Set bfsExcludingEdge(String start, edge excluded) { while (!queue.isEmpty()) { String current = queue.poll(); - for (edge e : graph.getIncidentEdges(current)) { + for (Edge e : graph.getIncidentEdges(current)) { if (e == excluded) continue; Collection endpoints = graph.getEndpoints(e); for (String neighbor : endpoints) { diff --git a/Gvisual/src/gvisual/BipartiteAnalyzer.java b/Gvisual/src/gvisual/BipartiteAnalyzer.java index 4438efd..192c358 100644 --- a/Gvisual/src/gvisual/BipartiteAnalyzer.java +++ b/Gvisual/src/gvisual/BipartiteAnalyzer.java @@ -33,7 +33,7 @@ public class BipartiteAnalyzer { private static final String NIL = "__NIL__"; private static final int INF = Integer.MAX_VALUE; - private final Graph graph; + private final Graph graph; private Map coloring; private boolean bipartite; private boolean computed; @@ -45,7 +45,7 @@ public class BipartiteAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public BipartiteAnalyzer(Graph graph) { + public BipartiteAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/ChordalGraphAnalyzer.java b/Gvisual/src/gvisual/ChordalGraphAnalyzer.java index c8fc5a6..bf5de59 100644 --- a/Gvisual/src/gvisual/ChordalGraphAnalyzer.java +++ b/Gvisual/src/gvisual/ChordalGraphAnalyzer.java @@ -192,7 +192,7 @@ public String toTextReport() { * @param graph the graph * @return MCS ordering (last eliminated first) */ - public static List maximumCardinalitySearch(Graph graph) { + public static List maximumCardinalitySearch(Graph graph) { if (graph == null) return Collections.emptyList(); Collection vertices = graph.getVertices(); if (vertices == null || vertices.isEmpty()) return Collections.emptyList(); @@ -247,7 +247,7 @@ public static List maximumCardinalitySearch(Graph graph) { * @param graph the graph * @return ChordalityResult with PEO if chordal, or a chordless cycle if not */ - public static ChordalityResult testChordality(Graph graph) { + public static ChordalityResult testChordality(Graph graph) { if (graph == null || graph.getVertexCount() == 0) { return new ChordalityResult(true, Collections.emptyList(), null); } @@ -349,7 +349,7 @@ private static List findChordlessCycle(Map> adj, * @param graph the graph * @return coloring result */ - public static ColoringResult optimalColoring(Graph graph) { + public static ColoringResult optimalColoring(Graph graph) { if (graph == null || graph.getVertexCount() == 0) { return new ColoringResult(Collections.emptyMap(), 0); } @@ -396,7 +396,7 @@ public static ColoringResult optimalColoring(Graph graph) { * @param graph the graph * @return vertices of a maximum clique */ - public static Set maximumClique(Graph graph) { + public static Set maximumClique(Graph graph) { if (graph == null || graph.getVertexCount() == 0) { return Collections.emptySet(); } @@ -433,7 +433,7 @@ public static Set maximumClique(Graph graph) { return best; } - private static Set findMaxCliqueGreedy(Graph graph) { + private static Set findMaxCliqueGreedy(Graph graph) { Map> adj = GraphUtils.buildAdjacencyMap(graph); // Sort vertices by degree descending List sorted = new ArrayList<>(graph.getVertices()); @@ -467,7 +467,7 @@ private static Set findMaxCliqueGreedy(Graph graph) { * @param graph the graph * @return list of maximal cliques */ - public static List> allMaximalCliques(Graph graph) { + public static List> allMaximalCliques(Graph graph) { if (graph == null || graph.getVertexCount() == 0) { return Collections.emptyList(); } @@ -528,7 +528,7 @@ public static List> allMaximalCliques(Graph graph) { * @param graph the graph * @return list of clique tree nodes with neighbor relationships */ - public static List buildCliqueTree(Graph graph) { + public static List buildCliqueTree(Graph graph) { List> cliques = allMaximalCliques(graph); if (cliques.isEmpty()) return Collections.emptyList(); @@ -597,7 +597,7 @@ private static int intersectionSize(Set a, Set b) { * @param graph the graph * @return fill-in result with list of edges to add */ - public static FillInResult computeFillIn(Graph graph) { + public static FillInResult computeFillIn(Graph graph) { if (graph == null || graph.getVertexCount() == 0) { return new FillInResult(Collections.emptyList()); } @@ -633,7 +633,7 @@ public static FillInResult computeFillIn(Graph graph) { String u = laterNeighbors.get(a); String w = laterNeighbors.get(b); if (!augmented.get(u).contains(w)) { - // Add fill edge + // Add fill Edge augmented.get(u).add(w); augmented.get(w).add(u); String first = u.compareTo(w) < 0 ? u : w; @@ -656,7 +656,7 @@ public static FillInResult computeFillIn(Graph graph) { * @param graph the graph * @return list of minimal separators */ - public static List> minimalSeparators(Graph graph) { + public static List> minimalSeparators(Graph graph) { List> cliques = allMaximalCliques(graph); List tree = buildCliqueTree(graph); if (tree.size() <= 1) return Collections.emptyList(); @@ -684,7 +684,7 @@ public static List> minimalSeparators(Graph graph) { * @param graph the graph * @return treewidth, or -1 for empty graph */ - public static int treewidth(Graph graph) { + public static int treewidth(Graph graph) { Set mc = maximumClique(graph); return mc.isEmpty() ? -1 : mc.size() - 1; } @@ -698,7 +698,7 @@ public static int treewidth(Graph graph) { * @param order elimination order * @return list of cliques formed at each elimination step */ - public static List> eliminationCliques(Graph graph, + public static List> eliminationCliques(Graph graph, List order) { if (graph == null || order == null) return Collections.emptyList(); @@ -745,7 +745,7 @@ public static List> eliminationCliques(Graph graph, * @param graph the graph * @return full analysis report */ - public static ChordalReport analyze(Graph graph) { + public static ChordalReport analyze(Graph graph) { int vc = graph != null ? graph.getVertexCount() : 0; int ec = graph != null ? graph.getEdgeCount() : 0; diff --git a/Gvisual/src/gvisual/CircularLayout.java b/Gvisual/src/gvisual/CircularLayout.java index a5d18dc..6eb5b64 100644 --- a/Gvisual/src/gvisual/CircularLayout.java +++ b/Gvisual/src/gvisual/CircularLayout.java @@ -39,7 +39,7 @@ *
  • Edge crossing count metric
  • *
  • SVG export with node labels and edges
  • *
  • Layout quality report
  • - *
  • Works with any JUNG {@code Graph}
  • + *
  • Works with any JUNG {@code Graph}
  • * * *

    When to use

    @@ -83,7 +83,7 @@ public enum Ordering { MINIMIZE_CROSSINGS } - private final Graph graph; + private final Graph graph; private final double width; private final double height; private final double padding; @@ -114,7 +114,7 @@ private CircularLayout(Builder builder) { /** Builder for flexible construction. */ public static class Builder { - private final Graph graph; + private final Graph graph; private double width = 800; private double height = 800; private double padding = 50; @@ -123,7 +123,7 @@ public static class Builder { private boolean dualRing = false; private double hubThreshold = 0.9; - public Builder(Graph graph) { + public Builder(Graph graph) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); this.graph = graph; } @@ -294,7 +294,7 @@ private int countCrossingsForOrder(List order) { } List edgeIndices = new ArrayList<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 != null && v2 != null && indexMap.containsKey(v1) && indexMap.containsKey(v2)) { @@ -311,7 +311,7 @@ private int countCrossingsForOrder(List order) { for (int i = 0; i < edgeIndices.size(); i++) { for (int j = i + 1; j < edgeIndices.size(); j++) { int[] e1 = edgeIndices.get(i); - int[] e2 = edgeIndices.get(j); + int[] e2 = EdgeIndices.get(j); // Two chords on a circle cross iff their endpoints interleave if (chordsIntersect(e1[0], e1[1], e2[0], e2[1], n)) { crossings++; @@ -482,14 +482,14 @@ public String toSvg() { width, height)); // Draw edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 != null && v2 != null && positions.containsKey(v1) && positions.containsKey(v2)) { double[] p1 = positions.get(v1); double[] p2 = positions.get(v2); svg.append(String.format( - " \n", + " \n", p1[0], p1[1], p2[0], p2[1])); } } diff --git a/Gvisual/src/gvisual/CliqueAnalyzer.java b/Gvisual/src/gvisual/CliqueAnalyzer.java index 8962405..3301faf 100644 --- a/Gvisual/src/gvisual/CliqueAnalyzer.java +++ b/Gvisual/src/gvisual/CliqueAnalyzer.java @@ -30,7 +30,7 @@ */ public class CliqueAnalyzer { - private final Graph graph; + private final Graph graph; private Map> neighborCache; private List> cliques; private boolean computed; @@ -44,7 +44,7 @@ public class CliqueAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public CliqueAnalyzer(Graph graph) { + public CliqueAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/CommunityDetector.java b/Gvisual/src/gvisual/CommunityDetector.java index 88df83c..d1cc0bd 100644 --- a/Gvisual/src/gvisual/CommunityDetector.java +++ b/Gvisual/src/gvisual/CommunityDetector.java @@ -16,7 +16,7 @@ */ public class CommunityDetector { - private final Graph graph; + private final Graph graph; /** * Creates a new CommunityDetector for the given graph. @@ -24,7 +24,7 @@ public class CommunityDetector { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public CommunityDetector(Graph graph) { + public CommunityDetector(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -99,7 +99,7 @@ public double getAverageWeight() { } /** - * Returns the dominant (most common) edge type in this community. + * Returns the dominant (most common) Edge type in this community. */ public String getDominantType() { String dominant = "none"; @@ -175,7 +175,7 @@ public Community getCommunityOf(String node) { * Q = sum_c [ (e_c / m) - (d_c / 2m)^2 ] * where e_c = internal edges, m = total edges, d_c = sum of degrees. */ - public double getModularity(Graph graph) { + public double getModularity(Graph graph) { int m = graph.getEdgeCount(); if (m == 0) return 0.0; @@ -212,7 +212,7 @@ public DetectionResult detect() { int communityId = 0; // Track which edges have been counted globally to avoid double-counting - Set countedEdges = new HashSet(); + Set countedEdges = new HashSet(); // Find connected components via BFS, computing edge metrics inline for (String vertex : graph.getVertices()) { @@ -228,7 +228,7 @@ public DetectionResult detect() { community.members.add(current); nodeToCommunity.put(current, communityId); - for (edge e : graph.getIncidentEdges(current)) { + for (Edge e : graph.getIncidentEdges(current)) { String neighbor = getOtherEnd(e, current); if (neighbor == null) continue; @@ -267,7 +267,7 @@ public DetectionResult detect() { return new DetectionResult(communities, updatedMapping); } - private String getOtherEnd(edge e, String current) { + private String getOtherEnd(Edge e, String current) { return GraphUtils.getOtherEnd(e, current); } } diff --git a/Gvisual/src/gvisual/CommunityEvolutionTracker.java b/Gvisual/src/gvisual/CommunityEvolutionTracker.java index 7c6611a..6614270 100644 --- a/Gvisual/src/gvisual/CommunityEvolutionTracker.java +++ b/Gvisual/src/gvisual/CommunityEvolutionTracker.java @@ -131,16 +131,16 @@ public EvolutionResult track(int windowCount) { throw new IllegalArgumentException("Need at least 2 windows to track evolution"); } - List>> windows = + List>> windows = temporalGraph.generateWindows(windowCount); List snapshots = new ArrayList<>(); List events = new ArrayList<>(); // Detect communities at each window - for (Map.Entry> entry : windows) { + for (Map.Entry> entry : windows) { long timestamp = entry.getKey(); - Graph windowGraph = entry.getValue(); + Graph windowGraph = entry.getValue(); CommunityDetector detector = new CommunityDetector(windowGraph); CommunityDetector.DetectionResult detection = detector.detect(); @@ -178,7 +178,7 @@ public EvolutionResult trackAtTimePoints(List timePoints) { List events = new ArrayList<>(); for (long time : timePoints) { - Graph snapshot = temporalGraph.snapshotAt(time); + Graph snapshot = temporalGraph.snapshotAt(time); CommunityDetector detector = new CommunityDetector(snapshot); CommunityDetector.DetectionResult detection = detector.detect(); @@ -398,7 +398,7 @@ public static class CommunitySnapshot { public CommunitySnapshot(long timestamp, List communities, - Graph graph) { + Graph graph) { this.timestamp = timestamp; this.communities = Collections.unmodifiableList(new ArrayList<>(communities)); this.vertexCount = graph.getVertexCount(); diff --git a/Gvisual/src/gvisual/CsvReportExporter.java b/Gvisual/src/gvisual/CsvReportExporter.java index eb1d801..67a4586 100644 --- a/Gvisual/src/gvisual/CsvReportExporter.java +++ b/Gvisual/src/gvisual/CsvReportExporter.java @@ -34,8 +34,8 @@ */ public class CsvReportExporter { - private final Graph graph; - private final List allEdges; + private final Graph graph; + private final List allEdges; private String timestamp; /** @@ -45,12 +45,12 @@ public class CsvReportExporter { * @param allEdges all edges (including those possibly filtered out of the graph) * @throws IllegalArgumentException if graph is null */ - public CsvReportExporter(Graph graph, List allEdges) { + public CsvReportExporter(Graph graph, List allEdges) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } this.graph = graph; - this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); + this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); this.timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); } @@ -325,7 +325,7 @@ private void apDfs(String u, Set visited, */ private Map computeEdgeTypeCounts() { Map counts = new LinkedHashMap(); - for (edge e : allEdges) { + for (Edge e : allEdges) { if (!graph.containsEdge(e)) continue; String type = e.getType(); int idx = typeIndex(type); diff --git a/Gvisual/src/gvisual/CycleAnalyzer.java b/Gvisual/src/gvisual/CycleAnalyzer.java index 16e3c6a..f64d2f3 100644 --- a/Gvisual/src/gvisual/CycleAnalyzer.java +++ b/Gvisual/src/gvisual/CycleAnalyzer.java @@ -34,7 +34,7 @@ */ public class CycleAnalyzer { - private final Graph graph; + private final Graph graph; private final boolean isDirected; /** @@ -43,7 +43,7 @@ public class CycleAnalyzer { * @param graph the JUNG graph to analyze (directed or undirected) * @throws IllegalArgumentException if graph is null */ - public CycleAnalyzer(Graph graph) { + public CycleAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -72,12 +72,12 @@ public Cycle(List vertices) { public int length() { return vertices.size(); } /** Total weight of all edges in the cycle (0 if no weights). */ - public float totalWeight(Graph graph) { + public float totalWeight(Graph graph) { float w = 0; for (int i = 0; i < vertices.size(); i++) { String from = vertices.get(i); String to = vertices.get((i + 1) % vertices.size()); - edge e = graph.findEdge(from, to); + Edge e = graph.findEdge(from, to); if (e == null) e = graph.findEdge(to, from); if (e != null) w += e.getWeight(); } @@ -336,7 +336,7 @@ private int bfsShortestCycle(String start) { if (cycleLen < shortest) shortest = cycleLen; } } else { - // Undirected: non-parent back-edge + // Undirected: non-parent back-Edge if (!w.equals(parent.get(v))) { int cycleLen = d + 1 + dist.get(w); if (cycleLen < shortest) shortest = cycleLen; @@ -390,7 +390,7 @@ public List fundamentalCycleBasis() { } // Each non-tree edge defines a fundamental cycle - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 == null || v2 == null) continue; diff --git a/Gvisual/src/gvisual/DegreeDistributionAnalyzer.java b/Gvisual/src/gvisual/DegreeDistributionAnalyzer.java index 7ca0e68..b51b3b2 100644 --- a/Gvisual/src/gvisual/DegreeDistributionAnalyzer.java +++ b/Gvisual/src/gvisual/DegreeDistributionAnalyzer.java @@ -35,7 +35,7 @@ */ public class DegreeDistributionAnalyzer { - private final Graph graph; + private final Graph graph; private boolean computed; // ── Results ───────────────────────────────────────────────────── @@ -64,7 +64,7 @@ public class DegreeDistributionAnalyzer { * @param graph the JUNG graph to analyse * @throws IllegalArgumentException if graph is null */ - public DegreeDistributionAnalyzer(Graph graph) { + public DegreeDistributionAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -511,7 +511,7 @@ private void fitPowerLaw() { * Pearson correlation coefficient of degree(u), degree(v) over all edges. */ private void computeAssortativity(Map vertexDegree) { - Collection edges = graph.getEdges(); + Collection edges = graph.getEdges(); int m = edges.size(); if (m == 0) { assortativity = 0.0; @@ -522,7 +522,7 @@ private void computeAssortativity(Map vertexDegree) { double sumDegree = 0; double sumDegreeSq = 0; - for (edge e : edges) { + for (Edge e : edges) { Collection endpoints = graph.getIncidentVertices(e); if (endpoints == null || endpoints.size() != 2) continue; Iterator it = endpoints.iterator(); @@ -607,7 +607,7 @@ private void classifyNetwork(int n) { */ public static class DegreeDistributionResult { private final int vertexCount; - private final int edgeCount; + private final int EdgeCount; private final int minDegree; private final int maxDegree; private final double meanDegree; diff --git a/Gvisual/src/gvisual/DominatingSetAnalyzer.java b/Gvisual/src/gvisual/DominatingSetAnalyzer.java index ebefcc3..43bae34 100644 --- a/Gvisual/src/gvisual/DominatingSetAnalyzer.java +++ b/Gvisual/src/gvisual/DominatingSetAnalyzer.java @@ -40,7 +40,7 @@ */ public class DominatingSetAnalyzer { - private final Graph graph; + private final Graph graph; private final Map> adj; /** @@ -49,7 +49,7 @@ public class DominatingSetAnalyzer { * @param graph the JUNG graph to analyse * @throws IllegalArgumentException if graph is null */ - public DominatingSetAnalyzer(Graph graph) { + public DominatingSetAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -432,7 +432,7 @@ public String generateReport() { sb.append("=== Dominating Set Analysis ===\n\n"); int n = adj.size(); int edges = graph.getEdgeCount(); - sb.append(String.format("Graph: %d vertices, %d edges%n%n", n, edges)); + sb.append(String.format("Graph: %d vertices, %d edges%n%n", n, Edges)); // Bounds int lb = dominationLowerBound(); diff --git a/Gvisual/src/gvisual/DotExporter.java b/Gvisual/src/gvisual/DotExporter.java index 8121901..44789f8 100644 --- a/Gvisual/src/gvisual/DotExporter.java +++ b/Gvisual/src/gvisual/DotExporter.java @@ -37,7 +37,7 @@ */ public class DotExporter { - private final Graph graph; + private final Graph graph; private String graphName = "G"; private String timestamp; private String description; @@ -67,7 +67,7 @@ public class DotExporter { * @param graph the JUNG graph to export * @throws IllegalArgumentException if graph is null */ - public DotExporter(Graph graph) { + public DotExporter(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -171,7 +171,7 @@ public String exportToString() { // Legend as subgraph (if coloring by type) if (colorByEdgeType) { Set usedTypes = new HashSet<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (e.getType() != null) usedTypes.add(e.getType()); } if (!usedTypes.isEmpty()) { @@ -235,7 +235,7 @@ public String exportToString() { // Compute weight range for edge scaling float minWeight = Float.MAX_VALUE, maxWeight = Float.MIN_VALUE; if (scaleEdgesByWeight) { - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { float w = e.getWeight(); if (w < minWeight) minWeight = w; if (w > maxWeight) maxWeight = w; @@ -245,13 +245,13 @@ public String exportToString() { // Edges sb.append("\n // Edges\n"); Set emittedEdges = new HashSet<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); // Deduplicate for undirected graphs String edgeKey = directed ? v1 + "->" + v2 : (v1.compareTo(v2) < 0 ? v1 + "--" + v2 : v2 + "--" + v1); - String typeKey = (e.getType() != null) ? edgeKey + ":" + e.getType() : edgeKey; + String typeKey = (e.getType() != null) ? edgeKey + ":" + e.getType() : EdgeKey; if (!emittedEdges.add(typeKey)) continue; sb.append(" ").append(quote(v1)).append(connector).append(quote(v2)); diff --git a/Gvisual/src/gvisual/edge.java b/Gvisual/src/gvisual/Edge.java similarity index 95% rename from Gvisual/src/gvisual/edge.java rename to Gvisual/src/gvisual/Edge.java index bb1b6a4..4b6b4cf 100644 --- a/Gvisual/src/gvisual/edge.java +++ b/Gvisual/src/gvisual/Edge.java @@ -8,7 +8,7 @@ * * @author user */ -public class edge { +public class Edge { private String edgeType; private String vertex1; private String vertex2; @@ -46,7 +46,7 @@ public String getVertex2() /** * Constructor */ - public edge() + public Edge() { } @@ -56,7 +56,7 @@ public edge() * @param vertex1 vertex id * @param vertex2 vertex id */ - public edge(String edgeType,String vertex1,String vertex2) + public Edge(String edgeType,String vertex1,String vertex2) { this.edgeType = edgeType; this.vertex1 = vertex1; @@ -94,7 +94,7 @@ public void setTimestamp(Long timestamp) /** * Gets the timestamp (epoch millis) when this edge was first active. - * @return epoch millis, or null if this is an untimed/static edge + * @return epoch millis, or null if this is an untimed/static Edge */ public Long getTimestamp() { @@ -148,7 +148,7 @@ public boolean isActiveDuring(long start, long end) if (timestamp == null) return true; // untimed = always active long edgeStart = timestamp; long edgeEnd = (endTimestamp != null) ? endTimestamp : timestamp; - return edgeStart <= end && edgeEnd >= start; + return edgeStart <= end && EdgeEnd >= start; } } diff --git a/Gvisual/src/gvisual/EdgePersistenceAnalyzer.java b/Gvisual/src/gvisual/EdgePersistenceAnalyzer.java index 7f14516..e915b9b 100644 --- a/Gvisual/src/gvisual/EdgePersistenceAnalyzer.java +++ b/Gvisual/src/gvisual/EdgePersistenceAnalyzer.java @@ -53,26 +53,26 @@ public EdgePersistenceAnalyzer(TemporalGraph temporalGraph, int windowCount) { * * @return a map from each edge to its persistence classification */ - public Map classify() { - List>> windows = + public Map classify() { + List>> windows = temporalGraph.generateWindows(windowCount); // Count how many windows each edge appears in - Map edgeAppearances = new LinkedHashMap<>(); - for (edge e : temporalGraph.getFullGraph().getEdges()) { + Map edgeAppearances = new LinkedHashMap<>(); + for (Edge e : temporalGraph.getFullGraph().getEdges()) { edgeAppearances.put(e, 0); } - for (Map.Entry> window : windows) { - Graph g = window.getValue(); - for (edge e : g.getEdges()) { + for (Map.Entry> window : windows) { + Graph g = window.getValue(); + for (Edge e : g.getEdges()) { edgeAppearances.merge(e, 1, Integer::sum); } } // Classify based on appearance ratio - Map result = new LinkedHashMap<>(); - for (Map.Entry entry : edgeAppearances.entrySet()) { + Map result = new LinkedHashMap<>(); + for (Map.Entry entry : edgeAppearances.entrySet()) { double ratio = (double) entry.getValue() / windowCount; if (ratio >= 0.75) { result.put(entry.getKey(), PERSISTENT); @@ -91,7 +91,7 @@ public Map classify() { * @return map with keys "persistent", "periodic", "transient" and integer counts */ public Map summary() { - Map classified = classify(); + Map classified = classify(); Map counts = new LinkedHashMap<>(); counts.put(PERSISTENT, 0); counts.put(PERIODIC, 0); @@ -108,10 +108,10 @@ public Map summary() { * @param classification one of {@link #PERSISTENT}, {@link #PERIODIC}, {@link #TRANSIENT} * @return set of edges matching the classification */ - public Set getEdgesByClassification(String classification) { - Map classified = classify(); - Set result = new LinkedHashSet<>(); - for (Map.Entry entry : classified.entrySet()) { + public Set getEdgesByClassification(String classification) { + Map classified = classify(); + Set result = new LinkedHashSet<>(); + for (Map.Entry entry : classified.entrySet()) { if (classification.equals(entry.getValue())) { result.add(entry.getKey()); } diff --git a/Gvisual/src/gvisual/EulerianPathAnalyzer.java b/Gvisual/src/gvisual/EulerianPathAnalyzer.java index 6b0e7fd..20621d1 100644 --- a/Gvisual/src/gvisual/EulerianPathAnalyzer.java +++ b/Gvisual/src/gvisual/EulerianPathAnalyzer.java @@ -26,7 +26,7 @@ */ public class EulerianPathAnalyzer { - private final Graph graph; + private final Graph graph; /** * Create a new analyzer for the given graph. @@ -34,7 +34,7 @@ public class EulerianPathAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public EulerianPathAnalyzer(Graph graph) { + public EulerianPathAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -103,17 +103,17 @@ public int getMinEdgeDuplications() { */ public static class EulerianPathResult { private final List vertices; - private final List edges; + private final List edges; private final boolean isCircuit; - public EulerianPathResult(List vertices, List edges, boolean isCircuit) { + public EulerianPathResult(List vertices, List edges, boolean isCircuit) { this.vertices = Collections.unmodifiableList(new ArrayList(vertices)); - this.edges = Collections.unmodifiableList(new ArrayList(edges)); + this.edges = Collections.unmodifiableList(new ArrayList(edges)); this.isCircuit = isCircuit; } public List getVertices() { return vertices; } - public List getEdges() { return edges; } + public List getEdges() { return edges; } public boolean isCircuit() { return isCircuit; } public int getEdgeCount() { return edges.size(); } } @@ -168,14 +168,14 @@ public EulerianPathResult findEulerianPath() { return null; } - // Build adjacency with edge tracking + // Build adjacency with Edge tracking Map> adj = new LinkedHashMap>(); for (String v : graph.getVertices()) { adj.put(v, new LinkedList()); } - Set allEdges = new HashSet(); - for (edge e : graph.getEdges()) { + Set allEdges = new HashSet(); + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); EdgeEntry entry1 = new EdgeEntry(v2, e); @@ -206,14 +206,14 @@ public EulerianPathResult findEulerianPath() { if (graph.getVertexCount() > 0) { verts.add(graph.getVertices().iterator().next()); } - return new EulerianPathResult(verts, new ArrayList(), true); + return new EulerianPathResult(verts, new ArrayList(), true); } } // Hierholzer's algorithm Deque stack = new ArrayDeque(); List pathVertices = new ArrayList(); - List pathEdges = new ArrayList(); + List pathEdges = new ArrayList(); stack.push(start); @@ -241,12 +241,12 @@ public EulerianPathResult findEulerianPath() { Collections.reverse(pathVertices); // Reconstruct edges from vertex sequence - List orderedEdges = new ArrayList(); + List orderedEdges = new ArrayList(); for (int i = 0; i < pathVertices.size() - 1; i++) { String v1 = pathVertices.get(i); String v2 = pathVertices.get(i + 1); - edge found = null; - for (edge e : allEdges) { + Edge found = null; + for (Edge e : allEdges) { String e1 = graph.getEndpoints(e).getFirst(); String e2 = graph.getEndpoints(e).getSecond(); if ((e1.equals(v1) && e2.equals(v2)) || (e1.equals(v2) && e2.equals(v1))) { @@ -265,7 +265,7 @@ public EulerianPathResult findEulerianPath() { } /** - * Suggest which edges to add to make a non-Eulerian graph Eulerian. + * Suggest which Edges to add to make a non-Eulerian graph Eulerian. * Returns pairs of odd-degree vertices that should be connected. * * @return list of vertex pairs to connect, empty if already Eulerian @@ -292,7 +292,7 @@ public List suggestEdgesForEulerian() { * Uses iterative max-flow between a fixed source and all other vertices, * returning the minimum. * - * @return edge connectivity (0 if disconnected or single vertex) + * @return Edge connectivity (0 if disconnected or single vertex) */ public int computeEdgeConnectivity() { Collection vertices = graph.getVertices(); @@ -369,11 +369,11 @@ public String generateReport() { private static class EdgeEntry { final String target; - final edge e; + final Edge e; boolean used = false; EdgeEntry partner; - EdgeEntry(String target, edge e) { + EdgeEntry(String target, Edge e) { this.target = target; this.e = e; } @@ -413,7 +413,7 @@ private int maxFlowBFS(String source, String target) { for (String v : graph.getVertices()) { capacity.put(v, new HashMap()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); Integer cur = capacity.get(v1).get(v2); diff --git a/Gvisual/src/gvisual/FeedbackVertexSetAnalyzer.java b/Gvisual/src/gvisual/FeedbackVertexSetAnalyzer.java index a38448f..2378324 100644 --- a/Gvisual/src/gvisual/FeedbackVertexSetAnalyzer.java +++ b/Gvisual/src/gvisual/FeedbackVertexSetAnalyzer.java @@ -36,10 +36,10 @@ */ public class FeedbackVertexSetAnalyzer { - private final Graph graph; + private final Graph graph; private final boolean directed; - public FeedbackVertexSetAnalyzer(Graph graph) { + public FeedbackVertexSetAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -177,11 +177,11 @@ private void backtrack(List candidates, int idx, Set remaining, // ── Feedback Edge Set ───────────────────────────────────────── - public Set feedbackEdgeSet() { + public Set feedbackEdgeSet() { Set vertices = new HashSet<>(graph.getVertices()); if (vertices.isEmpty()) return new HashSet<>(); - Set treeEdges = new HashSet<>(); + Set treeEdges = new HashSet<>(); Set visited = new HashSet<>(); for (String start : vertices) { @@ -190,9 +190,9 @@ public Set feedbackEdgeSet() { queue.add(start); visited.add(start); while (!queue.isEmpty()) { String v = queue.poll(); - Collection incident = graph.getIncidentEdges(v); + Collection incident = graph.getIncidentEdges(v); if (incident == null) continue; - for (edge e : incident) { + for (Edge e : incident) { String other = GraphUtils.getOtherEnd(e, v); if (other != null && !visited.contains(other)) { visited.add(other); treeEdges.add(e); queue.add(other); @@ -201,7 +201,7 @@ public Set feedbackEdgeSet() { } } - Set feedback = new HashSet<>(graph.getEdges()); + Set feedback = new HashSet<>(graph.getEdges()); feedback.removeAll(treeEdges); return feedback; } @@ -318,13 +318,13 @@ public static class FVSReport { public final int vertexCount, edgeCount, cycleRank, lowerBound, upperBound; public final boolean isAcyclic; public final Set greedyFVS, exactFVS; - public final Set feedbackEdgeSet; + public final Set feedbackEdgeSet; public final Map criticality; public final List> cyclePacking; public final double approximationRatio; public FVSReport(int vertexCount, int edgeCount, int cycleRank, boolean isAcyclic, - Set greedyFVS, Set exactFVS, Set feedbackEdgeSet, + Set greedyFVS, Set exactFVS, Set feedbackEdgeSet, int lowerBound, int upperBound, Map criticality, List> cyclePacking, double approximationRatio) { this.vertexCount = vertexCount; this.edgeCount = edgeCount; diff --git a/Gvisual/src/gvisual/ForceDirectedLayout.java b/Gvisual/src/gvisual/ForceDirectedLayout.java index 06bb063..0c5a98e 100644 --- a/Gvisual/src/gvisual/ForceDirectedLayout.java +++ b/Gvisual/src/gvisual/ForceDirectedLayout.java @@ -24,7 +24,7 @@ *
  • Optional gravity force to prevent disconnected components from * drifting apart
  • *
  • Edge-weight awareness — heavier edges pull more strongly
  • - *
  • Layout quality metrics: edge crossing count, edge length uniformity, + *
  • Layout quality metrics: edge crossing count, Edge length uniformity, * angular resolution, stress
  • *
  • Bounding box normalization for display in arbitrary viewport sizes
  • *
  • Convergence detection via energy tracking
  • @@ -45,7 +45,7 @@ public class ForceDirectedLayout { /** Barnes-Hut opening angle: lower = more accurate, higher = faster. */ private static final double BH_THETA = 0.8; - private final Graph graph; + private final Graph graph; private final int maxIterations; private final double width; private final double height; @@ -65,7 +65,7 @@ public class ForceDirectedLayout { * @param graph the JUNG graph to lay out * @throws IllegalArgumentException if graph is null */ - public ForceDirectedLayout(Graph graph) { + public ForceDirectedLayout(Graph graph) { this(graph, 300, 800, 600, 0.1, true, 42L); } @@ -78,11 +78,11 @@ public ForceDirectedLayout(Graph graph) { * @param height canvas height for the layout area * @param gravity gravity constant pulling nodes toward center * (0.0 = none, 0.1 = gentle, 1.0 = strong) - * @param useEdgeWeights if true, edge weights scale attractive forces + * @param useEdgeWeights if true, Edge weights scale attractive forces * @param seed random seed for reproducible initial placement * @throws IllegalArgumentException if graph is null or parameters invalid */ - public ForceDirectedLayout(Graph graph, int maxIterations, + public ForceDirectedLayout(Graph graph, int maxIterations, double width, double height, double gravity, boolean useEdgeWeights, long seed) { if (graph == null) { @@ -164,10 +164,10 @@ public ForceDirectedLayout compute() { indexMap.put(vertexList.get(i), i); } - // Build edge list as index pairs with weights + // Build Edge list as index pairs with weights List edgeIndices = new ArrayList(); List edgeWeights = new ArrayList(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Integer u = indexMap.get(e.getVertex1()); Integer v = indexMap.get(e.getVertex2()); if (u != null && v != null && !u.equals(v)) { @@ -228,7 +228,7 @@ public ForceDirectedLayout compute() { double dist = Math.sqrt(dx * dx + dy * dy); if (dist < MIN_DIST) dist = MIN_DIST; - // Attractive force: dist² / k, scaled by edge weight + // Attractive force: dist² / k, scaled by Edge weight double force = (dist * dist) / k * w; double fx = (dx / dist) * force; double fy = (dy / dist) * force; @@ -387,7 +387,7 @@ public Map getNormalizedPositions(double vpWidth, */ public int countEdgeCrossings() { ensureComputed(); - List edges = new ArrayList(graph.getEdges()); + List edges = new ArrayList(graph.getEdges()); int m = edges.size(); // Pre-compute endpoint positions and vertex names into arrays @@ -400,7 +400,7 @@ public int countEdgeCrossings() { boolean[] valid = new boolean[m]; for (int i = 0; i < m; i++) { - edge e = edges.get(i); + Edge e = edges.get(i); v1[i] = e.getVertex1(); v2[i] = e.getVertex2(); ep1[i] = positions.get(v1[i]); @@ -436,10 +436,10 @@ public int countEdgeCrossings() { * * @return CV of edge lengths (0 = perfectly uniform) */ - public double edgeLengthUniformity() { + public double EdgeLengthUniformity() { ensureComputed(); List lengths = new ArrayList(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { double[] p1 = positions.get(e.getVertex1()); double[] p2 = positions.get(e.getVertex2()); if (p1 == null || p2 == null) continue; @@ -587,7 +587,7 @@ public LayoutQuality getQualityReport() { ensureComputed(); return new LayoutQuality( countEdgeCrossings(), - edgeLengthUniformity(), + EdgeLengthUniformity(), minAngularResolution(), computeStress(), iterationsUsed, @@ -622,12 +622,12 @@ public String toSVG(int svgWidth, int svgHeight, int nodeRadius) { sb.append(" \n"); // Draw edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { double[] p1 = norm.get(e.getVertex1()); double[] p2 = norm.get(e.getVertex2()); if (p1 == null || p2 == null) continue; sb.append(String.format( - " \n", p1[0], p1[1], p2[0], p2[1])); } @@ -727,7 +727,7 @@ public String toString() { return String.format( "LayoutQuality{crossings=%d, lengthCV=%.4f, " + "angularRes=%.1f°, stress=%.4f, iter=%d, converged=%s}", - edgeCrossings, edgeLengthCV, minAngularResolution, + edgeCrossings, EdgeLengthCV, minAngularResolution, stress, iterations, converged); } } diff --git a/Gvisual/src/gvisual/GexfExporter.java b/Gvisual/src/gvisual/GexfExporter.java index 5441ad1..c84b6f7 100644 --- a/Gvisual/src/gvisual/GexfExporter.java +++ b/Gvisual/src/gvisual/GexfExporter.java @@ -43,8 +43,8 @@ public class GexfExporter { private static final String GEXF_NS = "http://gexf.net/1.3"; private static final String VIZ_NS = "http://gexf.net/1.3/viz"; - private final Graph graph; - private final List allEdges; + private final Graph graph; + private final List allEdges; private String creator = "GraphVisual"; private String description = ""; private boolean includeVizData = true; @@ -66,12 +66,12 @@ public class GexfExporter { * @param allEdges all edges, including those filtered from the current view * @throws IllegalArgumentException if graph is null */ - public GexfExporter(Graph graph, List allEdges) { + public GexfExporter(Graph graph, List allEdges) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } this.graph = graph; - this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); + this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); } /** Sets the creator metadata field. */ @@ -139,7 +139,7 @@ public String exportToString() { sb.append(" \n"); // Graph element - sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); - sb.append(" \n"); - sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); sb.append(" \n"); sb.append(" \n"); @@ -181,10 +181,10 @@ public String exportToString() { sb.append(" \n"); // Edges — use visible edges from the graph - sb.append(" \n"); - Collection edges = graph.getEdges(); + sb.append(" \n"); + Collection edges = graph.getEdges(); int edgeId = 0; - for (edge e : edges) { + for (Edge e : edges) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); // Only include edges whose vertices are in the graph @@ -192,7 +192,7 @@ public String exportToString() { continue; } - sb.append(" \n"); @@ -225,9 +225,9 @@ public String exportToString() { sb.append(" \n"); } - sb.append(" \n"); + sb.append(" \n"); } - sb.append(" \n"); + sb.append(" \n"); sb.append(" \n"); sb.append("\n"); @@ -239,7 +239,7 @@ public String exportToString() { * Checks whether any edge in the graph carries temporal data. */ private boolean hasTemporalEdges() { - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (e.getTimestamp() != null) return true; } return false; diff --git a/Gvisual/src/gvisual/GraphAlgorithmAnimator.java b/Gvisual/src/gvisual/GraphAlgorithmAnimator.java index 5dd67e1..87b4586 100644 --- a/Gvisual/src/gvisual/GraphAlgorithmAnimator.java +++ b/Gvisual/src/gvisual/GraphAlgorithmAnimator.java @@ -37,7 +37,7 @@ */ public class GraphAlgorithmAnimator { - private final Graph graph; + private final Graph graph; private final Map positions; private final int defaultWidth; private final int defaultHeight; @@ -108,7 +108,7 @@ public AnimationFrame(int stepNumber, String algorithmName, * * @param graph the graph to animate */ - public GraphAlgorithmAnimator(Graph graph) { + public GraphAlgorithmAnimator(Graph graph) { this(graph, 800, 600, 18); } @@ -120,7 +120,7 @@ public GraphAlgorithmAnimator(Graph graph) { * @param height SVG viewport height * @param radius node circle radius */ - public GraphAlgorithmAnimator(Graph graph, + public GraphAlgorithmAnimator(Graph graph, int width, int height, int radius) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); this.graph = graph; @@ -136,7 +136,7 @@ public GraphAlgorithmAnimator(Graph graph, * @param graph the graph * @param positions map of vertex to {x, y} positions */ - public GraphAlgorithmAnimator(Graph graph, + public GraphAlgorithmAnimator(Graph graph, Map positions) { this(graph, positions, 800, 600, 18); } @@ -144,7 +144,7 @@ public GraphAlgorithmAnimator(Graph graph, /** * Create an animator with pre-computed positions and custom dimensions. */ - public GraphAlgorithmAnimator(Graph graph, + public GraphAlgorithmAnimator(Graph graph, Map positions, int width, int height, int radius) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); @@ -177,7 +177,7 @@ public List animateBFS(String source) { nodeState.put(v, COLOR_UNVISITED); nodeLabels.put(v, v); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { edgeState.put(edgeKey(e), COLOR_UNVISITED); } @@ -203,7 +203,7 @@ public List animateBFS(String source) { Collections.sort(neighbors); for (String neighbor : neighbors) { - edge e = findEdge(current, neighbor); + Edge e = findEdge(current, neighbor); if (e != null) { edgeState.put(edgeKey(e), COLOR_ACTIVE_EDGE); } @@ -259,7 +259,7 @@ public List animateDFS(String source) { nodeState.put(v, COLOR_UNVISITED); nodeLabels.put(v, v); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { edgeState.put(edgeKey(e), COLOR_UNVISITED); } @@ -302,7 +302,7 @@ private void dfsRecurse(String current, Set visited, for (String neighbor : neighbors) { if (!visited.contains(neighbor)) { - edge e = findEdge(current, neighbor); + Edge e = findEdge(current, neighbor); if (e != null) { edgeState.put(edgeKey(e), COLOR_TREE_EDGE); } @@ -341,7 +341,7 @@ public List animateDijkstra(String source) { dist.put(v, Double.MAX_VALUE); nodeLabels.put(v, v + " (\u221e)"); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { edgeState.put(edgeKey(e), COLOR_UNVISITED); } @@ -374,8 +374,8 @@ public List animateDijkstra(String source) { // Highlight the tree edge to this node if (prev.containsKey(u)) { - edge pe = findEdge(prev.get(u), u); - if (pe != null) edgeState.put(edgeKey(pe), COLOR_TREE_EDGE); + Edge pe = findEdge(prev.get(u), u); + if (pe != null) edgeState.put(EdgeKey(pe), COLOR_TREE_EDGE); } // Relax neighbors @@ -386,7 +386,7 @@ public List animateDijkstra(String source) { for (String v : neighbors) { if (finalized.contains(v)) continue; - edge e = findEdge(u, v); + Edge e = findEdge(u, v); double weight = (e != null) ? Math.max(e.getWeight(), 0.001) : 1.0; double alt = dist.get(u) + weight; @@ -414,7 +414,7 @@ public List animateDijkstra(String source) { frames.add(new AnimationFrame(step, "Dijkstra", "Dijkstra complete — " + finalized.size() + " vertices reached", - nodeState, edgeState, nodeLabels, null)); + nodeState, EdgeState, nodeLabels, null)); return frames; } @@ -438,12 +438,12 @@ public List animateKruskal() { nodeState.put(v, COLOR_UNVISITED); nodeLabels.put(v, v); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { edgeState.put(edgeKey(e), COLOR_UNVISITED); } // Sort edges by weight - List sortedEdges = new ArrayList<>(graph.getEdges()); + List sortedEdges = new ArrayList<>(graph.getEdges()); sortedEdges.sort(Comparator.comparingDouble(edge::getWeight)); // Union-Find @@ -463,7 +463,7 @@ public List animateKruskal() { int treeEdges = 0; double totalWeight = 0; - for (edge e : sortedEdges) { + for (Edge e : sortedEdges) { String u = e.getVertex1(); String v = e.getVertex2(); String ek = edgeKey(e); @@ -533,7 +533,7 @@ public List animatePageRank(double dampingFactor, Map edgeState = new LinkedHashMap<>(); Map nodeLabels = new LinkedHashMap<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { edgeState.put(edgeKey(e), COLOR_UNVISITED); } @@ -636,7 +636,7 @@ public String toSVG(AnimationFrame frame, int width, int height) { int offsetY = 60; // Draw edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String ek = edgeKey(e); String color = frame.edgeColors.getOrDefault(ek, COLOR_UNVISITED); double[] p1 = positions.get(e.getVertex1()); @@ -811,15 +811,15 @@ private void validateVertex(String v) { } } - private String edgeKey(edge e) { + private String edgeKey(Edge e) { if (e == null) return ""; String a = e.getVertex1(); String b = e.getVertex2(); return (a.compareTo(b) <= 0) ? a + "~~" + b : b + "~~" + a; } - private edge findEdge(String u, String v) { - edge e = graph.findEdge(u, v); + private Edge findEdge(String u, String v) { + Edge e = graph.findEdge(u, v); if (e == null) e = graph.findEdge(v, u); return e; } @@ -880,7 +880,7 @@ private void union(Map parent, * Compute a simple circular layout for the graph. */ private static Map computeLayout( - Graph graph, int width, int height, int radius) { + Graph graph, int width, int height, int radius) { Map pos = new LinkedHashMap<>(); List vertices = new ArrayList<>(graph.getVertices()); Collections.sort(vertices); diff --git a/Gvisual/src/gvisual/GraphAnnotationManager.java b/Gvisual/src/gvisual/GraphAnnotationManager.java index d0e3280..2b59b36 100644 --- a/Gvisual/src/gvisual/GraphAnnotationManager.java +++ b/Gvisual/src/gvisual/GraphAnnotationManager.java @@ -154,7 +154,7 @@ public static String edgeKey(String v1, String v2) { */ public Annotation annotateEdge(String v1, String v2) { String key = edgeKey(v1, v2); - return edgeAnnotations.computeIfAbsent(key, + return EdgeAnnotations.computeIfAbsent(key, id -> new Annotation(id, Annotation.ElementType.EDGE)); } diff --git a/Gvisual/src/gvisual/GraphAnomalyDetector.java b/Gvisual/src/gvisual/GraphAnomalyDetector.java index f0790ef..ecf8f71 100644 --- a/Gvisual/src/gvisual/GraphAnomalyDetector.java +++ b/Gvisual/src/gvisual/GraphAnomalyDetector.java @@ -49,7 +49,7 @@ public class GraphAnomalyDetector { /** Number of metric dimensions. */ private static final int NUM_DIMENSIONS = 4; - private final Graph graph; + private final Graph graph; private List results; private boolean analyzed; @@ -71,7 +71,7 @@ public class GraphAnomalyDetector { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public GraphAnomalyDetector(Graph graph) { + public GraphAnomalyDetector(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -403,7 +403,7 @@ private double computeClusteringCoeff(String v) { int k = nbrs.size(); if (k < 2) return 0.0; - // Count edges among neighbors (triangles) + // Count Edges among neighbors (triangles) int triangleEdges = 0; Set nbrSet = new HashSet(nbrs); for (int i = 0; i < k; i++) { @@ -427,12 +427,12 @@ private double computeClusteringCoeff(String v) { *

    Normalized to [0, 1] by dividing by log(numCategories).

    */ private double computeEdgeDiversity(String v) { - Collection edges = graph.getIncidentEdges(v); + Collection edges = graph.getIncidentEdges(v); if (edges == null || edges.isEmpty()) return 0.0; Map typeCounts = new HashMap(); int total = 0; - for (edge e : edges) { + for (Edge e : edges) { String type = e.getType(); if (type == null) type = "unknown"; Integer count = typeCounts.get(type); diff --git a/Gvisual/src/gvisual/GraphAsciiRenderer.java b/Gvisual/src/gvisual/GraphAsciiRenderer.java index 30cbabc..b0f3d46 100644 --- a/Gvisual/src/gvisual/GraphAsciiRenderer.java +++ b/Gvisual/src/gvisual/GraphAsciiRenderer.java @@ -39,7 +39,7 @@ */ public class GraphAsciiRenderer { - private final Graph graph; + private final Graph graph; private int width = 100; private int height = 35; private boolean unicode = false; @@ -74,7 +74,7 @@ public class GraphAsciiRenderer { * @param graph the JUNG graph to render * @throws IllegalArgumentException if graph is null */ - public GraphAsciiRenderer(Graph graph) { + public GraphAsciiRenderer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -161,7 +161,7 @@ public String render() { for (char[] row : grid) Arrays.fill(row, SPACE); // Draw edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 == null || v2 == null) continue; @@ -236,7 +236,7 @@ public String render() { if (showLegend) { sb.append('\n'); sb.append(" Graph: ").append(graph.getVertexCount()).append(" nodes, ") - .append(graph.getEdgeCount()).append(" edges\n"); + .append(graph.getEdgeCount()).append(" Edges\n"); if (!highlightNodes.isEmpty() || highlightDegreeThreshold >= 0) { char hChar = unicode ? HIGHLIGHT_UNICODE : HIGHLIGHT_ASCII; @@ -259,7 +259,7 @@ public String render() { // Edge type distribution Map typeCounts = new TreeMap<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String type = e.getType() != null ? e.getType() : "unknown"; typeCounts.merge(type, 1, Integer::sum); } @@ -386,7 +386,7 @@ private void computeLayout() { // Build adjacency for quick lookup Set edgeSet = new HashSet<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (e.getVertex1() != null && e.getVertex2() != null) { edgeSet.add(e.getVertex1() + "|" + e.getVertex2()); edgeSet.add(e.getVertex2() + "|" + e.getVertex1()); @@ -422,7 +422,7 @@ private void computeLayout() { } // Attractive forces along edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 == null || v2 == null) continue; diff --git a/Gvisual/src/gvisual/GraphBenchmarkSuite.java b/Gvisual/src/gvisual/GraphBenchmarkSuite.java index 030609d..226ba4f 100644 --- a/Gvisual/src/gvisual/GraphBenchmarkSuite.java +++ b/Gvisual/src/gvisual/GraphBenchmarkSuite.java @@ -14,13 +14,13 @@ public class GraphBenchmarkSuite { public static class BenchmarkGraph { private final String name; private final String description; - private final Graph graph; + private final Graph graph; private final int expectedNodes; private final int expectedEdges; private final Map properties; public BenchmarkGraph(String name, String description, - Graph graph, + Graph graph, int expectedNodes, int expectedEdges, Map properties) { this.name = name; @@ -33,7 +33,7 @@ public BenchmarkGraph(String name, String description, public String getName() { return name; } public String getDescription() { return description; } - public Graph getGraph() { return graph; } + public Graph getGraph() { return graph; } public int getExpectedNodes() { return expectedNodes; } public int getExpectedEdges() { return expectedEdges; } public Map getProperties() { return properties; } @@ -59,10 +59,10 @@ public String getSummary() { } } - private static void addEdge(Graph g, String v1, String v2) { + private static void addEdge(Graph g, String v1, String v2) { if (!g.containsVertex(v1)) g.addVertex(v1); if (!g.containsVertex(v2)) g.addVertex(v2); - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setLabel(v1 + "-" + v2); g.addEdge(e, v1, v2); } @@ -74,7 +74,7 @@ private static Map props(String... pairs) { } public BenchmarkGraph zacharyKarateClub() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); int[][] edges = { {1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,11},{1,12}, {1,13},{1,14},{1,18},{1,20},{1,22},{1,32}, @@ -95,7 +95,7 @@ public BenchmarkGraph zacharyKarateClub() { } public BenchmarkGraph petersenGraph() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); int[][] edges = {{0,1},{1,2},{2,3},{3,4},{4,0},{5,7},{7,9},{9,6},{6,8},{8,5},{0,5},{1,6},{2,7},{3,8},{4,9}}; for (int[] p : edges) addEdge(g, String.valueOf(p[0]), String.valueOf(p[1])); return new BenchmarkGraph("Petersen Graph", @@ -104,7 +104,7 @@ public BenchmarkGraph petersenGraph() { } public BenchmarkGraph florentineFamilies() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); String[][] edges = { {"Medici","Barbadori"},{"Medici","Ridolfi"},{"Medici","Tornabuoni"}, {"Medici","Albizzi"},{"Medici","Salviati"},{"Medici","Acciaiuoli"}, @@ -122,7 +122,7 @@ public BenchmarkGraph florentineFamilies() { } public BenchmarkGraph cubeGraph() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); int[][] edges = {{0,1},{0,2},{0,4},{1,3},{1,5},{2,3},{2,6},{3,7},{4,5},{4,6},{5,7},{6,7}}; for (int[] p : edges) { String v1 = String.format("%03d", Integer.parseInt(Integer.toBinaryString(p[0]))); @@ -135,7 +135,7 @@ public BenchmarkGraph cubeGraph() { } public BenchmarkGraph dodecahedron() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); int[][] edges = { {1,2},{2,3},{3,4},{4,5},{5,1},{1,6},{2,7},{3,8},{4,9},{5,10}, {6,11},{6,15},{7,11},{7,12},{8,12},{8,13},{9,13},{9,14},{10,14},{10,15}, @@ -148,7 +148,7 @@ public BenchmarkGraph dodecahedron() { } public BenchmarkGraph tutteGraph() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); int[][] edges = { {1,2},{1,4},{1,26}, {2,3},{2,5},{3,4},{3,8},{4,29}, @@ -171,7 +171,7 @@ public BenchmarkGraph tutteGraph() { public BenchmarkGraph friendshipGraph(int n) { if (n < 1) throw new IllegalArgumentException("n must be >= 1"); - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); g.addVertex("0"); for (int i = 0; i < n; i++) { String a = String.valueOf(2 * i + 1), b = String.valueOf(2 * i + 2); diff --git a/Gvisual/src/gvisual/GraphCentralityCorrelator.java b/Gvisual/src/gvisual/GraphCentralityCorrelator.java index 23757e2..4d9cc35 100644 --- a/Gvisual/src/gvisual/GraphCentralityCorrelator.java +++ b/Gvisual/src/gvisual/GraphCentralityCorrelator.java @@ -17,7 +17,7 @@ */ public class GraphCentralityCorrelator { - private final Graph graph; + private final Graph graph; private final NodeCentralityAnalyzer centralityAnalyzer; private boolean computed; @@ -158,7 +158,7 @@ public int hashCode() { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public GraphCentralityCorrelator(Graph graph) { + public GraphCentralityCorrelator(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/GraphClusterQualityAnalyzer.java b/Gvisual/src/gvisual/GraphClusterQualityAnalyzer.java index 235dc0c..9c52313 100644 --- a/Gvisual/src/gvisual/GraphClusterQualityAnalyzer.java +++ b/Gvisual/src/gvisual/GraphClusterQualityAnalyzer.java @@ -39,7 +39,7 @@ * *

    Usage

    *
    {@code
    - * Graph g = ...;
    + * Graph g = ...;
      * Map clustering = new HashMap<>();
      * clustering.put("A", 0);
      * clustering.put("B", 0);
    @@ -55,7 +55,7 @@
      */
     public class GraphClusterQualityAnalyzer {
     
    -    private final Graph graph;
    +    private final Graph graph;
     
         /**
          * Creates a new cluster quality analyzer for the given graph.
    @@ -63,7 +63,7 @@ public class GraphClusterQualityAnalyzer {
          * @param graph the JUNG graph whose clustering will be evaluated
          * @throws IllegalArgumentException if graph is null
          */
    -    public GraphClusterQualityAnalyzer(Graph graph) {
    +    public GraphClusterQualityAnalyzer(Graph graph) {
             if (graph == null) {
                 throw new IllegalArgumentException("Graph must not be null");
             }
    @@ -264,7 +264,7 @@ public QualityReport evaluate(Map clustering) {
             // Count intra-cluster and inter-cluster edges
             int intraEdges = 0;
             int interEdges = 0;
    -        for (edge e : graph.getEdges()) {
    +        for (Edge e : graph.getEdges()) {
                 String v1 = e.getVertex1();
                 String v2 = e.getVertex2();
                 Integer c1 = clustering.get(v1);
    @@ -307,10 +307,10 @@ public QualityReport evaluate(Map clustering) {
                 int totalDegree = 0;
     
                 for (String node : members) {
    -                Collection incidents = graph.getIncidentEdges(node);
    +                Collection incidents = graph.getIncidentEdges(node);
                     if (incidents == null) continue;
                     totalDegree += incidents.size();
    -                for (edge e : incidents) {
    +                for (Edge e : incidents) {
                         String neighbor = getOtherEnd(e, node);
                         Integer neighborCluster = clustering.get(neighbor);
                         if (neighborCluster != null && neighborCluster.equals(cid)) {
    @@ -540,10 +540,10 @@ private double computeModularity(
                 int clusterDegreeSum = 0;
     
                 for (String node : members) {
    -                Collection incidents = graph.getIncidentEdges(node);
    +                Collection incidents = graph.getIncidentEdges(node);
                     if (incidents == null) continue;
                     clusterDegreeSum += incidents.size();
    -                for (edge e : incidents) {
    +                for (Edge e : incidents) {
                         String neighbor = getOtherEnd(e, node);
                         if (members.contains(neighbor)) {
                             clusterIntra++;
    @@ -584,7 +584,7 @@ private Map> invertClustering(Map clusteri
             return result;
         }
     
    -    private String getOtherEnd(edge e, String node) {
    +    private String getOtherEnd(Edge e, String node) {
             return e.getVertex1().equals(node) ? e.getVertex2() : e.getVertex1();
         }
     
    diff --git a/Gvisual/src/gvisual/GraphColoringAnalyzer.java b/Gvisual/src/gvisual/GraphColoringAnalyzer.java
    index 5747dbd..5af1a0c 100644
    --- a/Gvisual/src/gvisual/GraphColoringAnalyzer.java
    +++ b/Gvisual/src/gvisual/GraphColoringAnalyzer.java
    @@ -7,7 +7,7 @@
      * Comprehensive graph coloring analyzer -- greedy coloring with multiple
      * vertex orderings (natural, largest-first, smallest-last, DSatur),
      * chromatic number bounds, k-colorability checking, coloring verification,
    - * color class analysis, edge chromatic number estimation (Vizing's theorem),
    + * color class analysis, Edge chromatic number estimation (Vizing's theorem),
      * and report generation.
      *
      * 

    Graph coloring assigns labels (colors) to vertices so that no two @@ -43,7 +43,7 @@ public enum VertexOrdering { DSATUR } - private final Graph graph; + private final Graph graph; /** * Creates a new GraphColoringAnalyzer for the given graph. @@ -51,7 +51,7 @@ public enum VertexOrdering { * @param graph the JUNG graph to color * @throws IllegalArgumentException if graph is null */ - public GraphColoringAnalyzer(Graph graph) { + public GraphColoringAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -395,7 +395,7 @@ public List findConflicts(Map assignment) { throw new IllegalArgumentException("Assignment must not be null"); } List conflicts = new ArrayList<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); Integer c1 = assignment.get(v1); @@ -518,7 +518,7 @@ public int maxDegree() { /** * Generates a comprehensive coloring report including greedy and - * DSatur results, chromatic bounds, edge chromatic bounds, and + * DSatur results, chromatic bounds, Edge chromatic bounds, and * color class analysis. * * @return formatted report string @@ -674,7 +674,7 @@ private Map> buildColorClasses( } private boolean validate(Map assignment) { - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); Integer c1 = assignment.get(v1); diff --git a/Gvisual/src/gvisual/GraphCompressor.java b/Gvisual/src/gvisual/GraphCompressor.java index 352a646..b286838 100644 --- a/Gvisual/src/gvisual/GraphCompressor.java +++ b/Gvisual/src/gvisual/GraphCompressor.java @@ -49,7 +49,7 @@ */ public class GraphCompressor { - private final Graph graph; + private final Graph graph; /** * Creates a compressor for the given graph. @@ -57,7 +57,7 @@ public class GraphCompressor { * @param graph the graph to compress (must not be null) * @throws IllegalArgumentException if graph is null */ - public GraphCompressor(Graph graph) { + public GraphCompressor(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -289,7 +289,7 @@ public String compressibilityReport() { // ── Quotient Graph Builder ────────────────────────────────────── private CompressionResult buildQuotientGraph(List> groups, String strategy) { - Graph quotient = new UndirectedSparseGraph<>(); + Graph quotient = new UndirectedSparseGraph<>(); Map> supernodeMembers = new LinkedHashMap<>(); Map nodeToSupernode = new HashMap<>(); @@ -314,7 +314,7 @@ private CompressionResult buildQuotientGraph(List> groups, String s int edgeCounter = 0; Map superEdgeInfos = new HashMap<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); String s1 = nodeToSupernode.get(v1); @@ -328,7 +328,7 @@ private CompressionResult buildQuotientGraph(List> groups, String s info = new SuperEdgeInfo(); superEdgeInfos.put(edgeKey, info); - edge superEdge = new edge("super", s1, s2); + Edge superEdge = new Edge("super", s1, s2); superEdge.setLabel("compressed"); quotient.addEdge(superEdge, s1, s2); info.edge = superEdge; @@ -339,7 +339,7 @@ private CompressionResult buildQuotientGraph(List> groups, String s // Set aggregated weights for (SuperEdgeInfo info : superEdgeInfos.values()) { - info.edge.setWeight(info.totalWeight); + info.Edge.setWeight(info.totalWeight); } return new CompressionResult( @@ -368,7 +368,7 @@ private String formatReportLine(String label, CompressionResult result) { } private static class SuperEdgeInfo { - edge edge; + Edge edge; int count; float totalWeight; } @@ -380,14 +380,14 @@ private static class SuperEdgeInfo { * graph, supernode membership mappings, and compression statistics. */ public static class CompressionResult { - private final Graph original; - private final Graph compressed; + private final Graph original; + private final Graph compressed; private final Map> supernodeMembers; private final Map nodeToSupernode; private final String strategy; - CompressionResult(Graph original, - Graph compressed, + CompressionResult(Graph original, + Graph compressed, Map> supernodeMembers, Map nodeToSupernode, String strategy) { @@ -399,7 +399,7 @@ public static class CompressionResult { } /** Returns the compressed quotient graph. */ - public Graph getCompressedGraph() { return compressed; } + public Graph getCompressedGraph() { return compressed; } /** Returns a map from supernode ID to its member node IDs. */ public Map> getSupernodeMembers() { return supernodeMembers; } diff --git a/Gvisual/src/gvisual/GraphDiameterAnalyzer.java b/Gvisual/src/gvisual/GraphDiameterAnalyzer.java index aa28883..65473dd 100644 --- a/Gvisual/src/gvisual/GraphDiameterAnalyzer.java +++ b/Gvisual/src/gvisual/GraphDiameterAnalyzer.java @@ -23,7 +23,7 @@ */ public class GraphDiameterAnalyzer { - private final Graph graph; + private final Graph graph; private Map eccentricities; private int diameter; private int radius; @@ -38,7 +38,7 @@ public class GraphDiameterAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public GraphDiameterAnalyzer(Graph graph) { + public GraphDiameterAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -216,7 +216,7 @@ private Set findLargestComponent() { return GraphUtils.findLargestComponent(graph); } - private String getOtherEnd(edge e, String current) { + private String getOtherEnd(Edge e, String current) { return GraphUtils.getOtherEnd(e, current); } diff --git a/Gvisual/src/gvisual/GraphDiffAnalyzer.java b/Gvisual/src/gvisual/GraphDiffAnalyzer.java index 14314e9..429ef51 100644 --- a/Gvisual/src/gvisual/GraphDiffAnalyzer.java +++ b/Gvisual/src/gvisual/GraphDiffAnalyzer.java @@ -28,8 +28,8 @@ */ public class GraphDiffAnalyzer { - private final Graph graphA; - private final Graph graphB; + private final Graph graphA; + private final Graph graphB; /** * Create a diff analyzer comparing graphA (baseline) to graphB (target). @@ -38,7 +38,7 @@ public class GraphDiffAnalyzer { * @param graphB the target graph to compare against * @throws IllegalArgumentException if either graph is null */ - public GraphDiffAnalyzer(Graph graphA, Graph graphB) { + public GraphDiffAnalyzer(Graph graphA, Graph graphB) { if (graphA == null || graphB == null) { throw new IllegalArgumentException("Both graphs must not be null"); } @@ -182,7 +182,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return edgeKey.hashCode(); + return EdgeKey.hashCode(); } @Override @@ -285,9 +285,9 @@ public int computeEditDistance() { // ── Helpers ───────────────────────────────────────────────── - private Set extractEdges(Graph g) { + private Set extractEdges(Graph g) { Set edges = new HashSet<>(); - for (edge e : g.getEdges()) { + for (Edge e : g.getEdges()) { Collection endpoints = g.getEndpoints(e); if (endpoints != null && endpoints.size() == 2) { Iterator it = endpoints.iterator(); diff --git a/Gvisual/src/gvisual/GraphDiffHtmlExporter.java b/Gvisual/src/gvisual/GraphDiffHtmlExporter.java index 3ac26e5..7b8d062 100644 --- a/Gvisual/src/gvisual/GraphDiffHtmlExporter.java +++ b/Gvisual/src/gvisual/GraphDiffHtmlExporter.java @@ -34,8 +34,8 @@ */ public class GraphDiffHtmlExporter { - private final Graph graphA; - private final Graph graphB; + private final Graph graphA; + private final Graph graphB; private String title = "Graph Diff Visualization"; private String labelA = "Graph A"; private String labelB = "Graph B"; @@ -43,7 +43,7 @@ public class GraphDiffHtmlExporter { private int width = 1200; private int height = 700; - public GraphDiffHtmlExporter(Graph graphA, Graph graphB) { + public GraphDiffHtmlExporter(Graph graphA, Graph graphB) { if (graphA == null || graphB == null) { throw new IllegalArgumentException("Both graphs must not be null"); } diff --git a/Gvisual/src/gvisual/GraphDistanceDistribution.java b/Gvisual/src/gvisual/GraphDistanceDistribution.java index 2c5d875..d897c41 100644 --- a/Gvisual/src/gvisual/GraphDistanceDistribution.java +++ b/Gvisual/src/gvisual/GraphDistanceDistribution.java @@ -28,7 +28,7 @@ */ public class GraphDistanceDistribution { - private final Graph graph; + private final Graph graph; private Map> distanceMatrix; private boolean computed; @@ -38,7 +38,7 @@ public class GraphDistanceDistribution { * @param graph the JUNG graph to analyse * @throws IllegalArgumentException if graph is null */ - public GraphDistanceDistribution(Graph graph) { + public GraphDistanceDistribution(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/GraphEntropyAnalyzer.java b/Gvisual/src/gvisual/GraphEntropyAnalyzer.java index 7104449..441e6ed 100644 --- a/Gvisual/src/gvisual/GraphEntropyAnalyzer.java +++ b/Gvisual/src/gvisual/GraphEntropyAnalyzer.java @@ -53,7 +53,7 @@ public class GraphEntropyAnalyzer { private static final double EPSILON = 1e-12; private static final int JACOBI_MAX_SWEEPS = 100; - private final Graph graph; + private final Graph graph; private boolean computed; // ── Results ───────────────────────────────────────────────────── @@ -68,7 +68,7 @@ public class GraphEntropyAnalyzer { private double avgNeighbourhoodEntropy; private String complexityClass; - public GraphEntropyAnalyzer(Graph graph) { + public GraphEntropyAnalyzer(Graph graph) { this.graph = Objects.requireNonNull(graph, "graph must not be null"); this.computed = false; this.neighbourhoodEntropy = new LinkedHashMap<>(); @@ -251,7 +251,7 @@ private void computeEdgeTypeEntropy() { if (m == 0) { edgeTypeEntropy = 0; return; } Map freq = new HashMap<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String type = e.getType(); if (type == null) type = "unknown"; Integer old = freq.get(type); @@ -479,7 +479,7 @@ private double[][] buildLaplacian() { for (int i = 0; i < n; i++) idx.put(vList.get(i), i); double[][] L = new double[n][n]; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); int i = idx.get(v1); @@ -580,7 +580,7 @@ public String generateReport() { sb.append(String.format(" Max degree entropy: %.4f bits\n", getMaxDegreeEntropy())); sb.append(String.format(" Normalised degree entropy: %.4f\n", getNormalisedDegreeEntropy())); sb.append(String.format(" Von Neumann entropy: %.4f bits\n", vonNeumannEntropy)); - sb.append(String.format(" Edge type entropy: %.4f bits\n", edgeTypeEntropy)); + sb.append(String.format(" Edge type entropy: %.4f bits\n", EdgeTypeEntropy)); sb.append(String.format(" Topological info content: %.4f bits\n", topologicalInfoContent)); sb.append(String.format(" Random walk entropy rate: %.4f bits/step\n", randomWalkEntropyRate)); sb.append(String.format(" Chromatic entropy: %.4f bits\n", chromaticEntropy)); diff --git a/Gvisual/src/gvisual/GraphFileParser.java b/Gvisual/src/gvisual/GraphFileParser.java index 3138641..bc7fe6b 100644 --- a/Gvisual/src/gvisual/GraphFileParser.java +++ b/Gvisual/src/gvisual/GraphFileParser.java @@ -42,13 +42,13 @@ public class GraphFileParser { * lists, and the set of all vertices found. */ public static class ParseResult { - private final Graph graph; - private final Map> edgesByType; + private final Graph graph; + private final Map> edgesByType; private final Set vertices; private final int skippedLines; - ParseResult(Graph graph, - Map> edgesByType, + ParseResult(Graph graph, + Map> edgesByType, Set vertices, int skippedLines) { this.graph = graph; @@ -58,13 +58,13 @@ public static class ParseResult { } /** The parsed JUNG graph (undirected, sparse). */ - public Graph getGraph() { return graph; } + public Graph getGraph() { return graph; } /** Edges grouped by {@link EdgeType}. */ - public Map> getEdgesByType() { return edgesByType; } + public Map> getEdgesByType() { return edgesByType; } /** Convenience accessor for a single edge type's list (never null). */ - public List getEdges(EdgeType type) { + public List getEdges(EdgeType type) { return edgesByType.getOrDefault(type, Collections.emptyList()); } @@ -82,14 +82,14 @@ public List getEdges(EdgeType type) { * @param visibleFilter predicate that returns {@code true} for edge type * codes that should be added to the graph (not just * classified). Pass {@code code -> true} to include all. - * @return parsed result containing graph, edge lists, and vertices + * @return parsed result containing graph, Edge lists, and vertices * @throws IOException if the file cannot be read */ public static ParseResult parse(String filePath, Predicate visibleFilter) throws IOException { - Graph g = new UndirectedSparseGraph<>(); - Map> edgesByType = new EnumMap<>(EdgeType.class); + Graph g = new UndirectedSparseGraph<>(); + Map> edgesByType = new EnumMap<>(EdgeType.class); for (EdgeType t : EdgeType.values()) { edgesByType.put(t, new ArrayList<>()); } @@ -150,13 +150,13 @@ public static ParseResult parse(String filePath, Predicate visibleFilter continue; } - edge curEdge = new edge(parts[0], parts[1], parts[2]); + Edge curEdge = new Edge(parts[0], parts[1], parts[2]); curEdge.setWeight(weight); // Classify by type EdgeType edgeType = EdgeType.fromCode(parts[0]); if (edgeType != null) { - List typeList = edgesByType.get(edgeType); + List typeList = edgesByType.get(edgeType); // Set label on first edge of each type for the legend if (typeList.stream().noneMatch(e -> e.getLabel() != null)) { curEdge.setLabel(edgeType.getDisplayLabel()); diff --git a/Gvisual/src/gvisual/GraphGenerator.java b/Gvisual/src/gvisual/GraphGenerator.java index 8832448..d7552fd 100644 --- a/Gvisual/src/gvisual/GraphGenerator.java +++ b/Gvisual/src/gvisual/GraphGenerator.java @@ -10,7 +10,7 @@ *

    Useful for testing analysis algorithms, benchmarking performance, * exploring graph properties, and creating example networks for * demonstrations. All generated graphs use the same JUNG graph type - * ({@code UndirectedSparseGraph}) as the rest of the + * ({@code UndirectedSparseGraph}) as the rest of the * application.

    * *

    Supported topologies:

    @@ -33,7 +33,7 @@ * * // Create a scale-free network with 100 nodes * GraphGenerator.GeneratedGraph sf = gen.scaleFreeBa(100, 3); - * Graph graph = sf.getGraph(); + * Graph graph = sf.getGraph(); * * // Create a small-world network * GraphGenerator.GeneratedGraph sw = gen.smallWorldWs(50, 4, 0.1); @@ -70,11 +70,11 @@ public GraphGenerator(long seed) { * Holds a generated graph along with metadata about how it was created. */ public static class GeneratedGraph { - private final Graph graph; + private final Graph graph; private final String topology; private final Map parameters; - GeneratedGraph(Graph graph, String topology, + GeneratedGraph(Graph graph, String topology, Map parameters) { this.graph = graph; this.topology = topology; @@ -82,7 +82,7 @@ public static class GeneratedGraph { } /** The generated JUNG graph. */ - public Graph getGraph() { return graph; } + public Graph getGraph() { return graph; } /** Name of the topology used. */ public String getTopology() { return topology; } @@ -144,20 +144,20 @@ private String nodeName(int i) { return "n" + i; } - private edge createEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge createEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setLabel("gen_" + (edgeCounter++)); e.setWeight(1.0f); return e; } - private void addNodes(Graph graph, int n) { + private void addNodes(Graph graph, int n) { for (int i = 0; i < n; i++) { graph.addVertex(nodeName(i)); } } - private void addEdgeIfAbsent(Graph graph, String v1, String v2) { + private void addEdgeIfAbsent(Graph graph, String v1, String v2) { if (v1.equals(v2)) return; if (graph.findEdge(v1, v2) == null) { graph.addEdge(createEdge(v1, v2), v1, v2); @@ -179,7 +179,7 @@ private void addEdgeIfAbsent(Graph graph, String v1, String v2) { */ public GeneratedGraph complete(int n) { if (n < 1) throw new IllegalArgumentException("n must be >= 1"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addNodes(g, n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { @@ -204,7 +204,7 @@ public GeneratedGraph complete(int n) { */ public GeneratedGraph ring(int n) { if (n < 3) throw new IllegalArgumentException("Ring requires n >= 3"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addNodes(g, n); for (int i = 0; i < n; i++) { int next = (i + 1) % n; @@ -228,7 +228,7 @@ public GeneratedGraph ring(int n) { */ public GeneratedGraph star(int n) { if (n < 2) throw new IllegalArgumentException("Star requires n >= 2"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addNodes(g, n); String hub = nodeName(0); for (int i = 1; i < n; i++) { @@ -254,7 +254,7 @@ public GeneratedGraph star(int n) { */ public GeneratedGraph grid(int rows, int cols) { if (rows < 1 || cols < 1) throw new IllegalArgumentException("rows and cols must be >= 1"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); int n = rows * cols; addNodes(g, n); for (int r = 0; r < rows; r++) { @@ -290,7 +290,7 @@ public GeneratedGraph grid(int rows, int cols) { */ public GeneratedGraph path(int n) { if (n < 2) throw new IllegalArgumentException("Path requires n >= 2"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addNodes(g, n); for (int i = 0; i < n - 1; i++) { g.addEdge(createEdge(nodeName(i), nodeName(i + 1)), @@ -317,7 +317,7 @@ public GeneratedGraph path(int n) { public GeneratedGraph tree(int branchingFactor, int depth) { if (branchingFactor < 1) throw new IllegalArgumentException("branchingFactor must be >= 1"); if (depth < 0) throw new IllegalArgumentException("depth must be >= 0"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); int nodeId = 0; g.addVertex(nodeName(nodeId)); @@ -362,7 +362,7 @@ public GeneratedGraph tree(int branchingFactor, int depth) { public GeneratedGraph randomErdosRenyi(int n, double p) { if (n < 1) throw new IllegalArgumentException("n must be >= 1"); if (p < 0.0 || p > 1.0) throw new IllegalArgumentException("p must be in [0, 1]"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addNodes(g, n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { @@ -398,7 +398,7 @@ public GeneratedGraph randomErdosRenyi(int n, double p) { public GeneratedGraph scaleFreeBa(int n, int m) { if (m < 1) throw new IllegalArgumentException("m must be >= 1"); if (n <= m) throw new IllegalArgumentException("n must be > m"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // Start with a complete graph of m+1 nodes for (int i = 0; i <= m; i++) { @@ -471,7 +471,7 @@ public GeneratedGraph smallWorldWs(int n, int k, double beta) { if (k >= n) throw new IllegalArgumentException("k must be < n"); if (beta < 0.0 || beta > 1.0) throw new IllegalArgumentException("beta must be in [0, 1]"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addNodes(g, n); // Create ring lattice @@ -487,7 +487,7 @@ public GeneratedGraph smallWorldWs(int n, int k, double beta) { for (int j = 1; j <= k / 2; j++) { if (random.nextDouble() < beta) { int oldNeighbor = (i + j) % n; - edge existing = g.findEdge(nodeName(i), nodeName(oldNeighbor)); + Edge existing = g.findEdge(nodeName(i), nodeName(oldNeighbor)); if (existing == null) continue; // Find a new target (not self, not already connected) @@ -535,7 +535,7 @@ public GeneratedGraph bipartite(int groupASize, int groupBSize, double p) { if (p < 0.0 || p > 1.0) throw new IllegalArgumentException("p must be in [0, 1]"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); int total = groupASize + groupBSize; addNodes(g, total); diff --git a/Gvisual/src/gvisual/GraphIsomorphismAnalyzer.java b/Gvisual/src/gvisual/GraphIsomorphismAnalyzer.java index 9e40fbb..09849bf 100644 --- a/Gvisual/src/gvisual/GraphIsomorphismAnalyzer.java +++ b/Gvisual/src/gvisual/GraphIsomorphismAnalyzer.java @@ -14,7 +14,7 @@ * *

    Uses a multi-stage approach:

    *
      - *
    1. Fast rejection: vertex count, edge count, degree sequence
    2. + *
    3. Fast rejection: vertex count, Edge count, degree sequence
    4. *
    5. Degree-based partitioning: vertices grouped by degree
    6. *
    7. Backtracking search: VF2-style matching with feasibility pruning
    8. *
    @@ -26,8 +26,8 @@ */ public class GraphIsomorphismAnalyzer { - private final Graph graph1; - private final Graph graph2; + private final Graph graph1; + private final Graph graph2; /** * Create a new isomorphism analyzer for two graphs. @@ -36,8 +36,8 @@ public class GraphIsomorphismAnalyzer { * @param graph2 the second graph (must not be null) * @throws IllegalArgumentException if either graph is null */ - public GraphIsomorphismAnalyzer(Graph graph1, - Graph graph2) { + public GraphIsomorphismAnalyzer(Graph graph1, + Graph graph2) { if (graph1 == null || graph2 == null) { throw new IllegalArgumentException("Both graphs must not be null"); } @@ -193,7 +193,7 @@ public boolean areIsomorphic() { /** * Compute the sorted degree sequence of a graph. */ - private List getSortedDegreeSequence(Graph g, + private List getSortedDegreeSequence(Graph g, List vertices) { List degrees = new ArrayList(vertices.size()); for (String v : vertices) { @@ -209,7 +209,7 @@ private List getSortedDegreeSequence(Graph g, /** * Group vertices by their degree. */ - private Map> groupByDegree(Graph g, + private Map> groupByDegree(Graph g, List vertices) { Map> groups = new HashMap>(); diff --git a/Gvisual/src/gvisual/GraphLayoutComparer.java b/Gvisual/src/gvisual/GraphLayoutComparer.java index 243caaf..f6c4cc5 100644 --- a/Gvisual/src/gvisual/GraphLayoutComparer.java +++ b/Gvisual/src/gvisual/GraphLayoutComparer.java @@ -36,10 +36,10 @@ */ public class GraphLayoutComparer { - private final Graph graph; + private final Graph graph; private String title = "Graph Layout Comparison"; - public GraphLayoutComparer(Graph graph) { + public GraphLayoutComparer(Graph graph) { this.graph = Objects.requireNonNull(graph, "graph must not be null"); } @@ -63,7 +63,7 @@ public void export(File file) throws IOException { public String exportToString() { StringBuilder sb = new StringBuilder(16384); Collection vertices = graph.getVertices(); - Collection edges = graph.getEdges(); + Collection edges = graph.getEdges(); // Build JSON data StringBuilder nodeJson = new StringBuilder("["); @@ -81,7 +81,7 @@ public String exportToString() { StringBuilder linkJson = new StringBuilder("["); boolean first = true; - for (edge e : edges) { + for (Edge e : edges) { String v1 = e.getVertex1() != null ? e.getVertex1() : graph.getEndpoints(e).getFirst().toString(); String v2 = e.getVertex2() != null ? e.getVertex2() : diff --git a/Gvisual/src/gvisual/GraphMLExporter.java b/Gvisual/src/gvisual/GraphMLExporter.java index be986df..431dc00 100644 --- a/Gvisual/src/gvisual/GraphMLExporter.java +++ b/Gvisual/src/gvisual/GraphMLExporter.java @@ -15,7 +15,7 @@ *
      *
    • All vertices with their node IDs
    • *
    • All edges with type, weight, label, and endpoint metadata
    • - *
    • Graph metadata (timestamp, node count, edge count)
    • + *
    • Graph metadata (timestamp, node count, Edge count)
    • *
    • GraphML key definitions for custom attributes
    • *
    * @@ -32,8 +32,8 @@ */ public class GraphMLExporter { - private final Graph graph; - private final List allEdges; + private final Graph graph; + private final List allEdges; private String timestamp; private String description; @@ -43,12 +43,12 @@ public class GraphMLExporter { * @param graph the JUNG graph to export * @param allEdges all edges (including those not currently visible in graph) */ - public GraphMLExporter(Graph graph, List allEdges) { + public GraphMLExporter(Graph graph, List allEdges) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } this.graph = graph; - this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); + this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); this.timestamp = ""; this.description = ""; } @@ -109,9 +109,9 @@ public void export(File file) throws IOException { * @return the complete GraphML XML as a string */ public String exportToString() { - List edgesToExport = !allEdges.isEmpty() + List edgesToExport = !allEdges.isEmpty() ? allEdges - : new ArrayList(graph.getEdges()); + : new ArrayList(graph.getEdges()); return exportToString(edgesToExport); } @@ -121,7 +121,7 @@ public String exportToString() { * @return GraphML XML string with only visible edges */ public String exportVisibleToString() { - return exportToString(new ArrayList(graph.getEdges())); + return exportToString(new ArrayList(graph.getEdges())); } /** @@ -130,7 +130,7 @@ public String exportVisibleToString() { * @param edgesToExport the edges to include in the export * @return the complete GraphML XML as a string */ - private String exportToString(List edgesToExport) { + private String exportToString(List edgesToExport) { StringBuilder sb = new StringBuilder(); // XML header @@ -145,13 +145,13 @@ private String exportToString(List edgesToExport) { sb.append(" \n"); sb.append(" \n"); - sb.append(" \n"); - sb.append(" \n"); - sb.append(" \n"); - sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); + sb.append(" \n"); // Graph element - sb.append(" \n"); + sb.append(" \n"); // Graph metadata as desc element if (!timestamp.isEmpty() || !description.isEmpty()) { @@ -179,9 +179,9 @@ private String exportToString(List edgesToExport) { // Edges — use the provided edgesToExport list int edgeIndex = 0; - for (edge e : edgesToExport) { + for (Edge e : edgesToExport) { String edgeId = "e" + edgeIndex++; - sb.append(" \n"); @@ -199,7 +199,7 @@ private String exportToString(List edgesToExport) { sb.append(" ").append(escapeXml(e.getLabel())).append("\n"); } - sb.append(" \n"); + sb.append(" \n"); } sb.append(" \n"); diff --git a/Gvisual/src/gvisual/GraphMerger.java b/Gvisual/src/gvisual/GraphMerger.java index 68ce656..f635bd4 100644 --- a/Gvisual/src/gvisual/GraphMerger.java +++ b/Gvisual/src/gvisual/GraphMerger.java @@ -76,7 +76,7 @@ public enum EdgeConflict { * Result of a merge operation, including the merged graph and statistics. */ public static final class MergeResult { - private final Graph mergedGraph; + private final Graph mergedGraph; private final Strategy strategy; private final EdgeConflict edgeConflict; private final int vertexCountA; @@ -90,7 +90,7 @@ public static final class MergeResult { private final Set onlyInA; private final Set onlyInB; - MergeResult(Graph mergedGraph, Strategy strategy, + MergeResult(Graph mergedGraph, Strategy strategy, EdgeConflict edgeConflict, int vertexCountA, int vertexCountB, int edgeCountA, int edgeCountB, @@ -112,7 +112,7 @@ public static final class MergeResult { this.onlyInB = Collections.unmodifiableSet(onlyInB); } - public Graph getMergedGraph() { return mergedGraph; } + public Graph getMergedGraph() { return mergedGraph; } public Strategy getStrategy() { return strategy; } public EdgeConflict getEdgeConflict() { return edgeConflict; } public int getVertexCountA() { return vertexCountA; } @@ -155,7 +155,7 @@ public String getSummary() { /** * Merge two graphs with default settings (UNION + KEEP_LEFT). */ - public static MergeResult merge(Graph a, Graph b) { + public static MergeResult merge(Graph a, Graph b) { return merge(a, b, Strategy.UNION, EdgeConflict.KEEP_LEFT); } @@ -169,7 +169,7 @@ public static MergeResult merge(Graph a, Graph b) { * @return merge result with the combined graph and statistics * @throws IllegalArgumentException if any argument is null */ - public static MergeResult merge(Graph a, Graph b, + public static MergeResult merge(Graph a, Graph b, Strategy strategy, EdgeConflict edgeConflict) { if (a == null || b == null) throw new IllegalArgumentException("Graphs must not be null"); if (strategy == null) throw new IllegalArgumentException("Strategy must not be null"); @@ -187,7 +187,7 @@ public static MergeResult merge(Graph a, Graph b, Set onlyB = new HashSet<>(vertsB); onlyB.removeAll(vertsA); - Graph merged = new UndirectedSparseGraph<>(); + Graph merged = new UndirectedSparseGraph<>(); int[] conflicts = {0}; switch (strategy) { @@ -216,14 +216,14 @@ public static MergeResult merge(Graph a, Graph b, // ── Strategy Implementations ─────────────────────────────────── - private static void mergeUnion(Graph a, Graph b, - Graph result, + private static void mergeUnion(Graph a, Graph b, + Graph result, EdgeConflict conflict, int[] conflicts) { - Map edgeIndex = new HashMap<>(); + Map edgeIndex = new HashMap<>(); // Add all from A for (String v : a.getVertices()) result.addVertex(v); - for (edge e : a.getEdges()) { + for (Edge e : a.getEdges()) { String key = edgeKey(e); result.addEdge(cloneEdge(e), e.getVertex1(), e.getVertex2()); edgeIndex.put(key, findEdge(result, e.getVertex1(), e.getVertex2())); @@ -235,11 +235,11 @@ private static void mergeUnion(Graph a, Graph b, } // Add/merge edges from B - for (edge e : b.getEdges()) { + for (Edge e : b.getEdges()) { String key = edgeKey(e); if (edgeIndex.containsKey(key)) { // Conflict — resolve weight - edge existing = edgeIndex.get(key); + Edge existing = edgeIndex.get(key); existing.setWeight(resolveWeight(existing.getWeight(), e.getWeight(), conflict)); conflicts[0]++; } else { @@ -248,27 +248,27 @@ private static void mergeUnion(Graph a, Graph b, } } - private static void mergeIntersection(Graph a, Graph b, - Graph result, + private static void mergeIntersection(Graph a, Graph b, + Graph result, Set shared, EdgeConflict conflict, int[] conflicts) { // Add only shared vertices for (String v : shared) result.addVertex(v); // Build edge index for B - Map bEdges = new HashMap<>(); - for (edge e : b.getEdges()) { + Map bEdges = new HashMap<>(); + for (Edge e : b.getEdges()) { bEdges.put(edgeKey(e), e); } // Add edges present in both graphs (between shared vertices) - for (edge e : a.getEdges()) { + for (Edge e : a.getEdges()) { if (!shared.contains(e.getVertex1()) || !shared.contains(e.getVertex2())) continue; String key = edgeKey(e); - edge bEdge = bEdges.get(key); + Edge bEdge = bEdges.get(key); if (bEdge != null) { - edge merged = cloneEdge(e); + Edge merged = cloneEdge(e); merged.setWeight(resolveWeight(e.getWeight(), bEdge.getWeight(), conflict)); result.addEdge(merged, e.getVertex1(), e.getVertex2()); if (e.getWeight() != bEdge.getWeight()) conflicts[0]++; @@ -276,21 +276,21 @@ private static void mergeIntersection(Graph a, Graph } } - private static void mergeSymmetricDifference(Graph a, Graph b, - Graph result, + private static void mergeSymmetricDifference(Graph a, Graph b, + Graph result, Set shared) { // Build edge sets Set aEdgeKeys = new HashSet<>(); - for (edge e : a.getEdges()) aEdgeKeys.add(edgeKey(e)); + for (Edge e : a.getEdges()) aEdgeKeys.add(edgeKey(e)); Set bEdgeKeys = new HashSet<>(); - for (edge e : b.getEdges()) bEdgeKeys.add(edgeKey(e)); + for (Edge e : b.getEdges()) bEdgeKeys.add(edgeKey(e)); // Add vertices that appear in edges unique to one graph Set addedVerts = new HashSet<>(); // Edges only in A - for (edge e : a.getEdges()) { + for (Edge e : a.getEdges()) { if (!bEdgeKeys.contains(edgeKey(e))) { ensureVertex(result, e.getVertex1(), addedVerts); ensureVertex(result, e.getVertex2(), addedVerts); @@ -299,7 +299,7 @@ private static void mergeSymmetricDifference(Graph a, Graph a, Graph primary, Graph secondary, - Graph result, + private static void mergeLeftJoin(Graph primary, Graph secondary, + Graph result, EdgeConflict conflict, int[] conflicts) { // Add all vertices and edges from primary for (String v : primary.getVertices()) result.addVertex(v); - Map edgeIndex = new HashMap<>(); - for (edge e : primary.getEdges()) { + Map edgeIndex = new HashMap<>(); + for (Edge e : primary.getEdges()) { result.addEdge(cloneEdge(e), e.getVertex1(), e.getVertex2()); edgeIndex.put(edgeKey(e), findEdge(result, e.getVertex1(), e.getVertex2())); } // Add edges from secondary that connect primary's vertices Set primaryVerts = new HashSet<>(primary.getVertices()); - for (edge e : secondary.getEdges()) { + for (Edge e : secondary.getEdges()) { if (!primaryVerts.contains(e.getVertex1()) || !primaryVerts.contains(e.getVertex2())) { continue; } String key = edgeKey(e); if (edgeIndex.containsKey(key)) { - edge existing = edgeIndex.get(key); + Edge existing = edgeIndex.get(key); existing.setWeight(resolveWeight(existing.getWeight(), e.getWeight(), conflict)); conflicts[0]++; } else { @@ -348,21 +348,21 @@ private static void mergeLeftJoin(Graph primary, Graph g, String v1, String v2) { - edge e = g.findEdge(v1, v2); + private static Edge findEdge(Graph g, String v1, String v2) { + Edge e = g.findEdge(v1, v2); return e != null ? e : g.findEdge(v2, v1); } /** Clone an edge (deep copy). */ - private static edge cloneEdge(edge e) { - edge clone = new edge(e.getType(), e.getVertex1(), e.getVertex2()); + private static Edge cloneEdge(Edge e) { + Edge clone = new Edge(e.getType(), e.getVertex1(), e.getVertex2()); clone.setWeight(e.getWeight()); clone.setLabel(e.getLabel()); clone.setTimestamp(e.getTimestamp()); @@ -371,7 +371,7 @@ private static edge cloneEdge(edge e) { } /** Add vertex to graph if not already present. */ - private static void ensureVertex(Graph g, String v, Set tracker) { + private static void ensureVertex(Graph g, String v, Set tracker) { if (!tracker.contains(v)) { if (!g.containsVertex(v)) g.addVertex(v); tracker.add(v); diff --git a/Gvisual/src/gvisual/GraphMinorAnalyzer.java b/Gvisual/src/gvisual/GraphMinorAnalyzer.java index e1ffccc..417e38c 100644 --- a/Gvisual/src/gvisual/GraphMinorAnalyzer.java +++ b/Gvisual/src/gvisual/GraphMinorAnalyzer.java @@ -29,9 +29,9 @@ */ public class GraphMinorAnalyzer { - private final Graph graph; + private final Graph graph; - public GraphMinorAnalyzer(Graph graph) { + public GraphMinorAnalyzer(Graph graph) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); this.graph = graph; } @@ -41,14 +41,14 @@ public GraphMinorAnalyzer(Graph graph) { /** * Creates a deep copy of a graph. */ - public static Graph copyGraph(Graph g) { - Graph copy = new UndirectedSparseGraph<>(); + public static Graph copyGraph(Graph g) { + Graph copy = new UndirectedSparseGraph<>(); for (String v : g.getVertices()) copy.addVertex(v); - for (edge e : g.getEdges()) { + for (Edge e : g.getEdges()) { Collection endpoints = g.getEndpoints(e); Iterator it = endpoints.iterator(); String v1 = it.next(), v2 = it.next(); - copy.addEdge(new edge(e.getType(), v1, v2), v1, v2); + copy.addEdge(new Edge(e.getType(), v1, v2), v1, v2); } return copy; } @@ -58,10 +58,10 @@ public static Graph copyGraph(Graph g) { /** * Returns a new graph with the given vertex removed. */ - public Graph deleteVertex(String vertex) { + public Graph deleteVertex(String vertex) { if (!graph.containsVertex(vertex)) throw new IllegalArgumentException("Vertex not found: " + vertex); - Graph result = copyGraph(graph); + Graph result = copyGraph(graph); result.removeVertex(vertex); return result; } @@ -69,8 +69,8 @@ public Graph deleteVertex(String vertex) { /** * Returns a new graph with the given vertices removed. */ - public Graph deleteVertices(Collection vertices) { - Graph result = copyGraph(graph); + public Graph deleteVertices(Collection vertices) { + Graph result = copyGraph(graph); for (String v : vertices) result.removeVertex(v); return result; } @@ -80,9 +80,9 @@ public Graph deleteVertices(Collection vertices) { /** * Returns a new graph with the edge between v1 and v2 removed. */ - public Graph deleteEdge(String v1, String v2) { - Graph result = copyGraph(graph); - edge e = result.findEdge(v1, v2); + public Graph deleteEdge(String v1, String v2) { + Graph result = copyGraph(graph); + Edge e = result.findEdge(v1, v2); if (e == null) throw new IllegalArgumentException("No edge between " + v1 + " and " + v2); result.removeEdge(e); return result; @@ -94,10 +94,10 @@ public Graph deleteEdge(String v1, String v2) { * Contracts the edge between v1 and v2, merging v2 into v1. * Returns a new graph. The merged vertex keeps v1's name. */ - public static Graph contractEdge(Graph g, String v1, String v2) { + public static Graph contractEdge(Graph g, String v1, String v2) { if (g.findEdge(v1, v2) == null) throw new IllegalArgumentException("No edge between " + v1 + " and " + v2); - Graph result = copyGraph(g); + Graph result = copyGraph(g); // Get v2's neighbors (excluding v1) Collection v2Neighbors = new ArrayList<>(result.getNeighbors(v2)); v2Neighbors.remove(v1); @@ -105,7 +105,7 @@ public static Graph contractEdge(Graph g, String v1, int eid = result.getEdgeCount(); for (String n : v2Neighbors) { if (result.findEdge(v1, n) == null) { - result.addEdge(new edge("contracted_" + eid++, v1, n), v1, n); + result.addEdge(new Edge("contracted_" + eid++, v1, n), v1, n); } } result.removeVertex(v2); @@ -115,7 +115,7 @@ public static Graph contractEdge(Graph g, String v1, /** * Contracts the edge between v1 and v2 on the instance graph. */ - public Graph contractEdge(String v1, String v2) { + public Graph contractEdge(String v1, String v2) { return contractEdge(graph, v1, v2); } @@ -152,15 +152,15 @@ public String toString() { /** * Applies a sequence of minor operations starting from the instance graph. */ - public Graph applySequence(List ops) { - Graph g = copyGraph(graph); + public Graph applySequence(List ops) { + Graph g = copyGraph(graph); for (MinorOp op : ops) { switch (op.type) { case DELETE_VERTEX: g.removeVertex(op.v1); break; case DELETE_EDGE: - edge de = g.findEdge(op.v1, op.v2); + Edge de = g.findEdge(op.v1, op.v2); if (de != null) g.removeEdge(de); break; case CONTRACT_EDGE: @@ -185,7 +185,7 @@ public int hadwigerNumber() { if (graph.getEdgeCount() == 0) return 1; // Build adjacency - Graph g = copyGraph(graph); + Graph g = copyGraph(graph); int best = 1; // Greedy: find largest complete minor by contracting edges @@ -203,7 +203,7 @@ public int hadwigerNumber() { // Find best edge to contract: endpoints sharing most neighbors String bestV1 = null, bestV2 = null; int bestScore = -1; - for (edge e : g.getEdges()) { + for (Edge e : g.getEdges()) { Collection ep = g.getEndpoints(e); Iterator it = ep.iterator(); String a = it.next(), b = it.next(); @@ -224,7 +224,7 @@ public int hadwigerNumber() { return best; } - private int findLargestClique(Graph g) { + private int findLargestClique(Graph g) { // Simple greedy clique finder List vertices = new ArrayList<>(g.getVertices()); vertices.sort((a, b) -> Integer.compare(g.degree(b), g.degree(a))); @@ -270,7 +270,7 @@ public boolean hasK33Minor() { if (graph.getEdgeCount() < 9) return false; // Try contracting graph down and checking for K33 - Graph g = copyGraph(graph); + Graph g = copyGraph(graph); // Remove degree-1 vertices iteratively (they can't help with K33) boolean changed = true; @@ -296,7 +296,7 @@ public boolean hasK33Minor() { return findK33Contraction(g); } - private boolean findK33Brute(Graph g, List verts) { + private boolean findK33Brute(Graph g, List verts) { int n = verts.size(); // Try all combinations of 3+3 for (int i = 0; i < n - 5; i++) @@ -312,19 +312,19 @@ private boolean findK33Brute(Graph g, List verts) { return false; } - private boolean isCompleteBipartite(Graph g, String[] left, String[] right) { + private boolean isCompleteBipartite(Graph g, String[] left, String[] right) { for (String l : left) for (String r : right) if (g.findEdge(l, r) == null) return false; return true; } - private boolean findK33Contraction(Graph g) { + private boolean findK33Contraction(Graph g) { // Contract high-degree edges and check smaller graph while (g.getVertexCount() > 15 && g.getEdgeCount() > 0) { - edge e = null; + Edge e = null; int bestDeg = -1; - for (edge candidate : g.getEdges()) { + for (Edge candidate : g.getEdges()) { Collection ep = g.getEndpoints(candidate); Iterator it = ep.iterator(); String a = it.next(), b = it.next(); @@ -412,14 +412,14 @@ public int contractionDegeneracy() { * Subdivides an edge: replaces edge (v1,v2) with v1-new-v2. * Returns a new graph with the subdivision vertex added. */ - public Graph subdivideEdge(String v1, String v2, String newVertex) { - Graph result = copyGraph(graph); - edge e = result.findEdge(v1, v2); + public Graph subdivideEdge(String v1, String v2, String newVertex) { + Graph result = copyGraph(graph); + Edge e = result.findEdge(v1, v2); if (e == null) throw new IllegalArgumentException("No edge between " + v1 + " and " + v2); result.removeEdge(e); result.addVertex(newVertex); - result.addEdge(new edge("sub_a", v1, newVertex), v1, newVertex); - result.addEdge(new edge("sub_b", newVertex, v2), newVertex, v2); + result.addEdge(new Edge("sub_a", v1, newVertex), v1, newVertex); + result.addEdge(new Edge("sub_b", newVertex, v2), newVertex, v2); return result; } diff --git a/Gvisual/src/gvisual/GraphNeighborhoodAnalyzer.java b/Gvisual/src/gvisual/GraphNeighborhoodAnalyzer.java index ed5dfb1..bf43894 100644 --- a/Gvisual/src/gvisual/GraphNeighborhoodAnalyzer.java +++ b/Gvisual/src/gvisual/GraphNeighborhoodAnalyzer.java @@ -35,7 +35,7 @@ */ public class GraphNeighborhoodAnalyzer { - private final Graph graph; + private final Graph graph; /** * Constructs an analyser for the given graph. @@ -43,7 +43,7 @@ public class GraphNeighborhoodAnalyzer { * @param graph the graph to analyse (must not be null) * @throws IllegalArgumentException if graph is null */ - public GraphNeighborhoodAnalyzer(Graph graph) { + public GraphNeighborhoodAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -204,7 +204,7 @@ public double getLocalDensity(String source, int k) { } int edgeCount = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String src = graph.getEndpoints(e).getFirst(); String dst = graph.getEndpoints(e).getSecond(); if (neighborhood.contains(src) && neighborhood.contains(dst)) { @@ -213,7 +213,7 @@ public double getLocalDensity(String source, int k) { } double maxEdges = (double) n * (n - 1) / 2.0; - return edgeCount / maxEdges; + return EdgeCount / maxEdges; } // ------------------------------------------------------------------ diff --git a/Gvisual/src/gvisual/GraphNetworkProfiler.java b/Gvisual/src/gvisual/GraphNetworkProfiler.java index 6d71a91..4a55c3c 100644 --- a/Gvisual/src/gvisual/GraphNetworkProfiler.java +++ b/Gvisual/src/gvisual/GraphNetworkProfiler.java @@ -130,7 +130,7 @@ public MetricResult(String name, String category, double value, public String getInterpretation() { return interpretation; } } - private final Graph graph; + private final Graph graph; private final Random random; private boolean analyzed; @@ -155,11 +155,11 @@ public MetricResult(String name, String category, double value, private static final int SAMPLE_SIZE = 50; - public GraphNetworkProfiler(Graph graph) { + public GraphNetworkProfiler(Graph graph) { this(graph, new Random(42)); } - public GraphNetworkProfiler(Graph graph, Random random) { + public GraphNetworkProfiler(Graph graph, Random random) { this.graph = Objects.requireNonNull(graph, "graph must not be null"); this.random = random; this.analyzed = false; @@ -253,7 +253,7 @@ private void computeAssortativity() { if (graph.getEdgeCount() == 0) { assortativity = 0; return; } double sumProd = 0, sumI = 0, sumJ = 0, sumISq = 0, sumJSq = 0; int m = graph.getEdgeCount(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); int di = graph.degree(v1); diff --git a/Gvisual/src/gvisual/GraphPartitioner.java b/Gvisual/src/gvisual/GraphPartitioner.java index b3753bb..dff9cbf 100644 --- a/Gvisual/src/gvisual/GraphPartitioner.java +++ b/Gvisual/src/gvisual/GraphPartitioner.java @@ -16,7 +16,7 @@ * of the Laplacian) to find a natural split, refined with KL swaps. * * - *

    Produces a {@link PartitionResult} with per-partition membership, edge cut count, + *

    Produces a {@link PartitionResult} with per-partition membership, Edge cut count, * imbalance ratio, cut ratio, and partition-level metrics (size, internal/external edges, * conductance).

    * @@ -42,7 +42,7 @@ public enum Strategy { SPECTRAL } - private final Graph graph; + private final Graph graph; /** * Creates a new GraphPartitioner for the given graph. @@ -50,7 +50,7 @@ public enum Strategy { * @param graph the JUNG graph to partition * @throws IllegalArgumentException if graph is null */ - public GraphPartitioner(Graph graph) { + public GraphPartitioner(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -606,7 +606,7 @@ public static class PartitionResult { private final double cutRatio; private final List partitions; - PartitionResult(Map assignment, int k, Graph graph) { + PartitionResult(Map assignment, int k, Graph graph) { this.assignment = Collections.unmodifiableMap(new HashMap<>(assignment)); this.k = k; @@ -624,7 +624,7 @@ public static class PartitionResult { Map internalEdges = new HashMap<>(); Map externalEdges = new HashMap<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); if (endpoints.size() < 2) continue; Iterator it = endpoints.iterator(); diff --git a/Gvisual/src/gvisual/GraphPathExplorer.java b/Gvisual/src/gvisual/GraphPathExplorer.java index ced2b6a..c2cb61c 100644 --- a/Gvisual/src/gvisual/GraphPathExplorer.java +++ b/Gvisual/src/gvisual/GraphPathExplorer.java @@ -39,7 +39,7 @@ public class GraphPathExplorer { /** Default maximum number of paths to return. */ private static final int DEFAULT_MAX_PATHS = 1000; - private final Graph graph; + private final Graph graph; private final Map> adjacency; private final Map> weightMap; @@ -51,7 +51,7 @@ public class GraphPathExplorer { * @param graph the JUNG graph to explore * @throws IllegalArgumentException if graph is null or empty */ - public GraphPathExplorer(Graph graph) { + public GraphPathExplorer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -65,7 +65,7 @@ public GraphPathExplorer(Graph graph) { private Map> buildWeightMap() { Map> wm = new HashMap<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); float w = e.getWeight() > 0 ? e.getWeight() : 1.0f; @@ -333,7 +333,7 @@ public Path findConstrainedPath(String source, String target, * @param source start vertex * @param target end vertex * @param avoidNodes vertices to skip (may be null or empty) - * @param avoidEdgePairs edges to skip as "v1|v2" strings (may be null) + * @param avoidEdgePairs Edges to skip as "v1|v2" strings (may be null) * @return shortest path avoiding the constraints, or null if none exists * @throws IllegalArgumentException if source or target not in graph */ diff --git a/Gvisual/src/gvisual/GraphPathExplorerTest.java b/Gvisual/src/gvisual/GraphPathExplorerTest.java index bbdbbd4..e78b744 100644 --- a/Gvisual/src/gvisual/GraphPathExplorerTest.java +++ b/Gvisual/src/gvisual/GraphPathExplorerTest.java @@ -21,8 +21,8 @@ public class GraphPathExplorerTest { /** * Linear: A - B - C - D - E */ - private static Graph linearGraph() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph linearGraph() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addVertex("E"); addEdge(g, "A", "B", 1); addEdge(g, "B", "C", 1); @@ -37,8 +37,8 @@ private static Graph linearGraph() { * \ / * D */ - private static Graph diamondGraph() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph diamondGraph() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); addEdge(g, "A", "B", 1); addEdge(g, "A", "C", 1); @@ -54,8 +54,8 @@ private static Graph diamondGraph() { * | | | * G - H - I */ - private static Graph gridGraph() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph gridGraph() { + Graph g = new UndirectedSparseGraph<>(); String[] nodes = {"A","B","C","D","E","F","G","H","I"}; for (String n : nodes) g.addVertex(n); // Horizontal @@ -76,8 +76,8 @@ private static Graph gridGraph() { * | | * D -1- E */ - private static Graph weightedGraph() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph weightedGraph() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addVertex("E"); addEdge(g, "A", "B", 1); addEdge(g, "B", "C", 2); @@ -89,8 +89,8 @@ private static Graph weightedGraph() { /** * Disconnected: A - B - C D - E */ - private static Graph disconnectedGraph() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph disconnectedGraph() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addVertex("E"); addEdge(g, "A", "B", 1); addEdge(g, "B", "C", 1); @@ -101,8 +101,8 @@ private static Graph disconnectedGraph() { /** * Complete K4: A, B, C, D — all connected */ - private static Graph completeK4() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph completeK4() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); addEdge(g, "A", "B", 1); addEdge(g, "A", "C", 1); @@ -117,8 +117,8 @@ private static Graph completeK4() { * E - F - X (same X) * X is the only path between {A,B} and {C,D,E,F} */ - private static Graph bottleneckGraph() { - Graph g = new UndirectedSparseGraph<>(); + private static Graph bottleneckGraph() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("X"); g.addVertex("C"); g.addVertex("D"); addEdge(g, "A", "B", 1); addEdge(g, "B", "X", 1); @@ -127,8 +127,8 @@ private static Graph bottleneckGraph() { } private static int edgeCounter = 0; - private static void addEdge(Graph g, String v1, String v2, float w) { - edge e = new edge("e", v1, v2); + private static void addEdge(Graph g, String v1, String v2, float w) { + Edge e = new Edge("e", v1, v2); e.setWeight(w); e.setLabel("e" + (edgeCounter++)); g.addEdge(e, v1, v2); @@ -192,7 +192,7 @@ private static void testConstructor() { checkThrows("empty graph", () -> new GraphPathExplorer(new UndirectedSparseGraph<>()), IllegalArgumentException.class); - Graph g = linearGraph(); + Graph g = linearGraph(); GraphPathExplorer ex = new GraphPathExplorer(g); check("valid construction", ex != null); } @@ -345,7 +345,7 @@ private static void testAvoidanceRouting() { avoidEdges.add(GraphPathExplorer.edgeKey("A", "B")); p = dia.findPathAvoiding("A", "D", null, avoidEdges); check("diamond: avoid A-B edge exists", p != null); - check("diamond: goes through C (edge avoided)", + check("diamond: goes through C (Edge avoided)", p.getVertices().contains("C")); // Avoid source returns null diff --git a/Gvisual/src/gvisual/GraphProductCalculator.java b/Gvisual/src/gvisual/GraphProductCalculator.java index 8c0c6f9..67fa133 100644 --- a/Gvisual/src/gvisual/GraphProductCalculator.java +++ b/Gvisual/src/gvisual/GraphProductCalculator.java @@ -25,10 +25,10 @@ *

    Usage:

    *
    {@code
      * GraphProductCalculator calc = new GraphProductCalculator(graphG, graphH);
    - * Graph cartesian = calc.cartesianProduct();
    - * Graph tensor = calc.tensorProduct();
    - * Graph strong = calc.strongProduct();
    - * Graph lex = calc.lexicographicProduct();
    + * Graph cartesian = calc.cartesianProduct();
    + * Graph tensor = calc.tensorProduct();
    + * Graph strong = calc.strongProduct();
    + * Graph lex = calc.lexicographicProduct();
      *
      * // Product metadata
      * ProductInfo info = calc.getProductInfo(ProductType.CARTESIAN);
    @@ -95,11 +95,11 @@ public String toString() {
             }
         }
     
    -    private final Graph graphG;
    -    private final Graph graphH;
    +    private final Graph graphG;
    +    private final Graph graphH;
         private final List verticesG;
         private final List verticesH;
    -    private final Map> cache;
    +    private final Map> cache;
         private final Map infoCache;
     
         /**
    @@ -109,7 +109,7 @@ public String toString() {
          * @param graphH the second graph (H)
          * @throws IllegalArgumentException if either graph is null
          */
    -    public GraphProductCalculator(Graph graphG, Graph graphH) {
    +    public GraphProductCalculator(Graph graphG, Graph graphH) {
             if (graphG == null || graphH == null) {
                 throw new IllegalArgumentException("Both graphs must be non-null");
             }
    @@ -117,7 +117,7 @@ public GraphProductCalculator(Graph graphG, Graph gr
             this.graphH = graphH;
             this.verticesG = new ArrayList(graphG.getVertices());
             this.verticesH = new ArrayList(graphH.getVertices());
    -        this.cache = new EnumMap>(ProductType.class);
    +        this.cache = new EnumMap>(ProductType.class);
             this.infoCache = new EnumMap(ProductType.class);
         }
     
    @@ -131,7 +131,7 @@ private String productVertex(String u, String v) {
         /**
          * Checks if two vertices are adjacent in the given graph.
          */
    -    private boolean areAdjacent(Graph g, String v1, String v2) {
    +    private boolean areAdjacent(Graph g, String v1, String v2) {
             return g.findEdge(v1, v2) != null;
         }
     
    @@ -140,8 +140,8 @@ private boolean areAdjacent(Graph g, String v1, String v2) {
         /**
          * Creates a fresh product edge.
          */
    -    private edge newProductEdge(String u1, String v1, String u2, String v2) {
    -        edge e = new edge("product",
    +    private Edge newProductEdge(String u1, String v1, String u2, String v2) {
    +        Edge e = new Edge("product",
                     productVertex(u1, v1),
                     productVertex(u2, v2));
             e.setLabel("e" + (edgeCounter++));
    @@ -155,12 +155,12 @@ private edge newProductEdge(String u1, String v1, String u2, String v2) {
          *
          * @return the Cartesian product graph
          */
    -    public Graph cartesianProduct() {
    +    public Graph cartesianProduct() {
             if (cache.containsKey(ProductType.CARTESIAN)) {
                 return cache.get(ProductType.CARTESIAN);
             }
             long start = System.currentTimeMillis();
    -        Graph product = new UndirectedSparseGraph();
    +        Graph product = new UndirectedSparseGraph();
     
             // Add all product vertices
             for (String u : verticesG) {
    @@ -213,12 +213,12 @@ public Graph cartesianProduct() {
          *
          * @return the tensor product graph
          */
    -    public Graph tensorProduct() {
    +    public Graph tensorProduct() {
             if (cache.containsKey(ProductType.TENSOR)) {
                 return cache.get(ProductType.TENSOR);
             }
             long start = System.currentTimeMillis();
    -        Graph product = new UndirectedSparseGraph();
    +        Graph product = new UndirectedSparseGraph();
     
             for (String u : verticesG) {
                 for (String v : verticesH) {
    @@ -263,12 +263,12 @@ public Graph tensorProduct() {
          *
          * @return the strong product graph
          */
    -    public Graph strongProduct() {
    +    public Graph strongProduct() {
             if (cache.containsKey(ProductType.STRONG)) {
                 return cache.get(ProductType.STRONG);
             }
             long start = System.currentTimeMillis();
    -        Graph product = new UndirectedSparseGraph();
    +        Graph product = new UndirectedSparseGraph();
     
             for (String u : verticesG) {
                 for (String v : verticesH) {
    @@ -318,8 +318,8 @@ public Graph strongProduct() {
                     else if (uAdj && vAdj) connected = true;    // Tensor
     
                     if (connected) {
    -                    edge e = new edge("product", pv1, pv2);
    -                    e.setLabel("e" + (edgeCounter++));
    +                    Edge e = new Edge("product", pv1, pv2);
    +                    e.setLabel("e" + (EdgeCounter++));
                         product.addEdge(e, pv1, pv2);
                     }
                 }
    @@ -341,12 +341,12 @@ public Graph strongProduct() {
          *
          * @return the lexicographic product graph
          */
    -    public Graph lexicographicProduct() {
    +    public Graph lexicographicProduct() {
             if (cache.containsKey(ProductType.LEXICOGRAPHIC)) {
                 return cache.get(ProductType.LEXICOGRAPHIC);
             }
             long start = System.currentTimeMillis();
    -        Graph product = new UndirectedSparseGraph();
    +        Graph product = new UndirectedSparseGraph();
     
             for (String u : verticesG) {
                 for (String v : verticesH) {
    @@ -434,7 +434,7 @@ public String getReport() {
     
             for (ProductType type : ProductType.values()) {
                 ProductInfo info = getProductInfo(type);
    -            sb.append(String.format("%-15s  %5d edges  density=%.4f  (%dms)\n",
    +            sb.append(String.format("%-15s  %5d Edges  density=%.4f  (%dms)\n",
                         type + ":", info.getEdgeCount(), info.getDensity(), info.getComputeTimeMs()));
             }
     
    @@ -462,7 +462,7 @@ public String getReport() {
          * @return sorted degree sequence (descending)
          */
         public List getDegreeSequence(ProductType type) {
    -        Graph product;
    +        Graph product;
             switch (type) {
                 case CARTESIAN: product = cartesianProduct(); break;
                 case TENSOR: product = tensorProduct(); break;
    diff --git a/Gvisual/src/gvisual/GraphQueryEngine.java b/Gvisual/src/gvisual/GraphQueryEngine.java
    index b95c602..ec2ba39 100644
    --- a/Gvisual/src/gvisual/GraphQueryEngine.java
    +++ b/Gvisual/src/gvisual/GraphQueryEngine.java
    @@ -42,9 +42,9 @@
      */
     public class GraphQueryEngine {
     
    -    private final Graph graph;
    +    private final Graph graph;
     
    -    public GraphQueryEngine(Graph graph) {
    +    public GraphQueryEngine(Graph graph) {
             this.graph = Objects.requireNonNull(graph, "graph must not be null");
         }
     
    @@ -104,7 +104,7 @@ public QueryStats stats() {
             }
             if (nodeCount == 0) minDeg = 0;
     
    -        for (edge e : graph.getEdges()) {
    +        for (Edge e : graph.getEdges()) {
                 String t = e.getType() != null ? e.getType() : "unknown";
                 typeCounts.merge(t, 1, Integer::sum);
             }
    @@ -119,10 +119,10 @@ public QueryStats stats() {
          * Chainable builder for filtering graph vertices.
          */
         public static class NodeQuery {
    -        private final Graph graph;
    +        private final Graph graph;
             private final List> filters = new ArrayList<>();
     
    -        NodeQuery(Graph graph) {
    +        NodeQuery(Graph graph) {
                 this.graph = graph;
             }
     
    @@ -172,7 +172,7 @@ public NodeQuery inSet(Set allowed) {
             /** Keep only nodes that have at least one edge of the given type. */
             public NodeQuery connectedByType(String edgeType) {
                 filters.add(v -> {
    -                for (edge e : graph.getIncidentEdges(v)) {
    +                for (Edge e : graph.getIncidentEdges(v)) {
                         if (edgeType.equals(e.getType())) return true;
                     }
                     return false;
    @@ -247,10 +247,10 @@ public String summary() {
          * Chainable builder for filtering graph edges.
          */
         public static class EdgeQuery {
    -        private final Graph graph;
    -        private final List> filters = new ArrayList<>();
    +        private final Graph graph;
    +        private final List> filters = new ArrayList<>();
     
    -        EdgeQuery(Graph graph) {
    +        EdgeQuery(Graph graph) {
                 this.graph = graph;
             }
     
    @@ -272,7 +272,7 @@ public EdgeQuery withMaxWeight(float max) {
                 return this;
             }
     
    -        /** Keep only edges where both endpoints are in the given set. */
    +        /** Keep only Edges where both endpoints are in the given set. */
             public EdgeQuery betweenNodes(Set nodeSet) {
                 filters.add(e -> nodeSet.contains(e.getVertex1()) && nodeSet.contains(e.getVertex2()));
                 return this;
    @@ -315,13 +315,13 @@ public EdgeQuery temporal() {
             }
     
             /** Add a custom predicate filter. */
    -        public EdgeQuery where(Predicate predicate) {
    +        public EdgeQuery where(Predicate predicate) {
                 filters.add(predicate);
                 return this;
             }
     
             /** Execute the query and return matching edges. */
    -        public Set results() {
    +        public Set results() {
                 return graph.getEdges().stream()
                         .filter(e -> filters.stream().allMatch(f -> f.test(e)))
                         .collect(Collectors.toCollection(LinkedHashSet::new));
    @@ -333,7 +333,7 @@ public int count() {
             }
     
             /** Execute and return results sorted by weight (descending). */
    -        public List sortedByWeight() {
    +        public List sortedByWeight() {
                 return results().stream()
                         .sorted(Comparator.comparing(edge::getWeight).reversed())
                         .collect(Collectors.toList());
    @@ -342,7 +342,7 @@ public List sortedByWeight() {
             /** Execute and return a type breakdown of matching edges. */
             public Map typeBreakdown() {
                 Map counts = new LinkedHashMap<>();
    -            for (edge e : results()) {
    +            for (Edge e : results()) {
                     String t = e.getType() != null ? e.getType() : "unknown";
                     counts.merge(t, 1, Integer::sum);
                 }
    @@ -351,12 +351,12 @@ public Map typeBreakdown() {
     
             /** Execute and return a summary string for display. */
             public String summary() {
    -            Set r = results();
    +            Set r = results();
                 if (r.isEmpty()) return "No matching edges.";
                 StringBuilder sb = new StringBuilder();
                 sb.append(String.format("Found %d edge(s):\n", r.size()));
                 int shown = 0;
    -            for (edge e : r) {
    +            for (Edge e : r) {
                     sb.append(String.format("  %s --%s--> %s  (w=%.2f)\n",
                             e.getVertex1(), e.getType(), e.getVertex2(), e.getWeight()));
                     if (++shown >= 50) {
    diff --git a/Gvisual/src/gvisual/GraphRenderers.java b/Gvisual/src/gvisual/GraphRenderers.java
    index 3434090..8fded03 100644
    --- a/Gvisual/src/gvisual/GraphRenderers.java
    +++ b/Gvisual/src/gvisual/GraphRenderers.java
    @@ -25,30 +25,30 @@ public class GraphRenderers {
     
         // ── overlay state (set externally by Main) ──────────────────────────
     
    -    private Set pathEdges;
    +    private Set pathEdges;
         private Set pathVertices;
         private String pathSource;
         private String pathTarget;
     
         private boolean mstOverlayActive;
    -    private Set mstEdges;
    +    private Set mstEdges;
     
         private boolean communityOverlayActive;
         private Map nodeCommunityMap;
     
         private boolean articulationOverlayActive;
         private Set articulationPoints;
    -    private Set bridgeEdges;
    +    private Set bridgeEdges;
     
         private boolean egoOverlayActive;
         private String egoCenter;
         private Set egoNeighbors;
    -    private Set egoEdges;
    +    private Set egoEdges;
     
         private Collection oldVertices;
     
         /** Graph reference for vertex‐paint edge‐type lookup. */
    -    private Graph graph;
    +    private Graph graph;
     
         // ── constants (mirrored from Main) ──────────────────────────────────
     
    @@ -71,7 +71,7 @@ public class GraphRenderers {
     
         // ── setters ─────────────────────────────────────────────────────────
     
    -    public void setPathState(Set pathEdges, Set pathVertices,
    +    public void setPathState(Set pathEdges, Set pathVertices,
                                  String pathSource, String pathTarget) {
             this.pathEdges = pathEdges;
             this.pathVertices = pathVertices;
    @@ -79,7 +79,7 @@ public void setPathState(Set pathEdges, Set pathVertices,
             this.pathTarget = pathTarget;
         }
     
    -    public void setMstState(boolean active, Set mstEdges) {
    +    public void setMstState(boolean active, Set mstEdges) {
             this.mstOverlayActive = active;
             this.mstEdges = mstEdges;
         }
    @@ -90,13 +90,13 @@ public void setCommunityState(boolean active, Map nodeCommunity
         }
     
         public void setArticulationState(boolean active, Set articulationPoints,
    -                                     Set bridgeEdges) {
    +                                     Set bridgeEdges) {
             this.articulationOverlayActive = active;
             this.articulationPoints = articulationPoints;
             this.bridgeEdges = bridgeEdges;
         }
     
    -    public void setEgoState(boolean active, String center, Set neighbors, Set edges) {
    +    public void setEgoState(boolean active, String center, Set neighbors, Set edges) {
             this.egoOverlayActive = active;
             this.egoCenter = center;
             this.egoNeighbors = neighbors;
    @@ -107,14 +107,14 @@ public void setOldVertices(Collection oldVertices) {
             this.oldVertices = oldVertices;
         }
     
    -    public void setGraph(Graph graph) {
    +    public void setGraph(Graph graph) {
             this.graph = graph;
         }
     
         // ── transformers ────────────────────────────────────────────────────
     
    -    public Transformer edgePaintTransformer() {
    -        return (edge e) -> {
    +    public Transformer edgePaintTransformer() {
    +        return (Edge e) -> {
                     if (pathEdges != null && pathEdges.contains(e)) {
                         return Color.YELLOW;
                     }
    @@ -179,7 +179,7 @@ public Transformer vertexPaintTransformer() {
                     // Determine vertex colour based on connected edge types
                     if (graph != null) {
                         Set connectedTypes = new HashSet<>();
    -                    for (edge x : graph.getOutEdges(vertex)) {
    +                    for (Edge x : graph.getOutEdges(vertex)) {
                             EdgeType et = EdgeType.fromCode(x.getType());
                             if (et != null) {
                                 connectedTypes.add(et);
    @@ -229,8 +229,8 @@ public Transformer vertexShapeTransformer() {
                 };
         }
     
    -    public Transformer edgeStrokeTransformer() {
    -        return (edge i) -> {
    +    public Transformer edgeStrokeTransformer() {
    +        return (Edge i) -> {
                     if (pathEdges != null && pathEdges.contains(i)) {
                         return new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
                     }
    diff --git a/Gvisual/src/gvisual/GraphResilienceAnalyzer.java b/Gvisual/src/gvisual/GraphResilienceAnalyzer.java
    index fc5f8ad..e636b55 100644
    --- a/Gvisual/src/gvisual/GraphResilienceAnalyzer.java
    +++ b/Gvisual/src/gvisual/GraphResilienceAnalyzer.java
    @@ -22,7 +22,7 @@
      */
     public class GraphResilienceAnalyzer {
     
    -    private final Graph graph;
    +    private final Graph graph;
         private List degreeAttackCurve;
         private List betweennessAttackCurve;
         private List randomAttackCurve;
    @@ -34,7 +34,7 @@ public class GraphResilienceAnalyzer {
          *
          * @param graph the JUNG graph to analyze
          */
    -    public GraphResilienceAnalyzer(Graph graph) {
    +    public GraphResilienceAnalyzer(Graph graph) {
             this.graph = graph;
             this.randomTrials = 10;
             this.computed = false;
    @@ -174,7 +174,7 @@ public String exportCSV() {
         // --- Private simulation methods ---
     
         private List simulateDegreeAttack() {
    -        Graph copy = copyGraph();
    +        Graph copy = copyGraph();
             List curve = new ArrayList<>();
             int originalSize = copy.getVertexCount();
     
    @@ -199,7 +199,7 @@ private List simulateDegreeAttack() {
         }
     
         private List simulateBetweennessAttack() {
    -        Graph copy = copyGraph();
    +        Graph copy = copyGraph();
             List curve = new ArrayList<>();
             int originalSize = copy.getVertexCount();
     
    @@ -231,7 +231,7 @@ private List simulateRandomAttack(int trials) {
     
             Random rng = new Random(42);
             for (int t = 0; t < trials; t++) {
    -            Graph copy = copyGraph();
    +            Graph copy = copyGraph();
                 List vertices = new ArrayList<>(copy.getVertices());
                 Collections.shuffle(vertices, rng);
     
    @@ -259,11 +259,11 @@ private List simulateRandomAttack(int trials) {
             return curve;
         }
     
    -    private Graph copyGraph() {
    +    private Graph copyGraph() {
             return GraphUtils.copyGraph(graph);
         }
     
    -    private ResilienceStep captureStep(Graph g, int originalSize,
    +    private ResilienceStep captureStep(Graph g, int originalSize,
                                             int step, String removedNode) {
             return new ResilienceStep(
                     step,
    @@ -274,21 +274,21 @@ private ResilienceStep captureStep(Graph g, int originalSize,
                     removedNode);
         }
     
    -    private int largestComponentSize(Graph g) {
    +    private int largestComponentSize(Graph g) {
             if (g.getVertexCount() == 0) return 0;
             return GraphUtils.findLargestComponent(g).size();
         }
     
    -    private int countComponents(Graph g) {
    +    private int countComponents(Graph g) {
             if (g.getVertexCount() == 0) return 0;
             return GraphUtils.findComponents(g).size();
         }
     
    -    private double globalEfficiency(Graph g) {
    +    private double globalEfficiency(Graph g) {
             return GraphUtils.globalEfficiency(g);
         }
     
    -    private Map computeBetweenness(Graph g) {
    +    private Map computeBetweenness(Graph g) {
             return GraphUtils.computeBetweenness(g);
         }
     
    diff --git a/Gvisual/src/gvisual/GraphSampler.java b/Gvisual/src/gvisual/GraphSampler.java
    index 8a256c4..9c88ec2 100644
    --- a/Gvisual/src/gvisual/GraphSampler.java
    +++ b/Gvisual/src/gvisual/GraphSampler.java
    @@ -43,7 +43,7 @@
      */
     public class GraphSampler {
     
    -    private final Graph graph;
    +    private final Graph graph;
         private final Random rng;
     
         /**
    @@ -52,7 +52,7 @@ public class GraphSampler {
          * @param graph the source graph
          * @throws IllegalArgumentException if graph is null
          */
    -    public GraphSampler(Graph graph) {
    +    public GraphSampler(Graph graph) {
             this(graph, new Random());
         }
     
    @@ -62,7 +62,7 @@ public GraphSampler(Graph graph) {
          * @param graph the source graph
          * @param rng   random number generator
          */
    -    public GraphSampler(Graph graph, Random rng) {
    +    public GraphSampler(Graph graph, Random rng) {
             if (graph == null) throw new IllegalArgumentException("Graph must not be null");
             if (rng == null) throw new IllegalArgumentException("RNG must not be null");
             this.graph = graph;
    @@ -107,13 +107,13 @@ public SampleResult randomEdge(double fraction) {
             int m = graph.getEdgeCount();
             int target = Math.max(1, (int) Math.ceil(m * fraction));
     
    -        List edges = new ArrayList(graph.getEdges());
    +        List edges = new ArrayList(graph.getEdges());
             Collections.shuffle(edges, rng);
     
             Set sampled = new LinkedHashSet();
    -        Set sampledEdges = new LinkedHashSet();
    +        Set sampledEdges = new LinkedHashSet();
             for (int i = 0; i < Math.min(target, edges.size()); i++) {
    -            edge e = edges.get(i);
    +            Edge e = Edges.get(i);
                 Collection endpoints = graph.getEndpoints(e);
                 if (endpoints != null && endpoints.size() == 2) {
                     Iterator it = endpoints.iterator();
    @@ -351,19 +351,19 @@ private void validateFraction(double fraction) {
          * Build a SampleResult by inducing the subgraph on the sampled nodes.
          */
         private SampleResult buildResult(Set sampledNodes, String strategy) {
    -        Graph sample = new UndirectedSparseGraph();
    +        Graph sample = new UndirectedSparseGraph();
             for (String v : sampledNodes) {
                 sample.addVertex(v);
             }
     
    -        for (edge e : graph.getEdges()) {
    +        for (Edge e : graph.getEdges()) {
                 Collection endpoints = graph.getEndpoints(e);
                 if (endpoints == null || endpoints.size() < 2) continue;
                 Iterator it = endpoints.iterator();
                 String v1 = it.next();
                 String v2 = it.next();
                 if (sampledNodes.contains(v1) && sampledNodes.contains(v2)) {
    -                edge copy = new edge(e.getType(), v1, v2);
    +                Edge copy = new Edge(e.getType(), v1, v2);
                     copy.setWeight(e.getWeight());
                     copy.setLabel(e.getLabel());
                     if (e.getTimestamp() != null) copy.setTimestamp(e.getTimestamp());
    @@ -380,20 +380,20 @@ private SampleResult buildResult(Set sampledNodes, String strategy) {
          * Build a SampleResult from pre-selected edges (for edge sampling).
          */
         private SampleResult buildResultFromEdges(Set sampledNodes,
    -                                              Set sampledEdges,
    +                                              Set sampledEdges,
                                                   String strategy) {
    -        Graph sample = new UndirectedSparseGraph();
    +        Graph sample = new UndirectedSparseGraph();
             for (String v : sampledNodes) {
                 sample.addVertex(v);
             }
     
    -        for (edge e : sampledEdges) {
    +        for (Edge e : sampledEdges) {
                 Collection endpoints = graph.getEndpoints(e);
                 if (endpoints == null || endpoints.size() < 2) continue;
                 Iterator it = endpoints.iterator();
                 String v1 = it.next();
                 String v2 = it.next();
    -            edge copy = new edge(e.getType(), v1, v2);
    +            Edge copy = new Edge(e.getType(), v1, v2);
                 copy.setWeight(e.getWeight());
                 copy.setLabel(e.getLabel());
                 if (e.getTimestamp() != null) copy.setTimestamp(e.getTimestamp());
    @@ -403,7 +403,7 @@ private SampleResult buildResultFromEdges(Set sampledNodes,
     
             // Also add any induced edges between sampled nodes that weren't
             // directly selected (edges between endpoints of sampled edges)
    -        for (edge e : graph.getEdges()) {
    +        for (Edge e : graph.getEdges()) {
                 if (sampledEdges.contains(e)) continue;
                 Collection endpoints = graph.getEndpoints(e);
                 if (endpoints == null || endpoints.size() < 2) continue;
    @@ -412,7 +412,7 @@ private SampleResult buildResultFromEdges(Set sampledNodes,
                 String v2 = it.next();
                 if (sampledNodes.contains(v1) && sampledNodes.contains(v2)
                         && sample.findEdge(v1, v2) == null) {
    -                edge copy = new edge(e.getType(), v1, v2);
    +                Edge copy = new Edge(e.getType(), v1, v2);
                     copy.setWeight(e.getWeight());
                     copy.setLabel(e.getLabel());
                     if (e.getTimestamp() != null) copy.setTimestamp(e.getTimestamp());
    @@ -434,7 +434,7 @@ private SampleResult buildResultFromEdges(Set sampledNodes,
          * representativeness metrics, and a summary.
          */
         public static class SampleResult {
    -        private final Graph sample;
    +        private final Graph sample;
             private final int originalNodes;
             private final int originalEdges;
             private final String strategy;
    @@ -444,7 +444,7 @@ public static class SampleResult {
             private final double originalDensity;
             private final int componentCount;
     
    -        SampleResult(Graph sample, int originalNodes,
    +        SampleResult(Graph sample, int originalNodes,
                          int originalEdges, String strategy) {
                 this.sample = sample;
                 this.originalNodes = originalNodes;
    @@ -467,7 +467,7 @@ public static class SampleResult {
             }
     
             /** The sampled subgraph. */
    -        public Graph getSample() { return sample; }
    +        public Graph getSample() { return sample; }
     
             /** Number of nodes in the sample. */
             public int getNodeCount() { return sample.getVertexCount(); }
    diff --git a/Gvisual/src/gvisual/GraphSimilarityAnalyzer.java b/Gvisual/src/gvisual/GraphSimilarityAnalyzer.java
    index d439458..c8829d5 100644
    --- a/Gvisual/src/gvisual/GraphSimilarityAnalyzer.java
    +++ b/Gvisual/src/gvisual/GraphSimilarityAnalyzer.java
    @@ -19,7 +19,7 @@
      *       level.
      *   
  • Entropy Profile Distance — L2 (Euclidean) distance between * normalised entropy vectors (degree entropy, Von Neumann entropy, - * neighbourhood entropy, edge type entropy, topological info content, + * neighbourhood entropy, Edge type entropy, topological info content, * random walk entropy rate). Captures multi-faceted structural * differences.
  • *
  • Similarity score — combined [0, 1] similarity derived from @@ -41,8 +41,8 @@ public class GraphSimilarityAnalyzer { private static final double EPSILON = 1e-12; private static final int JACOBI_MAX_SWEEPS = 100; - private final Graph graph1; - private final Graph graph2; + private final Graph graph1; + private final Graph graph2; private boolean computed; // ── Results ───────────────────────────────────────────────────── @@ -62,8 +62,8 @@ public class GraphSimilarityAnalyzer { * @param graph2 the second graph * @throws NullPointerException if either graph is null */ - public GraphSimilarityAnalyzer(Graph graph1, - Graph graph2) { + public GraphSimilarityAnalyzer(Graph graph1, + Graph graph2) { this.graph1 = Objects.requireNonNull(graph1, "graph1 must not be null"); this.graph2 = Objects.requireNonNull(graph2, "graph2 must not be null"); this.computed = false; @@ -299,7 +299,7 @@ private void ensureComputed() { /** * Gets the degree probability distribution for a graph. */ - private Map getDegreeDistribution(Graph g) { + private Map getDegreeDistribution(Graph g) { Map freq = new HashMap<>(); int n = g.getVertexCount(); if (n == 0) return new HashMap<>(); @@ -320,7 +320,7 @@ private Map getDegreeDistribution(Graph g) { /** * Gets sorted Laplacian eigenvalues for a graph. */ - private double[] getLaplacianEigenvalues(Graph g) { + private double[] getLaplacianEigenvalues(Graph g) { int n = g.getVertexCount(); if (n <= 1) return new double[0]; @@ -470,7 +470,7 @@ public String generateReport() { StringBuilder sb = new StringBuilder(); sb.append("=== Graph Similarity Analysis ===\n\n"); sb.append(String.format("Graph 1: %d vertices, %d edges\n", n1, m1)); - sb.append(String.format("Graph 2: %d vertices, %d edges\n\n", n2, m2)); + sb.append(String.format("Graph 2: %d vertices, %d Edges\n\n", n2, m2)); sb.append("── Divergence Measures ──\n"); sb.append(String.format(" Jensen-Shannon Divergence: %.6f", jensenShannonDivergence)); diff --git a/Gvisual/src/gvisual/GraphSparsificationAnalyzer.java b/Gvisual/src/gvisual/GraphSparsificationAnalyzer.java index 7dee229..fc13e82 100644 --- a/Gvisual/src/gvisual/GraphSparsificationAnalyzer.java +++ b/Gvisual/src/gvisual/GraphSparsificationAnalyzer.java @@ -24,9 +24,9 @@ */ public class GraphSparsificationAnalyzer { - private final Graph graph; + private final Graph graph; - public GraphSparsificationAnalyzer(Graph graph) { + public GraphSparsificationAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -34,12 +34,12 @@ public GraphSparsificationAnalyzer(Graph graph) { } /** Scores each edge by importance (0.0-1.0). Higher = more important. */ - public Map scoreEdgeImportance() { - Map scores = new LinkedHashMap(); + public Map scoreEdgeImportance() { + Map scores = new LinkedHashMap(); if (graph.getEdgeCount() == 0) return scores; - Map betweenness = computeEdgeBetweenness(); - Set bridges = findBridges(); + Map betweenness = computeEdgeBetweenness(); + Set bridges = findBridges(); double maxBet = 0; for (double val : betweenness.values()) { @@ -51,7 +51,7 @@ public Map scoreEdgeImportance() { if (graph.degree(vtx) > maxDeg) maxDeg = graph.degree(vtx); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { double score = 0; if (bridges.contains(e)) score += 0.5; double bet = betweenness.containsKey(e) ? betweenness.get(e) : 0; @@ -67,8 +67,8 @@ public Map scoreEdgeImportance() { } /** Finds bridge edges whose removal disconnects the graph. */ - public Set findBridges() { - Set bridges = new LinkedHashSet(); + public Set findBridges() { + Set bridges = new LinkedHashSet(); if (graph.getVertexCount() == 0) return bridges; Map disc = new HashMap(); Map low = new HashMap(); @@ -81,7 +81,7 @@ public Set findBridges() { } private void bridgeDFS(String u, Map disc, Map low, - Map parent, int[] timer, Set bridges) { + Map parent, int[] timer, Set bridges) { disc.put(u, timer[0]); low.put(u, timer[0]); timer[0]++; @@ -91,7 +91,7 @@ private void bridgeDFS(String u, Map disc, Map bridgeDFS(nb, disc, low, parent, timer, bridges); low.put(u, Math.min(low.get(u), low.get(nb))); if (low.get(nb) > disc.get(u)) { - edge be = graph.findEdge(u, nb); + Edge be = graph.findEdge(u, nb); if (be != null) bridges.add(be); } } else if (!nb.equals(parent.get(u))) { @@ -101,23 +101,23 @@ private void bridgeDFS(String u, Map disc, Map } /** Spanning tree (Kruskal's MST). */ - public Graph spanningTreeSparsify() { - Graph sparse = new UndirectedSparseGraph(); + public Graph spanningTreeSparsify() { + Graph sparse = new UndirectedSparseGraph(); for (String vtx : graph.getVertices()) sparse.addVertex(vtx); if (graph.getVertexCount() <= 1) return sparse; - List edges = new ArrayList(graph.getEdges()); - Collections.sort(edges, (edge a, edge b) -> { return Float.compare(a.getWeight(), b.getWeight()); }); + List edges = new ArrayList(graph.getEdges()); + Collections.sort(edges, (Edge a, Edge b) -> { return Float.compare(a.getWeight(), b.getWeight()); }); Map par = new HashMap(); Map rnk = new HashMap(); for (String vtx : graph.getVertices()) { par.put(vtx, vtx); rnk.put(vtx, 0); } - for (edge e : edges) { + for (Edge e : edges) { String u = e.getVertex1(), vt = e.getVertex2(); if (u == null || vt == null) continue; String ru = ufFind(par, u), rv = ufFind(par, vt); if (!ru.equals(rv)) { - edge ne = new edge(e.getType(), u, vt); + Edge ne = new Edge(e.getType(), u, vt); ne.setWeight(e.getWeight()); ne.setLabel(e.getLabel()); sparse.addEdge(ne, u, vt); ufUnion(par, rnk, ru, rv); @@ -137,16 +137,16 @@ private void ufUnion(Map p, Map r, String a, St } /** Random sparsification — keeps each edge with given probability. */ - public Graph randomSparsify(double keepProb, long seed) { + public Graph randomSparsify(double keepProb, long seed) { if (keepProb < 0 || keepProb > 1) throw new IllegalArgumentException("keepProbability must be between 0 and 1"); - Graph sparse = new UndirectedSparseGraph(); + Graph sparse = new UndirectedSparseGraph(); for (String vtx : graph.getVertices()) sparse.addVertex(vtx); Random rng = new Random(seed); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (rng.nextDouble() < keepProb) { String u = e.getVertex1(), vt = e.getVertex2(); if (u != null && vt != null) { - edge ne = new edge(e.getType(), u, vt); + Edge ne = new Edge(e.getType(), u, vt); ne.setWeight(e.getWeight()); ne.setLabel(e.getLabel()); sparse.addEdge(ne, u, vt); } @@ -155,15 +155,15 @@ public Graph randomSparsify(double keepProb, long seed) { return sparse; } - /** Threshold sparsification — keeps edges with weight >= threshold. */ - public Graph thresholdSparsify(float threshold) { - Graph sparse = new UndirectedSparseGraph(); + /** Threshold sparsification — keeps Edges with weight >= threshold. */ + public Graph thresholdSparsify(float threshold) { + Graph sparse = new UndirectedSparseGraph(); for (String vtx : graph.getVertices()) sparse.addVertex(vtx); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (e.getWeight() >= threshold) { String u = e.getVertex1(), vt = e.getVertex2(); if (u != null && vt != null) { - edge ne = new edge(e.getType(), u, vt); + Edge ne = new Edge(e.getType(), u, vt); ne.setWeight(e.getWeight()); ne.setLabel(e.getLabel()); sparse.addEdge(ne, u, vt); } @@ -173,23 +173,23 @@ public Graph thresholdSparsify(float threshold) { } /** Local sparsification — keep top-k edges per vertex by weight. */ - public Graph localSparsify(int k) { + public Graph localSparsify(int k) { if (k < 1) throw new IllegalArgumentException("k must be at least 1"); - Graph sparse = new UndirectedSparseGraph(); + Graph sparse = new UndirectedSparseGraph(); for (String vtx : graph.getVertices()) sparse.addVertex(vtx); Set added = new HashSet(); for (String vertex : graph.getVertices()) { - List inc = new ArrayList(graph.getIncidentEdges(vertex)); - Collections.sort(inc, (edge a, edge b) -> { return Float.compare(b.getWeight(), a.getWeight()); }); + List inc = new ArrayList(graph.getIncidentEdges(vertex)); + Collections.sort(inc, (Edge a, Edge b) -> { return Float.compare(b.getWeight(), a.getWeight()); }); int cnt = 0; - for (edge e : inc) { + for (Edge e : inc) { if (cnt >= k) break; String u = e.getVertex1(), vt = e.getVertex2(); if (u == null || vt == null) continue; String key = u.compareTo(vt) < 0 ? u + "|" + vt : vt + "|" + u; if (!added.contains(key)) { - edge ne = new edge(e.getType(), u, vt); + Edge ne = new Edge(e.getType(), u, vt); ne.setWeight(e.getWeight()); ne.setLabel(e.getLabel()); sparse.addEdge(ne, u, vt); added.add(key); @@ -201,24 +201,24 @@ public Graph localSparsify(int k) { } /** Importance-based sparsification — keeps the most important edges. */ - public Graph importanceSparsify(double keepRatio) { + public Graph importanceSparsify(double keepRatio) { if (keepRatio < 0 || keepRatio > 1) throw new IllegalArgumentException("keepRatio must be between 0 and 1"); - Graph sparse = new UndirectedSparseGraph(); + Graph sparse = new UndirectedSparseGraph(); for (String vtx : graph.getVertices()) sparse.addVertex(vtx); - Map scores = scoreEdgeImportance(); - List> sorted = new ArrayList>(scores.entrySet()); - Collections.sort(sorted, (Map.Entry a, Map.Entry b) -> { + Map scores = scoreEdgeImportance(); + List> sorted = new ArrayList>(scores.entrySet()); + Collections.sort(sorted, (Map.Entry a, Map.Entry b) -> { return Double.compare(b.getValue(), a.getValue()); }); int keep = (int) Math.ceil(graph.getEdgeCount() * keepRatio); int cnt = 0; - for (Map.Entry entry : sorted) { + for (Map.Entry entry : sorted) { if (cnt >= keep) break; - edge e = entry.getKey(); + Edge e = entry.getKey(); String u = e.getVertex1(), vt = e.getVertex2(); if (u != null && vt != null) { - edge ne = new edge(e.getType(), u, vt); + Edge ne = new Edge(e.getType(), u, vt); ne.setWeight(e.getWeight()); ne.setLabel(e.getLabel()); sparse.addEdge(ne, u, vt); } @@ -257,7 +257,7 @@ public String getGrade() { } } - public SparsificationQuality evaluateQuality(Graph sparse) { + public SparsificationQuality evaluateQuality(Graph sparse) { if (sparse == null) throw new IllegalArgumentException("Sparse graph must not be null"); int ov = graph.getVertexCount(), oe = graph.getEdgeCount(); int sv = sparse.getVertexCount(), se = sparse.getEdgeCount(); @@ -270,11 +270,11 @@ public SparsificationQuality evaluateQuality(Graph sparse) { return new SparsificationQuality(ov, oe, sv, se, er, oc == sc, oc, sc, od, sd, ado, ads, degreeCorr(graph, sparse)); } - private int countComponents(Graph g) { + private int countComponents(Graph g) { return GraphUtils.findComponents(g).size(); } - private double degreeCorr(Graph g1, Graph g2) { + private double degreeCorr(Graph g1, Graph g2) { List common = new ArrayList(); for (String vtx : g1.getVertices()) { if (g2.containsVertex(vtx)) common.add(vtx); } if (common.size() < 2) return 0; @@ -292,9 +292,9 @@ private double pearson(double[] x, double[] y) { return (dx == 0 || dy == 0) ? 0 : num / Math.sqrt(dx * dy); } - private Map computeEdgeBetweenness() { - Map bet = new LinkedHashMap(); - for (edge e : graph.getEdges()) bet.put(e, 0.0); + private Map computeEdgeBetweenness() { + Map bet = new LinkedHashMap(); + for (Edge e : graph.getEdges()) bet.put(e, 0.0); for (String s : graph.getVertices()) { Stack stack = new Stack(); Map> pred = new HashMap>(); @@ -316,13 +316,13 @@ private Map computeEdgeBetweenness() { String w = stack.pop(); for (String vtx : pred.get(w)) { double c = (double) sigma.get(vtx) / sigma.get(w) * (1.0 + delta.get(w)); - edge e = graph.findEdge(vtx, w); + Edge e = graph.findEdge(vtx, w); if (e != null) bet.put(e, bet.get(e) + c); delta.put(vtx, delta.get(vtx) + c); } } } - for (edge e : bet.keySet()) bet.put(e, bet.get(e) / 2.0); + for (Edge e : bet.keySet()) bet.put(e, bet.get(e) / 2.0); return bet; } @@ -392,11 +392,11 @@ public String generateReport() { sb.append(String.format(" Bridges: %d (%.1f%%)\n", sm.bridgeCount, sm.bridgeFraction * 100)); sb.append("\n"); - Set bridges = findBridges(); + Set bridges = findBridges(); if (!bridges.isEmpty()) { sb.append("── Bridge Edges (critical) ──\n"); int cnt = 0; - for (edge e : bridges) { + for (Edge e : bridges) { if (cnt >= 10) { sb.append(String.format(" ... and %d more\n", bridges.size() - 10)); break; } sb.append(String.format(" %s — %s\n", e.getVertex1(), e.getVertex2())); cnt++; @@ -426,12 +426,12 @@ public String generateReport() { if (best != null) sb.append(String.format(" Recommended: %s\n\n", best)); sb.append("── Top Important Edges ──\n"); - Map importance = scoreEdgeImportance(); - List> sorted = new ArrayList>(importance.entrySet()); - Collections.sort(sorted, (Map.Entry a, Map.Entry b) -> { return Double.compare(b.getValue(), a.getValue()); }); + Map importance = scoreEdgeImportance(); + List> sorted = new ArrayList>(importance.entrySet()); + Collections.sort(sorted, (Map.Entry a, Map.Entry b) -> { return Double.compare(b.getValue(), a.getValue()); }); for (int i = 0; i < Math.min(10, sorted.size()); i++) { - Map.Entry entry = sorted.get(i); - edge e = entry.getKey(); + Map.Entry entry = sorted.get(i); + Edge e = entry.getKey(); sb.append(String.format(" %s — %s (importance: %.3f)\n", e.getVertex1(), e.getVertex2(), entry.getValue())); } } diff --git a/Gvisual/src/gvisual/GraphStats.java b/Gvisual/src/gvisual/GraphStats.java index 93e4113..76202bf 100644 --- a/Gvisual/src/gvisual/GraphStats.java +++ b/Gvisual/src/gvisual/GraphStats.java @@ -12,12 +12,12 @@ */ public class GraphStats { - private final Graph graph; - private final List friendEdges; - private final List fsEdges; - private final List classmateEdges; - private final List strangerEdges; - private final List studyGEdges; + private final Graph graph; + private final List friendEdges; + private final List fsEdges; + private final List classmateEdges; + private final List strangerEdges; + private final List studyGEdges; /** * @param graph the current JUNG graph @@ -27,12 +27,12 @@ public class GraphStats { * @param strangerEdges stranger edges * @param studyGEdges study group edges */ - public GraphStats(Graph graph, - List friendEdges, - List fsEdges, - List classmateEdges, - List strangerEdges, - List studyGEdges) { + public GraphStats(Graph graph, + List friendEdges, + List fsEdges, + List classmateEdges, + List strangerEdges, + List studyGEdges) { this.graph = graph; this.friendEdges = friendEdges; this.fsEdges = fsEdges; @@ -201,7 +201,7 @@ public double getAverageWeight() { if (graph.getEdgeCount() == 0) return 0.0; if (cachedTotalWeight < 0) { cachedTotalWeight = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { cachedTotalWeight += e.getWeight(); } } diff --git a/Gvisual/src/gvisual/GraphSummarizer.java b/Gvisual/src/gvisual/GraphSummarizer.java index 84ce57f..2f32758 100644 --- a/Gvisual/src/gvisual/GraphSummarizer.java +++ b/Gvisual/src/gvisual/GraphSummarizer.java @@ -25,14 +25,14 @@ */ public class GraphSummarizer { - private final Graph graph; + private final Graph graph; private final GraphStats stats; private final CommunityDetector communities; - private final List friendEdges; - private final List fsEdges; - private final List classmateEdges; - private final List strangerEdges; - private final List studyGEdges; + private final List friendEdges; + private final List fsEdges; + private final List classmateEdges; + private final List strangerEdges; + private final List studyGEdges; /** * Creates a new GraphSummarizer. @@ -45,21 +45,21 @@ public class GraphSummarizer { * @param studyGEdges study group edges * @throws IllegalArgumentException if graph is null */ - public GraphSummarizer(Graph graph, - List friendEdges, - List fsEdges, - List classmateEdges, - List strangerEdges, - List studyGEdges) { + public GraphSummarizer(Graph graph, + List friendEdges, + List fsEdges, + List classmateEdges, + List strangerEdges, + List studyGEdges) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } this.graph = graph; - this.friendEdges = friendEdges != null ? friendEdges : new ArrayList(); - this.fsEdges = fsEdges != null ? fsEdges : new ArrayList(); - this.classmateEdges = classmateEdges != null ? classmateEdges : new ArrayList(); - this.strangerEdges = strangerEdges != null ? strangerEdges : new ArrayList(); - this.studyGEdges = studyGEdges != null ? studyGEdges : new ArrayList(); + this.friendEdges = friendEdges != null ? friendEdges : new ArrayList(); + this.fsEdges = fsEdges != null ? fsEdges : new ArrayList(); + this.classmateEdges = classmateEdges != null ? classmateEdges : new ArrayList(); + this.strangerEdges = strangerEdges != null ? strangerEdges : new ArrayList(); + this.studyGEdges = studyGEdges != null ? studyGEdges : new ArrayList(); this.stats = new GraphStats(graph, this.friendEdges, this.fsEdges, this.classmateEdges, this.strangerEdges, this.studyGEdges); this.communities = new CommunityDetector(graph); @@ -283,7 +283,7 @@ private String classifySize(int nodes) { private String getSizeContext(int nodes, int edges) { if (nodes == 0) return "The graph contains no data."; if (edges == 0) return "No connections exist between nodes."; - double ratio = (double) edges / nodes; + double ratio = (double) Edges / nodes; if (ratio < 1) return "The network is sparsely connected."; if (ratio < 3) return "The network has moderate connectivity."; return "The network is richly interconnected."; diff --git a/Gvisual/src/gvisual/GraphSymmetryAnalyzer.java b/Gvisual/src/gvisual/GraphSymmetryAnalyzer.java index e6371f1..0ced7a5 100644 --- a/Gvisual/src/gvisual/GraphSymmetryAnalyzer.java +++ b/Gvisual/src/gvisual/GraphSymmetryAnalyzer.java @@ -39,16 +39,16 @@ */ public class GraphSymmetryAnalyzer { - private final Graph graph; + private final Graph graph; /** Lazily computed colour-refinement partition (vertex → orbit id). */ private Map vertexOrbitMap; /** Lazily computed orbit groups. */ private List> orbits; /** Lazily computed edge orbits. */ - private List> edgeOrbits; + private List> edgeOrbits; - public GraphSymmetryAnalyzer(Graph graph) { + public GraphSymmetryAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -151,8 +151,8 @@ private void ensureComputed() { // Build edge orbits: two edges are equivalent if their endpoint // orbit-pair (sorted) is identical - Map, Set> edgeGroups = new LinkedHashMap<>(); - for (edge e : graph.getEdges()) { + Map, Set> edgeGroups = new LinkedHashMap<>(); + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); int o1 = vertexOrbitMap.getOrDefault(v1, -1); @@ -160,7 +160,7 @@ private void ensureComputed() { List key = o1 <= o2 ? Arrays.asList(o1, o2) : Arrays.asList(o2, o1); - edgeGroups.computeIfAbsent(key, k -> new LinkedHashSet<>()).add(e); + EdgeGroups.computeIfAbsent(key, k -> new LinkedHashSet<>()).add(e); } edgeOrbits = new ArrayList<>(edgeGroups.values()); } @@ -216,7 +216,7 @@ public Set getOrbitOf(String vertex) { * Returns the list of edge orbits. Edges whose endpoint orbit-pairs * match are grouped together. */ - public List> getEdgeOrbits() { + public List> getEdgeOrbits() { ensureComputed(); return Collections.unmodifiableList(edgeOrbits); } diff --git a/Gvisual/src/gvisual/GraphTimelineExporter.java b/Gvisual/src/gvisual/GraphTimelineExporter.java index 0792c94..9ad4500 100644 --- a/Gvisual/src/gvisual/GraphTimelineExporter.java +++ b/Gvisual/src/gvisual/GraphTimelineExporter.java @@ -90,7 +90,7 @@ public String exportToString() { // Build snapshot data for each time point List> snapshots = new ArrayList<>(); for (Long t : timePoints) { - Graph snap = temporalGraph.snapshotAt(t); + Graph snap = temporalGraph.snapshotAt(t); Map s = new LinkedHashMap<>(); s.put("time", t); @@ -104,7 +104,7 @@ public String exportToString() { s.put("nodes", nodes); List> edges = new ArrayList<>(); - for (edge e : snap.getEdges()) { + for (Edge e : snap.getEdges()) { Map ed = new LinkedHashMap<>(); ed.put("source", e.getVertex1()); ed.put("target", e.getVertex2()); @@ -123,7 +123,7 @@ public String exportToString() { for (int i = 0; i < timePoints.size(); i++) { long tEnd = timePoints.get(i); long tStart = timePoints.get(0); - Graph cumSnap = temporalGraph.windowBetween(tStart, tEnd); + Graph cumSnap = temporalGraph.windowBetween(tStart, tEnd); Map s = new LinkedHashMap<>(); s.put("time", tEnd); @@ -137,7 +137,7 @@ public String exportToString() { s.put("nodes", nodes); List> edges = new ArrayList<>(); - for (edge e : cumSnap.getEdges()) { + for (Edge e : cumSnap.getEdges()) { Map ed = new LinkedHashMap<>(); ed.put("source", e.getVertex1()); ed.put("target", e.getVertex2()); diff --git a/Gvisual/src/gvisual/GraphUtils.java b/Gvisual/src/gvisual/GraphUtils.java index 0622f95..9864d2e 100644 --- a/Gvisual/src/gvisual/GraphUtils.java +++ b/Gvisual/src/gvisual/GraphUtils.java @@ -29,7 +29,7 @@ private GraphUtils() { /* utility class */ } * @return the other endpoint, or {@code null} if {@code current} is not * an endpoint of the edge */ - public static String getOtherEnd(edge e, String current) { + public static String getOtherEnd(Edge e, String current) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (current.equals(v1)) return v2; @@ -44,7 +44,7 @@ public static String getOtherEnd(edge e, String current) { * @return map from each vertex to its set of neighbor vertex IDs */ public static Map> buildAdjacencyMap( - Graph graph) { + Graph graph) { Map> adj = new HashMap>(); for (String v : graph.getVertices()) { Set neighbors = new HashSet(); @@ -66,12 +66,12 @@ public static Map> buildAdjacencyMap( * @return adjacency map (vertex → set of neighbours within the subset) */ public static Map> buildAdjacencyMap( - Graph graph, Set vertices) { + Graph graph, Set vertices) { Map> adj = new HashMap>(); for (String v : vertices) { adj.put(v, new HashSet()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection eps = graph.getEndpoints(e); if (eps == null || eps.size() != 2) continue; Iterator it = eps.iterator(); @@ -94,7 +94,7 @@ public static Map> buildAdjacencyMap( * @return map from vertex ID to its BFS distance from source */ public static Map bfsDistances( - Graph graph, String source) { + Graph graph, String source) { Map distances = new HashMap(); Queue queue = new LinkedList(); distances.put(source, 0); @@ -103,9 +103,9 @@ public static Map bfsDistances( while (!queue.isEmpty()) { String current = queue.poll(); int currentDist = distances.get(current); - Collection incidentEdges = graph.getIncidentEdges(current); + Collection incidentEdges = graph.getIncidentEdges(current); if (incidentEdges == null) continue; - for (edge e : incidentEdges) { + for (Edge e : incidentEdges) { String neighbor = getOtherEnd(e, current); if (neighbor != null && !distances.containsKey(neighbor)) { distances.put(neighbor, currentDist + 1); @@ -124,7 +124,7 @@ public static Map bfsDistances( * @return set of all vertices reachable from source (including source) */ public static Set bfsComponent( - Graph graph, String source) { + Graph graph, String source) { Set component = new LinkedHashSet(); Queue queue = new LinkedList(); component.add(source); @@ -132,9 +132,9 @@ public static Set bfsComponent( while (!queue.isEmpty()) { String current = queue.poll(); - Collection incidentEdges = graph.getIncidentEdges(current); + Collection incidentEdges = graph.getIncidentEdges(current); if (incidentEdges == null) continue; - for (edge e : incidentEdges) { + for (Edge e : incidentEdges) { String neighbor = getOtherEnd(e, current); if (neighbor != null && !component.contains(neighbor)) { component.add(neighbor); @@ -152,7 +152,7 @@ public static Set bfsComponent( * @return list of components, each a set of vertex IDs, sorted largest-first */ public static List> findComponents( - Graph graph) { + Graph graph) { Set visited = new HashSet(); List> components = new ArrayList>(); @@ -178,7 +178,7 @@ public static List> findComponents( * @return set of vertices in the largest component, or empty set if graph is empty */ public static Set findLargestComponent( - Graph graph) { + Graph graph) { List> components = findComponents(graph); return components.isEmpty() ? Collections.emptySet() : components.get(0); } @@ -213,7 +213,7 @@ public static Set getCommonNeighbors( * @return true if the induced subgraph contains a cycle */ public static boolean hasCycleInSubgraph( - Graph graph, Set vertices, boolean directed) { + Graph graph, Set vertices, boolean directed) { if (vertices.size() <= 1) return false; Set visited = new HashSet(); Set inStack = new HashSet(); @@ -230,7 +230,7 @@ public static boolean hasCycleInSubgraph( } private static boolean hasCycleDFS_undirected( - Graph graph, String v, String parent, + Graph graph, String v, String parent, Set vertices, Set visited) { visited.add(v); for (String n : graph.getNeighbors(v)) { @@ -245,7 +245,7 @@ private static boolean hasCycleDFS_undirected( } private static boolean hasCycleDFS_directed( - Graph graph, String v, Set vertices, + Graph graph, String v, Set vertices, Set visited, Set inStack) { visited.add(v); inStack.add(v); @@ -269,11 +269,11 @@ private static boolean hasCycleDFS_directed( * @return number of edges where both endpoints are in the vertex set */ public static int countEdgesInSubgraph( - Graph graph, Set vertices) { + Graph graph, Set vertices) { int count = 0; - Set seen = new HashSet(); + Set seen = new HashSet(); for (String v : vertices) { - for (edge e : graph.getIncidentEdges(v)) { + for (Edge e : graph.getIncidentEdges(v)) { if (seen.contains(e)) continue; boolean allIn = true; for (String ep : graph.getEndpoints(e)) { @@ -293,7 +293,7 @@ public static int countEdgesInSubgraph( * @return number of connected components within the subset */ public static int countComponentsInSubgraph( - Graph graph, Set vertices) { + Graph graph, Set vertices) { Set visited = new HashSet(); int components = 0; for (String v : vertices) { @@ -325,7 +325,7 @@ public static int countComponentsInSubgraph( * @return the cycle rank of the induced subgraph */ public static int cycleRankOfSubgraph( - Graph graph, Set vertices) { + Graph graph, Set vertices) { int edges = countEdgesInSubgraph(graph, vertices); int comps = countComponentsInSubgraph(graph, vertices); return edges - vertices.size() + comps; @@ -340,17 +340,17 @@ public static int cycleRankOfSubgraph( * @param graph the graph to copy * @return a new graph with identical structure */ - public static Graph copyGraph(Graph graph) { - Graph copy = new UndirectedSparseGraph(); + public static Graph copyGraph(Graph graph) { + Graph copy = new UndirectedSparseGraph(); for (String v : graph.getVertices()) { copy.addVertex(v); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String v1 = it.next(); String v2 = it.next(); - edge newEdge = new edge(e.getType(), v1, v2); + Edge newEdge = new Edge(e.getType(), v1, v2); newEdge.setWeight(e.getWeight()); newEdge.setLabel(e.getLabel()); copy.addEdge(newEdge, v1, v2); @@ -372,7 +372,7 @@ public static Graph copyGraph(Graph graph) { * @param graph the graph * @return map from vertex ID to betweenness centrality score */ - public static Map computeBetweenness(Graph graph) { + public static Map computeBetweenness(Graph graph) { int n = graph.getVertexCount(); if (n == 0) return Collections.emptyMap(); @@ -477,7 +477,7 @@ public static Map computeBetweenness(Graph graph) * @param graph the graph * @return global efficiency in [0, 1] */ - public static double globalEfficiency(Graph graph) { + public static double globalEfficiency(Graph graph) { int n = graph.getVertexCount(); if (n <= 1) return 0.0; @@ -568,7 +568,7 @@ public DijkstraResult(Map dist, Map prev) { * @param source the source vertex * @return distances and predecessors for all reachable vertices */ - public static DijkstraResult dijkstra(Graph graph, String source) { + public static DijkstraResult dijkstra(Graph graph, String source) { Map dist = new HashMap(); Map prev = new HashMap(); Set visited = new HashSet(); @@ -599,7 +599,7 @@ public static DijkstraResult dijkstra(Graph graph, String source) Double uDist = dist.get(u); if (uDist == null || entryDist > uDist) continue; - for (edge e : graph.getIncidentEdges(u)) { + for (Edge e : graph.getIncidentEdges(u)) { String v = getOtherEnd(e, u); if (v == null || visited.contains(v)) continue; @@ -660,7 +660,7 @@ public static List reconstructPath( * @return neighbors of v, or an empty collection if null */ public static Collection neighborsOf( - Graph graph, String v) { + Graph graph, String v) { Collection nbrs = graph.getNeighbors(v); return nbrs != null ? nbrs : Collections.emptyList(); } @@ -697,7 +697,7 @@ public DirectedAdj(Set vertices, * @return a {@link DirectedAdj} with successor and predecessor maps */ public static DirectedAdj buildDirectedAdjacencyMap( - Graph graph) { + Graph graph) { Map> successors = new HashMap>(); Map> predecessors = new HashMap>(); Set allVertices = new HashSet(); @@ -708,7 +708,7 @@ public static DirectedAdj buildDirectedAdjacencyMap( predecessors.put(v, new HashSet()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String from = e.getVertex1(); String to = e.getVertex2(); if (from != null && to != null diff --git a/Gvisual/src/gvisual/GrowthRateAnalyzer.java b/Gvisual/src/gvisual/GrowthRateAnalyzer.java index c9cd723..12cda18 100644 --- a/Gvisual/src/gvisual/GrowthRateAnalyzer.java +++ b/Gvisual/src/gvisual/GrowthRateAnalyzer.java @@ -4,7 +4,7 @@ import java.util.*; /** - * Tracks how graph metrics change over time: node count, edge count, + * Tracks how graph metrics change over time: node count, Edge count, * density, and average clustering coefficient across time windows. * Useful for identifying growth phases, stability periods, and * network degradation. @@ -66,12 +66,12 @@ public GrowthRateAnalyzer(TemporalGraph temporalGraph, int windowCount) { * @return ordered list of metric snapshots */ public List analyze() { - List>> windows = + List>> windows = temporalGraph.generateWindows(windowCount); List snapshots = new ArrayList<>(); - for (Map.Entry> window : windows) { - Graph g = window.getValue(); + for (Map.Entry> window : windows) { + Graph g = window.getValue(); int nodes = g.getVertexCount(); int edges = g.getEdgeCount(); double density = computeDensity(nodes, edges); @@ -115,7 +115,7 @@ private static double computeDensity(int nodes, int edges) { return edges / maxEdges; } - private static double computeAvgClustering(Graph g) { + private static double computeAvgClustering(Graph g) { if (g.getVertexCount() == 0) return 0.0; Map> adj = GraphUtils.buildAdjacencyMap(g); diff --git a/Gvisual/src/gvisual/HierarchicalLayout.java b/Gvisual/src/gvisual/HierarchicalLayout.java index 2502c94..54fde7e 100644 --- a/Gvisual/src/gvisual/HierarchicalLayout.java +++ b/Gvisual/src/gvisual/HierarchicalLayout.java @@ -55,7 +55,7 @@ public enum Orientation { // ── Configuration ──────────────────────────────────────────────── - private final Graph graph; + private final Graph graph; private final double layerSpacing; private final double nodeSpacing; private final int crossingSweeps; @@ -70,7 +70,7 @@ public enum Orientation { private List> layers; private List criticalPath; private int crossingCount; - private Set reversedEdges; + private Set reversedEdges; private boolean computed; // ── Constructors ───────────────────────────────────────────────── @@ -81,7 +81,7 @@ public enum Orientation { * @param graph the JUNG graph to lay out * @throws IllegalArgumentException if graph is null */ - public HierarchicalLayout(Graph graph) { + public HierarchicalLayout(Graph graph) { this(graph, 120, 80, 24, Orientation.TOP_TO_BOTTOM, 1200, 800); } @@ -97,7 +97,7 @@ public HierarchicalLayout(Graph graph) { * @param height canvas height * @throws IllegalArgumentException if parameters are invalid */ - public HierarchicalLayout(Graph graph, double layerSpacing, + public HierarchicalLayout(Graph graph, double layerSpacing, double nodeSpacing, int crossingSweeps, Orientation orientation, double width, double height) { @@ -147,7 +147,7 @@ public HierarchicalLayout compute() { layers = new ArrayList>(); criticalPath = new ArrayList(); crossingCount = 0; - reversedEdges = new HashSet(); + reversedEdges = new HashSet(); computed = true; return this; } @@ -159,7 +159,7 @@ public HierarchicalLayout compute() { successors.put(v, new HashSet()); predecessors.put(v, new HashSet()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String u = e.getVertex1(); String v = e.getVertex2(); if (u != null && v != null && !u.equals(v) @@ -170,7 +170,7 @@ public HierarchicalLayout compute() { } // Step 1: Cycle removal (greedy DFS-based) - reversedEdges = new HashSet(); + reversedEdges = new HashSet(); Map> dagSuccessors = removeCycles( vertices, successors, predecessors); Map> dagPredecessors = invertAdjacency( @@ -239,7 +239,7 @@ private Map> removeCycles( dag.get(be[1]).add(be[0]); // Track the original edge objects - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (be[0].equals(e.getVertex1()) && be[1].equals(e.getVertex2())) { reversedEdges.add(e); } @@ -496,7 +496,7 @@ private int countEdgeCrossings(Map> succ) { lowerPos.put(lower.get(j), j); } - // Collect edges between these two layers + // Collect Edges between these two layers List edges = new ArrayList(); for (String u : upper) { for (String v : succ.getOrDefault(u, Collections.emptySet())) { @@ -512,7 +512,7 @@ private int countEdgeCrossings(Map> succ) { for (int a = 0; a < edges.size(); a++) { for (int b = a + 1; b < edges.size(); b++) { int u1 = edges.get(a)[0], v1 = edges.get(a)[1]; - int u2 = edges.get(b)[0], v2 = edges.get(b)[1]; + int u2 = edges.get(b)[0], v2 = Edges.get(b)[1]; if ((u1 < u2 && v1 > v2) || (u1 > u2 && v1 < v2)) { crossings++; } @@ -645,7 +645,7 @@ public int getEdgeCrossings() { * @return set of edge objects that were reversed * @throws IllegalStateException if compute() has not been called */ - public Set getReversedEdges() { + public Set getReversedEdges() { ensureComputed(); return Collections.unmodifiableSet(reversedEdges); } @@ -761,7 +761,7 @@ public String toSVG(int svgWidth, int svgHeight, int nodeRadius) { sb.append(" \n"); // Draw edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String u = e.getVertex1(); String v = e.getVertex2(); if (u == null || v == null) continue; diff --git a/Gvisual/src/gvisual/IndependentSetAnalyzer.java b/Gvisual/src/gvisual/IndependentSetAnalyzer.java index 031918b..2a51179 100644 --- a/Gvisual/src/gvisual/IndependentSetAnalyzer.java +++ b/Gvisual/src/gvisual/IndependentSetAnalyzer.java @@ -35,7 +35,7 @@ */ public class IndependentSetAnalyzer { - private final Graph graph; + private final Graph graph; /** * Constructs an analyzer for the given undirected graph. @@ -43,7 +43,7 @@ public class IndependentSetAnalyzer { * @param graph the graph to analyze (should be undirected) * @throws IllegalArgumentException if graph is null */ - public IndependentSetAnalyzer(Graph graph) { + public IndependentSetAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -536,15 +536,15 @@ public Map vertexIndependenceImpact() { Map impact = new LinkedHashMap<>(); for (String v : graph.getVertices()) { // Build subgraph without v - Graph sub = new UndirectedSparseGraph<>(); + Graph sub = new UndirectedSparseGraph<>(); for (String u : graph.getVertices()) { if (!u.equals(v)) sub.addVertex(u); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); if (!v1.equals(v) && !v2.equals(v)) { - sub.addEdge(new edge(e.getType(), v1, v2), v1, v2); + sub.addEdge(new Edge(e.getType(), v1, v2), v1, v2); } } IndependentSetAnalyzer subAnalyzer = new IndependentSetAnalyzer(sub); @@ -610,13 +610,13 @@ public int[] independencePolynomial() { * @return the maximum clique (independent set of complement) */ public Set maximumCliqueViaComplement() { - Graph complement = buildComplement(); + Graph complement = buildComplement(); IndependentSetAnalyzer compAnalyzer = new IndependentSetAnalyzer(complement); return compAnalyzer.exactMaximumIndependentSet(); } - private Graph buildComplement() { - Graph comp = new UndirectedSparseGraph<>(); + private Graph buildComplement() { + Graph comp = new UndirectedSparseGraph<>(); List vertices = new ArrayList<>(graph.getVertices()); for (String v : vertices) comp.addVertex(v); int edgeId = 0; @@ -624,7 +624,7 @@ private Graph buildComplement() { for (int j = i + 1; j < vertices.size(); j++) { String u = vertices.get(i), w = vertices.get(j); if (graph.findEdge(u, w) == null) { - comp.addEdge(new edge("comp_" + (edgeId++), u, w), u, w); + comp.addEdge(new Edge("comp_" + (edgeId++), u, w), u, w); } } } @@ -638,7 +638,7 @@ private Graph buildComplement() { */ public static class IndependentSetReport { public final int vertexCount; - public final int edgeCount; + public final int EdgeCount; public final Set greedyIS; public final Set maximumIS; public final int independenceNumber; @@ -693,7 +693,7 @@ public IndependentSetReport fullReport() { StringBuilder sb = new StringBuilder(); sb.append("=== Independent Set Analysis Report ===\n"); - sb.append(String.format("Graph: %d vertices, %d edges\n", n, m)); + sb.append(String.format("Graph: %d vertices, %d Edges\n", n, m)); sb.append(String.format("Independence number α(G) = %d\n", alpha)); sb.append(String.format("Maximum IS: %s\n", maximum)); sb.append(String.format("Greedy IS size: %d\n", greedy.size())); diff --git a/Gvisual/src/gvisual/InfluenceSpreadSimulator.java b/Gvisual/src/gvisual/InfluenceSpreadSimulator.java index cb41f6d..f0c4cba 100644 --- a/Gvisual/src/gvisual/InfluenceSpreadSimulator.java +++ b/Gvisual/src/gvisual/InfluenceSpreadSimulator.java @@ -45,7 +45,7 @@ public enum NodeState { RECOVERED } - private final Graph graph; + private final Graph graph; private final Random random; /** @@ -71,7 +71,7 @@ public enum NodeState { */ private final Map> predecessorCache; - public InfluenceSpreadSimulator(Graph graph) { + public InfluenceSpreadSimulator(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -82,7 +82,7 @@ public InfluenceSpreadSimulator(Graph graph) { this.predecessorCache = buildPredecessorCache(); } - public InfluenceSpreadSimulator(Graph graph, long seed) { + public InfluenceSpreadSimulator(Graph graph, long seed) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -119,7 +119,7 @@ private Map> buildNeighborCache() { */ private Map buildEdgeWeightCache() { Map cache = new HashMap(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { double w = e.getWeight(); if (w > 0 && w <= 1.0) { Collection endpoints = graph.getEndpoints(e); @@ -153,7 +153,7 @@ private Map> buildPredecessorCache() { // Undirected: predecessors == neighbors return neighborCache; } - DirectedGraph dg = (DirectedGraph) graph; + DirectedGraph dg = (DirectedGraph) graph; Map> cache = new HashMap>(); for (String node : graph.getVertices()) { Collection preds = dg.getPredecessors(node); @@ -201,7 +201,7 @@ public SimulationResult simulateIC(Collection seeds, for (String neighbor : getNeighbors(node)) { if (state.get(neighbor) == NodeState.SUSCEPTIBLE) { double edgeProb = getEdgeProbability(node, neighbor, probability); - if (random.nextDouble() < edgeProb) { + if (random.nextDouble() < EdgeProb) { state.put(neighbor, NodeState.INFECTED); nextInfected.add(neighbor); timeline.add(new InfectionEvent(node, neighbor, round)); @@ -333,7 +333,7 @@ public SimulationResult simulateSIR(Collection seeds, if (state.get(neighbor) == NodeState.SUSCEPTIBLE && !toInfect.contains(neighbor)) { double edgeProb = getEdgeProbability(node, neighbor, infectionRate); - if (random.nextDouble() < edgeProb) { + if (random.nextDouble() < EdgeProb) { toInfect.add(neighbor); infectedBy.put(neighbor, node); } @@ -486,7 +486,7 @@ public VaccinationStrategy findVaccinationTargets(int k) { // of its endpoints is a vaccination target. Counting by degree // double-counts edges where both endpoints are vaccinated. int totalEdgesBlocked = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); boolean blocked = false; for (String ep : endpoints) { diff --git a/Gvisual/src/gvisual/InteractiveHtmlExporter.java b/Gvisual/src/gvisual/InteractiveHtmlExporter.java index 8bd7d9a..856b3e5 100644 --- a/Gvisual/src/gvisual/InteractiveHtmlExporter.java +++ b/Gvisual/src/gvisual/InteractiveHtmlExporter.java @@ -37,7 +37,7 @@ */ public class InteractiveHtmlExporter { - private final Graph graph; + private final Graph graph; private String title = "Graph Visualization"; private String description = ""; private boolean showStats = true; @@ -51,7 +51,7 @@ public class InteractiveHtmlExporter { * Creates an exporter for the given graph. * @param graph the JUNG graph to visualize */ - public InteractiveHtmlExporter(Graph graph) { + public InteractiveHtmlExporter(Graph graph) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); this.graph = graph; } @@ -98,7 +98,7 @@ public String exportToString() { List edgeList = new ArrayList<>(); List edgeTypes = new ArrayList<>(); List edgeWeights = new ArrayList<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 != null && v2 != null && nodeIndex.containsKey(v1) && nodeIndex.containsKey(v2)) { @@ -196,7 +196,7 @@ public String exportToString() { sb.append(",type:\"").append(escJs(edgeTypes.get(i))).append("\""); sb.append(",weight:").append(edgeWeights.get(i)); sb.append("}"); - if (i < edgeList.size() - 1) sb.append(","); + if (i < EdgeList.size() - 1) sb.append(","); sb.append("\n"); } sb.append(" ]\n};\n"); diff --git a/Gvisual/src/gvisual/JsonGraphExporter.java b/Gvisual/src/gvisual/JsonGraphExporter.java index a16b2da..424d1ff 100644 --- a/Gvisual/src/gvisual/JsonGraphExporter.java +++ b/Gvisual/src/gvisual/JsonGraphExporter.java @@ -35,8 +35,8 @@ */ public class JsonGraphExporter { - private final Graph graph; - private final List allEdges; + private final Graph graph; + private final List allEdges; private String timestamp; private String description; private boolean prettyPrint; @@ -48,12 +48,12 @@ public class JsonGraphExporter { * @param graph the JUNG graph to export * @param allEdges all edges (including those not currently visible) */ - public JsonGraphExporter(Graph graph, List allEdges) { + public JsonGraphExporter(Graph graph, List allEdges) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } this.graph = graph; - this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); + this.allEdges = (allEdges != null) ? allEdges : new ArrayList(); this.timestamp = ""; this.description = ""; this.prettyPrint = true; @@ -93,7 +93,7 @@ public String exportToString() { String sep = prettyPrint ? " " : ""; Collection vertices = graph.getVertices(); - Collection edges = graph.getEdges(); + Collection edges = graph.getEdges(); sb.append("{").append(nl); @@ -149,9 +149,9 @@ public String exportToString() { sb.append(",").append(sep).append("\"inDegree\":").append(sep).append(inDeg); sb.append(",").append(sep).append("\"outDegree\":").append(sep).append(outDeg); } - // Count edges by type for this node + // Count Edges by type for this node Map typeCounts = new TreeMap(); - for (edge e : graph.getIncidentEdges(v)) { + for (Edge e : graph.getIncidentEdges(v)) { String type = e.getType() != null ? e.getType() : "unknown"; typeCounts.put(type, typeCounts.containsKey(type) ? typeCounts.get(type) + 1 : 1); } @@ -173,9 +173,9 @@ public String exportToString() { // Links sb.append(indent).append("\"links\":").append(sep).append("[").append(nl); - List sortedEdges = new ArrayList(edges); + List sortedEdges = new ArrayList(edges); for (int i = 0; i < sortedEdges.size(); i++) { - edge e = sortedEdges.get(i); + Edge e = sortedEdges.get(i); sb.append(indent2).append("{"); sb.append("\"source\":").append(sep).append(jsonString(e.getVertex1())).append(",").append(sep); sb.append("\"target\":").append(sep).append(jsonString(e.getVertex2())).append(",").append(sep); diff --git a/Gvisual/src/gvisual/KCoreDecomposition.java b/Gvisual/src/gvisual/KCoreDecomposition.java index 1a18044..9e38d08 100644 --- a/Gvisual/src/gvisual/KCoreDecomposition.java +++ b/Gvisual/src/gvisual/KCoreDecomposition.java @@ -40,7 +40,7 @@ */ public class KCoreDecomposition { - private final Graph graph; + private final Graph graph; private Map coreness; private int degeneracy; private boolean computed; @@ -51,7 +51,7 @@ public class KCoreDecomposition { * @param graph the JUNG graph to decompose * @throws IllegalArgumentException if graph is null */ - public KCoreDecomposition(Graph graph) { + public KCoreDecomposition(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -317,7 +317,7 @@ public List getCoreDensityProfile() { // Count edges within the k-core int edgeCount = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = graph.getEndpoints(e).getFirst(); String v2 = graph.getEndpoints(e).getSecond(); if (coreVertices.contains(v1) && coreVertices.contains(v2)) { diff --git a/Gvisual/src/gvisual/KTrussAnalyzer.java b/Gvisual/src/gvisual/KTrussAnalyzer.java index 227c81c..e1bc48b 100644 --- a/Gvisual/src/gvisual/KTrussAnalyzer.java +++ b/Gvisual/src/gvisual/KTrussAnalyzer.java @@ -37,9 +37,9 @@ */ public class KTrussAnalyzer { - private final Graph graph; - private Map trussNumbers; - private Map triangleSupport; + private final Graph graph; + private Map trussNumbers; + private Map triangleSupport; private int maxTrussNumber; private boolean computed; @@ -48,7 +48,7 @@ public class KTrussAnalyzer { * * @param graph the graph to analyze (treated as undirected) */ - public KTrussAnalyzer(Graph graph) { + public KTrussAnalyzer(Graph graph) { this.graph = graph; this.trussNumbers = new LinkedHashMap<>(); this.triangleSupport = new LinkedHashMap<>(); @@ -70,18 +70,18 @@ private void ensureComputed() { */ private void compute() { // Build adjacency structures for efficient triangle enumeration - Set remainingEdges = new LinkedHashSet<>(graph.getEdges()); + Set remainingEdges = new LinkedHashSet<>(graph.getEdges()); Map> adjacency = buildAdjacency(remainingEdges); - Map> edgeTrianglePartners = new LinkedHashMap<>(); + Map> edgeTrianglePartners = new LinkedHashMap<>(); // Step 1: compute initial triangle support for each edge - for (edge e : remainingEdges) { + for (Edge e : remainingEdges) { triangleSupport.put(e, 0); edgeTrianglePartners.put(e, new LinkedHashSet<>()); } // Find all triangles - for (edge e : remainingEdges) { + for (Edge e : remainingEdges) { String u = getEndpoint1(e); String v = getEndpoint2(e); if (u == null || v == null) continue; @@ -93,8 +93,8 @@ private void compute() { if (neighborsV.contains(w)) { // Triangle u-v-w found triangleSupport.merge(e, 1, Integer::sum); - edge uw = findEdge(remainingEdges, u, w); - edge vw = findEdge(remainingEdges, v, w); + Edge uw = findEdge(remainingEdges, u, w); + Edge vw = findEdge(remainingEdges, v, w); if (uw != null) { triangleSupport.merge(uw, 1, Integer::sum); edgeTrianglePartners.get(e).add(uw); @@ -113,12 +113,12 @@ private void compute() { // but each edge in a triangle gets counted twice for neighbors // Actually, let me recalculate properly using a direct approach triangleSupport.clear(); - for (edge e : remainingEdges) { + for (Edge e : remainingEdges) { triangleSupport.put(e, 0); } // Enumerate triangles properly: for each edge (u,v), count common neighbors - for (edge e : remainingEdges) { + for (Edge e : remainingEdges) { String u = getEndpoint1(e); String v = getEndpoint2(e); if (u == null || v == null) continue; @@ -136,25 +136,25 @@ private void compute() { } // Step 2: Peeling — iteratively remove edges with lowest support - Set active = new LinkedHashSet<>(remainingEdges); - Map support = new LinkedHashMap<>(triangleSupport); + Set active = new LinkedHashSet<>(remainingEdges); + Map support = new LinkedHashMap<>(triangleSupport); int k = 2; while (!active.isEmpty()) { boolean changed = true; while (changed) { changed = false; - Iterator it = active.iterator(); - List toRemove = new ArrayList<>(); + Iterator it = active.iterator(); + List toRemove = new ArrayList<>(); while (it.hasNext()) { - edge e = it.next(); + Edge e = it.next(); if (support.getOrDefault(e, 0) < k - 2) { toRemove.add(e); } } - for (edge e : toRemove) { + for (Edge e : toRemove) { active.remove(e); trussNumbers.put(e, k); changed = true; @@ -164,7 +164,7 @@ private void compute() { String v = getEndpoint2(e); if (u == null || v == null) continue; - for (edge other : active) { + for (Edge other : active) { String ou = getEndpoint1(other); String ov = getEndpoint2(other); if (ou == null || ov == null) continue; @@ -195,8 +195,8 @@ private void compute() { } } - // All remaining edges have support >= k-2, increase k - for (edge e : active) { + // All remaining Edges have support >= k-2, increase k + for (Edge e : active) { trussNumbers.put(e, k + 1); // tentative — will be overwritten if removed later } k++; @@ -217,7 +217,7 @@ private void compute() { * @param e the edge * @return the truss number, or 0 if edge not in graph */ - public int getTrussNumber(edge e) { + public int getTrussNumber(Edge e) { ensureComputed(); return trussNumbers.getOrDefault(e, 0); } @@ -239,13 +239,13 @@ public int getMaxTrussNumber() { * @param k the truss parameter (k ≥ 2) * @return a new graph containing only edges in the k-truss */ - public Graph getKTruss(int k) { + public Graph getKTruss(int k) { ensureComputed(); - Graph subgraph = new UndirectedSparseGraph<>(); + Graph subgraph = new UndirectedSparseGraph<>(); - for (Map.Entry entry : trussNumbers.entrySet()) { + for (Map.Entry entry : trussNumbers.entrySet()) { if (entry.getValue() >= k) { - edge e = entry.getKey(); + Edge e = entry.getKey(); String u = getEndpoint1(e); String v = getEndpoint2(e); if (u != null && v != null) { @@ -280,7 +280,7 @@ public Map getTrussDistribution() { * @param e the edge * @return number of triangles containing this edge */ - public int getTriangleSupport(edge e) { + public int getTriangleSupport(Edge e) { ensureComputed(); return triangleSupport.getOrDefault(e, 0); } @@ -291,10 +291,10 @@ public int getTriangleSupport(edge e) { * * @return map from k to the set of edges in the k-truss but not in the (k+1)-truss */ - public Map> getTrussHierarchy() { + public Map> getTrussHierarchy() { ensureComputed(); - Map> hierarchy = new TreeMap<>(); - for (Map.Entry entry : trussNumbers.entrySet()) { + Map> hierarchy = new TreeMap<>(); + for (Map.Entry entry : trussNumbers.entrySet()) { hierarchy.computeIfAbsent(entry.getValue(), k -> new ArrayList<>()) .add(entry.getKey()); } @@ -323,7 +323,7 @@ public List compareTrussVsCore() { Map vertexTruss = new LinkedHashMap<>(); for (String v : graph.getVertices()) { int maxT = 0; - for (edge e : graph.getIncidentEdges(v)) { + for (Edge e : graph.getIncidentEdges(v)) { maxT = Math.max(maxT, trussNumbers.getOrDefault(e, 0)); } vertexTruss.put(v, maxT); @@ -397,9 +397,9 @@ public String getSummary() { // --- Helper methods --- - private Map> buildAdjacency(Set edges) { + private Map> buildAdjacency(Set edges) { Map> adj = new LinkedHashMap<>(); - for (edge e : edges) { + for (Edge e : edges) { String u = getEndpoint1(e); String v = getEndpoint2(e); if (u != null && v != null) { @@ -410,14 +410,14 @@ private Map> buildAdjacency(Set edges) { return adj; } - private String getEndpoint1(edge e) { + private String getEndpoint1(Edge e) { Collection endpoints = graph.getEndpoints(e); if (endpoints == null || endpoints.isEmpty()) return null; Iterator it = endpoints.iterator(); return it.next(); } - private String getEndpoint2(edge e) { + private String getEndpoint2(Edge e) { Collection endpoints = graph.getEndpoints(e); if (endpoints == null || endpoints.size() < 2) return null; Iterator it = endpoints.iterator(); @@ -425,8 +425,8 @@ private String getEndpoint2(edge e) { return it.next(); } - private edge findEdge(Set edges, String u, String v) { - for (edge e : edges) { + private Edge findEdge(Set edges, String u, String v) { + for (Edge e : edges) { String eu = getEndpoint1(e); String ev = getEndpoint2(e); if ((u.equals(eu) && v.equals(ev)) || (u.equals(ev) && v.equals(eu))) { @@ -436,8 +436,8 @@ private edge findEdge(Set edges, String u, String v) { return null; } - private boolean hasActiveEdge(Set active, String u, String v) { - for (edge e : active) { + private boolean hasActiveEdge(Set active, String u, String v) { + for (Edge e : active) { String eu = getEndpoint1(e); String ev = getEndpoint2(e); if ((u.equals(eu) && v.equals(ev)) || (u.equals(ev) && v.equals(eu))) { diff --git a/Gvisual/src/gvisual/LaplacianBuilder.java b/Gvisual/src/gvisual/LaplacianBuilder.java index 5c3fe82..7df045e 100644 --- a/Gvisual/src/gvisual/LaplacianBuilder.java +++ b/Gvisual/src/gvisual/LaplacianBuilder.java @@ -41,7 +41,7 @@ private LaplacianBuilder() { * @param vertexList ordered list of vertices (defines row/column mapping) * @return n×n adjacency matrix */ - public static double[][] buildAdjacencyMatrix(Graph graph, + public static double[][] buildAdjacencyMatrix(Graph graph, List vertexList) { int n = vertexList.size(); double[][] A = new double[n][n]; @@ -50,7 +50,7 @@ public static double[][] buildAdjacencyMatrix(Graph graph, indexMap.put(vertexList.get(i), i); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -114,7 +114,7 @@ public static double[][] buildLaplacian(double[][] A, int n) { * @param vertexList ordered list of vertices * @return L = D − A */ - public static double[][] buildLaplacian(Graph graph, + public static double[][] buildLaplacian(Graph graph, List vertexList) { double[][] A = buildAdjacencyMatrix(graph, vertexList); return buildLaplacian(A, vertexList.size()); @@ -128,7 +128,7 @@ public static double[][] buildLaplacian(Graph graph, * @param vertices ordered subset of vertices * @return n×n Laplacian for the induced subgraph */ - public static double[][] buildSubgraphLaplacian(Graph graph, + public static double[][] buildSubgraphLaplacian(Graph graph, List vertices) { int n = vertices.size(); Map index = new HashMap<>(); @@ -191,7 +191,7 @@ public static double[][] buildNormalizedLaplacian(double[][] A, int n) { * @param vertexList ordered list of vertices * @return normalized Laplacian matrix */ - public static double[][] buildNormalizedLaplacian(Graph graph, + public static double[][] buildNormalizedLaplacian(Graph graph, List vertexList) { double[][] A = buildAdjacencyMatrix(graph, vertexList); return buildNormalizedLaplacian(A, vertexList.size()); @@ -233,7 +233,7 @@ public static double[][] buildRandomWalkLaplacian(double[][] A, int n) { * @param vertexList ordered list of vertices * @return random walk Laplacian matrix */ - public static double[][] buildRandomWalkLaplacian(Graph graph, + public static double[][] buildRandomWalkLaplacian(Graph graph, List vertexList) { double[][] A = buildAdjacencyMatrix(graph, vertexList); return buildRandomWalkLaplacian(A, vertexList.size()); diff --git a/Gvisual/src/gvisual/LineGraphAnalyzer.java b/Gvisual/src/gvisual/LineGraphAnalyzer.java index 0c9aac8..b14442f 100644 --- a/Gvisual/src/gvisual/LineGraphAnalyzer.java +++ b/Gvisual/src/gvisual/LineGraphAnalyzer.java @@ -31,13 +31,13 @@ */ public class LineGraphAnalyzer { - private final Graph graph; - private Graph lineGraph; - private Map vertexToEdge; + private final Graph graph; + private Graph lineGraph; + private Map vertexToEdge; private Map edgeToVertex; private boolean computed; - public LineGraphAnalyzer(Graph graph) { + public LineGraphAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -53,13 +53,13 @@ private void ensureComputed() { } private void buildLineGraph() { - lineGraph = new UndirectedSparseGraph(); - vertexToEdge = new LinkedHashMap(); + lineGraph = new UndirectedSparseGraph(); + vertexToEdge = new LinkedHashMap(); edgeToVertex = new HashMap(); - List edges = new ArrayList(graph.getEdges()); + List edges = new ArrayList(graph.getEdges()); for (int i = 0; i < edges.size(); i++) { - edge e = edges.get(i); + Edge e = edges.get(i); String label = edgeLabel(e); lineGraph.addVertex(label); vertexToEdge.put(label, e); @@ -68,12 +68,12 @@ private void buildLineGraph() { for (int i = 0; i < edges.size(); i++) { for (int j = i + 1; j < edges.size(); j++) { - edge e1 = edges.get(i); - edge e2 = edges.get(j); + Edge e1 = edges.get(i); + Edge e2 = edges.get(j); if (sharesEndpoint(e1, e2)) { String v1 = edgeToVertex.get(edgeKey(e1)); String v2 = edgeToVertex.get(edgeKey(e2)); - edge lgEdge = new edge("lg", v1, v2); + Edge lgEdge = new Edge("lg", v1, v2); lgEdge.setLabel(v1 + "-" + v2); lineGraph.addEdge(lgEdge, v1, v2); } @@ -81,7 +81,7 @@ private void buildLineGraph() { } } - private String edgeLabel(edge e) { + private String edgeLabel(Edge e) { String v1 = null, v2 = null; Collection endpoints = graph.getEndpoints(e); if (endpoints != null && endpoints.size() == 2) { @@ -98,18 +98,18 @@ private String edgeLabel(edge e) { return "e" + System.identityHashCode(e); } - private String edgeKey(edge e) { + private String edgeKey(Edge e) { return edgeLabel(e); } - private boolean sharesEndpoint(edge e1, edge e2) { + private boolean sharesEndpoint(Edge e1, Edge e2) { String[] ep1 = getEndpoints(e1); String[] ep2 = getEndpoints(e2); return ep1[0].equals(ep2[0]) || ep1[0].equals(ep2[1]) || ep1[1].equals(ep2[0]) || ep1[1].equals(ep2[1]); } - private String[] getEndpoints(edge e) { + private String[] getEndpoints(Edge e) { Collection endpoints = graph.getEndpoints(e); if (endpoints != null && endpoints.size() == 2) { Iterator it = endpoints.iterator(); @@ -122,12 +122,12 @@ private String[] getEndpoints(edge e) { // ── Accessors ─────────────────────────────────────────────────── - public Graph getLineGraph() { + public Graph getLineGraph() { ensureComputed(); return lineGraph; } - public Map getVertexToEdgeMapping() { + public Map getVertexToEdgeMapping() { ensureComputed(); return Collections.unmodifiableMap(vertexToEdge); } @@ -286,12 +286,12 @@ public IteratedResult iteratedLineGraphs(int iterations) { List seq = new ArrayList(); seq.add(new int[]{graph.getVertexCount(), graph.getEdgeCount()}); - Graph current = graph; + Graph current = graph; String convergence = "growing"; for (int i = 0; i < iterations; i++) { if (current.getEdgeCount() == 0) { - convergence = "collapsed (no edges)"; + convergence = "collapsed (no Edges)"; break; } if (current.getEdgeCount() > 10000) { @@ -502,7 +502,7 @@ public Map> vertexEdgeCliques() { for (String v : graph.getVertices()) { Set clique = new TreeSet(); - for (edge e : graph.getIncidentEdges(v)) { + for (Edge e : graph.getIncidentEdges(v)) { String label = edgeToVertex.get(edgeKey(e)); if (label != null) clique.add(label); } diff --git a/Gvisual/src/gvisual/LinkPredictionAnalyzer.java b/Gvisual/src/gvisual/LinkPredictionAnalyzer.java index 950c003..ab08ff9 100644 --- a/Gvisual/src/gvisual/LinkPredictionAnalyzer.java +++ b/Gvisual/src/gvisual/LinkPredictionAnalyzer.java @@ -28,7 +28,7 @@ */ public class LinkPredictionAnalyzer { - private final Graph graph; + private final Graph graph; /** * Create a new link prediction analyzer. @@ -36,7 +36,7 @@ public class LinkPredictionAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public LinkPredictionAnalyzer(Graph graph) { + public LinkPredictionAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/LouvainCommunityDetector.java b/Gvisual/src/gvisual/LouvainCommunityDetector.java index 5beec01..82154af 100644 --- a/Gvisual/src/gvisual/LouvainCommunityDetector.java +++ b/Gvisual/src/gvisual/LouvainCommunityDetector.java @@ -21,14 +21,14 @@ */ public class LouvainCommunityDetector { - private final Graph graph; + private final Graph graph; private final double resolution; - public LouvainCommunityDetector(Graph graph) { + public LouvainCommunityDetector(Graph graph) { this(graph, 1.0); } - public LouvainCommunityDetector(Graph graph, double resolution) { + public LouvainCommunityDetector(Graph graph, double resolution) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); if (resolution <= 0) throw new IllegalArgumentException("Resolution must be positive"); this.graph = graph; @@ -75,7 +75,7 @@ public int compareTo(Community other) { @Override public String toString() { - return String.format("Community %d: %d members, %d internal edges, density=%.4f", + return String.format("Community %d: %d members, %d internal Edges, density=%.4f", id, members.size(), internalEdges, getIntraDensity()); } } @@ -209,7 +209,7 @@ public String generateReport() { } sb.append("Communities (sorted by size):\n"); for (Community c : communities) { - sb.append(String.format(" #%d: %d members, %d internal edges, %d external edges, density=%.4f\n", + sb.append(String.format(" #%d: %d members, %d internal edges, %d external Edges, density=%.4f\n", c.getId(), c.getSize(), c.getInternalEdges(), c.getExternalEdges(), c.getIntraDensity())); } sb.append("\nHierarchy:\n"); @@ -324,8 +324,8 @@ public LouvainResult detect() { cmap.get(cid).members.add(e.getKey()); } - Set counted = new HashSet(); - for (edge e : graph.getEdges()) { + Set counted = new HashSet(); + for (Edge e : graph.getEdges()) { if (counted.contains(e)) continue; counted.add(e); Integer c1 = finalAssign.get(e.getVertex1()); @@ -360,7 +360,7 @@ public LouvainResult detect() { private List> buildAdjacency(Map nodeIndex, int n) { List> adj = new ArrayList>(); for (int i = 0; i < n; i++) adj.add(new HashMap()); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Integer i = nodeIndex.get(e.getVertex1()); Integer j = nodeIndex.get(e.getVertex2()); if (i == null || j == null) continue; @@ -418,7 +418,7 @@ private boolean phase1(List> adj, double[] degree, int curC = community[i]; double ki = degree[i]; - // Aggregate neighbor edge weights by community, reusing nw map + // Aggregate neighbor Edge weights by community, reusing nw map touchedCount = 0; for (Map.Entry e : adj.get(i).entrySet()) { int cj = community[e.getKey()]; diff --git a/Gvisual/src/gvisual/Main.java b/Gvisual/src/gvisual/Main.java index ca70024..594c627 100644 --- a/Gvisual/src/gvisual/Main.java +++ b/Gvisual/src/gvisual/Main.java @@ -65,9 +65,9 @@ public class Main extends JFrame { private String month; private String date; private String timeStamp; - private Graph g; - private VisualizationViewer vv; - private Layout graphLayout; + private Graph g; + private VisualizationViewer vv; + private Layout graphLayout; private final GraphRenderers renderers = new GraphRenderers(); /** @@ -83,11 +83,11 @@ private void syncRenderers() { renderers.setEgoState(egoOverlayActive, egoCenter, egoNeighbors, egoEdges); renderers.setOldVertices(OldVertices); } - private List friendEdges = new ArrayList<>(); - private List fsEdges = new ArrayList<>(); - private List classmateEdges = new ArrayList<>(); - private List strangerEdges = new ArrayList<>(); - private List studyGEdges = new ArrayList<>(); + private List friendEdges = new ArrayList<>(); + private List fsEdges = new ArrayList<>(); + private List classmateEdges = new ArrayList<>(); + private List strangerEdges = new ArrayList<>(); + private List studyGEdges = new ArrayList<>(); private String fileName; private Box parameterSpace; private JPanel notesPanel; @@ -131,7 +131,7 @@ private void syncRenderers() { private String pathSource; private String pathTarget; private Set pathVertices; - private Set pathEdges; + private Set pathEdges; private JPanel pathPanel; private JLabel pathSourceLabel; private JLabel pathTargetLabel; @@ -149,7 +149,7 @@ private void syncRenderers() { private JLabel mstStatsLabel; private JLabel mstComponentsLabel; private boolean mstOverlayActive; - private Set mstEdges; + private Set mstEdges; // --- Centrality analysis fields --- private JPanel centralityPanel; @@ -181,7 +181,7 @@ private void syncRenderers() { private JLabel articulationDetailsLabel; private boolean articulationOverlayActive; private Set articulationPoints; - private Set bridgeEdges; + private Set bridgeEdges; // --- Resilience analysis fields --- private JPanel resiliencePanel; @@ -200,7 +200,7 @@ private void syncRenderers() { private boolean egoOverlayActive; private String egoCenter; private Set egoNeighbors; - private Set egoEdges; + private Set egoEdges; private static final Color[] COMMUNITY_COLORS = { new Color(0, 200, 120), // Emerald green @@ -258,7 +258,7 @@ public Main() throws FileNotFoundException, Exception { * Returns the edge list for the given edge type. * Used to replace the cascading if/else chain in addGraph(). */ - private List getEdgeList(EdgeType type) { + private List getEdgeList(EdgeType type) { switch (type) { case FRIEND: return friendEdges; case CLASSMATE: return classmateEdges; @@ -290,7 +290,7 @@ private boolean isEdgeTypeVisible(String typeCode) { * Create the layout for the graph */ public void createLayout() { - graphLayout = new StaticLayout(g); + graphLayout = new StaticLayout(g); List> clusters = new ArrayList<>(); for (int i = 0; i < 9; i++) { @@ -304,7 +304,7 @@ public void createLayout() { boolean isS = false; boolean isSg = false; int areaId; - for (edge y : g.getOutEdges(x)) { + for (Edge y : g.getOutEdges(x)) { EdgeType type = EdgeType.fromCode(y.getType()); if (type != null) { switch (type) { @@ -469,7 +469,7 @@ private static class CategoryRow { * @return a fully-initialised {@code CategoryRow} */ private CategoryRow createCategoryRow(final EdgeType type, - final List edgeList, + final List edgeList, String labelText, int durMax) { JButton settingsBtn = new JButton(new ImageIcon("./images/settings.png")); @@ -479,9 +479,9 @@ private CategoryRow createCategoryRow(final EdgeType type, cb.setSelected(true); cb.addActionListener(e -> { if (cb.isSelected()) { - for (edge x : edgeList) { g.addEdge(x, x.getVertex1(), x.getVertex2()); } + for (Edge x : edgeList) { g.addEdge(x, x.getVertex1(), x.getVertex2()); } } else { - for (edge x : edgeList) { g.removeEdge(x); } + for (Edge x : edgeList) { g.removeEdge(x); } } imagePanel.setVisible(false); imagePanel.setVisible(true); @@ -609,7 +609,7 @@ public void addGraph() throws ParserConfigurationException, IOException, SAXExce // Populate classified edge lists from parse result for (EdgeType type : EdgeType.values()) { - List list = getEdgeList(type); + List list = getEdgeList(type); if (list != null) { list.clear(); list.addAll(parseResult.getEdges(type)); @@ -617,7 +617,7 @@ public void addGraph() throws ParserConfigurationException, IOException, SAXExce } createLayout(); - vv = new VisualizationViewer(graphLayout); + vv = new VisualizationViewer(graphLayout); vv.setSize(new Dimension(100, 0)); DefaultModalGraphMouse gm = new DefaultModalGraphMouse(); @@ -626,7 +626,7 @@ public void addGraph() throws ParserConfigurationException, IOException, SAXExce vv.setGraphMouse(gm); - Transformer edgeLabel = (edge i) -> { + Transformer edgeLabel = (Edge i) -> { return i.getLabel(); }; @@ -735,7 +735,7 @@ public final void initializePathPanel() { pathSource = null; pathTarget = null; pathVertices = new HashSet(); - pathEdges = new HashSet(); + pathEdges = new HashSet(); pathPanel = new JPanel(); pathPanel.setLayout(new BoxLayout(pathPanel, BoxLayout.Y_AXIS)); @@ -914,7 +914,7 @@ private void computeAndHighlightPath() { String mode = pathByWeight.isSelected() ? "weight-optimal" : "hop-optimal"; StringBuilder edgeTypes = new StringBuilder(); - for (edge e : result.getEdges()) { + for (Edge e : result.getEdges()) { if (edgeTypes.length() > 0) edgeTypes.append("→"); edgeTypes.append(e.getType()); } @@ -1132,7 +1132,7 @@ private void clearCommunityOverlay() { public final void initializeMSTPanel() { mstOverlayActive = false; syncRenderers(); - mstEdges = new HashSet(); + mstEdges = new HashSet(); mstPanel = new JPanel(); mstPanel.setLayout(new BoxLayout(mstPanel, BoxLayout.Y_AXIS)); @@ -1214,12 +1214,12 @@ private void runMSTComputation() { stats.append(String.format("Avg Weight: %.1f
    ", result.getAverageWeight())); if (result.getHeaviestEdge() != null) { - edge heavy = result.getHeaviestEdge(); + Edge heavy = result.getHeaviestEdge(); stats.append(String.format("Bottleneck: %s↔%s (%.1f)
    ", heavy.getVertex1(), heavy.getVertex2(), heavy.getWeight())); } if (result.getLightestEdge() != null) { - edge light = result.getLightestEdge(); + Edge light = result.getLightestEdge(); stats.append(String.format("Lightest: %s↔%s (%.1f)
    ", light.getVertex1(), light.getVertex2(), light.getWeight())); } @@ -1245,7 +1245,7 @@ private void runMSTComputation() { int shown = Math.min(result.getComponents().size(), 6); for (int i = 0; i < shown; i++) { MinimumSpanningTree.MSTComponent comp = result.getComponents().get(i); - comps.append(String.format(" C%d: %d nodes, %d edges, wt=%.1f", + comps.append(String.format(" C%d: %d nodes, %d Edges, wt=%.1f", comp.getId(), comp.getSize(), comp.getEdges().size(), comp.getTotalWeight())); String dominant = comp.getDominantType(); if (dominant != null) { @@ -1753,7 +1753,7 @@ private void runEgoSearch() { } // Collect edges: center-to-neighbor and neighbor-to-neighbor - for (edge e : g.getEdges()) { + for (Edge e : g.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); boolean v1InEgo = v1.equals(egoCenter) || egoNeighbors.contains(v1); @@ -1770,7 +1770,7 @@ private void runEgoSearch() { // Count edge types Map typeCounts = new HashMap<>(); - for (edge e : g.getEdges()) { + for (Edge e : g.getEdges()) { if (e.getVertex1().equals(egoCenter) || e.getVertex2().equals(egoCenter)) { String typeLabel = e.getType(); EdgeType et = EdgeType.fromCode(e.getType()); @@ -2257,7 +2257,7 @@ private void paintCategoryPanel() { /** * initialize the category panel — creates one {@link CategoryRow} - * per edge type using the shared {@code createCategoryRow()} helper. + * per Edge type using the shared {@code createCategoryRow()} helper. */ public final void initializeCategoryPanel() { categoryRows = new CategoryRow[5]; @@ -2484,7 +2484,7 @@ public final void initializeToolBar() { if (fc.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return; try { GraphFileParser.ParseResult parseResult = GraphFileParser.parse(fc.getSelectedFile().getAbsolutePath()); - Graph graphB = parseResult.getGraph(); + Graph graphB = parseResult.getGraph(); GraphDiffHtmlExporter exporter = new GraphDiffHtmlExporter(g, graphB); exporter.setTitle("Graph Diff: current vs " + fc.getSelectedFile().getName()); exporter.setLabelA("Current Graph"); @@ -2532,10 +2532,10 @@ public final void initializeToolBar() { * Collects all edges from every category into a single list. * Replaces the 5-line addAll() pattern duplicated across export handlers. */ - private List collectAllEdges() { - List allEdges = new ArrayList<>(); + private List collectAllEdges() { + List allEdges = new ArrayList<>(); for (EdgeType type : EdgeType.values()) { - List list = getEdgeList(type); + List list = getEdgeList(type); if (list != null) { allEdges.addAll(list); } diff --git a/Gvisual/src/gvisual/MaxCutAnalyzer.java b/Gvisual/src/gvisual/MaxCutAnalyzer.java index b1151d4..f08350f 100644 --- a/Gvisual/src/gvisual/MaxCutAnalyzer.java +++ b/Gvisual/src/gvisual/MaxCutAnalyzer.java @@ -38,11 +38,11 @@ */ public class MaxCutAnalyzer { - private final Graph graph; + private final Graph graph; private static final int EXACT_LIMIT = 20; private static final int RANDOM_RESTARTS = 25; - public MaxCutAnalyzer(Graph graph) { + public MaxCutAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -54,20 +54,20 @@ public static class CutResult { private final Set setT; private final double cutValue; private final int cutEdgeCount; - private final List cutEdges; + private final List cutEdges; private final String algorithm; private final int totalEdges; private final double cutRatio; public CutResult(Set setS, Set setT, double cutValue, int cutEdgeCount, - List cutEdges, String algorithm, + List cutEdges, String algorithm, int totalEdges) { this.setS = Collections.unmodifiableSet(new LinkedHashSet(setS)); this.setT = Collections.unmodifiableSet(new LinkedHashSet(setT)); this.cutValue = cutValue; this.cutEdgeCount = cutEdgeCount; - this.cutEdges = Collections.unmodifiableList(new ArrayList(cutEdges)); + this.cutEdges = Collections.unmodifiableList(new ArrayList(cutEdges)); this.algorithm = algorithm; this.totalEdges = totalEdges; this.cutRatio = totalEdges > 0 ? (double) cutEdgeCount / totalEdges : 0.0; @@ -77,7 +77,7 @@ public CutResult(Set setS, Set setT, public Set getSetT() { return setT; } public double getCutValue() { return cutValue; } public int getCutEdgeCount() { return cutEdgeCount; } - public List getCutEdges() { return cutEdges; } + public List getCutEdges() { return cutEdges; } public String getAlgorithm() { return algorithm; } public int getTotalEdges() { return totalEdges; } public double getCutRatio() { return cutRatio; } @@ -186,7 +186,7 @@ public double computeUpperBound() { int n = graph.getVertexCount(); if (n <= 1 || edgeCount == 0) return 0.0; double totalWeight = 0; - for (edge e : graph.getEdges()) totalWeight += Math.max(e.getWeight(), 1.0f); + for (Edge e : graph.getEdges()) totalWeight += Math.max(e.getWeight(), 1.0f); // Edwards bound is a guaranteed lower bound, not an upper bound. // The trivial upper bound is total edge weight (every edge cut). return totalWeight; @@ -195,13 +195,13 @@ public double computeUpperBound() { public double computeLowerBound() { int edgeCount = graph.getEdgeCount(); if (edgeCount == 0) return 0.0; - return (double) edgeCount / 2.0; + return (double) EdgeCount / 2.0; } public Map computeVertexContributions(CutResult result) { Map contributions = new LinkedHashMap(); for (String v : graph.getVertices()) contributions.put(v, 0); - for (edge e : result.getCutEdges()) { + for (Edge e : result.getCutEdges()) { String v1 = e.getVertex1(), v2 = e.getVertex2(); if (contributions.containsKey(v1)) contributions.put(v1, contributions.get(v1) + 1); if (contributions.containsKey(v2)) contributions.put(v2, contributions.get(v2) + 1); @@ -337,9 +337,9 @@ private int countNeighborsIn(String v, Set set) { private double weightedNeighborsIn(String v, Set set) { double total = 0; - Collection incidentEdges = graph.getIncidentEdges(v); + Collection incidentEdges = graph.getIncidentEdges(v); if (incidentEdges != null) { - for (edge e : incidentEdges) { + for (Edge e : incidentEdges) { String other = GraphUtils.getOtherEnd(e, v); if (other != null && set.contains(other)) total += Math.max(e.getWeight(), 1.0f); } @@ -370,7 +370,7 @@ private CutResult refineByFlipping(Set setS, Set setT, String al private double evaluateCutByMask(List vertexList, long mask) { double cutValue = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { int i1 = vertexList.indexOf(e.getVertex1()), i2 = vertexList.indexOf(e.getVertex2()); if (i1 < 0 || i2 < 0) continue; if (((mask & (1L << i1)) != 0) != ((mask & (1L << i2)) != 0)) @@ -381,8 +381,8 @@ private double evaluateCutByMask(List vertexList, long mask) { private CutResult buildResult(Set setS, Set setT, String algorithm) { double cutValue = 0; int cutEdgeCount = 0; - List cutEdges = new ArrayList(); - for (edge e : graph.getEdges()) { + List cutEdges = new ArrayList(); + for (Edge e : graph.getEdges()) { if (setS.contains(e.getVertex1()) != setS.contains(e.getVertex2())) { cutEdges.add(e); cutEdgeCount++; cutValue += Math.max(e.getWeight(), 1.0f); @@ -393,6 +393,6 @@ private CutResult buildResult(Set setS, Set setT, String algorit private CutResult emptyCut(String algorithm) { return new CutResult(new LinkedHashSet(), new LinkedHashSet(), - 0.0, 0, new ArrayList(), algorithm, 0); + 0.0, 0, new ArrayList(), algorithm, 0); } } diff --git a/Gvisual/src/gvisual/MetricDimensionAnalyzer.java b/Gvisual/src/gvisual/MetricDimensionAnalyzer.java index 258553a..700c1d3 100644 --- a/Gvisual/src/gvisual/MetricDimensionAnalyzer.java +++ b/Gvisual/src/gvisual/MetricDimensionAnalyzer.java @@ -57,7 +57,7 @@ */ public class MetricDimensionAnalyzer { - private final Graph graph; + private final Graph graph; private List vertices; private int n; private int[][] dist; @@ -73,7 +73,7 @@ public class MetricDimensionAnalyzer { /** Maximum vertex count for exact computation. */ private static final int EXACT_LIMIT = 30; - public MetricDimensionAnalyzer(Graph graph) { + public MetricDimensionAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/MinimumSpanningTree.java b/Gvisual/src/gvisual/MinimumSpanningTree.java index 5441c97..7d87ec8 100644 --- a/Gvisual/src/gvisual/MinimumSpanningTree.java +++ b/Gvisual/src/gvisual/MinimumSpanningTree.java @@ -15,7 +15,7 @@ *

    Features:

    *
      *
    • Kruskal's algorithm with path compression + union by rank
    • - *
    • MST statistics (total weight, edge count, component count)
    • + *
    • MST statistics (total weight, Edge count, component count)
    • *
    • Per-component breakdown (vertices, edges, weight)
    • *
    • Edge type distribution within the MST
    • *
    • Programmatic API for all results
    • @@ -23,7 +23,7 @@ */ public class MinimumSpanningTree { - private final Graph graph; + private final Graph graph; /** * Create a new MST analyzer for the given graph. @@ -31,7 +31,7 @@ public class MinimumSpanningTree { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public MinimumSpanningTree(Graph graph) { + public MinimumSpanningTree(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -49,31 +49,31 @@ public MSTResult compute() { if (vertexCount == 0) { return new MSTResult( - Collections.emptyList(), + Collections.emptyList(), Collections.emptyList(), 0, 0.0f, 0, vertexCount); } // Collect all edges and sort by weight (Kruskal's) - List sortedEdges = new ArrayList(); - Set seen = new HashSet(); - for (edge e : graph.getEdges()) { + List sortedEdges = new ArrayList(); + Set seen = new HashSet(); + for (Edge e : graph.getEdges()) { if (!seen.contains(e)) { sortedEdges.add(e); seen.add(e); } } - Collections.sort(sortedEdges, (edge a, edge b) -> { + Collections.sort(sortedEdges, (Edge a, Edge b) -> { return Float.compare(a.getWeight(), b.getWeight()); }); // Union-Find UnionFind uf = new UnionFind(vertices); - List mstEdges = new ArrayList(); + List mstEdges = new ArrayList(); float totalWeight = 0.0f; - for (edge e : sortedEdges) { + for (Edge e : sortedEdges) { String u = e.getVertex1(); String v = e.getVertex2(); if (!uf.find(u).equals(uf.find(v))) { @@ -96,12 +96,12 @@ public MSTResult compute() { } // Map edges to their component - Map> rootToEdges = new LinkedHashMap>(); - for (edge e : mstEdges) { + Map> rootToEdges = new LinkedHashMap>(); + for (Edge e : mstEdges) { String root = uf.find(e.getVertex1()); - List compEdges = rootToEdges.get(root); + List compEdges = rootToEdges.get(root); if (compEdges == null) { - compEdges = new ArrayList(); + compEdges = new ArrayList(); rootToEdges.put(root, compEdges); } compEdges.add(e); @@ -119,11 +119,11 @@ public MSTResult compute() { for (Map.Entry> entry : sortedComps) { String root = entry.getKey(); List members = entry.getValue(); - List compEdges = rootToEdges.get(root); - if (compEdges == null) compEdges = Collections.emptyList(); + List compEdges = rootToEdges.get(root); + if (compEdges == null) compEdges = Collections.emptyList(); float compWeight = 0.0f; - for (edge e : compEdges) { + for (Edge e : compEdges) { compWeight += e.getWeight(); } @@ -204,14 +204,14 @@ void union(String a, String b) { * Complete MST computation result. */ public static class MSTResult { - private final List edges; + private final List edges; private final List components; private final int componentCount; private final float totalWeight; private final int edgeCount; private final int vertexCount; - MSTResult(List edges, List components, + MSTResult(List edges, List components, int componentCount, float totalWeight, int edgeCount, int vertexCount) { this.edges = Collections.unmodifiableList(edges); this.components = Collections.unmodifiableList(components); @@ -222,7 +222,7 @@ public static class MSTResult { } /** All MST edges. */ - public List getEdges() { return edges; } + public List getEdges() { return edges; } /** Per-component breakdown. */ public List getComponents() { return components; } @@ -250,11 +250,11 @@ public boolean isConnected() { /** * Get edge type distribution in the MST. * - * @return map of edge type → count + * @return map of Edge type → count */ public Map getEdgeTypeDistribution() { Map dist = new LinkedHashMap(); - for (edge e : edges) { + for (Edge e : edges) { String type = e.getType(); if (type == null) type = "unknown"; Integer count = dist.get(type); @@ -282,9 +282,9 @@ public String getSummary() { * * @return the heaviest edge, or null if MST is empty */ - public edge getHeaviestEdge() { - edge heaviest = null; - for (edge e : edges) { + public Edge getHeaviestEdge() { + Edge heaviest = null; + for (Edge e : edges) { if (heaviest == null || e.getWeight() > heaviest.getWeight()) { heaviest = e; } @@ -297,9 +297,9 @@ public edge getHeaviestEdge() { * * @return the lightest edge, or null if MST is empty */ - public edge getLightestEdge() { - edge lightest = null; - for (edge e : edges) { + public Edge getLightestEdge() { + Edge lightest = null; + for (Edge e : edges) { if (lightest == null || e.getWeight() < lightest.getWeight()) { lightest = e; } @@ -314,7 +314,7 @@ public edge getLightestEdge() { */ public float getAverageWeight() { if (edgeCount == 0) return 0.0f; - return totalWeight / edgeCount; + return totalWeight / EdgeCount; } } @@ -324,10 +324,10 @@ public float getAverageWeight() { public static class MSTComponent { private final int id; private final List vertices; - private final List edges; + private final List edges; private final float totalWeight; - MSTComponent(int id, List vertices, List edges, float totalWeight) { + MSTComponent(int id, List vertices, List edges, float totalWeight) { this.id = id; this.vertices = Collections.unmodifiableList(vertices); this.edges = Collections.unmodifiableList(edges); @@ -341,7 +341,7 @@ public static class MSTComponent { public List getVertices() { return vertices; } /** MST edges in this component. */ - public List getEdges() { return edges; } + public List getEdges() { return edges; } /** Total weight of MST edges in this component. */ public float getTotalWeight() { return totalWeight; } @@ -356,7 +356,7 @@ public static class MSTComponent { */ public String getDominantType() { Map counts = new HashMap(); - for (edge e : edges) { + for (Edge e : edges) { String type = e.getType(); if (type == null) type = "unknown"; Integer c = counts.get(type); diff --git a/Gvisual/src/gvisual/MotifAnalyzer.java b/Gvisual/src/gvisual/MotifAnalyzer.java index c898108..58a8a48 100644 --- a/Gvisual/src/gvisual/MotifAnalyzer.java +++ b/Gvisual/src/gvisual/MotifAnalyzer.java @@ -37,7 +37,7 @@ */ public class MotifAnalyzer { - private final Graph graph; + private final Graph graph; private Map> neighborCache; private boolean computed; @@ -61,7 +61,7 @@ public class MotifAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public MotifAnalyzer(Graph graph) { + public MotifAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -138,7 +138,7 @@ private void countTrianglesAndWedges(List vertices) { for (int i = 0; i < nList.size(); i++) { for (int j = i + 1; j < nList.size(); j++) { - localWedges++; + localWEdges++; String a = nList.get(i); String b = nList.get(j); Set aN = neighborCache.get(a); @@ -406,7 +406,7 @@ public int getPathCount() { /** * Returns the global clustering coefficient (3 × triangles / wedges). - * Ranges from 0.0 (no clustering) to 1.0 (every wedge is closed). + * Ranges from 0.0 (no clustering) to 1.0 (every wEdge is closed). * @return clustering coefficient */ public double getClusteringCoefficient() { diff --git a/Gvisual/src/gvisual/NetworkFlowAnalyzer.java b/Gvisual/src/gvisual/NetworkFlowAnalyzer.java index 87a636b..722936c 100644 --- a/Gvisual/src/gvisual/NetworkFlowAnalyzer.java +++ b/Gvisual/src/gvisual/NetworkFlowAnalyzer.java @@ -38,7 +38,7 @@ */ public class NetworkFlowAnalyzer { - private final Graph graph; + private final Graph graph; // Residual capacities: directedKey -> remaining capacity private Map, Double> residualCapacity; @@ -49,7 +49,7 @@ public class NetworkFlowAnalyzer { // Original capacities private Map, Double> capacity; // Edge lookup: directedKey -> original edge (null for reverse arcs) - private Map, edge> edgeLookup; + private Map, Edge> edgeLookup; private String source; private String sink; @@ -63,7 +63,7 @@ public class NetworkFlowAnalyzer { * two directed arcs) * @throws IllegalArgumentException if graph is null */ - public NetworkFlowAnalyzer(Graph graph) { + public NetworkFlowAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -172,7 +172,7 @@ public String getSink() { public Map getEdgeFlows() { ensureComputed(); Map result = new LinkedHashMap(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { List fwd = directedKey(e.getVertex1(), e.getVertex2()); List rev = directedKey(e.getVertex2(), e.getVertex1()); @@ -240,14 +240,14 @@ private Set findReachableFromSource() { * * @return list of edges in the minimum cut */ - public List getMinCut() { + public List getMinCut() { ensureComputed(); Set reachable = findReachableFromSource(); // Min cut edges: original edges with one end in reachable, other not - List cut = new ArrayList(); - for (edge e : graph.getEdges()) { + List cut = new ArrayList(); + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if ((reachable.contains(v1) && !reachable.contains(v2)) || @@ -275,10 +275,10 @@ public Set getSourceSide() { * * @return list of bottleneck edges */ - public List getBottleneckEdges() { + public List getBottleneckEdges() { ensureComputed(); - List bottlenecks = new ArrayList(); - for (edge e : graph.getEdges()) { + List bottlenecks = new ArrayList(); + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); double cap = getEdgeCapacity(e); @@ -302,7 +302,7 @@ public List getBottleneckEdges() { public double getTotalCapacity() { ensureComputed(); double total = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { total += getEdgeCapacity(e); } return total; @@ -317,7 +317,7 @@ public double getTotalCapacity() { public double getUtilisation() { ensureComputed(); double sourceCapacity = 0; - for (edge e : graph.getIncidentEdges(source)) { + for (Edge e : graph.getIncidentEdges(source)) { sourceCapacity += getEdgeCapacity(e); } if (sourceCapacity <= 0) return 0; @@ -486,8 +486,8 @@ public FlowResult(String source, String sink, double maxFlow, public FlowResult getResult() { ensureComputed(); List paths = decomposeFlowPaths(); - List minCut = getMinCut(); - List bottlenecks = getBottleneckEdges(); + List minCut = getMinCut(); + List bottlenecks = getBottleneckEdges(); return new FlowResult( source, sink, maxFlowValue, getTotalCapacity(), getUtilisation(), @@ -508,8 +508,8 @@ public String getSummary() { // Compute expensive results once List paths = decomposeFlowPaths(); - List minCut = getMinCut(); - List bottlenecks = getBottleneckEdges(); + List minCut = getMinCut(); + List bottlenecks = getBottleneckEdges(); StringBuilder sb = new StringBuilder(); sb.append("=== Network Flow Analysis ===\n"); @@ -533,7 +533,7 @@ public String getSummary() { Map edgeFlows = getEdgeFlows(); if (!edgeFlows.isEmpty()) { sb.append("\n--- Edge flows ---\n"); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); List fwdKey = directedKey(v1, v2); @@ -565,14 +565,14 @@ private void buildResidualGraph() { flow = new HashMap, Double>(); residualAdj = new HashMap>(); capacity = new HashMap, Double>(); - edgeLookup = new HashMap, edge>(); + edgeLookup = new HashMap, Edge>(); // Initialise adjacency sets for all vertices for (String v : graph.getVertices()) { residualAdj.put(v, new LinkedHashSet()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); double cap = getEdgeCapacity(e); @@ -634,7 +634,7 @@ private double bfsAugmentingPath(Map parent, return 0; // no augmenting path } - private double getEdgeCapacity(edge e) { + private double getEdgeCapacity(Edge e) { float w = e.getWeight(); return w > 0 ? w : 1.0; } diff --git a/Gvisual/src/gvisual/NetworkReportGenerator.java b/Gvisual/src/gvisual/NetworkReportGenerator.java index b0a7514..aa15351 100644 --- a/Gvisual/src/gvisual/NetworkReportGenerator.java +++ b/Gvisual/src/gvisual/NetworkReportGenerator.java @@ -33,26 +33,26 @@ */ public class NetworkReportGenerator { - private final Graph graph; - private final List friendEdges; - private final List fsEdges; - private final List classmateEdges; - private final List strangerEdges; - private final List studyGEdges; + private final Graph graph; + private final List friendEdges; + private final List fsEdges; + private final List classmateEdges; + private final List strangerEdges; + private final List studyGEdges; private String title = "Network Analysis Report"; - public NetworkReportGenerator(Graph graph, - List friendEdges, - List fsEdges, - List classmateEdges, - List strangerEdges, - List studyGEdges) { + public NetworkReportGenerator(Graph graph, + List friendEdges, + List fsEdges, + List classmateEdges, + List strangerEdges, + List studyGEdges) { this.graph = graph; - this.friendEdges = friendEdges != null ? friendEdges : Collections.emptyList(); - this.fsEdges = fsEdges != null ? fsEdges : Collections.emptyList(); - this.classmateEdges = classmateEdges != null ? classmateEdges : Collections.emptyList(); - this.strangerEdges = strangerEdges != null ? strangerEdges : Collections.emptyList(); - this.studyGEdges = studyGEdges != null ? studyGEdges : Collections.emptyList(); + this.friendEdges = friendEdges != null ? friendEdges : Collections.emptyList(); + this.fsEdges = fsEdges != null ? fsEdges : Collections.emptyList(); + this.classmateEdges = classmateEdges != null ? classmateEdges : Collections.emptyList(); + this.strangerEdges = strangerEdges != null ? strangerEdges : Collections.emptyList(); + this.studyGEdges = studyGEdges != null ? studyGEdges : Collections.emptyList(); } /** Set the report title. */ @@ -80,7 +80,7 @@ public String generate() { int nodeCount = graph.getVertexCount(); int edgeCount = graph.getEdgeCount(); double density = nodeCount < 2 ? 0.0 : (2.0 * edgeCount) / ((long) nodeCount * (nodeCount - 1)); - double avgDegree = nodeCount == 0 ? 0.0 : (2.0 * edgeCount) / nodeCount; + double avgDegree = nodeCount == 0 ? 0.0 : (2.0 * EdgeCount) / nodeCount; // Degree distribution Map degreeDistribution = new TreeMap(); diff --git a/Gvisual/src/gvisual/NetworkRoleClassifier.java b/Gvisual/src/gvisual/NetworkRoleClassifier.java index 95836c2..d87f877 100644 --- a/Gvisual/src/gvisual/NetworkRoleClassifier.java +++ b/Gvisual/src/gvisual/NetworkRoleClassifier.java @@ -145,7 +145,7 @@ public double getPercentage(StructuralRole role) { // ── Instance fields ───────────────────────────────────────── - private final Graph graph; + private final Graph graph; private final Map roles; private boolean classified; @@ -161,7 +161,7 @@ public double getPercentage(StructuralRole role) { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public NetworkRoleClassifier(Graph graph) { + public NetworkRoleClassifier(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/NodeCentralityAnalyzer.java b/Gvisual/src/gvisual/NodeCentralityAnalyzer.java index f98b8e8..5887bfe 100644 --- a/Gvisual/src/gvisual/NodeCentralityAnalyzer.java +++ b/Gvisual/src/gvisual/NodeCentralityAnalyzer.java @@ -20,7 +20,7 @@ */ public class NodeCentralityAnalyzer { - private final Graph graph; + private final Graph graph; private Map degreeCentrality; private Map betweennessCentrality; private Map closenessCentrality; @@ -32,7 +32,7 @@ public class NodeCentralityAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public NodeCentralityAnalyzer(Graph graph) { + public NodeCentralityAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -409,7 +409,7 @@ private void computeBetweennessAndCloseness() { for (int i = 0; i < n; i++) { adjTmp[i] = new ArrayList(); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Integer ui = idxMap.get(e.getVertex1()); Integer vi = idxMap.get(e.getVertex2()); if (ui != null && vi != null && !ui.equals(vi)) { @@ -525,7 +525,7 @@ private void computeBetweennessAndCloseness() { } } - private String getOtherEnd(edge e, String current) { + private String getOtherEnd(Edge e, String current) { return GraphUtils.getOtherEnd(e, current); } } diff --git a/Gvisual/src/gvisual/NodeSimilarityAnalyzer.java b/Gvisual/src/gvisual/NodeSimilarityAnalyzer.java index 4261c17..4a553a9 100644 --- a/Gvisual/src/gvisual/NodeSimilarityAnalyzer.java +++ b/Gvisual/src/gvisual/NodeSimilarityAnalyzer.java @@ -66,7 +66,7 @@ public String toString() { } } - private final Graph graph; + private final Graph graph; // Cached neighbor sets for performance private final Map> neighborCache; @@ -76,7 +76,7 @@ public String toString() { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public NodeSimilarityAnalyzer(Graph graph) { + public NodeSimilarityAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/PageRankAnalyzer.java b/Gvisual/src/gvisual/PageRankAnalyzer.java index 17238df..fffbd33 100644 --- a/Gvisual/src/gvisual/PageRankAnalyzer.java +++ b/Gvisual/src/gvisual/PageRankAnalyzer.java @@ -40,7 +40,7 @@ public class PageRankAnalyzer { /** Default maximum iterations before stopping. */ public static final int DEFAULT_MAX_ITERATIONS = 100; - private final Graph graph; + private final Graph graph; private final double dampingFactor; private final double tolerance; private final int maxIterations; @@ -56,7 +56,7 @@ public class PageRankAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null */ - public PageRankAnalyzer(Graph graph) { + public PageRankAnalyzer(Graph graph) { this(graph, DEFAULT_DAMPING, DEFAULT_TOLERANCE, DEFAULT_MAX_ITERATIONS); } @@ -67,7 +67,7 @@ public PageRankAnalyzer(Graph graph) { * @param dampingFactor probability of following a link (typically 0.85) * @throws IllegalArgumentException if graph is null or damping factor out of range */ - public PageRankAnalyzer(Graph graph, double dampingFactor) { + public PageRankAnalyzer(Graph graph, double dampingFactor) { this(graph, dampingFactor, DEFAULT_TOLERANCE, DEFAULT_MAX_ITERATIONS); } @@ -80,7 +80,7 @@ public PageRankAnalyzer(Graph graph, double dampingFactor) { * @param maxIterations maximum number of power iterations * @throws IllegalArgumentException if graph is null or parameters out of range */ - public PageRankAnalyzer(Graph graph, double dampingFactor, + public PageRankAnalyzer(Graph graph, double dampingFactor, double tolerance, int maxIterations) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); @@ -217,10 +217,10 @@ public void compute() { boolean[] isDangling = new boolean[n]; for (int i = 0; i < n; i++) { String node = vertexList.get(i); - Collection edges = graph.getIncidentEdges(node); + Collection edges = graph.getIncidentEdges(node); List nodeAdj = new ArrayList(); if (edges != null) { - for (edge e : edges) { + for (Edge e : edges) { String other = getOtherEnd(e, node); if (other != null) { Integer idx = vertexIndex.get(other); @@ -753,7 +753,7 @@ public String toString() { // ──────────────── Private helpers ──────────────── - private String getOtherEnd(edge e, String current) { + private String getOtherEnd(Edge e, String current) { return GraphUtils.getOtherEnd(e, current); } } diff --git a/Gvisual/src/gvisual/PlanarGraphAnalyzer.java b/Gvisual/src/gvisual/PlanarGraphAnalyzer.java index 1e416d4..cd0f0df 100644 --- a/Gvisual/src/gvisual/PlanarGraphAnalyzer.java +++ b/Gvisual/src/gvisual/PlanarGraphAnalyzer.java @@ -184,7 +184,7 @@ public String toText() { * Uses Euler's formula bound (E ≤ 3V - 6) as a quick reject, * then attempts to build a planar embedding via ordered DFS. */ - public static PlanarityResult testPlanarity(Graph graph) { + public static PlanarityResult testPlanarity(Graph graph) { if (graph == null) throw new IllegalArgumentException("graph is null"); int V = graph.getVertexCount(); @@ -197,7 +197,7 @@ public static PlanarityResult testPlanarity(Graph graph) { if (V == 2) { boolean ok = E <= 1; return new PlanarityResult(ok, V, E, C, - ok ? "trivially planar (2 vertices)" : "multi-edge exceeds bound"); + ok ? "trivially planar (2 vertices)" : "multi-Edge exceeds bound"); } // Euler bound: E ≤ 3V - 6 for simple connected planar graph with V≥3 if (V >= 3 && E > 3 * V - 6) { @@ -221,7 +221,7 @@ public static PlanarityResult testPlanarity(Graph graph) { * Enumerates all faces of a planar graph by building a combinatorial * embedding and tracing face-walks. Returns null if non-planar. */ - public static List enumerateFaces(Graph graph) { + public static List enumerateFaces(Graph graph) { PlanarityResult pr = testPlanarity(graph); if (!pr.isPlanar()) return null; @@ -294,7 +294,7 @@ public static List enumerateFaces(Graph graph) { * Each face becomes a node; two nodes are adjacent if their faces * share an edge. */ - public static DualGraph buildDualGraph(Graph graph) { + public static DualGraph buildDualGraph(Graph graph) { List faces = enumerateFaces(graph); if (faces == null) return null; @@ -307,7 +307,7 @@ public static DualGraph buildDualGraph(Graph graph) { String b = verts.get((i + 1) % verts.size()); String edgeKey = makeEdgeKey(a, b); if (!edgeToFaces.containsKey(edgeKey)) { - edgeToFaces.put(edgeKey, new ArrayList()); + edgeToFaces.put(EdgeKey, new ArrayList()); } edgeToFaces.get(edgeKey).add(f.getId()); } @@ -339,7 +339,7 @@ public static DualGraph buildDualGraph(Graph graph) { * Returns null if the graph is planar. */ public static KuratowskiSubgraph findKuratowskiSubgraph( - Graph graph) { + Graph graph) { PlanarityResult pr = testPlanarity(graph); if (pr.isPlanar()) return null; @@ -361,7 +361,7 @@ public static KuratowskiSubgraph findKuratowskiSubgraph( /** * Generates a comprehensive planarity report. */ - public static PlanarityReport analyze(Graph graph) { + public static PlanarityReport analyze(Graph graph) { PlanarityResult result = testPlanarity(graph); List faces = null; DualGraph dual = null; @@ -449,7 +449,7 @@ private static boolean isTriangleFree(Map> adj) { } /** Count connected components via BFS. */ - static int countComponents(Graph graph) { + static int countComponents(Graph graph) { Set visited = new HashSet(); int count = 0; for (String v : graph.getVertices()) { @@ -479,7 +479,7 @@ static int countComponents(Graph graph) { * Uses a proper graph minor / subdivision check approach. */ private static boolean attemptPlanarEmbedding( - Map> adj, Graph graph) { + Map> adj, Graph graph) { // Decompose into biconnected components and test each List> bicomponents = findBiconnectedComponents(adj); @@ -655,7 +655,7 @@ private static boolean tryContractionStrategy(Map> adj, return false; } - /** Contract edge (u,v) by merging v into u. */ + /** Contract Edge (u,v) by merging v into u. */ private static void contractEdge(Map> g, String remove, String keep) { Set removeNbrs = g.get(remove); @@ -762,7 +762,7 @@ private static List> findBiconnectedComponents( Collections.emptyList().iterator()}); } else if (!v.equals(par.get(u)) && disc.get(v) < disc.get(u)) { - edgeStack.push(new String[]{u, v}); + EdgeStack.push(new String[]{u, v}); low.put(u, Math.min(low.get(u), disc.get(v))); } } else { @@ -841,7 +841,7 @@ private static int countDfsChildren(Map> adj, * neighbors by angle. */ private static Map> buildPlanarEmbedding( - Graph graph) { + Graph graph) { Map> embedding = new LinkedHashMap>(); Map> adj = GraphUtils.buildAdjacencyMap(graph); List vertices = new ArrayList(graph.getVertices()); @@ -878,7 +878,7 @@ private static Map> buildPlanarEmbedding( } } - // Attraction along edges + // Attraction along Edges for (String v : vertices) { Set nbrs = adj.get(v); if (nbrs == null) continue; @@ -926,7 +926,7 @@ private static String makeEdgeKey(String a, String b) { /** Try to find a K₅ subdivision by looking for 5 high-degree vertices. */ private static KuratowskiSubgraph findK5Subdivision( - Map> adj, Graph graph) { + Map> adj, Graph graph) { // Find vertices with degree >= 4 as candidates List candidates = new ArrayList(); for (Map.Entry> entry : adj.entrySet()) { @@ -964,7 +964,7 @@ private static KuratowskiSubgraph findK5Subdivision( /** Try to find a K₃,₃ subdivision. */ private static KuratowskiSubgraph findK33Subdivision( - Map> adj, Graph graph) { + Map> adj, Graph graph) { List candidates = new ArrayList(); for (Map.Entry> entry : adj.entrySet()) { if (entry.getValue().size() >= 3) { diff --git a/Gvisual/src/gvisual/RichClubAnalyzer.java b/Gvisual/src/gvisual/RichClubAnalyzer.java index 0a13c26..d7cbd7c 100644 --- a/Gvisual/src/gvisual/RichClubAnalyzer.java +++ b/Gvisual/src/gvisual/RichClubAnalyzer.java @@ -40,7 +40,7 @@ */ public class RichClubAnalyzer { - private final Graph graph; + private final Graph graph; private final Random random; /** @@ -48,7 +48,7 @@ public class RichClubAnalyzer { * @param graph the JUNG graph to analyze * @throws IllegalArgumentException if graph is null or empty */ - public RichClubAnalyzer(Graph graph) { + public RichClubAnalyzer(Graph graph) { this(graph, new Random(42)); } @@ -57,7 +57,7 @@ public RichClubAnalyzer(Graph graph) { * @param graph the JUNG graph to analyze * @param random random number generator for rewiring */ - public RichClubAnalyzer(Graph graph, Random random) { + public RichClubAnalyzer(Graph graph, Random random) { if (graph == null) throw new IllegalArgumentException("Graph must not be null"); if (graph.getVertexCount() == 0) throw new IllegalArgumentException("Graph must not be empty"); if (random == null) throw new IllegalArgumentException("Random must not be null"); @@ -183,7 +183,7 @@ public double internalEdgeFraction(int k) { } /** - * Computes degree assortativity (Pearson correlation of degrees at edge endpoints). + * Computes degree assortativity (Pearson correlation of degrees at Edge endpoints). * Positive values indicate rich-club tendency (hubs connect to hubs). * Negative values indicate disassortative mixing (hubs connect to periphery). * @@ -191,13 +191,13 @@ public double internalEdgeFraction(int k) { */ public double degreeAssortativity() { Map degrees = computeDegrees(); - Collection edges = graph.getEdges(); + Collection edges = graph.getEdges(); if (edges.isEmpty()) return 0.0; double sumXY = 0, sumX = 0, sumY = 0, sumX2 = 0, sumY2 = 0; int m = 0; - for (edge e : edges) { + for (Edge e : edges) { Collection endpoints = graph.getIncidentVertices(e); if (endpoints == null || endpoints.size() != 2) continue; Iterator it = endpoints.iterator(); @@ -302,7 +302,7 @@ private int maxDegree() { private int countInternalEdges(Set memberSet) { int count = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getIncidentVertices(e); if (endpoints == null || endpoints.size() != 2) continue; Iterator it = endpoints.iterator(); @@ -338,7 +338,7 @@ private double richClubCoefficientFromDegrees(Map degrees, int int nk = aboveK.size(); if (nk < 2) return 0.0; - // Expected edges in configuration model among nodes with degree > k: + // Expected Edges in configuration model among nodes with degree > k: // E_rand = (Σ d_i)^2 / (2 × 2M) for the subgroup double sumD = aboveK.stream().mapToDouble(Integer::doubleValue).sum(); double twoM = 2.0 * graph.getEdgeCount(); diff --git a/Gvisual/src/gvisual/ShortestPathFinder.java b/Gvisual/src/gvisual/ShortestPathFinder.java index 8af7497..9a17b44 100644 --- a/Gvisual/src/gvisual/ShortestPathFinder.java +++ b/Gvisual/src/gvisual/ShortestPathFinder.java @@ -15,7 +15,7 @@ */ public class ShortestPathFinder { - private final Graph graph; + private final Graph graph; /** * Creates a new ShortestPathFinder for the given graph. @@ -23,7 +23,7 @@ public class ShortestPathFinder { * @param graph the JUNG graph to search * @throws IllegalArgumentException if graph is null */ - public ShortestPathFinder(Graph graph) { + public ShortestPathFinder(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -36,7 +36,7 @@ public ShortestPathFinder(Graph graph) { */ public static class PathResult { private final List vertices; - private final List edges; + private final List edges; private final double totalWeight; /** @@ -44,9 +44,9 @@ public static class PathResult { * @param edges ordered list of edges along the path * @param totalWeight sum of edge weights along the path */ - public PathResult(List vertices, List edges, double totalWeight) { + public PathResult(List vertices, List edges, double totalWeight) { this.vertices = Collections.unmodifiableList(new ArrayList(vertices)); - this.edges = Collections.unmodifiableList(new ArrayList(edges)); + this.edges = Collections.unmodifiableList(new ArrayList(edges)); this.totalWeight = totalWeight; } @@ -56,7 +56,7 @@ public List getVertices() { } /** Ordered edges from source to target. */ - public List getEdges() { + public List getEdges() { return edges; } @@ -102,13 +102,13 @@ public PathResult findShortestByHops(String source, String target) { if (source.equals(target)) { return new PathResult( Collections.singletonList(source), - Collections.emptyList(), + Collections.emptyList(), 0.0); } // BFS Map predecessor = new HashMap(); - Map predecessorEdge = new HashMap(); + Map predecessorEdge = new HashMap(); Queue queue = new LinkedList(); predecessor.put(source, null); @@ -121,7 +121,7 @@ public PathResult findShortestByHops(String source, String target) { return buildPath(source, target, predecessor, predecessorEdge); } - for (edge e : graph.getIncidentEdges(current)) { + for (Edge e : graph.getIncidentEdges(current)) { String neighbor = getOtherEnd(e, current); if (neighbor != null && !predecessor.containsKey(neighbor)) { predecessor.put(neighbor, current); @@ -154,7 +154,7 @@ public PathResult findShortestByWeight(String source, String target) { if (source.equals(target)) { return new PathResult( Collections.singletonList(source), - Collections.emptyList(), + Collections.emptyList(), 0.0); } @@ -164,7 +164,7 @@ public PathResult findShortestByWeight(String source, String target) { // at insertion time. Stale entries are skipped via the visited set. final Map dist = new HashMap(); Map predecessor = new HashMap(); - Map predecessorEdge = new HashMap(); + Map predecessorEdge = new HashMap(); PriorityQueue pq = new PriorityQueue(11, (double[] a, double[] b) -> { return Double.compare(a[0], b[0]); @@ -195,7 +195,7 @@ public PathResult findShortestByWeight(String source, String target) { return buildPath(source, target, predecessor, predecessorEdge, true); } - for (edge e : graph.getIncidentEdges(current)) { + for (Edge e : graph.getIncidentEdges(current)) { String neighbor = getOtherEnd(e, current); if (neighbor == null || visited.contains(neighbor)) continue; @@ -209,7 +209,7 @@ public PathResult findShortestByWeight(String source, String target) { // Default unset weights (0.0) to 1.0 to match GraphUtils.dijkstra // and prevent zero-weight edges from collapsing all distances. if (edgeWeight == 0) edgeWeight = 1.0; - double newDist = entryDist + edgeWeight; + double newDist = entryDist + EdgeWeight; Double oldDist = dist.get(neighbor); if (oldDist == null || newDist < oldDist) { @@ -248,7 +248,7 @@ public Set getReachableVertices(String source) { while (!queue.isEmpty()) { String current = queue.poll(); - for (edge e : graph.getIncidentEdges(current)) { + for (Edge e : graph.getIncidentEdges(current)) { String neighbor = getOtherEnd(e, current); if (neighbor != null && !reachable.contains(neighbor)) { reachable.add(neighbor); @@ -282,7 +282,7 @@ public boolean areConnected(String source, String target) { while (!queue.isEmpty()) { String current = queue.poll(); - for (edge e : graph.getIncidentEdges(current)) { + for (Edge e : graph.getIncidentEdges(current)) { String neighbor = getOtherEnd(e, current); if (neighbor != null && !visited.contains(neighbor)) { if (neighbor.equals(target)) return true; @@ -307,13 +307,13 @@ private void validateVertex(String vertex, String name) { } } - private String getOtherEnd(edge e, String current) { + private String getOtherEnd(Edge e, String current) { return GraphUtils.getOtherEnd(e, current); } private PathResult buildPath(String source, String target, Map predecessor, - Map predecessorEdge) { + Map predecessorEdge) { return buildPath(source, target, predecessor, predecessorEdge, false); } @@ -326,16 +326,16 @@ private PathResult buildPath(String source, String target, */ private PathResult buildPath(String source, String target, Map predecessor, - Map predecessorEdge, + Map predecessorEdge, boolean normalizeZeroWeights) { List vertices = new ArrayList(); - List edges = new ArrayList(); + List edges = new ArrayList(); double totalWeight = 0; String current = target; while (current != null) { vertices.add(current); - edge e = predecessorEdge.get(current); + Edge e = predecessorEdge.get(current); if (e != null) { edges.add(e); double w = e.getWeight(); diff --git a/Gvisual/src/gvisual/SignedGraphAnalyzer.java b/Gvisual/src/gvisual/SignedGraphAnalyzer.java index 2fd1509..12c909b 100644 --- a/Gvisual/src/gvisual/SignedGraphAnalyzer.java +++ b/Gvisual/src/gvisual/SignedGraphAnalyzer.java @@ -38,7 +38,7 @@ */ public class SignedGraphAnalyzer { - private final Graph graph; + private final Graph graph; /** * Constructs an analyzer for the given graph. @@ -48,7 +48,7 @@ public class SignedGraphAnalyzer { * @param graph the graph to analyze * @throws IllegalArgumentException if graph is null */ - public SignedGraphAnalyzer(Graph graph) { + public SignedGraphAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -61,7 +61,7 @@ public SignedGraphAnalyzer(Graph graph) { * @param e the edge * @return true if edge is negative (weight < 0 or label is "-"/"negative") */ - public boolean isNegative(edge e) { + public boolean isNegative(Edge e) { if (e.getWeight() < 0) return true; String label = e.getLabel(); return label != null && (label.equals("-") || label.equalsIgnoreCase("negative")); @@ -73,7 +73,7 @@ public boolean isNegative(edge e) { * @param e the edge * @return true if edge is positive */ - public boolean isPositive(edge e) { + public boolean isPositive(Edge e) { return !isNegative(e); } @@ -85,7 +85,7 @@ public boolean isPositive(edge e) { */ public int countPositiveEdges() { int count = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (isPositive(e)) count++; } return count; @@ -97,7 +97,7 @@ public int countPositiveEdges() { */ public int countNegativeEdges() { int count = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (isNegative(e)) count++; } return count; @@ -116,20 +116,20 @@ public double negativityRatio() { // ---- Vertex Polarization ---- /** - * Computes per-vertex polarization (fraction of incident edges that are negative). + * Computes per-vertex polarization (fraction of incident Edges that are negative). * * @return map of vertex → polarization (0.0 = all positive, 1.0 = all negative) */ public Map vertexPolarization() { Map result = new LinkedHashMap<>(); for (String v : graph.getVertices()) { - Collection incident = graph.getIncidentEdges(v); + Collection incident = graph.getIncidentEdges(v); if (incident == null || incident.isEmpty()) { result.put(v, 0.0); continue; } long negCount = 0; - for (edge e : incident) { + for (Edge e : incident) { if (isNegative(e)) negCount++; } result.put(v, (double) negCount / incident.size()); @@ -224,12 +224,12 @@ public TriangleCensus triangleCensus() { // Build adjacency for fast lookup Map> adj = new HashMap<>(); - Map> edgeMap = new HashMap<>(); + Map> edgeMap = new HashMap<>(); for (String v : vertices) { adj.put(v, new HashSet<>()); edgeMap.put(v, new HashMap<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -279,13 +279,13 @@ public boolean isStronglyBalanced() { if (graph.getVertexCount() == 0) return true; // BFS/DFS coloring: try to 2-color vertices such that - // positive edges connect same-color and negative edges connect different-color + // positive edges connect same-color and negative Edges connect different-color Map color = new HashMap<>(); List vertices = new ArrayList<>(graph.getVertices()); // Build adjacency Map> adj = buildAdjacency(); - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); for (String start : vertices) { if (color.containsKey(start)) continue; @@ -297,7 +297,7 @@ public boolean isStronglyBalanced() { String u = queue.poll(); int cu = color.get(u); for (String v : adj.getOrDefault(u, Collections.emptyList())) { - edge e = edgeMap.get(u).get(v); + Edge e = edgeMap.get(u).get(v); int expectedColor = isNegative(e) ? (1 - cu) : cu; if (color.containsKey(v)) { if (color.get(v) != expectedColor) return false; @@ -332,9 +332,9 @@ public boolean isWeaklyBalanced() { for (String v : graph.getVertices()) { posAdj.put(v, new ArrayList<>()); } - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (isPositive(e)) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); @@ -365,7 +365,7 @@ public boolean isWeaklyBalanced() { } // Check that all negative edges go between different components - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (isNegative(e)) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); @@ -399,7 +399,7 @@ public List> findCoalitions() { private List> findStrongCoalitions() { Map color = new HashMap<>(); Map> adj = buildAdjacency(); - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); for (String start : graph.getVertices()) { if (color.containsKey(start)) continue; @@ -411,7 +411,7 @@ private List> findStrongCoalitions() { int cu = color.get(u); for (String v : adj.getOrDefault(u, Collections.emptyList())) { if (color.containsKey(v)) continue; - edge e = edgeMap.get(u).get(v); + Edge e = edgeMap.get(u).get(v); color.put(v, isNegative(e) ? (1 - cu) : cu); queue.add(v); } @@ -432,7 +432,7 @@ private List> findWeakCoalitions() { for (String v : graph.getVertices()) { posAdj.put(v, new ArrayList<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (isPositive(e)) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); @@ -495,7 +495,7 @@ private int exactFrustration(List vertices) { Map idx = new HashMap<>(); for (int i = 0; i < n; i++) idx.put(vertices.get(i), i); - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); Map> adj = buildAdjacency(); int bestFrustration = graph.getEdgeCount(); // worst case @@ -504,7 +504,7 @@ private int exactFrustration(List vertices) { int limit = 1 << (n - 1); for (int mask = 0; mask < limit; mask++) { int frustration = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); String u = it.next(); @@ -533,7 +533,7 @@ private int greedyFrustration(List vertices) { // Greedy: start with BFS coloring, count frustrated edges Map color = new HashMap<>(); Map> adj = buildAdjacency(); - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); for (String start : vertices) { if (color.containsKey(start)) continue; @@ -545,7 +545,7 @@ private int greedyFrustration(List vertices) { int cu = color.get(u); for (String v : adj.getOrDefault(u, Collections.emptyList())) { if (color.containsKey(v)) continue; - edge e = edgeMap.get(u).get(v); + Edge e = edgeMap.get(u).get(v); color.put(v, isNegative(e) ? (1 - cu) : cu); queue.add(v); } @@ -553,7 +553,7 @@ private int greedyFrustration(List vertices) { } int frustration = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); String u = it.next(); @@ -573,13 +573,13 @@ private int greedyFrustration(List vertices) { * * @return list of frustrated edges */ - public List findFrustratedEdges() { + public List findFrustratedEdges() { if (graph.getEdgeCount() == 0) return Collections.emptyList(); Map color = computePartition(); - List frustrated = new ArrayList<>(); + List frustrated = new ArrayList<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); String u = it.next(); @@ -596,7 +596,7 @@ public List findFrustratedEdges() { private Map computePartition() { Map color = new HashMap<>(); Map> adj = buildAdjacency(); - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); for (String start : graph.getVertices()) { if (color.containsKey(start)) continue; @@ -608,7 +608,7 @@ private Map computePartition() { int cu = color.get(u); for (String v : adj.getOrDefault(u, Collections.emptyList())) { if (color.containsKey(v)) continue; - edge e = edgeMap.get(u).get(v); + Edge e = edgeMap.get(u).get(v); color.put(v, isNegative(e) ? (1 - cu) : cu); queue.add(v); } @@ -639,7 +639,7 @@ public int predictSign(String u, String v) { throw new IllegalArgumentException("Vertex not found: " + v); } - Map> edgeMap = buildEdgeMap(); + Map> edgeMap = buildEdgeMap(); Set neighborsU = new HashSet<>(edgeMap.getOrDefault(u, Collections.emptyMap()).keySet()); Set neighborsV = new HashSet<>(edgeMap.getOrDefault(v, Collections.emptyMap()).keySet()); @@ -771,7 +771,7 @@ private Map> buildAdjacency() { for (String v : graph.getVertices()) { adj.put(v, new ArrayList<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); String u = it.next(); @@ -782,12 +782,12 @@ private Map> buildAdjacency() { return adj; } - private Map> buildEdgeMap() { - Map> edgeMap = new HashMap<>(); + private Map> buildEdgeMap() { + Map> edgeMap = new HashMap<>(); for (String v : graph.getVertices()) { edgeMap.put(v, new HashMap<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection eps = graph.getEndpoints(e); Iterator it = eps.iterator(); String u = it.next(); diff --git a/Gvisual/src/gvisual/SmallWorldAnalyzer.java b/Gvisual/src/gvisual/SmallWorldAnalyzer.java index 71a839a..9707e48 100644 --- a/Gvisual/src/gvisual/SmallWorldAnalyzer.java +++ b/Gvisual/src/gvisual/SmallWorldAnalyzer.java @@ -47,7 +47,7 @@ */ public class SmallWorldAnalyzer { - private final Graph graph; + private final Graph graph; private boolean computed; // ── Results ───────────────────────────────────────────────────── @@ -69,7 +69,7 @@ public class SmallWorldAnalyzer { * @param graph a JUNG undirected graph * @throws IllegalArgumentException if graph is null */ - public SmallWorldAnalyzer(Graph graph) { + public SmallWorldAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -280,7 +280,7 @@ private void compute() { return; } - double meanDegree = 2.0 * edgeCount / n; + double meanDegree = 2.0 * EdgeCount / n; if (meanDegree < 2) { computeClustering(); avgPathLength = 0; diff --git a/Gvisual/src/gvisual/SpectralAnalyzer.java b/Gvisual/src/gvisual/SpectralAnalyzer.java index 0235a72..9d225e1 100644 --- a/Gvisual/src/gvisual/SpectralAnalyzer.java +++ b/Gvisual/src/gvisual/SpectralAnalyzer.java @@ -49,7 +49,7 @@ public class SpectralAnalyzer { private static final double EPSILON = 1e-10; private static final int MAX_SWEEPS = 100; - private final Graph graph; + private final Graph graph; private boolean computed; // Ordered vertex list (defines row/column mapping) @@ -76,7 +76,7 @@ public class SpectralAnalyzer { * @param graph the JUNG graph to analyse * @throws IllegalArgumentException if graph is null */ - public SpectralAnalyzer(Graph graph) { + public SpectralAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } diff --git a/Gvisual/src/gvisual/SteinerTreeAnalyzer.java b/Gvisual/src/gvisual/SteinerTreeAnalyzer.java index d909c52..f2e6fb2 100644 --- a/Gvisual/src/gvisual/SteinerTreeAnalyzer.java +++ b/Gvisual/src/gvisual/SteinerTreeAnalyzer.java @@ -48,10 +48,10 @@ */ public class SteinerTreeAnalyzer { - private final Graph graph; + private final Graph graph; private int syntheticEdgeId = 0; - public SteinerTreeAnalyzer(Graph graph) { + public SteinerTreeAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -253,7 +253,7 @@ public SteinerTreeResult shortestPathHeuristic(Set terminals) { if (bestPath == null) break; // Remaining terminals unreachable - // Add path edges to tree + // Add path Edges to tree for (int i = 0; i < bestPath.size() - 1; i++) { String u = bestPath.get(i); String v = bestPath.get(i + 1); @@ -325,7 +325,7 @@ public SteinerTreeResult mstHeuristic(Set terminals) { mstEdges.add(new String[]{bestFrom, bestTo}); } - // Map MST edges back to original graph paths + // Map MST Edges back to original graph paths Set treeEdges = new HashSet<>(); Set treeVertices = new HashSet<>(); double totalWeight = 0; @@ -396,7 +396,7 @@ public SteinerTreeResult exact(Set terminals) { verts.add(u); verts.add(v); } verts.removeAll(valid); - return new SteinerTreeResult(valid, verts, edges, w, true, "dreyfus-wagner"); + return new SteinerTreeResult(valid, verts, Edges, w, true, "dreyfus-wagner"); } // Map vertices to indices @@ -415,7 +415,7 @@ public SteinerTreeResult exact(Set terminals) { for (double[] row : dist) Arrays.fill(row, Double.MAX_VALUE / 2); for (int[] row : next) Arrays.fill(row, -1); for (int i = 0; i < V; i++) { dist[i][i] = 0; next[i][i] = i; } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator eit = endpoints.iterator(); String u = eit.next(), v = eit.next(); @@ -523,7 +523,7 @@ private void reconstructDP(double[][] dp, int[][][] parent, double[][] dist, if (splitMask < 0) return; if (splitMask == S) { - // Came from edge relaxation: dp[S][v] = dp[S][splitVert] + dist[splitVert][v] + // Came from Edge relaxation: dp[S][v] = dp[S][splitVert] + dist[splitVert][v] // Add path from splitVert to v addShortestPath(next, splitVert, v, vertList, treeEdges, treeVertices); reconstructDP(dp, parent, dist, next, S, splitVert, vertList, idx, termList, treeEdges, treeVertices); @@ -585,7 +585,7 @@ public SteinerTreeResult solve(Set terminals) { * Finds the bottleneck (heaviest) edge in a Steiner tree. */ public EdgeInfo bottleneckEdge(SteinerTreeResult result) { - return result.edges.stream() + return result.Edges.stream() .max(Comparator.comparingDouble(e -> e.weight)) .orElse(null); } @@ -737,7 +737,7 @@ private String sorted(Set set) { } private double getEdgeWeight(String u, String v) { - edge e = graph.findEdge(u, v); + Edge e = graph.findEdge(u, v); if (e == null) e = graph.findEdge(v, u); if (e == null) return 1.0; return e.getWeight() > 0 ? e.getWeight() : 1.0; @@ -765,7 +765,7 @@ private void pruneTree(Set edges, Set terminals, Set v .filter(e -> e.from.equals(v) || e.to.equals(v)) .count(); if (degree <= 1) { - edges.removeIf(e -> e.from.equals(v) || e.to.equals(v)); + Edges.removeIf(e -> e.from.equals(v) || e.to.equals(v)); it.remove(); changed = true; } diff --git a/Gvisual/src/gvisual/StronglyConnectedComponentsAnalyzer.java b/Gvisual/src/gvisual/StronglyConnectedComponentsAnalyzer.java index f34ab74..03376d4 100644 --- a/Gvisual/src/gvisual/StronglyConnectedComponentsAnalyzer.java +++ b/Gvisual/src/gvisual/StronglyConnectedComponentsAnalyzer.java @@ -37,7 +37,7 @@ */ public class StronglyConnectedComponentsAnalyzer { - private final Graph graph; + private final Graph graph; /** * Create a new SCC analyzer for the given graph. @@ -45,7 +45,7 @@ public class StronglyConnectedComponentsAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public StronglyConnectedComponentsAnalyzer(Graph graph) { + public StronglyConnectedComponentsAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -86,12 +86,12 @@ public String toString() { public static class SCCResult { private final List components; private final Map vertexToComponent; - private final Graph condensation; - private final List bridgeEdges; + private final Graph condensation; + private final List bridgeEdges; private final String algorithm; public SCCResult(List components, Map vertexToComponent, - Graph condensation, List bridgeEdges, String algorithm) { + Graph condensation, List bridgeEdges, String algorithm) { this.components = Collections.unmodifiableList(components); this.vertexToComponent = Collections.unmodifiableMap(vertexToComponent); this.condensation = condensation; @@ -102,8 +102,8 @@ public SCCResult(List components, Map vertexToCompon public List getComponents() { return components; } public int getComponentCount() { return components.size(); } public Map getVertexToComponent() { return vertexToComponent; } - public Graph getCondensation() { return condensation; } - public List getBridgeEdges() { return bridgeEdges; } + public Graph getCondensation() { return condensation; } + public List getBridgeEdges() { return bridgeEdges; } public String getAlgorithm() { return algorithm; } /** Get the component containing a specific vertex. */ @@ -276,7 +276,7 @@ public SCCResult kosaraju() { for (String v : graph.getVertices()) { transpose.put(v, new ArrayList()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String src = getSource(e); String dst = getDest(e); if (src != null && dst != null) { @@ -363,16 +363,16 @@ private SCCResult buildResult(List> rawComponents, String algorithm) } // Build condensation DAG - Graph condensation = new DirectedSparseGraph(); + Graph condensation = new DirectedSparseGraph(); for (Component c : components) { condensation.addVertex("SCC-" + c.getId()); } - List bridgeEdges = new ArrayList(); + List bridgeEdges = new ArrayList(); Set condensationEdgeSet = new HashSet(); int edgeId = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String src = getSource(e); String dst = getDest(e); if (src == null || dst == null) continue; @@ -385,7 +385,7 @@ private SCCResult buildResult(List> rawComponents, String algorithm) String key = srcComp + "->" + dstComp; if (!condensationEdgeSet.contains(key)) { condensationEdgeSet.add(key); - edge ce = new edge("bridge", "SCC-" + srcComp, "SCC-" + dstComp); + Edge ce = new Edge("bridge", "SCC-" + srcComp, "SCC-" + dstComp); ce.setLabel("ce" + edgeId++); condensation.addEdge(ce, "SCC-" + srcComp, "SCC-" + dstComp); } @@ -474,9 +474,9 @@ public int minEdgesToStronglyConnect(SCCResult result) { private List getSuccessors(String v) { List result = new ArrayList(); - Collection outEdges = graph.getOutEdges(v); + Collection outEdges = graph.getOutEdges(v); if (outEdges != null) { - for (edge e : outEdges) { + for (Edge e : outEdges) { String dest = getDest(e); if (dest != null && !dest.equals(v)) { result.add(dest); @@ -489,11 +489,11 @@ private List getSuccessors(String v) { return result; } - private String getSource(edge e) { + private String getSource(Edge e) { return e.getVertex1(); } - private String getDest(edge e) { + private String getDest(Edge e) { return e.getVertex2(); } } diff --git a/Gvisual/src/gvisual/StructuralHoleAnalyzer.java b/Gvisual/src/gvisual/StructuralHoleAnalyzer.java index 2f40a52..1ab7852 100644 --- a/Gvisual/src/gvisual/StructuralHoleAnalyzer.java +++ b/Gvisual/src/gvisual/StructuralHoleAnalyzer.java @@ -50,7 +50,7 @@ */ public class StructuralHoleAnalyzer { - private final Graph graph; + private final Graph graph; private final Map> neighborCache; /** @@ -59,7 +59,7 @@ public class StructuralHoleAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public StructuralHoleAnalyzer(Graph graph) { + public StructuralHoleAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -289,7 +289,7 @@ public List findBridgingEdges() { List bridges = new ArrayList<>(); Set seen = new HashSet<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); if (endpoints == null || endpoints.size() != 2) continue; @@ -563,7 +563,7 @@ Map computePairwiseConstraint(String vertex, Set neighbo if (neighbors.size() <= 1) return neighbors.isEmpty() ? 0.0 : 1.0; // Count neighbor pairs that are NOT connected - // (edges to them are bridging) + // (Edges to them are bridging) int bridgingCount = 0; List nbrList = new ArrayList<>(neighbors); diff --git a/Gvisual/src/gvisual/SubgraphExtractor.java b/Gvisual/src/gvisual/SubgraphExtractor.java index ab92de7..313c3a1 100644 --- a/Gvisual/src/gvisual/SubgraphExtractor.java +++ b/Gvisual/src/gvisual/SubgraphExtractor.java @@ -50,8 +50,8 @@ */ public class SubgraphExtractor { - private final Graph sourceGraph; - private final List allEdges; + private final Graph sourceGraph; + private final List allEdges; // Filter state private final Set allowedEdgeTypes = new HashSet<>(); @@ -72,7 +72,7 @@ public class SubgraphExtractor { * @param graph the source JUNG graph * @param allEdges the full edge list (used for filtering before graph insertion) */ - public SubgraphExtractor(Graph graph, List allEdges) { + public SubgraphExtractor(Graph graph, List allEdges) { if (graph == null) throw new IllegalArgumentException("graph must not be null"); if (allEdges == null) throw new IllegalArgumentException("allEdges must not be null"); this.sourceGraph = graph; @@ -130,7 +130,7 @@ public SubgraphExtractor filterByDegreeRange(Integer minDegree, Integer maxDegre /** * Extract only the k-hop neighborhood around a seed node. - * All other filters still apply to the edges within the neighborhood. + * All other filters still apply to the Edges within the neighborhood. * * @param seed the center node ID * @param k number of hops (1 = immediate neighbors, 2 = neighbors of neighbors, etc.) @@ -191,8 +191,8 @@ public Result extract() { Set candidateNodes = determineCandidateNodes(); // Step 2: Filter edges - List filteredEdges = new ArrayList<>(); - for (edge e : allEdges) { + List filteredEdges = new ArrayList<>(); + for (Edge e : allEdges) { if (!candidateNodes.contains(e.getVertex1()) || !candidateNodes.contains(e.getVertex2())) { continue; } @@ -212,7 +212,7 @@ public Result extract() { } // Step 3: Build subgraph - Graph subgraph = new UndirectedSparseGraph<>(); + Graph subgraph = new UndirectedSparseGraph<>(); // Add all candidate nodes first (unless connectedOnly) if (!connectedOnly) { @@ -221,7 +221,7 @@ public Result extract() { } } - for (edge e : filteredEdges) { + for (Edge e : filteredEdges) { subgraph.addVertex(e.getVertex1()); subgraph.addVertex(e.getVertex2()); subgraph.addEdge(e, e.getVertex1(), e.getVertex2()); @@ -302,12 +302,12 @@ private Set determineCandidateNodes() { * the filtered edge list, and summary statistics. */ public static class Result { - private final Graph graph; - private final List edges; + private final Graph graph; + private final List edges; private final int originalNodeCount; private final int originalEdgeCount; - Result(Graph graph, List edges, + Result(Graph graph, List edges, int originalNodeCount, int originalEdgeCount) { this.graph = graph; this.edges = Collections.unmodifiableList(new ArrayList<>(edges)); @@ -316,12 +316,12 @@ public static class Result { } /** Returns the extracted subgraph. */ - public Graph getGraph() { + public Graph getGraph() { return graph; } /** Returns the filtered edges in the subgraph. */ - public List getEdges() { + public List getEdges() { return edges; } @@ -350,7 +350,7 @@ public double getEdgeRetention() { /** Returns a per-edge-type count breakdown. */ public Map getEdgeTypeBreakdown() { Map breakdown = new TreeMap<>(); - for (edge e : edges) { + for (Edge e : edges) { String type = e.getType(); EdgeType et = EdgeType.fromCode(type); String label = et != null ? et.getDisplayLabel() : type; @@ -396,7 +396,7 @@ public void exportEdgeList(File file) throws IOException { try (PrintWriter pw = new PrintWriter( new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { pw.println("source,target,type,weight,label"); - for (edge e : edges) { + for (Edge e : edges) { pw.printf("%s,%s,%s,%.2f,%s%n", csvEscape(e.getVertex1()), csvEscape(e.getVertex2()), @@ -415,7 +415,7 @@ public void exportEdgeList(File file) throws IOException { public String exportEdgeListToString() { StringBuilder sb = new StringBuilder(); sb.append("source,target,type,weight,label\n"); - for (edge e : edges) { + for (Edge e : edges) { sb.append(String.format("%s,%s,%s,%.2f,%s%n", csvEscape(e.getVertex1()), csvEscape(e.getVertex2()), diff --git a/Gvisual/src/gvisual/SubgraphPatternMatcher.java b/Gvisual/src/gvisual/SubgraphPatternMatcher.java index 463bb15..c27096c 100644 --- a/Gvisual/src/gvisual/SubgraphPatternMatcher.java +++ b/Gvisual/src/gvisual/SubgraphPatternMatcher.java @@ -50,8 +50,8 @@ */ public class SubgraphPatternMatcher { - private final Graph target; - private final Graph pattern; + private final Graph target; + private final Graph pattern; private final boolean degreeConstrained; private final String edgeTypeFilter; private final int maxMatches; @@ -62,8 +62,8 @@ public class SubgraphPatternMatcher { * Fluent builder for configuring a SubgraphPatternMatcher. */ public static class Builder { - private final Graph target; - private final Graph pattern; + private final Graph target; + private final Graph pattern; private boolean degreeConstrained = false; private String edgeTypeFilter = null; private int maxMatches = 10_000; @@ -77,8 +77,8 @@ public static class Builder { * @throws IllegalArgumentException if either is null or pattern is * too small */ - public Builder(Graph target, - Graph pattern) { + public Builder(Graph target, + Graph pattern) { if (target == null) { throw new IllegalArgumentException("Target graph must not be null"); } @@ -107,7 +107,7 @@ public Builder degreeConstrained(boolean dc) { * Null (default) means all edges are considered. */ public Builder edgeTypeFilter(String type) { - this.edgeTypeFilter = type; + this.EdgeTypeFilter = type; return this; } @@ -461,7 +461,7 @@ private Map> buildTargetAdjacency() { for (String v : target.getVertices()) { adj.put(v, new HashSet<>()); } - for (edge e : target.getEdges()) { + for (Edge e : target.getEdges()) { if (edgeTypeFilter != null && !edgeTypeFilter.equals(e.getType())) { continue; @@ -482,7 +482,7 @@ private Map> buildPatternAdjacency() { for (String v : pattern.getVertices()) { adj.put(v, new HashSet<>()); } - for (edge e : pattern.getEdges()) { + for (Edge e : pattern.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (v1 != null && v2 != null) { @@ -498,27 +498,27 @@ private Map> buildPatternAdjacency() { /** * Create a triangle pattern (3 mutually connected nodes). */ - public static Graph trianglePattern() { - Graph g = new UndirectedSparseGraph<>(); + public static Graph trianglePattern() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("P0"); g.addVertex("P1"); g.addVertex("P2"); - g.addEdge(new edge(null, "P0", "P1"), "P0", "P1"); - g.addEdge(new edge(null, "P1", "P2"), "P1", "P2"); - g.addEdge(new edge(null, "P0", "P2"), "P0", "P2"); + g.addEdge(new Edge(null, "P0", "P1"), "P0", "P1"); + g.addEdge(new Edge(null, "P1", "P2"), "P1", "P2"); + g.addEdge(new Edge(null, "P0", "P2"), "P0", "P2"); return g; } /** * Create a square/4-cycle pattern (C4). */ - public static Graph squarePattern() { - Graph g = new UndirectedSparseGraph<>(); + public static Graph squarePattern() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 4; i++) g.addVertex("P" + i); - g.addEdge(new edge(null, "P0", "P1"), "P0", "P1"); - g.addEdge(new edge(null, "P1", "P2"), "P1", "P2"); - g.addEdge(new edge(null, "P2", "P3"), "P2", "P3"); - g.addEdge(new edge(null, "P3", "P0"), "P3", "P0"); + g.addEdge(new Edge(null, "P0", "P1"), "P0", "P1"); + g.addEdge(new Edge(null, "P1", "P2"), "P1", "P2"); + g.addEdge(new Edge(null, "P2", "P3"), "P2", "P3"); + g.addEdge(new Edge(null, "P3", "P0"), "P3", "P0"); return g; } @@ -528,14 +528,14 @@ public static Graph squarePattern() { * * @param k number of leaves (must be ≥ 2) */ - public static Graph starPattern(int k) { + public static Graph starPattern(int k) { if (k < 2) throw new IllegalArgumentException("Star needs >= 2 leaves"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("hub"); for (int i = 0; i < k; i++) { String leaf = "L" + i; g.addVertex(leaf); - g.addEdge(new edge(null, "hub", leaf), "hub", leaf); + g.addEdge(new Edge(null, "hub", leaf), "hub", leaf); } return g; } @@ -545,12 +545,12 @@ public static Graph starPattern(int k) { * * @param n path length (edges), must be ≥ 1 */ - public static Graph pathPattern(int n) { + public static Graph pathPattern(int n) { if (n < 1) throw new IllegalArgumentException("Path length must be >= 1"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i <= n; i++) g.addVertex("P" + i); for (int i = 0; i < n; i++) { - g.addEdge(new edge(null, "P" + i, "P" + (i + 1)), + g.addEdge(new Edge(null, "P" + i, "P" + (i + 1)), "P" + i, "P" + (i + 1)); } return g; @@ -560,15 +560,15 @@ public static Graph pathPattern(int n) { * Create a diamond pattern (K4 minus one edge: 4 nodes, 5 edges). * Shape: two triangles sharing an edge. */ - public static Graph diamondPattern() { - Graph g = new UndirectedSparseGraph<>(); + public static Graph diamondPattern() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 4; i++) g.addVertex("P" + i); // P0-P1, P0-P2, P0-P3, P1-P2, P2-P3 (missing P1-P3) - g.addEdge(new edge(null, "P0", "P1"), "P0", "P1"); - g.addEdge(new edge(null, "P0", "P2"), "P0", "P2"); - g.addEdge(new edge(null, "P0", "P3"), "P0", "P3"); - g.addEdge(new edge(null, "P1", "P2"), "P1", "P2"); - g.addEdge(new edge(null, "P2", "P3"), "P2", "P3"); + g.addEdge(new Edge(null, "P0", "P1"), "P0", "P1"); + g.addEdge(new Edge(null, "P0", "P2"), "P0", "P2"); + g.addEdge(new Edge(null, "P0", "P3"), "P0", "P3"); + g.addEdge(new Edge(null, "P1", "P2"), "P1", "P2"); + g.addEdge(new Edge(null, "P2", "P3"), "P2", "P3"); return g; } @@ -576,17 +576,17 @@ public static Graph diamondPattern() { * Create a bowtie pattern (two triangles sharing one vertex: 5 nodes, * 6 edges). */ - public static Graph bowtiePattern() { - Graph g = new UndirectedSparseGraph<>(); + public static Graph bowtiePattern() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 5; i++) g.addVertex("P" + i); // Triangle 1: P0-P1-P2 - g.addEdge(new edge(null, "P0", "P1"), "P0", "P1"); - g.addEdge(new edge(null, "P1", "P2"), "P1", "P2"); - g.addEdge(new edge(null, "P0", "P2"), "P0", "P2"); + g.addEdge(new Edge(null, "P0", "P1"), "P0", "P1"); + g.addEdge(new Edge(null, "P1", "P2"), "P1", "P2"); + g.addEdge(new Edge(null, "P0", "P2"), "P0", "P2"); // Triangle 2: P0-P3-P4 (P0 is shared) - g.addEdge(new edge(null, "P0", "P3"), "P0", "P3"); - g.addEdge(new edge(null, "P3", "P4"), "P3", "P4"); - g.addEdge(new edge(null, "P0", "P4"), "P0", "P4"); + g.addEdge(new Edge(null, "P0", "P3"), "P0", "P3"); + g.addEdge(new Edge(null, "P3", "P4"), "P3", "P4"); + g.addEdge(new Edge(null, "P0", "P4"), "P0", "P4"); return g; } @@ -595,13 +595,13 @@ public static Graph bowtiePattern() { * * @param n number of nodes (must be ≥ 2) */ - public static Graph completePattern(int n) { + public static Graph completePattern(int n) { if (n < 2) throw new IllegalArgumentException("Complete graph needs >= 2 nodes"); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) g.addVertex("P" + i); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { - g.addEdge(new edge(null, "P" + i, "P" + j), + g.addEdge(new Edge(null, "P" + i, "P" + j), "P" + i, "P" + j); } } @@ -611,17 +611,17 @@ public static Graph completePattern(int n) { /** * Create a house pattern (square + triangle on top: 5 nodes, 6 edges). */ - public static Graph housePattern() { - Graph g = new UndirectedSparseGraph<>(); + public static Graph housePattern() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 5; i++) g.addVertex("P" + i); // Square base: P0-P1-P2-P3 - g.addEdge(new edge(null, "P0", "P1"), "P0", "P1"); - g.addEdge(new edge(null, "P1", "P2"), "P1", "P2"); - g.addEdge(new edge(null, "P2", "P3"), "P2", "P3"); - g.addEdge(new edge(null, "P3", "P0"), "P3", "P0"); + g.addEdge(new Edge(null, "P0", "P1"), "P0", "P1"); + g.addEdge(new Edge(null, "P1", "P2"), "P1", "P2"); + g.addEdge(new Edge(null, "P2", "P3"), "P2", "P3"); + g.addEdge(new Edge(null, "P3", "P0"), "P3", "P0"); // Roof triangle: P2-P4-P3 - g.addEdge(new edge(null, "P2", "P4"), "P2", "P4"); - g.addEdge(new edge(null, "P3", "P4"), "P3", "P4"); + g.addEdge(new Edge(null, "P2", "P4"), "P2", "P4"); + g.addEdge(new Edge(null, "P3", "P4"), "P3", "P4"); return g; } } diff --git a/Gvisual/src/gvisual/SvgExporter.java b/Gvisual/src/gvisual/SvgExporter.java index 84a6939..73b9910 100644 --- a/Gvisual/src/gvisual/SvgExporter.java +++ b/Gvisual/src/gvisual/SvgExporter.java @@ -42,7 +42,7 @@ */ public class SvgExporter { - private final Graph graph; + private final Graph graph; private int width = 800; private int height = 600; private int margin = 60; @@ -82,7 +82,7 @@ public class SvgExporter { * @param graph the JUNG graph to export * @throws IllegalArgumentException if graph is null */ - public SvgExporter(Graph graph) { + public SvgExporter(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -166,16 +166,16 @@ public String exportToString() { maxDegree = Math.max(maxDegree, graph.degree(v)); } float minWeight = Float.MAX_VALUE, maxWeight = Float.MIN_VALUE; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { minWeight = Math.min(minWeight, e.getWeight()); maxWeight = Math.max(maxWeight, e.getWeight()); } if (minWeight == Float.MAX_VALUE) { minWeight = 0; maxWeight = 1; } if (maxWeight <= minWeight) maxWeight = minWeight + 1; - // Collect used edge types + // Collect used Edge types Set usedTypes = new LinkedHashSet<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (e.getType() != null) usedTypes.add(e.getType()); } @@ -232,9 +232,9 @@ public String exportToString() { } // Edges (drawn first, beneath nodes) - sb.append(" \n"); + sb.append(" \n"); Set emitted = new HashSet<>(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); String key = v1.compareTo(v2) < 0 ? v1 + "|" + v2 : v2 + "|" + v1; @@ -256,7 +256,7 @@ public String exportToString() { strokeWidth = 0.5 + ratio * 3.5; } - sb.append(" computeLayout() { } // Attractive forces along edges - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Integer i = index.get(e.getVertex1()); Integer j = index.get(e.getVertex2()); if (i == null || j == null || i.equals(j)) continue; diff --git a/Gvisual/src/gvisual/TemporalGraph.java b/Gvisual/src/gvisual/TemporalGraph.java index d33d1f3..2c2cba6 100644 --- a/Gvisual/src/gvisual/TemporalGraph.java +++ b/Gvisual/src/gvisual/TemporalGraph.java @@ -7,7 +7,7 @@ /** * A lightweight wrapper around a JUNG graph that provides time-windowed views * of the network. This enables temporal analysis without changing any existing - * analyzer — analyzers receive a normal {@code Graph} for a + * analyzer — analyzers receive a normal {@code Graph} for a * specific time window. * *

      Supports three modes of temporal access:

      @@ -25,7 +25,7 @@ */ public class TemporalGraph { - private final Graph fullGraph; + private final Graph fullGraph; /** * Creates a TemporalGraph wrapping an existing JUNG graph. @@ -33,7 +33,7 @@ public class TemporalGraph { * @param graph the full graph containing edges with optional timestamps * @throws IllegalArgumentException if graph is null */ - public TemporalGraph(Graph graph) { + public TemporalGraph(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -45,7 +45,7 @@ public TemporalGraph(Graph graph) { * * @return the full graph */ - public Graph getFullGraph() { + public Graph getFullGraph() { return fullGraph; } @@ -57,9 +57,9 @@ public Graph getFullGraph() { * @param time the point in time (epoch millis) * @return a new graph containing only edges active at {@code time} */ - public Graph snapshotAt(long time) { - Graph snapshot = new UndirectedSparseGraph<>(); - for (edge e : fullGraph.getEdges()) { + public Graph snapshotAt(long time) { + Graph snapshot = new UndirectedSparseGraph<>(); + for (Edge e : fullGraph.getEdges()) { if (e.isActiveAt(time)) { addEdgeToGraph(snapshot, e); } @@ -76,13 +76,13 @@ public Graph snapshotAt(long time) { * @return a new graph containing only edges active during the window * @throws IllegalArgumentException if start > end */ - public Graph windowBetween(long start, long end) { + public Graph windowBetween(long start, long end) { if (start > end) { throw new IllegalArgumentException( "Start time must not be after end time: " + start + " > " + end); } - Graph window = new UndirectedSparseGraph<>(); - for (edge e : fullGraph.getEdges()) { + Graph window = new UndirectedSparseGraph<>(); + for (Edge e : fullGraph.getEdges()) { if (e.isActiveDuring(start, end)) { addEdgeToGraph(window, e); } @@ -98,7 +98,7 @@ public Graph windowBetween(long start, long end) { */ public List getTimePoints() { TreeSet times = new TreeSet<>(); - for (edge e : fullGraph.getEdges()) { + for (Edge e : fullGraph.getEdges()) { if (e.getTimestamp() != null) { times.add(e.getTimestamp()); } @@ -128,7 +128,7 @@ public int getTimePointCount() { * @throws IllegalArgumentException if windowCount < 1 * @throws IllegalStateException if the graph has no timestamped edges */ - public List>> generateWindows(int windowCount) { + public List>> generateWindows(int windowCount) { if (windowCount < 1) { throw new IllegalArgumentException("windowCount must be at least 1"); } @@ -142,7 +142,7 @@ public List>> generateWindows(int windowCoun long maxTime = times.get(times.size() - 1); long windowWidth = Math.max(1, (maxTime - minTime + 1) / windowCount); - List>> windows = new ArrayList<>(); + List>> windows = new ArrayList<>(); for (int i = 0; i < windowCount; i++) { long wStart = minTime + (i * windowWidth); long wEnd = (i == windowCount - 1) ? maxTime : wStart + windowWidth - 1; @@ -156,7 +156,7 @@ public List>> generateWindows(int windowCoun * Adds an edge and its endpoints to a graph, skipping if the edge * or vertices already exist. */ - private void addEdgeToGraph(Graph graph, edge e) { + private void addEdgeToGraph(Graph graph, Edge e) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (!graph.containsVertex(v1)) graph.addVertex(v1); diff --git a/Gvisual/src/gvisual/TopologicalSortAnalyzer.java b/Gvisual/src/gvisual/TopologicalSortAnalyzer.java index 3574df4..901c3b8 100644 --- a/Gvisual/src/gvisual/TopologicalSortAnalyzer.java +++ b/Gvisual/src/gvisual/TopologicalSortAnalyzer.java @@ -31,7 +31,7 @@ */ public class TopologicalSortAnalyzer { - private final Graph graph; + private final Graph graph; /** * Create a new analyzer for the given graph. @@ -39,7 +39,7 @@ public class TopologicalSortAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public TopologicalSortAnalyzer(Graph graph) { + public TopologicalSortAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -117,18 +117,18 @@ public TopologicalSortResult(boolean isDAG, List sortedOrder, */ public static class CycleInfo { private final List vertices; - private final List edges; + private final List edges; - public CycleInfo(List vertices, List edges) { + public CycleInfo(List vertices, List edges) { this.vertices = Collections.unmodifiableList(new ArrayList(vertices)); - this.edges = Collections.unmodifiableList(new ArrayList(edges)); + this.edges = Collections.unmodifiableList(new ArrayList(edges)); } /** Vertices forming the cycle, in traversal order. */ public List getVertices() { return vertices; } /** Edges forming the cycle. */ - public List getEdges() { return edges; } + public List getEdges() { return edges; } /** Number of vertices in the cycle. */ public int size() { return vertices.size(); } @@ -521,7 +521,7 @@ private void dfsCycleDetect(String v, Map> successors, if (color.get(w) == 1) { // Back edge found → extract cycle List cycleVertices = new ArrayList(); - List cycleEdges = new ArrayList(); + List cycleEdges = new ArrayList(); // Find w in the path and extract from there boolean found = false; @@ -534,7 +534,7 @@ private void dfsCycleDetect(String v, Map> successors, for (int i = 0; i < cycleVertices.size(); i++) { String from = cycleVertices.get(i); String to = cycleVertices.get((i + 1) % cycleVertices.size()); - edge e = findEdge(from, to); + Edge e = findEdge(from, to); if (e != null) cycleEdges.add(e); } @@ -568,8 +568,8 @@ private boolean isDuplicateCycle(List existing, List newCycle /** * Find an edge from vertex1 to vertex2 in the graph. */ - private edge findEdge(String from, String to) { - for (edge e : graph.getEdges()) { + private Edge findEdge(String from, String to) { + for (Edge e : graph.getEdges()) { if (from.equals(e.getVertex1()) && to.equals(e.getVertex2())) { return e; } diff --git a/Gvisual/src/gvisual/TournamentAnalyzer.java b/Gvisual/src/gvisual/TournamentAnalyzer.java index 52e734b..8de5c12 100644 --- a/Gvisual/src/gvisual/TournamentAnalyzer.java +++ b/Gvisual/src/gvisual/TournamentAnalyzer.java @@ -43,7 +43,7 @@ */ public class TournamentAnalyzer { - private final Graph graph; + private final Graph graph; private final List vertices; private final Map> beats; // u → set of v where u beats v @@ -53,7 +53,7 @@ public class TournamentAnalyzer { * @param graph the JUNG graph to analyze (must not be null) * @throws IllegalArgumentException if graph is null */ - public TournamentAnalyzer(Graph graph) { + public TournamentAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -71,7 +71,7 @@ private Map> buildAdjacency() { for (String v : vertices) { adj.put(v, new HashSet()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String from = e.getVertex1(); String to = e.getVertex2(); if (from != null && to != null && adj.containsKey(from)) { @@ -94,7 +94,7 @@ public boolean isTournament() { int n = vertices.size(); if (n <= 1) return true; - // A tournament on n vertices has exactly n*(n-1)/2 edges + // A tournament on n vertices has exactly n*(n-1)/2 Edges if (graph.getEdgeCount() != (long) n * (n - 1) / 2) return false; for (int i = 0; i < n; i++) { @@ -134,7 +134,7 @@ public List validate() { if (!uv && !vu) { errors.add("Missing edge between " + u + " and " + v); } else if (uv && vu) { - errors.add("Duplicate edge between " + u + " and " + v); + errors.add("Duplicate Edge between " + u + " and " + v); } } } @@ -800,7 +800,7 @@ private SlaterResult slaterGreedy() { } /** - * Counts disagreements in a linear ordering: number of edges (u→v) + * Counts disagreements in a linear ordering: number of Edges (u→v) * where u appears after v in the ordering. */ private int countDisagreements(List order) { diff --git a/Gvisual/src/gvisual/TreeAnalyzer.java b/Gvisual/src/gvisual/TreeAnalyzer.java index e97f579..20ab823 100644 --- a/Gvisual/src/gvisual/TreeAnalyzer.java +++ b/Gvisual/src/gvisual/TreeAnalyzer.java @@ -35,7 +35,7 @@ */ public class TreeAnalyzer { - private final Graph graph; + private final Graph graph; /** * Create a new tree analyzer for the given graph. @@ -43,7 +43,7 @@ public class TreeAnalyzer { * @param graph the JUNG graph to analyze (should be undirected) * @throws IllegalArgumentException if graph is null */ - public TreeAnalyzer(Graph graph) { + public TreeAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -191,7 +191,7 @@ public String query(String u, String v) { * * @param u first vertex * @param v second vertex - * @return distance (number of edges) between u and v + * @return distance (number of Edges) between u and v */ public int distance(String u, String v) { if (!firstOccurrence.containsKey(u) || !firstOccurrence.containsKey(v)) { @@ -555,7 +555,7 @@ public List encodePrufer() { * * @param sequence the Prüfer sequence * @param vertices the full set of vertex labels - * @return list of edges as [vertex1, vertex2] pairs + * @return list of Edges as [vertex1, vertex2] pairs * @throws IllegalArgumentException if sequence length != vertices.size() - 2 */ public static List decodePrufer(List sequence, List vertices) { diff --git a/Gvisual/src/gvisual/TreewidthAnalyzer.java b/Gvisual/src/gvisual/TreewidthAnalyzer.java index 0335c4f..0320786 100644 --- a/Gvisual/src/gvisual/TreewidthAnalyzer.java +++ b/Gvisual/src/gvisual/TreewidthAnalyzer.java @@ -28,7 +28,7 @@ */ public class TreewidthAnalyzer { - private final Graph graph; + private final Graph graph; /** * A bag in a tree decomposition. @@ -114,7 +114,7 @@ public TreewidthReport() { } } - public TreewidthAnalyzer(Graph graph) { + public TreewidthAnalyzer(Graph graph) { if (graph == null) throw new IllegalArgumentException("Graph cannot be null"); this.graph = graph; } @@ -301,7 +301,7 @@ public int computeDegeneracy() { /** * Computes MMD (minimum maximum degree) lower bound. - * Iteratively contracts the edge with minimum degree endpoint. + * Iteratively contracts the Edge with minimum degree endpoint. */ public int computeMMDLowerBound() { if (graph.getVertexCount() == 0) return 0; @@ -686,7 +686,7 @@ public boolean validateDecomposition(TreeDecomposition td) { } // Check every edge is covered by some bag - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); List epList = new ArrayList<>(endpoints); if (epList.size() != 2) continue; @@ -763,7 +763,7 @@ public String classifyByTreewidth() { } // Complete graph - if (edgeCount == (long) n * (n - 1) / 2) { + if (EdgeCount == (long) n * (n - 1) / 2) { return "complete graph K" + n + " (tw=" + (n - 1) + ")"; } @@ -903,7 +903,7 @@ public String generateTextReport() { sb.append("=== Treewidth Analysis Report ===\n\n"); sb.append("Graph: ").append(graph.getVertexCount()).append(" vertices, ") - .append(graph.getEdgeCount()).append(" edges\n"); + .append(graph.getEdgeCount()).append(" Edges\n"); sb.append("Classification: ").append(report.classification).append("\n\n"); sb.append("--- Bounds ---\n"); diff --git a/Gvisual/src/gvisual/VertexConnectivityAnalyzer.java b/Gvisual/src/gvisual/VertexConnectivityAnalyzer.java index 3d24e3c..5a08cb6 100644 --- a/Gvisual/src/gvisual/VertexConnectivityAnalyzer.java +++ b/Gvisual/src/gvisual/VertexConnectivityAnalyzer.java @@ -43,10 +43,10 @@ */ public class VertexConnectivityAnalyzer { - private final Graph graph; + private final Graph graph; private static final int ALL_CUTS_LIMIT = 20; - public VertexConnectivityAnalyzer(Graph graph) { + public VertexConnectivityAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -60,7 +60,7 @@ public static class ConnectivityResult { private final int edgeConnectivity; private final int minDegree; private final Set minimumVertexCut; - private final Set minimumEdgeCut; + private final Set minimumEdgeCut; private final boolean whitneyHolds; private final int vertexCount; private final int edgeCount; @@ -68,7 +68,7 @@ public static class ConnectivityResult { public ConnectivityResult(int vertexConnectivity, int edgeConnectivity, int minDegree, Set minimumVertexCut, - Set minimumEdgeCut, boolean whitneyHolds, + Set minimumEdgeCut, boolean whitneyHolds, int vertexCount, int edgeCount, boolean isConnected) { this.vertexConnectivity = vertexConnectivity; this.edgeConnectivity = edgeConnectivity; @@ -85,7 +85,7 @@ public ConnectivityResult(int vertexConnectivity, int edgeConnectivity, public int getEdgeConnectivity() { return edgeConnectivity; } public int getMinDegree() { return minDegree; } public Set getMinimumVertexCut() { return minimumVertexCut; } - public Set getMinimumEdgeCut() { return minimumEdgeCut; } + public Set getMinimumEdgeCut() { return minimumEdgeCut; } public boolean isWhitneyHolds() { return whitneyHolds; } public int getVertexCount() { return vertexCount; } public int getEdgeCount() { return edgeCount; } @@ -98,13 +98,13 @@ public static class PairwiseResult { private final int vertexConnectivity; private final int edgeConnectivity; private final Set minimumVertexCut; - private final Set minimumEdgeCut; + private final Set minimumEdgeCut; private final List> vertexDisjointPaths; private final List> edgeDisjointPaths; public PairwiseResult(String source, String target, int vertexConnectivity, int edgeConnectivity, - Set minimumVertexCut, Set minimumEdgeCut, + Set minimumVertexCut, Set minimumEdgeCut, List> vertexDisjointPaths, List> edgeDisjointPaths) { this.source = source; @@ -122,7 +122,7 @@ public PairwiseResult(String source, String target, public int getVertexConnectivity() { return vertexConnectivity; } public int getEdgeConnectivity() { return edgeConnectivity; } public Set getMinimumVertexCut() { return minimumVertexCut; } - public Set getMinimumEdgeCut() { return minimumEdgeCut; } + public Set getMinimumEdgeCut() { return minimumEdgeCut; } public List> getVertexDisjointPaths() { return vertexDisjointPaths; } public List> getEdgeDisjointPaths() { return edgeDisjointPaths; } } @@ -246,7 +246,7 @@ public Set minimumVertexCut() { /** * Find a minimum edge cut set. */ - public Set minimumEdgeCut() { + public Set minimumEdgeCut() { int n = graph.getVertexCount(); if (n <= 1 || !isConnected()) return Collections.emptySet(); @@ -281,7 +281,7 @@ public boolean isKVertexConnected(int k) { */ public boolean isKEdgeConnected(int k) { if (k <= 0) return true; - return edgeConnectivity() >= k; + return EdgeConnectivity() >= k; } /** @@ -297,7 +297,7 @@ public PairwiseResult pairwiseConnectivity(String s, String t) { int vc = maxFlowVertexSplit(s, t); Set vCut = extractVertexCut(s, t); int ec = maxFlowEdge(s, t); - Set eCut = extractEdgeCut(s, t); + Set eCut = extractEdgeCut(s, t); List> vPaths = findVertexDisjointPaths(s, t); List> ePaths = findEdgeDisjointPaths(s, t); @@ -356,7 +356,7 @@ public Map vertexCriticality() { Map criticality = new LinkedHashMap<>(); for (String v : graph.getVertices()) { - Graph reduced = removeVertex(v); + Graph reduced = removeVertex(v); VertexConnectivityAnalyzer sub = new VertexConnectivityAnalyzer(reduced); int subKappa; if (reduced.getVertexCount() <= 1) { @@ -376,10 +376,10 @@ public Map vertexCriticality() { */ public ConnectivityResult analyze() { int kappa = vertexConnectivity(); - int lambda = edgeConnectivity(); + int lambda = EdgeConnectivity(); int delta = minDegree(); Set vCut = minimumVertexCut(); - Set eCut = minimumEdgeCut(); + Set eCut = minimumEdgeCut(); boolean whitney = kappa <= lambda && lambda <= delta; return new ConnectivityResult(kappa, lambda, delta, vCut, eCut, @@ -406,7 +406,7 @@ public String generateReport() { } int kappa = vertexConnectivity(); - int lambda = edgeConnectivity(); + int lambda = EdgeConnectivity(); int delta = minDegree(); sb.append(String.format("Vertex connectivity κ(G) = %d\n", kappa)); @@ -438,10 +438,10 @@ public String generateReport() { sb.append(String.format(" Size: %d\n\n", vCut.size())); } - Set eCut = minimumEdgeCut(); + Set eCut = minimumEdgeCut(); if (!eCut.isEmpty()) { sb.append("Minimum edge cut:\n"); - for (edge e : eCut) { + for (Edge e : eCut) { sb.append(String.format(" %s\n", e)); } sb.append(String.format(" Size: %d\n\n", eCut.size())); @@ -489,7 +489,7 @@ private Map> buildVertexSplitNetwork(String s, Stri } } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -507,7 +507,7 @@ private int maxFlowEdge(String s, String t) { cap.putIfAbsent(v, new HashMap<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -635,12 +635,12 @@ private Set extractVertexCut(String s, String t) { return cut; } - private Set extractEdgeCut(String s, String t) { + private Set extractEdgeCut(String s, String t) { Map> cap = new HashMap<>(); for (String v : graph.getVertices()) { cap.putIfAbsent(v, new HashMap<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -694,8 +694,8 @@ private Set extractEdgeCut(String s, String t) { } } - Set cutEdges = new LinkedHashSet<>(); - for (edge e : graph.getEdges()) { + Set cutEdges = new LinkedHashSet<>(); + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -779,7 +779,7 @@ public List> findEdgeDisjointPaths(String s, String t) { for (String v : graph.getVertices()) { cap.putIfAbsent(v, new HashMap<>()); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); @@ -844,18 +844,18 @@ private void addCapacity(Map> cap, String from, Str cap.get(from).merge(to, c, Integer::sum); } - private Graph removeVertex(String toRemove) { - Graph g = new UndirectedSparseGraph<>(); + private Graph removeVertex(String toRemove) { + Graph g = new UndirectedSparseGraph<>(); for (String v : graph.getVertices()) { if (!v.equals(toRemove)) g.addVertex(v); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { Collection endpoints = graph.getEndpoints(e); Iterator it = endpoints.iterator(); String u = it.next(); String v = it.next(); if (!u.equals(toRemove) && !v.equals(toRemove)) { - g.addEdge(new edge("f", u, v), u, v); + g.addEdge(new Edge("f", u, v), u, v); } } return g; diff --git a/Gvisual/src/gvisual/VertexCoverAnalyzer.java b/Gvisual/src/gvisual/VertexCoverAnalyzer.java index b888680..5a08b41 100644 --- a/Gvisual/src/gvisual/VertexCoverAnalyzer.java +++ b/Gvisual/src/gvisual/VertexCoverAnalyzer.java @@ -41,7 +41,7 @@ */ public class VertexCoverAnalyzer { - private final Graph graph; + private final Graph graph; private final Map> adj; /** @@ -50,7 +50,7 @@ public class VertexCoverAnalyzer { * @param graph the JUNG graph to analyse * @throws IllegalArgumentException if graph is null */ - public VertexCoverAnalyzer(Graph graph) { + public VertexCoverAnalyzer(Graph graph) { if (graph == null) { throw new IllegalArgumentException("Graph must not be null"); } @@ -71,7 +71,7 @@ public Set approxVertexCover() { Set cover = new LinkedHashSet(); Set coveredEdgeKeys = new HashSet(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); String key = edgeKey(v1, v2); @@ -198,7 +198,7 @@ private Set findCoverRecursive(List vertices, List edges, for (int i = 0; i < targetSize; i++) { mask |= (1L << combo[i]); } - for (int[] ep : edges) { + for (int[] ep : Edges) { if ((mask & (1L << ep[0])) == 0 && (mask & (1L << ep[1])) == 0) { return null; } @@ -231,7 +231,7 @@ public boolean isVertexCover(Set cover) { if (cover == null) { throw new IllegalArgumentException("Cover set must not be null"); } - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (!cover.contains(e.getVertex1()) && !cover.contains(e.getVertex2())) { return false; } @@ -253,7 +253,7 @@ public List uncoveredEdges(Set cover) { throw new IllegalArgumentException("Cover set must not be null"); } List uncovered = new ArrayList(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { if (!cover.contains(e.getVertex1()) && !cover.contains(e.getVertex2())) { uncovered.add(new String[]{e.getVertex1(), e.getVertex2()}); } @@ -325,7 +325,7 @@ public CoverBounds coverBounds() { private int greedyMaxMatchingSize() { Set matched = new HashSet(); int count = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (!matched.contains(v1) && !matched.contains(v2)) { @@ -381,7 +381,7 @@ public Set weightedVertexCover(Map weights) { cover.add(best); for (String n : adj.get(best)) { - String key = edgeKey(best, n); + String key = EdgeKey(best, n); if (!coveredEdgeKeys.contains(key)) { coveredEdgeKeys.add(key); uncoveredDeg.put(n, uncoveredDeg.get(n) - 1); @@ -424,7 +424,7 @@ public int lpRelaxationBound() { // In the LP relaxation of vertex cover, the optimal fractional // solution assigns 0.5 to every vertex incident to any edge. Set incidentVertices = new HashSet(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { incidentVertices.add(e.getVertex1()); incidentVertices.add(e.getVertex2()); } @@ -541,7 +541,7 @@ public VertexCoverReport fullReport() { // ── Helpers ───────────────────────────────────────────────────────── - private String edgeKey(String a, String b) { + private String EdgeKey(String a, String b) { return a.compareTo(b) <= 0 ? a + "|" + b : b + "|" + a; } diff --git a/Gvisual/src/test/GraphTimelineExporterTest.java b/Gvisual/src/test/GraphTimelineExporterTest.java index 7cb8e04..ad2ae10 100644 --- a/Gvisual/src/test/GraphTimelineExporterTest.java +++ b/Gvisual/src/test/GraphTimelineExporterTest.java @@ -18,20 +18,20 @@ public class GraphTimelineExporterTest { @Before public void setUp() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(1000L); g.addEdge(e1, "A", "B"); - edge e2 = new edge("c", "B", "C"); + Edge e2 = new Edge("c", "B", "C"); e2.setTimestamp(2000L); g.addEdge(e2, "B", "C"); - edge e3 = new edge("s", "A", "C"); + Edge e3 = new Edge("s", "A", "C"); e3.setTimestamp(3000L); g.addEdge(e3, "A", "C"); diff --git a/Gvisual/src/test/gvisual/CycleAnalyzerTest.java b/Gvisual/src/test/gvisual/CycleAnalyzerTest.java index 03b8729..b388fda 100644 --- a/Gvisual/src/test/gvisual/CycleAnalyzerTest.java +++ b/Gvisual/src/test/gvisual/CycleAnalyzerTest.java @@ -19,18 +19,18 @@ public class CycleAnalyzerTest { private static int edgeCounter = 0; - private static edge addEdge(Graph g, String v1, String v2) { + private static Edge addEdge(Graph g, String v1, String v2) { g.addVertex(v1); g.addVertex(v2); - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); g.addEdge(e, v1, v2); return e; } - private static edge addWeightedEdge(Graph g, String v1, String v2, float w) { + private static Edge addWeightedEdge(Graph g, String v1, String v2, float w) { g.addVertex(v1); g.addVertex(v2); - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setWeight(w); g.addEdge(e, v1, v2); return e; @@ -47,14 +47,14 @@ public void testNullGraphThrows() { @Test public void testEmptyGraphHasNoCycles() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); CycleAnalyzer ca = new CycleAnalyzer(g); assertFalse(ca.hasCycles()); } @Test public void testSingleVertexNoCycle() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); assertFalse(new CycleAnalyzer(g).hasCycles()); } @@ -62,7 +62,7 @@ public void testSingleVertexNoCycle() { @Test public void testTreeNoCycleUndirected() { // A-B-C (path, no cycle) - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); assertFalse(new CycleAnalyzer(g).hasCycles()); @@ -70,7 +70,7 @@ public void testTreeNoCycleUndirected() { @Test public void testTriangleCycleUndirected() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -79,7 +79,7 @@ public void testTriangleCycleUndirected() { @Test public void testSquareCycleUndirected() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -91,7 +91,7 @@ public void testSquareCycleUndirected() { @Test public void testDAGNoCycle() { - Graph g = new DirectedSparseGraph<>(); + Graph g = new DirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "A", "C"); @@ -100,7 +100,7 @@ public void testDAGNoCycle() { @Test public void testDirectedTriangleCycle() { - Graph g = new DirectedSparseGraph<>(); + Graph g = new DirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -109,7 +109,7 @@ public void testDirectedTriangleCycle() { @Test public void testSelfLoopDirected() { - Graph g = new DirectedSparseGraph<>(); + Graph g = new DirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "A"); assertTrue(new CycleAnalyzer(g).hasCycles()); @@ -119,13 +119,13 @@ public void testSelfLoopDirected() { @Test public void testGirthEmptyGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); assertEquals(-1, new CycleAnalyzer(g).girth()); } @Test public void testGirthAcyclic() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); assertEquals(-1, new CycleAnalyzer(g).girth()); @@ -133,7 +133,7 @@ public void testGirthAcyclic() { @Test public void testGirthTriangle() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -143,7 +143,7 @@ public void testGirthTriangle() { @Test public void testGirthSquareWithDiagonal() { // Square A-B-C-D-A plus diagonal A-C → shortest cycle is triangle - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -154,7 +154,7 @@ public void testGirthSquareWithDiagonal() { @Test public void testGirthDirectedCycle() { - Graph g = new DirectedSparseGraph<>(); + Graph g = new DirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -165,14 +165,14 @@ public void testGirthDirectedCycle() { @Test public void testFundamentalBasisEmpty() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); List basis = new CycleAnalyzer(g).fundamentalCycleBasis(); assertTrue(basis.isEmpty()); } @Test public void testFundamentalBasisTree() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -183,7 +183,7 @@ public void testFundamentalBasisTree() { @Test public void testFundamentalBasisSingleCycle() { // Triangle: 1 non-tree edge → 1 fundamental cycle - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -195,7 +195,7 @@ public void testFundamentalBasisSingleCycle() { @Test public void testFundamentalBasisK4() { // K4: 4 vertices, 6 edges → cyclomatic number = 6 - 4 + 1 = 3 - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); String[] verts = {"A", "B", "C", "D"}; for (int i = 0; i < verts.length; i++) { for (int j = i + 1; j < verts.length; j++) { @@ -210,7 +210,7 @@ public void testFundamentalBasisK4() { @Test public void testEnumerateNoCycles() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); CycleAnalyzer.CycleEnumerationResult r = new CycleAnalyzer(g).findAllSimpleCycles(); assertEquals(0, r.count()); @@ -219,7 +219,7 @@ public void testEnumerateNoCycles() { @Test public void testEnumerateTriangle() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -231,7 +231,7 @@ public void testEnumerateTriangle() { @Test public void testEnumerateWithLimit() { // K4 has 7 cycles — set limit to 2 - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); String[] verts = {"A", "B", "C", "D"}; for (int i = 0; i < verts.length; i++) { for (int j = i + 1; j < verts.length; j++) { @@ -245,14 +245,14 @@ public void testEnumerateWithLimit() { @Test(expected = IllegalArgumentException.class) public void testEnumerateNegativeLimit() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); new CycleAnalyzer(g).findAllSimpleCycles(-1); } @Test public void testEnumerateDirectedCycles() { // A→B→C→A and A→B→D→A - Graph g = new DirectedSparseGraph<>(); + Graph g = new DirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -289,7 +289,7 @@ public void testCycleDifferentVerticesNotEqual() { @Test public void testCycleWeight() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addWeightedEdge(g, "A", "B", 1.5f); addWeightedEdge(g, "B", "C", 2.5f); addWeightedEdge(g, "C", "A", 3.0f); @@ -307,7 +307,7 @@ public void testCycleToString() { @Test public void testAnalyzeAcyclicGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); @@ -323,7 +323,7 @@ public void testAnalyzeAcyclicGraph() { @Test public void testAnalyzeTriangle() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -343,7 +343,7 @@ public void testAnalyzeTriangle() { @Test public void testAnalyzeK4() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); String[] verts = {"A", "B", "C", "D"}; for (int i = 0; i < verts.length; i++) { for (int j = i + 1; j < verts.length; j++) { @@ -364,7 +364,7 @@ public void testAnalyzeK4() { @Test public void testAnalyzeReportSummaryAcyclic() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); assertTrue(report.getSummary().contains("No cycles found")); @@ -374,7 +374,7 @@ public void testAnalyzeReportSummaryAcyclic() { @Test public void testDisconnectedGraphWithOneCyclicComponent() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // Component 1: triangle addEdge(g, "A", "B"); addEdge(g, "B", "C"); @@ -388,7 +388,7 @@ public void testDisconnectedGraphWithOneCyclicComponent() { @Test public void testDisconnectedAcyclic() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, "A", "B"); addEdge(g, "X", "Y"); assertFalse(new CycleAnalyzer(g).hasCycles()); diff --git a/Gvisual/src/test/gvisual/GraphCompressorTest.java b/Gvisual/src/test/gvisual/GraphCompressorTest.java index 4f23ed7..1896d38 100644 --- a/Gvisual/src/test/gvisual/GraphCompressorTest.java +++ b/Gvisual/src/test/gvisual/GraphCompressorTest.java @@ -14,7 +14,7 @@ */ public class GraphCompressorTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -480,7 +480,7 @@ public void testLargeStarGraph() { @Test public void testQuotientGraphHasEdges() { - // Two groups connected by edges + // Two groups connected by Edges addEdge("A", "B", "e1"); addEdge("A", "C", "e2"); addEdge("D", "B", "e3"); @@ -510,7 +510,7 @@ public void testEdgeReductionPercent_noEdges() { // ── Helper ────────────────────────────────────────────────────── private void addEdge(String v1, String v2, String id) { - edge e = new edge("test", v1, v2); + Edge e = new Edge("test", v1, v2); e.setLabel(id); graph.addEdge(e, v1, v2); } diff --git a/Gvisual/src/test/gvisual/GraphMergerTest.java b/Gvisual/src/test/gvisual/GraphMergerTest.java index bf92c31..f981276 100644 --- a/Gvisual/src/test/gvisual/GraphMergerTest.java +++ b/Gvisual/src/test/gvisual/GraphMergerTest.java @@ -12,8 +12,8 @@ */ public class GraphMergerTest { - private Graph graphA; - private Graph graphB; + private Graph graphA; + private Graph graphB; @Before public void setUp() { @@ -21,8 +21,8 @@ public void setUp() { graphB = new UndirectedSparseGraph<>(); } - private edge makeEdge(String v1, String v2, float weight) { - edge e = new edge("f", v1, v2); + private Edge makeEdge(String v1, String v2, float weight) { + Edge e = new Edge("f", v1, v2); e.setWeight(weight); return e; } @@ -75,7 +75,7 @@ public void testUnionConflictAverage() { assertEquals(1, result.getMergedEdgeCount()); assertEquals(1, result.getConflictsResolved()); - edge merged = result.getMergedGraph().getEdges().iterator().next(); + Edge merged = result.getMergedGraph().getEdges().iterator().next(); assertEquals(5.0f, merged.getWeight(), 0.001f); } @@ -90,7 +90,7 @@ public void testUnionConflictMax() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.MAX); - edge merged = result.getMergedGraph().getEdges().iterator().next(); + Edge merged = result.getMergedGraph().getEdges().iterator().next(); assertEquals(7.0f, merged.getWeight(), 0.001f); } @@ -105,7 +105,7 @@ public void testUnionConflictSum() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.SUM); - edge merged = result.getMergedGraph().getEdges().iterator().next(); + Edge merged = result.getMergedGraph().getEdges().iterator().next(); assertEquals(8.0f, merged.getWeight(), 0.001f); } diff --git a/Gvisual/src/test/gvisual/GraphProductCalculatorTest.java b/Gvisual/src/test/gvisual/GraphProductCalculatorTest.java index 88edcc0..9669f1f 100644 --- a/Gvisual/src/test/gvisual/GraphProductCalculatorTest.java +++ b/Gvisual/src/test/gvisual/GraphProductCalculatorTest.java @@ -15,41 +15,41 @@ */ public class GraphProductCalculatorTest { - private Graph triangle; // K3: 3 vertices, 3 edges - private Graph path2; // P2: 2 vertices, 1 edge - private Graph single; // K1: 1 vertex, 0 edges - private Graph k2; // K2: 2 vertices, 1 edge - private Graph empty3; // 3 isolated vertices + private Graph triangle; // K3: 3 vertices, 3 edges + private Graph path2; // P2: 2 vertices, 1 edge + private Graph single; // K1: 1 vertex, 0 edges + private Graph k2; // K2: 2 vertices, 1 edge + private Graph empty3; // 3 isolated vertices @Before public void setUp() { // Triangle K3: a-b, b-c, a-c - triangle = new UndirectedSparseGraph(); + triangle = new UndirectedSparseGraph(); triangle.addVertex("a"); triangle.addVertex("b"); triangle.addVertex("c"); - triangle.addEdge(new edge("e", "a", "b"), "a", "b"); - triangle.addEdge(new edge("e", "b", "c"), "b", "c"); - triangle.addEdge(new edge("e", "a", "c"), "a", "c"); + triangle.addEdge(new Edge("e", "a", "b"), "a", "b"); + triangle.addEdge(new Edge("e", "b", "c"), "b", "c"); + triangle.addEdge(new Edge("e", "a", "c"), "a", "c"); // Path P2: x-y - path2 = new UndirectedSparseGraph(); + path2 = new UndirectedSparseGraph(); path2.addVertex("x"); path2.addVertex("y"); - path2.addEdge(new edge("e", "x", "y"), "x", "y"); + path2.addEdge(new Edge("e", "x", "y"), "x", "y"); // Single vertex - single = new UndirectedSparseGraph(); + single = new UndirectedSparseGraph(); single.addVertex("s"); // K2: p-q - k2 = new UndirectedSparseGraph(); + k2 = new UndirectedSparseGraph(); k2.addVertex("p"); k2.addVertex("q"); - k2.addEdge(new edge("e", "p", "q"), "p", "q"); + k2.addEdge(new Edge("e", "p", "q"), "p", "q"); // Empty graph with 3 vertices - empty3 = new UndirectedSparseGraph(); + empty3 = new UndirectedSparseGraph(); empty3.addVertex("1"); empty3.addVertex("2"); empty3.addVertex("3"); @@ -70,7 +70,7 @@ public void testNullGraphH() { @Test public void testCartesianVertexCount() { GraphProductCalculator calc = new GraphProductCalculator(triangle, path2); - Graph result = calc.cartesianProduct(); + Graph result = calc.cartesianProduct(); assertEquals(6, result.getVertexCount()); // 3 * 2 } @@ -236,8 +236,8 @@ public void testDegreeSequence() { @Test public void testCachingReturnsSameInstance() { GraphProductCalculator calc = new GraphProductCalculator(triangle, path2); - Graph first = calc.cartesianProduct(); - Graph second = calc.cartesianProduct(); + Graph first = calc.cartesianProduct(); + Graph second = calc.cartesianProduct(); assertSame(first, second); } @@ -246,7 +246,7 @@ public void testCachingReturnsSameInstance() { @Test public void testVertexNaming() { GraphProductCalculator calc = new GraphProductCalculator(k2, k2); - Graph product = calc.cartesianProduct(); + Graph product = calc.cartesianProduct(); assertTrue(product.containsVertex("(p,p)")); assertTrue(product.containsVertex("(p,q)")); assertTrue(product.containsVertex("(q,p)")); @@ -258,7 +258,7 @@ public void testVertexNaming() { @Test public void testCartesianWithEmptyGraph() { GraphProductCalculator calc = new GraphProductCalculator(triangle, empty3); - Graph result = calc.cartesianProduct(); + Graph result = calc.cartesianProduct(); assertEquals(9, result.getVertexCount()); // |E_G|*|V_H| + |V_G|*|E_H| = 3*3 + 3*0 = 9 assertEquals(9, result.getEdgeCount()); diff --git a/Gvisual/src/test/gvisual/PageRankAnalyzerTest.java b/Gvisual/src/test/gvisual/PageRankAnalyzerTest.java index 6194a0d..9a53f40 100644 --- a/Gvisual/src/test/gvisual/PageRankAnalyzerTest.java +++ b/Gvisual/src/test/gvisual/PageRankAnalyzerTest.java @@ -15,7 +15,7 @@ public class PageRankAnalyzerTest { private static final double EPSILON = 1e-4; - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -77,7 +77,7 @@ public void testCompleteGraphUniformRanks() { // In a complete graph, all nodes should have equal PageRank GraphGenerator gen = new GraphGenerator(42); GraphGenerator.GeneratedGraph gg = gen.complete(5); - Graph g = gg.getGraph(); + Graph g = gg.getGraph(); PageRankAnalyzer pr = new PageRankAnalyzer(g); pr.compute(); @@ -94,7 +94,7 @@ public void testCompleteGraphUniformRanks() { public void testRingGraphUniformRanks() { GraphGenerator gen = new GraphGenerator(42); GraphGenerator.GeneratedGraph gg = gen.ring(6); - Graph g = gg.getGraph(); + Graph g = gg.getGraph(); PageRankAnalyzer pr = new PageRankAnalyzer(g); pr.compute(); @@ -111,7 +111,7 @@ public void testRingGraphUniformRanks() { public void testStarGraphHubHighestRank() { GraphGenerator gen = new GraphGenerator(42); GraphGenerator.GeneratedGraph gg = gen.star(6); - Graph g = gg.getGraph(); + Graph g = gg.getGraph(); PageRankAnalyzer pr = new PageRankAnalyzer(g); pr.compute(); @@ -130,7 +130,7 @@ public void testStarGraphHubHighestRank() { public void testRanksSumToOne() { GraphGenerator gen = new GraphGenerator(42); GraphGenerator.GeneratedGraph gg = gen.scaleFreeBa(20, 2); - Graph g = gg.getGraph(); + Graph g = gg.getGraph(); PageRankAnalyzer pr = new PageRankAnalyzer(g); pr.compute(); @@ -228,7 +228,7 @@ public void testGetSortedResults() { public void testGetTopK() { GraphGenerator gen = new GraphGenerator(42); GraphGenerator.GeneratedGraph gg = gen.scaleFreeBa(20, 2); - Graph g = gg.getGraph(); + Graph g = gg.getGraph(); PageRankAnalyzer pr = new PageRankAnalyzer(g); pr.compute(); @@ -323,7 +323,7 @@ public void testDanglingNodesGetRank() { private void addEdge(String v1, String v2) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setLabel("e" + (edgeId++)); e.setWeight(1.0f); graph.addEdge(e, v1, v2); diff --git a/Gvisual/test/gvisual/ArticulationPointAnalyzerTest.java b/Gvisual/test/gvisual/ArticulationPointAnalyzerTest.java index 7609eab..5a35542 100644 --- a/Gvisual/test/gvisual/ArticulationPointAnalyzerTest.java +++ b/Gvisual/test/gvisual/ArticulationPointAnalyzerTest.java @@ -14,15 +14,15 @@ */ public class ArticulationPointAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } - private edge addEdge(String v1, String v2, String type) { - edge e = new edge(type, v1, v2); + private Edge addEdge(String v1, String v2, String type) { + Edge e = new Edge(type, v1, v2); e.setLabel(v1 + "-" + v2); graph.addEdge(e, v1, v2); return e; @@ -165,7 +165,7 @@ public void testDisconnectedComponents() { assertEquals(2, result.getConnectedComponents()); // B is articulation point in component 1 assertTrue(result.getArticulationPoints().contains("B")); - // All edges are bridges + // All Edges are bridges assertEquals(3, result.getBridgeCount()); } diff --git a/Gvisual/test/gvisual/BipartiteAnalyzerTest.java b/Gvisual/test/gvisual/BipartiteAnalyzerTest.java index a2c3136..44b35b1 100644 --- a/Gvisual/test/gvisual/BipartiteAnalyzerTest.java +++ b/Gvisual/test/gvisual/BipartiteAnalyzerTest.java @@ -15,15 +15,15 @@ */ public class BipartiteAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -393,7 +393,7 @@ public void vertexCoverCoversAllEdges() { List cover = ba.getMinimumVertexCover(); java.util.Set coverSet = new java.util.HashSet(cover); // Every edge must have at least one endpoint in the cover - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { assertTrue("Edge not covered: " + e.getVertex1() + "-" + e.getVertex2(), coverSet.contains(e.getVertex1()) || coverSet.contains(e.getVertex2())); } @@ -430,7 +430,7 @@ public void coloringIsValid() { addEdge("C", "D"); BipartiteAnalyzer ba = new BipartiteAnalyzer(graph).compute(); Map coloring = ba.getColoring(); - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); assertNotEquals("Adjacent vertices have same color: " + v1 + "-" + v2, diff --git a/Gvisual/test/gvisual/ChordalGraphAnalyzerTest.java b/Gvisual/test/gvisual/ChordalGraphAnalyzerTest.java index 9b20a57..5ff693f 100644 --- a/Gvisual/test/gvisual/ChordalGraphAnalyzerTest.java +++ b/Gvisual/test/gvisual/ChordalGraphAnalyzerTest.java @@ -14,17 +14,17 @@ */ public class ChordalGraphAnalyzerTest { - private Graph emptyGraph; - private Graph singleVertex; - private Graph singleEdge; - private Graph triangle; // K3 — chordal - private Graph path4; // A-B-C-D — chordal - private Graph cycle4; // A-B-C-D-A — NOT chordal - private Graph cycle5; // 5-cycle — NOT chordal - private Graph complete4; // K4 — chordal - private Graph diamond; // K4 minus one edge — chordal - private Graph star5; // star — chordal - private Graph fan; // fan graph — chordal + private Graph emptyGraph; + private Graph singleVertex; + private Graph singleEdge; + private Graph triangle; // K3 — chordal + private Graph path4; // A-B-C-D — chordal + private Graph cycle4; // A-B-C-D-A — NOT chordal + private Graph cycle5; // 5-cycle — NOT chordal + private Graph complete4; // K4 — chordal + private Graph diamond; // K4 minus one edge — chordal + private Graph star5; // star — chordal + private Graph fan; // fan graph — chordal private int edgeCounter; @@ -97,10 +97,10 @@ public void setUp() { addEdge(fan, "X", "D"); } - private void addEdge(Graph g, String u, String v) { + private void addEdge(Graph g, String u, String v) { if (!g.containsVertex(u)) g.addVertex(u); if (!g.containsVertex(v)) g.addVertex(v); - g.addEdge(new edge("e" + (++edgeCounter), u, v), u, v); + g.addEdge(new Edge("e" + (++edgeCounter), u, v), u, v); } // ── MCS ordering ──────────────────────────────────────────────────── @@ -247,7 +247,7 @@ public void testColoringStar() { public void testColoringIsValid() { ChordalGraphAnalyzer.ColoringResult c = ChordalGraphAnalyzer.optimalColoring(fan); Map colors = c.getColors(); - for (edge e : fan.getEdges()) { + for (Edge e : fan.getEdges()) { assertNotEquals("Adjacent vertices must have different colors: " + e.getVertex1() + "-" + e.getVertex2(), colors.get(e.getVertex1()), colors.get(e.getVertex2())); } diff --git a/Gvisual/test/gvisual/CircularLayoutTest.java b/Gvisual/test/gvisual/CircularLayoutTest.java index ce07ab8..57ac3ed 100644 --- a/Gvisual/test/gvisual/CircularLayoutTest.java +++ b/Gvisual/test/gvisual/CircularLayoutTest.java @@ -10,13 +10,13 @@ /** * Tests for CircularLayout — verifies all ordering strategies, dual-ring mode, - * SVG export, edge crossing counts, and edge cases. + * SVG export, Edge crossing counts, and edge cases. */ public class CircularLayoutTest { - private Graph triangle; - private Graph star; - private Graph empty; + private Graph triangle; + private Graph star; + private Graph empty; @Before public void setUp() { @@ -41,8 +41,8 @@ public void setUp() { empty = new UndirectedSparseGraph<>(); } - private edge makeEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge makeEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); e.setLabel(v1 + "-" + v2); return e; @@ -104,7 +104,7 @@ public void testBfsOrdering() { @Test public void testCommunityOrdering() { // Two disconnected components - Graph disconnected = new UndirectedSparseGraph<>(); + Graph disconnected = new UndirectedSparseGraph<>(); disconnected.addVertex("A1"); disconnected.addVertex("A2"); disconnected.addEdge(makeEdge("A1", "A2"), "A1", "A2"); @@ -202,7 +202,7 @@ public void testSvgExport() { @Test public void testSvgHidesLabelsForLargeGraphs() { // Create graph with 100 nodes - Graph large = new UndirectedSparseGraph<>(); + Graph large = new UndirectedSparseGraph<>(); for (int i = 0; i < 100; i++) { large.addVertex("n" + i); } @@ -232,7 +232,7 @@ public void testNullGraph() { @Test public void testSingleNode() { - Graph single = new UndirectedSparseGraph<>(); + Graph single = new UndirectedSparseGraph<>(); single.addVertex("alone"); CircularLayout layout = new CircularLayout.Builder(single) .ordering(CircularLayout.Ordering.ALPHABETICAL) diff --git a/Gvisual/test/gvisual/CliqueAnalyzerTest.java b/Gvisual/test/gvisual/CliqueAnalyzerTest.java index edee4e3..6b3f07e 100644 --- a/Gvisual/test/gvisual/CliqueAnalyzerTest.java +++ b/Gvisual/test/gvisual/CliqueAnalyzerTest.java @@ -14,17 +14,17 @@ */ public class CliqueAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helpers --- - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/CommunityDetectorTest.java b/Gvisual/test/gvisual/CommunityDetectorTest.java index 63a6eda..37604a4 100644 --- a/Gvisual/test/gvisual/CommunityDetectorTest.java +++ b/Gvisual/test/gvisual/CommunityDetectorTest.java @@ -14,11 +14,11 @@ */ public class CommunityDetectorTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } @Test(expected = IllegalArgumentException.class) @@ -60,7 +60,7 @@ public void testTwoDisconnectedNodes() { public void testTwoConnectedNodes() { graph.addVertex("A"); graph.addVertex("B"); - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(5.0f); graph.addEdge(e, "A", "B"); @@ -77,9 +77,9 @@ public void testTwoCommunities() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(3.0f); - edge e2 = new edge("f", "B", "C"); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(4.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -87,7 +87,7 @@ public void testTwoCommunities() { // Community 2: D-E graph.addVertex("D"); graph.addVertex("E"); - edge e3 = new edge("c", "D", "E"); + Edge e3 = new Edge("c", "D", "E"); e3.setWeight(6.0f); graph.addEdge(e3, "D", "E"); @@ -104,7 +104,7 @@ public void testTwoCommunities() { public void testNodeToCommunityMapping() { graph.addVertex("A"); graph.addVertex("B"); - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); @@ -127,9 +127,9 @@ public void testCommunityDensity() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1.0f); - edge e3 = new edge("f", "A", "C"); e3.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1.0f); + Edge e3 = new Edge("f", "A", "C"); e3.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); graph.addEdge(e3, "A", "C"); @@ -152,9 +152,9 @@ public void testEdgeTypeCounts() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("f", "A", "C"); e3.setWeight(3.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(2.0f); + Edge e3 = new Edge("f", "A", "C"); e3.setWeight(3.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); graph.addEdge(e3, "A", "C"); @@ -173,8 +173,8 @@ public void testAverageWeight() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(10.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(20.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(10.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(20.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -189,14 +189,14 @@ public void testSignificantCommunities() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); graph.addVertex("D"); graph.addVertex("E"); - edge e3 = new edge("c", "D", "E"); e3.setWeight(1.0f); + Edge e3 = new Edge("c", "D", "E"); e3.setWeight(1.0f); graph.addEdge(e3, "D", "E"); graph.addVertex("F"); // isolated @@ -215,7 +215,7 @@ public void testSignificantCommunities() { public void testGetCommunityOf() { graph.addVertex("A"); graph.addVertex("B"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); CommunityDetector detector = new CommunityDetector(graph); @@ -235,9 +235,9 @@ public void testModularity() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1.0f); - edge e3 = new edge("f", "A", "C"); e3.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1.0f); + Edge e3 = new Edge("f", "A", "C"); e3.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); graph.addEdge(e3, "A", "C"); @@ -245,9 +245,9 @@ public void testModularity() { graph.addVertex("D"); graph.addVertex("E"); graph.addVertex("F"); - edge e4 = new edge("c", "D", "E"); e4.setWeight(1.0f); - edge e5 = new edge("c", "E", "F"); e5.setWeight(1.0f); - edge e6 = new edge("c", "D", "F"); e6.setWeight(1.0f); + Edge e4 = new Edge("c", "D", "E"); e4.setWeight(1.0f); + Edge e5 = new Edge("c", "E", "F"); e5.setWeight(1.0f); + Edge e6 = new Edge("c", "D", "F"); e6.setWeight(1.0f); graph.addEdge(e4, "D", "E"); graph.addEdge(e5, "E", "F"); graph.addEdge(e6, "D", "F"); @@ -273,7 +273,7 @@ public void testModularitySingleComponent() { // All in one component → modularity should be 0 graph.addVertex("A"); graph.addVertex("B"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); CommunityDetector detector = new CommunityDetector(graph); @@ -287,7 +287,7 @@ public void testModularitySingleComponent() { public void testCommunityToString() { graph.addVertex("A"); graph.addVertex("B"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(5.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(5.0f); graph.addEdge(e1, "A", "B"); CommunityDetector detector = new CommunityDetector(graph); @@ -311,8 +311,8 @@ public void testTotalWeight() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(7.5f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.5f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(7.5f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.5f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -332,10 +332,10 @@ public void testLargerGraph() { graph.addVertex("F"); graph.addVertex("G"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "A", "C"); e2.setWeight(2.0f); - edge e3 = new edge("s", "A", "D"); e3.setWeight(3.0f); - edge e4 = new edge("sg", "A", "E"); e4.setWeight(4.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("c", "A", "C"); e2.setWeight(2.0f); + Edge e3 = new Edge("s", "A", "D"); e3.setWeight(3.0f); + Edge e4 = new Edge("sg", "A", "E"); e4.setWeight(4.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "A", "C"); graph.addEdge(e3, "A", "D"); @@ -359,9 +359,9 @@ public void testMultipleEdgeTypes() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("fs", "B", "C"); e2.setWeight(1.0f); - edge e3 = new edge("sg", "A", "C"); e3.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("fs", "B", "C"); e2.setWeight(1.0f); + Edge e3 = new Edge("sg", "A", "C"); e3.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); graph.addEdge(e3, "A", "C"); @@ -400,14 +400,14 @@ public void testGetCommunityOfValidNodeAfterDetect() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); graph.addVertex("D"); graph.addVertex("E"); - edge e3 = new edge("c", "D", "E"); e3.setWeight(1.0f); + Edge e3 = new Edge("c", "D", "E"); e3.setWeight(1.0f); graph.addEdge(e3, "D", "E"); CommunityDetector detector = new CommunityDetector(graph); @@ -436,7 +436,7 @@ public void testGetCommunityOfConsistentWithDirectIndex() { // Verify getCommunityOf returns same object as communities.get(id) graph.addVertex("A"); graph.addVertex("B"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addVertex("C"); // isolated @@ -457,7 +457,7 @@ public void testDetectInPlaceIdReassignment() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); // C is isolated → two communities diff --git a/Gvisual/test/gvisual/CommunityEvolutionTrackerTest.java b/Gvisual/test/gvisual/CommunityEvolutionTrackerTest.java index 2505eb2..2002c7a 100644 --- a/Gvisual/test/gvisual/CommunityEvolutionTrackerTest.java +++ b/Gvisual/test/gvisual/CommunityEvolutionTrackerTest.java @@ -18,20 +18,20 @@ public class CommunityEvolutionTrackerTest { // ── Helper Methods ───────────────────────────────────────────── - private edge timedEdge(String type, String v1, String v2, long timestamp) { - edge e = new edge(type, v1, v2); + private Edge timedEdge(String type, String v1, String v2, long timestamp) { + Edge e = new Edge(type, v1, v2); e.setTimestamp(timestamp); return e; } - private edge intervalEdge(String type, String v1, String v2, long start, long end) { - edge e = new edge(type, v1, v2); + private Edge intervalEdge(String type, String v1, String v2, long start, long end) { + Edge e = new Edge(type, v1, v2); e.setTimestamp(start); e.setEndTimestamp(end); return e; } - private void addEdge(Graph graph, edge e) { + private void addEdge(Graph graph, Edge e) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (!graph.containsVertex(v1)) graph.addVertex(v1); @@ -57,7 +57,7 @@ public void constructor_nullGraph_throws() { @Test(expected = IllegalArgumentException.class) public void track_singleWindow_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.track(1); @@ -65,7 +65,7 @@ public void track_singleWindow_throws() { @Test(expected = IllegalArgumentException.class) public void trackAtTimePoints_nullList_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.trackAtTimePoints(null); @@ -73,7 +73,7 @@ public void trackAtTimePoints_nullList_throws() { @Test(expected = IllegalArgumentException.class) public void trackAtTimePoints_singlePoint_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.trackAtTimePoints(Collections.singletonList(100L)); @@ -83,7 +83,7 @@ public void trackAtTimePoints_singlePoint_throws() { @Test(expected = IllegalArgumentException.class) public void setMatchThreshold_negative_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.setMatchThreshold(-0.1); @@ -91,7 +91,7 @@ public void setMatchThreshold_negative_throws() { @Test(expected = IllegalArgumentException.class) public void setMatchThreshold_overOne_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.setMatchThreshold(1.1); @@ -99,7 +99,7 @@ public void setMatchThreshold_overOne_throws() { @Test(expected = IllegalArgumentException.class) public void setChangeThreshold_negative_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.setChangeThreshold(-0.1); @@ -107,7 +107,7 @@ public void setChangeThreshold_negative_throws() { @Test(expected = IllegalArgumentException.class) public void setChangeThreshold_overOne_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.setChangeThreshold(1.1); @@ -115,7 +115,7 @@ public void setChangeThreshold_overOne_throws() { @Test(expected = IllegalArgumentException.class) public void setMinCommunitySize_zero_throws() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); tracker.setMinCommunitySize(0); @@ -123,7 +123,7 @@ public void setMinCommunitySize_zero_throws() { @Test public void gettersReturnDefaults() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); assertEquals(0.3, tracker.getMatchThreshold(), 0.001); @@ -135,7 +135,7 @@ public void gettersReturnDefaults() { @Test public void stableCommunity_sameGroupAcrossTime() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); addEdge(g, intervalEdge("f", "A", "C", 100, 200)); @@ -154,7 +154,7 @@ public void stableCommunity_sameGroupAcrossTime() { @Test public void communityBirth_newGroupAppears() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -172,7 +172,7 @@ public void communityBirth_newGroupAppears() { @Test public void communityDeath_groupDisappears() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "B", "C", 100)); addEdge(g, intervalEdge("f", "X", "Y", 100, 200)); @@ -190,7 +190,7 @@ public void communityDeath_groupDisappears() { @Test public void communityGrowth_membersAdded() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, timedEdge("f", "B", "C", 200)); addEdge(g, timedEdge("f", "C", "D", 200)); @@ -208,7 +208,7 @@ public void communityGrowth_membersAdded() { @Test public void communityContraction_membersLeave() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // A-B persists, but C, D, E only at t=100 addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, timedEdge("f", "B", "C", 100)); @@ -227,7 +227,7 @@ public void communityContraction_membersLeave() { @Test public void communityMerge_twoBecomesOne() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // Two separate communities persist, bridge appears at t=200 addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -248,7 +248,7 @@ public void communityMerge_twoBecomesOne() { @Test public void communitySplit_oneBecomesTwo() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // All connected at t=100 via persistent edges + bridge addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -303,7 +303,7 @@ public void jaccard_oneEmpty() { @Test public void nodeLineage_tracksNodeAcrossSnapshots() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 300)); addEdge(g, intervalEdge("f", "B", "C", 100, 300)); @@ -322,7 +322,7 @@ public void nodeLineage_tracksNodeAcrossSnapshots() { @Test public void nodeLineage_missingNode_emptyList() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); @@ -338,7 +338,7 @@ public void nodeLineage_missingNode_emptyList() { @Test public void stabilityScore_inRange() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -352,7 +352,7 @@ public void stabilityScore_inRange() { @Test public void volatilityScore_inRange() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "B", "C", 100)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -370,7 +370,7 @@ public void volatilityScore_inRange() { @Test public void getEventsByType_filtersCorrectly() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "B", "C", 100)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -391,7 +391,7 @@ public void getEventsByType_filtersCorrectly() { @Test public void getEventsAtTransition_filtersCorrectly() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 300)); addEdge(g, intervalEdge("f", "B", "C", 100, 300)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -412,7 +412,7 @@ public void getEventsAtTransition_filtersCorrectly() { @Test public void eventCounts_sumsToTotalEvents() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "B", "C", 100)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -433,7 +433,7 @@ public void eventCounts_sumsToTotalEvents() { @Test public void summary_containsKeyInfo() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -452,7 +452,7 @@ public void summary_containsKeyInfo() { @Test public void snapshot_vertexAndEdgeCounts() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); addEdge(g, intervalEdge("f", "C", "A", 100, 200)); @@ -469,7 +469,7 @@ public void snapshot_vertexAndEdgeCounts() { @Test public void snapshot_averageCommunitySize() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -484,7 +484,7 @@ public void snapshot_averageCommunitySize() { @Test public void snapshot_emptyGraph_producesEvents() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "X", "Y", 300)); @@ -499,7 +499,7 @@ public void snapshot_emptyGraph_producesEvents() { @Test public void topMigrants_returnsLimitedResults() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 300)); addEdge(g, intervalEdge("f", "B", "C", 100, 300)); addEdge(g, timedEdge("f", "X", "Y", 100)); @@ -517,7 +517,7 @@ public void topMigrants_returnsLimitedResults() { @Test public void minCommunitySize_filtersSingletons() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -536,7 +536,7 @@ public void minCommunitySize_filtersSingletons() { @Test public void minCommunitySize_one_includesSingletons() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); CommunityEvolutionTracker tracker = new CommunityEvolutionTracker(new TemporalGraph(g)); @@ -552,7 +552,7 @@ public void minCommunitySize_one_includesSingletons() { @Test public void track_withWindows_producesSnapshots() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 400)); addEdge(g, intervalEdge("f", "B", "C", 100, 400)); addEdge(g, timedEdge("f", "X", "Y", 300)); @@ -569,7 +569,7 @@ public void track_withWindows_producesSnapshots() { @Test public void eventToString_containsType() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "B", "C", 100)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -590,7 +590,7 @@ public void eventToString_containsType() { @Test public void nodeLineageEntry_toString() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -611,7 +611,7 @@ public void nodeLineageEntry_toString() { @Test public void snapshotToString_containsCounts() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); @@ -629,7 +629,7 @@ public void snapshotToString_containsCounts() { @Test public void complexScenario_multiPhaseEvolution() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // Persistent edges within sub-groups addEdge(g, intervalEdge("f", "Alice", "Bob", 100, 300)); @@ -669,7 +669,7 @@ public void complexScenario_multiPhaseEvolution() { @Test public void highMatchThreshold_runs() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); addEdge(g, timedEdge("f", "C", "D", 100)); @@ -685,7 +685,7 @@ public void highMatchThreshold_runs() { @Test public void lowChangeThreshold_runs() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); addEdge(g, timedEdge("f", "C", "D", 200)); @@ -702,7 +702,7 @@ public void lowChangeThreshold_runs() { @Test public void eventProperties_accessible() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, timedEdge("f", "A", "B", 100)); addEdge(g, timedEdge("f", "B", "C", 100)); addEdge(g, timedEdge("f", "X", "Y", 200)); @@ -726,7 +726,7 @@ public void eventProperties_accessible() { @Test public void snapshot_totalMembers() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); addEdge(g, intervalEdge("f", "X", "Y", 100, 200)); @@ -743,7 +743,7 @@ public void snapshot_totalMembers() { @Test public void nodeLineageEntry_properties() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); addEdge(g, intervalEdge("f", "A", "B", 100, 200)); addEdge(g, intervalEdge("f", "B", "C", 100, 200)); diff --git a/Gvisual/test/gvisual/CsvReportExporterTest.java b/Gvisual/test/gvisual/CsvReportExporterTest.java index c476096..0ccad16 100644 --- a/Gvisual/test/gvisual/CsvReportExporterTest.java +++ b/Gvisual/test/gvisual/CsvReportExporterTest.java @@ -25,7 +25,7 @@ public void testNullGraphThrows() { @Test public void testNullEdgeListAccepted() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); CsvReportExporter exporter = new CsvReportExporter(g, null); assertNotNull(exporter.exportToString()); } @@ -34,8 +34,8 @@ public void testNullEdgeListAccepted() { @Test public void testEmptyGraphProducesHeaderOnly() { - Graph g = new UndirectedSparseGraph<>(); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + Graph g = new UndirectedSparseGraph<>(); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); exporter.setTimestamp("2026-01-01 00:00:00"); String csv = exporter.exportToString(); @@ -51,9 +51,9 @@ public void testEmptyGraphProducesHeaderOnly() { @Test public void testSingleNodeNoEdges() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Alice"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue(csv.contains("Nodes: 1")); @@ -65,12 +65,12 @@ public void testSingleNodeNoEdges() { @Test public void testTriangleGraphMetrics() { - Graph g = new UndirectedSparseGraph<>(); - List edges = new ArrayList<>(); + Graph g = new UndirectedSparseGraph<>(); + List edges = new ArrayList<>(); - edge e1 = new edge("f", "A", "B"); - edge e2 = new edge("f", "B", "C"); - edge e3 = new edge("f", "A", "C"); + Edge e1 = new Edge("f", "A", "B"); + Edge e2 = new Edge("f", "B", "C"); + Edge e3 = new Edge("f", "A", "C"); edges.add(e1); edges.add(e2); edges.add(e3); @@ -104,11 +104,11 @@ public void testTriangleGraphMetrics() { @Test public void testBridgeGraphHasArticulationPoint() { // A-B-C where B is an articulation point - Graph g = new UndirectedSparseGraph<>(); - List edges = new ArrayList<>(); + Graph g = new UndirectedSparseGraph<>(); + List edges = new ArrayList<>(); - edge e1 = new edge("f", "A", "B"); - edge e2 = new edge("c", "B", "C"); + Edge e1 = new Edge("f", "A", "B"); + Edge e2 = new Edge("c", "B", "C"); edges.add(e1); edges.add(e2); g.addEdge(e1, "A", "B"); @@ -142,12 +142,12 @@ public void testBridgeGraphHasArticulationPoint() { @Test public void testEdgeTypeCounts() { - Graph g = new UndirectedSparseGraph<>(); - List edges = new ArrayList<>(); + Graph g = new UndirectedSparseGraph<>(); + List edges = new ArrayList<>(); - edge e1 = new edge("f", "X", "Y"); // friend - edge e2 = new edge("fs", "X", "Z"); // familiar stranger - edge e3 = new edge("sg", "Y", "Z"); // study group + Edge e1 = new Edge("f", "X", "Y"); // friend + Edge e2 = new Edge("fs", "X", "Z"); // familiar stranger + Edge e3 = new Edge("sg", "Y", "Z"); // study group edges.add(e1); edges.add(e2); edges.add(e3); @@ -174,9 +174,9 @@ public void testEdgeTypeCounts() { @Test public void testNodeNameWithCommaIsEscaped() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Last, First"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue("Comma in node name should be quoted", csv.contains("\"Last, First\"")); @@ -186,9 +186,9 @@ public void testNodeNameWithCommaIsEscaped() { @Test public void testExportToFile() throws IOException { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Solo"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); File tempFile = File.createTempFile("graph-report-", ".csv"); tempFile.deleteOnExit(); @@ -203,8 +203,8 @@ public void testExportToFile() throws IOException { @Test public void testSetTimestamp() { - Graph g = new UndirectedSparseGraph<>(); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + Graph g = new UndirectedSparseGraph<>(); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); exporter.setTimestamp("2099-12-31 23:59:59"); String csv = exporter.exportToString(); assertTrue(csv.contains("2099-12-31 23:59:59")); @@ -214,11 +214,11 @@ public void testSetTimestamp() { @Test public void testNodeOutputIsSorted() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Charlie"); g.addVertex("Alice"); g.addVertex("Bob"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); int idxA = csv.indexOf("Alice,"); @@ -232,9 +232,9 @@ public void testNodeOutputIsSorted() { @Test public void testFormulaInjectionNodeEquals() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("=CMD()"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue("Formula prefix defused", csv.contains("\"'=CMD()\"")); assertFalse("Raw formula not present", csv.contains(",=CMD(),")); @@ -242,36 +242,36 @@ public void testFormulaInjectionNodeEquals() { @Test public void testFormulaInjectionNodePlus() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("+1234"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue("Plus-prefix defused", csv.contains("\"'+1234\"")); } @Test public void testFormulaInjectionNodeMinus() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("-DROP"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue("Minus-prefix defused", csv.contains("\"'-DROP\"")); } @Test public void testFormulaInjectionNodeAt() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("@SUM(A1:A10)"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue("At-prefix defused", csv.contains("\"'@SUM(A1:A10)\"")); } @Test public void testSafeNodeNotPrefixed() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Alice"); - CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); + CsvReportExporter exporter = new CsvReportExporter(g, new ArrayList()); String csv = exporter.exportToString(); assertTrue("Safe name present", csv.contains("Alice,")); assertFalse("No spurious quoting", csv.contains("\"'Alice\"")); diff --git a/Gvisual/test/gvisual/CycleAnalyzerTest.java b/Gvisual/test/gvisual/CycleAnalyzerTest.java index abe0694..898364b 100644 --- a/Gvisual/test/gvisual/CycleAnalyzerTest.java +++ b/Gvisual/test/gvisual/CycleAnalyzerTest.java @@ -17,44 +17,44 @@ public class CycleAnalyzerTest { // ── Helper methods ────────────────────────────────────────── - private Graph buildUndirected(String[][] edges) { - Graph g = new UndirectedSparseGraph(); + private Graph buildUndirected(String[][] edges) { + Graph g = new UndirectedSparseGraph(); int id = 0; for (String[] e : edges) { if (!g.containsVertex(e[0])) g.addVertex(e[0]); if (!g.containsVertex(e[1])) g.addVertex(e[1]); - edge ed = new edge("link", e[0], e[1]); + Edge ed = new Edge("link", e[0], e[1]); ed.setLabel("e" + id++); g.addEdge(ed, e[0], e[1]); } return g; } - private Graph buildDirected(String[][] edges) { - Graph g = new DirectedSparseGraph(); + private Graph buildDirected(String[][] edges) { + Graph g = new DirectedSparseGraph(); int id = 0; for (String[] e : edges) { if (!g.containsVertex(e[0])) g.addVertex(e[0]); if (!g.containsVertex(e[1])) g.addVertex(e[1]); - edge ed = new edge("link", e[0], e[1]); + Edge ed = new Edge("link", e[0], e[1]); ed.setLabel("e" + id++); g.addEdge(ed, e[0], e[1]); } return g; } - private Graph emptyUndirected() { - return new UndirectedSparseGraph(); + private Graph emptyUndirected() { + return new UndirectedSparseGraph(); } - private Graph emptyDirected() { - return new DirectedSparseGraph(); + private Graph emptyDirected() { + return new DirectedSparseGraph(); } - private Graph singleVertex(boolean directed) { - Graph g = directed - ? new DirectedSparseGraph() - : new UndirectedSparseGraph(); + private Graph singleVertex(boolean directed) { + Graph g = directed + ? new DirectedSparseGraph() + : new UndirectedSparseGraph(); g.addVertex("A"); return g; } @@ -80,7 +80,7 @@ public void hasCycles_singleVertexUndirected_false() { @Test public void hasCycles_treeUndirected_false() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"B", "D"} }); assertFalse(new CycleAnalyzer(g).hasCycles()); @@ -88,7 +88,7 @@ public void hasCycles_treeUndirected_false() { @Test public void hasCycles_triangleUndirected_true() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); assertTrue(new CycleAnalyzer(g).hasCycles()); @@ -96,7 +96,7 @@ public void hasCycles_triangleUndirected_true() { @Test public void hasCycles_squareUndirected_true() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"} }); assertTrue(new CycleAnalyzer(g).hasCycles()); @@ -104,7 +104,7 @@ public void hasCycles_squareUndirected_true() { @Test public void hasCycles_disconnectedWithOneCyclic_true() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"}, // triangle {"D", "E"} // separate tree edge }); @@ -125,7 +125,7 @@ public void hasCycles_singleVertexDirected_false() { @Test public void hasCycles_dagDirected_false() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"A", "C"}, {"B", "D"}, {"C", "D"} }); assertFalse(new CycleAnalyzer(g).hasCycles()); @@ -133,7 +133,7 @@ public void hasCycles_dagDirected_false() { @Test public void hasCycles_directedTriangle_true() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); assertTrue(new CycleAnalyzer(g).hasCycles()); @@ -141,7 +141,7 @@ public void hasCycles_directedTriangle_true() { @Test public void hasCycles_selfLoop_directed_true() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "A"} }); assertTrue(new CycleAnalyzer(g).hasCycles()); @@ -149,7 +149,7 @@ public void hasCycles_selfLoop_directed_true() { @Test public void hasCycles_twoNodeCycleDirected_true() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "A"} }); assertTrue(new CycleAnalyzer(g).hasCycles()); @@ -164,7 +164,7 @@ public void girth_emptyGraph_negative1() { @Test public void girth_tree_negative1() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"} }); assertEquals(-1, new CycleAnalyzer(g).girth()); @@ -172,7 +172,7 @@ public void girth_tree_negative1() { @Test public void girth_triangle_3() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); assertEquals(3, new CycleAnalyzer(g).girth()); @@ -180,7 +180,7 @@ public void girth_triangle_3() { @Test public void girth_square_4() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"} }); assertEquals(4, new CycleAnalyzer(g).girth()); @@ -189,7 +189,7 @@ public void girth_square_4() { @Test public void girth_squareWithDiagonal_3() { // Square ABCD with diagonal AC creates two triangles - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"}, {"A", "C"} }); assertEquals(3, new CycleAnalyzer(g).girth()); @@ -197,7 +197,7 @@ public void girth_squareWithDiagonal_3() { @Test public void girth_directed_triangle_3() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); assertEquals(3, new CycleAnalyzer(g).girth()); @@ -205,7 +205,7 @@ public void girth_directed_triangle_3() { @Test public void girth_directed_selfLoop_1() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "A"} }); assertEquals(1, new CycleAnalyzer(g).girth()); @@ -213,7 +213,7 @@ public void girth_directed_selfLoop_1() { @Test public void girth_directed_twoNodeCycle_2() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "A"} }); assertEquals(2, new CycleAnalyzer(g).girth()); @@ -223,7 +223,7 @@ public void girth_directed_twoNodeCycle_2() { @Test public void fundamentalBasis_tree_empty() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"} }); List basis = new CycleAnalyzer(g).fundamentalCycleBasis(); @@ -232,7 +232,7 @@ public void fundamentalBasis_tree_empty() { @Test public void fundamentalBasis_triangle_oneCycle() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); List basis = new CycleAnalyzer(g).fundamentalCycleBasis(); @@ -243,7 +243,7 @@ public void fundamentalBasis_triangle_oneCycle() { @Test public void fundamentalBasis_squareWithDiagonal_twoCycles() { // 4 vertices, 5 edges, 1 component → cyclomatic number = 5-4+1 = 2 - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"}, {"A", "C"} }); List basis = new CycleAnalyzer(g).fundamentalCycleBasis(); @@ -253,7 +253,7 @@ public void fundamentalBasis_squareWithDiagonal_twoCycles() { @Test public void fundamentalBasis_K4_threeCycles() { // K4: 4 vertices, 6 edges, 1 component → 6-4+1 = 3 - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); @@ -264,7 +264,7 @@ public void fundamentalBasis_K4_threeCycles() { @Test public void fundamentalBasis_disconnected_correctCount() { // Two triangles: 6V, 6E, 2 components → 6-6+2 = 2 - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"}, {"D", "E"}, {"E", "F"}, {"F", "D"} }); @@ -283,7 +283,7 @@ public void fundamentalBasis_emptyGraph_empty() { @Test public void allCycles_tree_none() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"} }); CycleAnalyzer.CycleEnumerationResult result = @@ -294,7 +294,7 @@ public void allCycles_tree_none() { @Test public void allCycles_triangle_oneCycle() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); CycleAnalyzer.CycleEnumerationResult result = @@ -306,7 +306,7 @@ public void allCycles_triangle_oneCycle() { @Test public void allCycles_K4_sevenCycles() { // K4 has 7 simple cycles: 4 triangles + 3 four-cycles - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); @@ -318,7 +318,7 @@ public void allCycles_K4_sevenCycles() { @Test public void allCycles_directedTriangle_oneCycle() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); CycleAnalyzer.CycleEnumerationResult result = @@ -328,7 +328,7 @@ public void allCycles_directedTriangle_oneCycle() { @Test public void allCycles_directedTwoNodeCycle() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "A"} }); CycleAnalyzer.CycleEnumerationResult result = @@ -340,7 +340,7 @@ public void allCycles_directedTwoNodeCycle() { @Test public void allCycles_limit_respectsBound() { // K4 has 7 cycles; limit to 3 - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); @@ -358,7 +358,7 @@ public void allCycles_negativeLimit_throws() { @Test public void allCycles_noDuplicates() { // Square ABCD: should find exactly 1 cycle - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"} }); CycleAnalyzer.CycleEnumerationResult result = @@ -369,7 +369,7 @@ public void allCycles_noDuplicates() { @Test public void allCycles_squareWithDiagonal() { // Square + diagonal: 3 cycles (2 triangles + 1 square) - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"}, {"A", "C"} }); CycleAnalyzer.CycleEnumerationResult result = @@ -413,11 +413,11 @@ public void cycle_notEqual_differentVertices() { @Test public void cycle_totalWeight() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); // Set weights - for (edge e : g.getEdges()) { + for (Edge e : g.getEdges()) { e.setWeight(2.0f); } CycleAnalyzer.Cycle c = new CycleAnalyzer.Cycle( @@ -441,7 +441,7 @@ public void cycle_immutableVertices() { @Test public void analyze_acyclicGraph() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"} }); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); @@ -459,7 +459,7 @@ public void analyze_acyclicGraph() { @Test public void analyze_triangle() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); @@ -475,7 +475,7 @@ public void analyze_triangle() { @Test public void analyze_K4_vertexParticipation() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); @@ -500,7 +500,7 @@ public void analyze_K4_vertexParticipation() { @Test public void analyze_summary_containsKey_info() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"} }); String summary = new CycleAnalyzer(g).analyze().getSummary(); @@ -512,7 +512,7 @@ public void analyze_summary_containsKey_info() { @Test public void analyze_summary_acyclic() { - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"} }); String summary = new CycleAnalyzer(g).analyze().getSummary(); @@ -523,7 +523,7 @@ public void analyze_summary_acyclic() { @Test public void analyze_directed_dag() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"A", "C"}, {"B", "D"}, {"C", "D"} }); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); @@ -534,7 +534,7 @@ public void analyze_directed_dag() { @Test public void analyze_directed_withCycle() { - Graph g = buildDirected(new String[][] { + Graph g = buildDirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "A"}, {"C", "D"} }); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); @@ -547,7 +547,7 @@ public void analyze_directed_withCycle() { @Test public void analyze_circumference_longestCycle() { // Pentagon: single 5-cycle - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "E"}, {"E", "A"} }); CycleAnalyzer.CycleReport report = new CycleAnalyzer(g).analyze(); @@ -559,7 +559,7 @@ public void analyze_circumference_longestCycle() { @Test public void analyze_withLimit_reportsIncomplete() { // K4 has 7 cycles, limit to 2 - Graph g = buildUndirected(new String[][] { + Graph g = buildUndirected(new String[][] { {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); diff --git a/Gvisual/test/gvisual/DegreeDistributionAnalyzerTest.java b/Gvisual/test/gvisual/DegreeDistributionAnalyzerTest.java index 9f9e6b6..50f7b70 100644 --- a/Gvisual/test/gvisual/DegreeDistributionAnalyzerTest.java +++ b/Gvisual/test/gvisual/DegreeDistributionAnalyzerTest.java @@ -15,17 +15,17 @@ */ public class DegreeDistributionAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helpers --- - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/DominatingSetAnalyzerTest.java b/Gvisual/test/gvisual/DominatingSetAnalyzerTest.java index ddaedd0..a5c32be 100644 --- a/Gvisual/test/gvisual/DominatingSetAnalyzerTest.java +++ b/Gvisual/test/gvisual/DominatingSetAnalyzerTest.java @@ -14,15 +14,15 @@ */ public class DominatingSetAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/DotExporterTest.java b/Gvisual/test/gvisual/DotExporterTest.java index 2e2a629..442570e 100644 --- a/Gvisual/test/gvisual/DotExporterTest.java +++ b/Gvisual/test/gvisual/DotExporterTest.java @@ -17,8 +17,8 @@ */ public class DotExporterTest { - private Graph undirectedGraph; - private Graph directedGraph; + private Graph undirectedGraph; + private Graph directedGraph; @Before public void setUp() { @@ -27,11 +27,11 @@ public void setUp() { undirectedGraph.addVertex("A"); undirectedGraph.addVertex("B"); undirectedGraph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(2.0f); e1.setLabel("friendship"); undirectedGraph.addEdge(e1, "A", "B"); - edge e2 = new edge("c", "B", "C"); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(1.0f); undirectedGraph.addEdge(e2, "B", "C"); @@ -40,10 +40,10 @@ public void setUp() { directedGraph.addVertex("X"); directedGraph.addVertex("Y"); directedGraph.addVertex("Z"); - edge d1 = new edge("s", "X", "Y"); + Edge d1 = new Edge("s", "X", "Y"); d1.setWeight(3.0f); directedGraph.addEdge(d1, "X", "Y"); - edge d2 = new edge("sg", "Y", "Z"); + Edge d2 = new Edge("sg", "Y", "Z"); d2.setWeight(5.0f); directedGraph.addEdge(d2, "Y", "Z"); } @@ -171,7 +171,7 @@ public void testCustomTypeColor() { @Test public void testEmptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); DotExporter exporter = new DotExporter(empty); String dot = exporter.exportToString(); assertTrue(dot.contains("graph G {")); @@ -195,10 +195,10 @@ public void testExportToFile() throws IOException { @Test public void testQuoteEscapesSpecialChars() { // Add a vertex with special characters - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Node\"With\"Quotes"); g.addVertex("Normal"); - edge e = new edge("f", "Node\"With\"Quotes", "Normal"); + Edge e = new Edge("f", "Node\"With\"Quotes", "Normal"); g.addEdge(e, "Node\"With\"Quotes", "Normal"); DotExporter exporter = new DotExporter(g); @@ -229,7 +229,7 @@ public void testScaleEdgesByWeightDisabled() { @Test public void testSingleVertexGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("Solo"); DotExporter exporter = new DotExporter(g); String dot = exporter.exportToString(); diff --git a/Gvisual/test/gvisual/EdgePersistenceAnalyzerTest.java b/Gvisual/test/gvisual/EdgePersistenceAnalyzerTest.java index 8d1c1b8..dfd3d19 100644 --- a/Gvisual/test/gvisual/EdgePersistenceAnalyzerTest.java +++ b/Gvisual/test/gvisual/EdgePersistenceAnalyzerTest.java @@ -14,7 +14,7 @@ */ public class EdgePersistenceAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -45,25 +45,25 @@ public void testConstructor_negativeWindows() { @Test public void testClassify_allPersistent() { // Edge spans entire time range -> persistent in all windows - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(1000L); graph.addEdge(e1, "A", "B"); TemporalGraph tg = new TemporalGraph(graph); EdgePersistenceAnalyzer epa = new EdgePersistenceAnalyzer(tg, 10); - Map result = epa.classify(); + Map result = epa.classify(); assertEquals(EdgePersistenceAnalyzer.PERSISTENT, result.get(e1)); } @Test public void testClassify_transientEdge() { // Edge active only in a tiny window of a long timeline - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(1000L); - edge e2 = new edge("f", "C", "D"); + Edge e2 = new Edge("f", "C", "D"); e2.setTimestamp(0L); e2.setEndTimestamp(10L); // only first ~1% of range @@ -72,18 +72,18 @@ public void testClassify_transientEdge() { TemporalGraph tg = new TemporalGraph(graph); EdgePersistenceAnalyzer epa = new EdgePersistenceAnalyzer(tg, 20); - Map result = epa.classify(); + Map result = epa.classify(); assertEquals(EdgePersistenceAnalyzer.TRANSIENT, result.get(e2)); } @Test public void testClassify_periodicEdge() { // Edge active in about half the windows - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(1000L); // full range marker - edge e2 = new edge("f", "C", "D"); + Edge e2 = new Edge("f", "C", "D"); e2.setTimestamp(0L); e2.setEndTimestamp(500L); // half the range @@ -92,7 +92,7 @@ public void testClassify_periodicEdge() { TemporalGraph tg = new TemporalGraph(graph); EdgePersistenceAnalyzer epa = new EdgePersistenceAnalyzer(tg, 10); - Map result = epa.classify(); + Map result = epa.classify(); // e2 should be periodic (present in ~50% of windows) String c2 = result.get(e2); assertTrue("Half-range edge should be periodic", @@ -109,14 +109,14 @@ public void testClassify_emptyGraph() { @Test public void testClassify_singleWindow() { - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(100L); e1.setEndTimestamp(200L); graph.addEdge(e1, "A", "B"); TemporalGraph tg = new TemporalGraph(graph); EdgePersistenceAnalyzer epa = new EdgePersistenceAnalyzer(tg, 1); - Map result = epa.classify(); + Map result = epa.classify(); // With 1 window, ratio is 1.0 => persistent assertEquals(EdgePersistenceAnalyzer.PERSISTENT, result.get(e1)); } @@ -125,9 +125,9 @@ public void testClassify_singleWindow() { @Test public void testSummary_countsMatchClassify() { - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(1000L); - edge e2 = new edge("f", "C", "D"); + Edge e2 = new Edge("f", "C", "D"); e2.setTimestamp(0L); e2.setEndTimestamp(10L); graph.addEdge(e1, "A", "B"); @@ -145,7 +145,7 @@ public void testSummary_countsMatchClassify() { @Test public void testSummary_allKeysPresent() { - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(100L); graph.addEdge(e1, "A", "B"); @@ -161,25 +161,25 @@ public void testSummary_allKeysPresent() { @Test public void testGetEdgesByClassification_persistent() { - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(1000L); graph.addEdge(e1, "A", "B"); TemporalGraph tg = new TemporalGraph(graph); EdgePersistenceAnalyzer epa = new EdgePersistenceAnalyzer(tg, 5); - Set persistent = epa.getEdgesByClassification(EdgePersistenceAnalyzer.PERSISTENT); + Set persistent = epa.getEdgesByClassification(EdgePersistenceAnalyzer.PERSISTENT); assertTrue(persistent.contains(e1)); } @Test public void testGetEdgesByClassification_noMatch() { - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setTimestamp(0L); e1.setEndTimestamp(1000L); graph.addEdge(e1, "A", "B"); TemporalGraph tg = new TemporalGraph(graph); EdgePersistenceAnalyzer epa = new EdgePersistenceAnalyzer(tg, 5); - Set transient_ = epa.getEdgesByClassification(EdgePersistenceAnalyzer.TRANSIENT); + Set transient_ = epa.getEdgesByClassification(EdgePersistenceAnalyzer.TRANSIENT); assertFalse(transient_.contains(e1)); } diff --git a/Gvisual/test/gvisual/EdgeTest.java b/Gvisual/test/gvisual/EdgeTest.java index 23138dd..b6bc1f0 100644 --- a/Gvisual/test/gvisual/EdgeTest.java +++ b/Gvisual/test/gvisual/EdgeTest.java @@ -15,7 +15,7 @@ public class EdgeTest { @Test public void testDefaultConstructorFieldsAreNull() { - edge e = new edge(); + Edge e = new Edge(); assertNull("type should be null after no-arg construction", e.getType()); assertNull("vertex1 should be null after no-arg construction", e.getVertex1()); assertNull("vertex2 should be null after no-arg construction", e.getVertex2()); @@ -25,7 +25,7 @@ public void testDefaultConstructorFieldsAreNull() { @Test public void testParameterizedConstructor() { - edge e = new edge("f", "Alice", "Bob"); + Edge e = new Edge("f", "Alice", "Bob"); assertEquals("f", e.getType()); assertEquals("Alice", e.getVertex1()); assertEquals("Bob", e.getVertex2()); @@ -35,31 +35,31 @@ public void testParameterizedConstructor() { @Test public void testFriendEdgeType() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); assertEquals("f", e.getType()); } @Test public void testFamiliarStrangerEdgeType() { - edge e = new edge("fs", "A", "B"); + Edge e = new Edge("fs", "A", "B"); assertEquals("fs", e.getType()); } @Test public void testClassmateEdgeType() { - edge e = new edge("c", "A", "B"); + Edge e = new Edge("c", "A", "B"); assertEquals("c", e.getType()); } @Test public void testStrangerEdgeType() { - edge e = new edge("s", "A", "B"); + Edge e = new Edge("s", "A", "B"); assertEquals("s", e.getType()); } @Test public void testStudyGroupEdgeType() { - edge e = new edge("sg", "A", "B"); + Edge e = new Edge("sg", "A", "B"); assertEquals("sg", e.getType()); } @@ -67,28 +67,28 @@ public void testStudyGroupEdgeType() { @Test public void testSetAndGetWeight() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(42.5f); assertEquals(42.5f, e.getWeight(), 0.001f); } @Test public void testZeroWeight() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(0.0f); assertEquals(0.0f, e.getWeight(), 0.001f); } @Test public void testNegativeWeight() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(-10.0f); assertEquals(-10.0f, e.getWeight(), 0.001f); } @Test public void testLargeWeight() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(999999.99f); assertEquals(999999.99f, e.getWeight(), 1.0f); } @@ -97,14 +97,14 @@ public void testLargeWeight() { @Test public void testSetAndGetLabel() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setLabel("friend"); assertEquals("friend", e.getLabel()); } @Test public void testLabelCanBeOverwritten() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setLabel("friend"); e.setLabel("best friend"); assertEquals("best friend", e.getLabel()); @@ -112,7 +112,7 @@ public void testLabelCanBeOverwritten() { @Test public void testLabelCanBeSetToNull() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setLabel("friend"); e.setLabel(null); assertNull(e.getLabel()); @@ -120,7 +120,7 @@ public void testLabelCanBeSetToNull() { @Test public void testEmptyLabel() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setLabel(""); assertEquals("", e.getLabel()); } @@ -129,14 +129,14 @@ public void testEmptyLabel() { @Test public void testVerticesPreserveIds() { - edge e = new edge("c", "node_123", "node_456"); + Edge e = new Edge("c", "node_123", "node_456"); assertEquals("node_123", e.getVertex1()); assertEquals("node_456", e.getVertex2()); } @Test public void testVerticesWithSpecialCharacters() { - edge e = new edge("f", "user@domain", "user#2"); + Edge e = new Edge("f", "user@domain", "user#2"); assertEquals("user@domain", e.getVertex1()); assertEquals("user#2", e.getVertex2()); } @@ -144,7 +144,7 @@ public void testVerticesWithSpecialCharacters() { @Test public void testSelfLoop() { // edge class doesn't prevent self-loops — verify it stores them - edge e = new edge("f", "X", "X"); + Edge e = new Edge("f", "X", "X"); assertEquals(e.getVertex1(), e.getVertex2()); } } diff --git a/Gvisual/test/gvisual/EulerianPathAnalyzerTest.java b/Gvisual/test/gvisual/EulerianPathAnalyzerTest.java index c8b6774..d5135f2 100644 --- a/Gvisual/test/gvisual/EulerianPathAnalyzerTest.java +++ b/Gvisual/test/gvisual/EulerianPathAnalyzerTest.java @@ -20,13 +20,13 @@ public class EulerianPathAnalyzerTest { private int edgeId = 0; - private Graph newGraph() { + private Graph newGraph() { edgeId = 0; - return new UndirectedSparseGraph(); + return new UndirectedSparseGraph(); } - private void addEdge(Graph g, String v1, String v2) { - edge e = new edge("f", v1, v2); + private void addEdge(Graph g, String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setLabel("e" + (edgeId++)); g.addEdge(e, v1, v2); } @@ -35,7 +35,7 @@ private void addEdge(Graph g, String v1, String v2) { @Test public void testTriangleIsEulerianCircuit() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -49,7 +49,7 @@ public void testTriangleIsEulerianCircuit() { public void testSquareWithDiagonalsIsEulerianCircuit() { // K4 minus one edge won't work; use a proper even-degree graph // Square: A-B-C-D-A, all degree 2 - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -61,7 +61,7 @@ public void testSquareWithDiagonalsIsEulerianCircuit() { @Test public void testK4IsNotEulerian() { // K4: every vertex has degree 3 (odd) - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "A", "C"); addEdge(g, "A", "D"); @@ -78,7 +78,7 @@ public void testK4IsNotEulerian() { @Test public void testSimplePathGraph() { // A-B-C: A and C have degree 1 (odd), B has degree 2 (even) - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -91,7 +91,7 @@ public void testSimplePathGraph() { public void testKoenigsbergBridges() { // Classic 7-bridges problem (simplified): 4 vertices, 7 edges // All vertices have odd degree → NOT_EULERIAN - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "A", "B"); // multi-edge simulated with different edge objects addEdge(g, "A", "C"); @@ -108,7 +108,7 @@ public void testKoenigsbergBridges() { @Test public void testFindCircuitInTriangle() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -123,7 +123,7 @@ public void testFindCircuitInTriangle() { @Test public void testFindPathInLinearGraph() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -136,7 +136,7 @@ public void testFindPathInLinearGraph() { @Test public void testNoPathInK4() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "A", "C"); addEdge(g, "A", "D"); @@ -150,7 +150,7 @@ public void testNoPathInK4() { @Test public void testFindPathVisitsAllEdges() { // House graph: square + triangle on top - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -168,7 +168,7 @@ public void testFindPathVisitsAllEdges() { @Test public void testEmptyGraph() { - Graph g = newGraph(); + Graph g = newGraph(); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); EulerianPathAnalyzer.EulerianAnalysis result = analyzer.analyze(); assertEquals(EulerianPathAnalyzer.EulerianType.EULERIAN_CIRCUIT, result.getType()); @@ -176,7 +176,7 @@ public void testEmptyGraph() { @Test public void testSingleVertex() { - Graph g = newGraph(); + Graph g = newGraph(); g.addVertex("A"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); assertEquals(EulerianPathAnalyzer.EulerianType.EULERIAN_CIRCUIT, analyzer.analyze().getType()); @@ -184,7 +184,7 @@ public void testSingleVertex() { @Test public void testSingleEdge() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); assertEquals(EulerianPathAnalyzer.EulerianType.EULERIAN_PATH, analyzer.analyze().getType()); @@ -197,7 +197,7 @@ public void testNullGraphThrows() { @Test public void testDisconnectedGraphNotEulerian() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "C", "D"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -208,7 +208,7 @@ public void testDisconnectedGraphNotEulerian() { @Test public void testIsolatedVerticesIgnored() { // Triangle + isolated vertex → still Eulerian circuit - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -221,7 +221,7 @@ public void testIsolatedVerticesIgnored() { @Test public void testDegreeMapCorrect() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -234,7 +234,7 @@ public void testDegreeMapCorrect() { @Test public void testDegreeMapImmutable() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); Map degrees = analyzer.analyze().getDegreeMap(); @@ -250,7 +250,7 @@ public void testDegreeMapImmutable() { @Test public void testSuggestEdgesForEulerianOnEulerianGraph() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -260,7 +260,7 @@ public void testSuggestEdgesForEulerianOnEulerianGraph() { @Test public void testSuggestEdgesForK4() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "A", "C"); addEdge(g, "A", "D"); @@ -276,7 +276,7 @@ public void testSuggestEdgesForK4() { @Test public void testEdgeConnectivityTriangle() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -287,7 +287,7 @@ public void testEdgeConnectivityTriangle() { @Test public void testEdgeConnectivityBridge() { // A-B-C: bridge at B - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -296,7 +296,7 @@ public void testEdgeConnectivityBridge() { @Test public void testEdgeConnectivitySingleVertex() { - Graph g = newGraph(); + Graph g = newGraph(); g.addVertex("A"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); assertEquals(0, analyzer.computeEdgeConnectivity()); @@ -306,7 +306,7 @@ public void testEdgeConnectivitySingleVertex() { @Test public void testReportContainsType() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -319,7 +319,7 @@ public void testReportContainsType() { @Test public void testReportForNonEulerian() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "A", "C"); addEdge(g, "A", "D"); @@ -335,7 +335,7 @@ public void testReportForNonEulerian() { @Test public void testReportForPath() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -347,7 +347,7 @@ public void testReportForPath() { @Test public void testMinDuplicationsEulerianCircuit() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -357,7 +357,7 @@ public void testMinDuplicationsEulerianCircuit() { @Test public void testMinDuplicationsEulerianPath() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -366,7 +366,7 @@ public void testMinDuplicationsEulerianPath() { @Test public void testMinDuplicationsK4() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "A", "C"); addEdge(g, "A", "D"); @@ -382,7 +382,7 @@ public void testMinDuplicationsK4() { @Test public void testPetersenGraphNotEulerian() { // Petersen graph: 10 vertices, 15 edges, all degree 3 - Graph g = newGraph(); + Graph g = newGraph(); // Outer cycle addEdge(g, "0", "1"); addEdge(g, "1", "2"); addEdge(g, "2", "3"); addEdge(g, "3", "4"); addEdge(g, "4", "0"); @@ -400,7 +400,7 @@ public void testPetersenGraphNotEulerian() { @Test public void testCompleteGraphK5HasEulerianCircuit() { // K5: 5 vertices, 10 edges, all degree 4 (even) → Eulerian circuit - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) { for (int j = i + 1; j < v.length; j++) { @@ -418,7 +418,7 @@ public void testCompleteGraphK5HasEulerianCircuit() { @Test public void testCircuitPathReturnsToStart() { // Square graph - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -436,7 +436,7 @@ public void testCircuitPathReturnsToStart() { @Test public void testAnalysisTotalEdges() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -446,7 +446,7 @@ public void testAnalysisTotalEdges() { @Test public void testAnalysisTotalVertices() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); g.addVertex("D"); @@ -456,7 +456,7 @@ public void testAnalysisTotalVertices() { @Test public void testAnalysisConnected() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -465,7 +465,7 @@ public void testAnalysisConnected() { @Test public void testAnalysisDisconnected() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "C", "D"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); @@ -474,7 +474,7 @@ public void testAnalysisDisconnected() { @Test public void testPathResultImmutable() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -493,7 +493,7 @@ public void testPathResultImmutable() { @Test public void testStarGraphNotEulerian() { // Star with 5 leaves: center has degree 5, leaves have degree 1 - Graph g = newGraph(); + Graph g = newGraph(); for (int i = 1; i <= 5; i++) { addEdge(g, "center", "leaf" + i); } @@ -504,7 +504,7 @@ public void testStarGraphNotEulerian() { @Test public void testStarWithEvenLeaves() { // Star with 2 leaves: center degree 2, leaves degree 1 → Eulerian path - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "center", "A"); addEdge(g, "center", "B"); EulerianPathAnalyzer analyzer = new EulerianPathAnalyzer(g); diff --git a/Gvisual/test/gvisual/FeedbackVertexSetAnalyzerTest.java b/Gvisual/test/gvisual/FeedbackVertexSetAnalyzerTest.java index 7caf54d..1a4aca5 100644 --- a/Gvisual/test/gvisual/FeedbackVertexSetAnalyzerTest.java +++ b/Gvisual/test/gvisual/FeedbackVertexSetAnalyzerTest.java @@ -14,22 +14,22 @@ */ public class FeedbackVertexSetAnalyzerTest { - private Graph emptyGraph; - private Graph singleVertex; - private Graph singleEdge; - private Graph triangle; - private Graph path4; - private Graph star5; - private Graph cycle4; - private Graph cycle5; - private Graph complete4; - private Graph twoCycles; - private Graph diamond; - private Graph petersen; + private Graph emptyGraph; + private Graph singleVertex; + private Graph singleEdge; + private Graph triangle; + private Graph path4; + private Graph star5; + private Graph cycle4; + private Graph cycle5; + private Graph complete4; + private Graph twoCycles; + private Graph diamond; + private Graph petersen; private int edgeId = 0; - private edge addEdge(Graph g, String u, String v) { - edge e = new edge("e", u, v); + private Edge addEdge(Graph g, String u, String v) { + Edge e = new Edge("e", u, v); e.setLabel("e" + (edgeId++)); g.addEdge(e, u, v); return e; @@ -412,7 +412,7 @@ public void testSingleEdge_noCycle() { @Test public void testExactEqualsOrBetterThanGreedy() { - for (Graph g : Arrays.asList(triangle, cycle4, cycle5, complete4, twoCycles, diamond)) { + for (Graph g : Arrays.asList(triangle, cycle4, cycle5, complete4, twoCycles, diamond)) { FeedbackVertexSetAnalyzer a = new FeedbackVertexSetAnalyzer(g); assertTrue(a.exactMinimumFVS().size() <= a.greedyFVS().size()); } @@ -420,7 +420,7 @@ public void testExactEqualsOrBetterThanGreedy() { @Test public void testFeedbackEdgeSetSizeEqualsCycleRank() { - for (Graph g : Arrays.asList(emptyGraph, singleVertex, singleEdge, path4, triangle, cycle5, complete4, twoCycles)) { + for (Graph g : Arrays.asList(emptyGraph, singleVertex, singleEdge, path4, triangle, cycle5, complete4, twoCycles)) { FeedbackVertexSetAnalyzer a = new FeedbackVertexSetAnalyzer(g); assertEquals(a.cycleRank(), a.feedbackEdgeSet().size()); } diff --git a/Gvisual/test/gvisual/ForceDirectedLayoutTest.java b/Gvisual/test/gvisual/ForceDirectedLayoutTest.java index b07038d..955bdb6 100644 --- a/Gvisual/test/gvisual/ForceDirectedLayoutTest.java +++ b/Gvisual/test/gvisual/ForceDirectedLayoutTest.java @@ -14,19 +14,19 @@ */ public class ForceDirectedLayoutTest { - private Graph graph; + private Graph graph; private int edgeCounter; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); edgeCounter = 0; } - private edge addEdge(String v1, String v2) { + private Edge addEdge(String v1, String v2) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge("test", v1, v2); + Edge e = new Edge("test", v1, v2); e.setWeight(1.0f); graph.addEdge(e, v1, v2); edgeCounter++; @@ -242,7 +242,7 @@ public void testEdgeWeightsInfluenceLayout() { Math.pow(pA[1] - pC[1], 2)); // With weights, heavy edge A-B should pull tighter than weak A-C - assertTrue("Heavy edge should produce closer nodes: AB=" + + assertTrue("Heavy Edge should produce closer nodes: AB=" + distAB + " AC=" + distAC, distAB < distAC); } @@ -520,7 +520,7 @@ public void testBarnesHutLargeGraph() { // Connected nodes should still be closer than random pairs on average double connectedDist = 0; int connectedCount = 0; - for (edge e : graph.getEdges()) { + for (Edge e : graph.getEdges()) { double[] p1 = layout.getPosition(e.getVertex1()); double[] p2 = layout.getPosition(e.getVertex2()); if (p1 != null && p2 != null) { diff --git a/Gvisual/test/gvisual/GexfExporterTest.java b/Gvisual/test/gvisual/GexfExporterTest.java index 87f867e..b762884 100644 --- a/Gvisual/test/gvisual/GexfExporterTest.java +++ b/Gvisual/test/gvisual/GexfExporterTest.java @@ -18,8 +18,8 @@ */ public class GexfExporterTest { - private Graph graph; - private List edges; + private Graph graph; + private List edges; @Before public void setUp() { @@ -28,12 +28,12 @@ public void setUp() { graph.addVertex("Bob"); graph.addVertex("Carol"); - edge e1 = new edge("f", "Alice", "Bob"); + Edge e1 = new Edge("f", "Alice", "Bob"); e1.setWeight(3.5f); e1.setLabel("friends"); graph.addEdge(e1, "Alice", "Bob"); - edge e2 = new edge("c", "Bob", "Carol"); + Edge e2 = new Edge("c", "Bob", "Carol"); e2.setWeight(1.0f); graph.addEdge(e2, "Bob", "Carol"); @@ -55,7 +55,7 @@ public void testExportToStringContainsGexfStructure() { assertTrue(xml.contains("")); - assertTrue(xml.contains("")); + assertTrue(xml.contains("")); assertTrue(xml.contains("")); assertTrue(xml.contains("Alice")); assertTrue(xml.contains("Bob")); @@ -91,12 +91,12 @@ public void testVizDataCanBeDisabled() { @Test public void testTemporalEdgesEnableDynamicMode() { - edge e1 = new edge("f", "Alice", "Bob"); + Edge e1 = new Edge("f", "Alice", "Bob"); e1.setWeight(1.0f); e1.setTimestamp(1000L); e1.setEndTimestamp(5000L); - Graph tGraph = new UndirectedSparseGraph<>(); + Graph tGraph = new UndirectedSparseGraph<>(); tGraph.addVertex("Alice"); tGraph.addVertex("Bob"); tGraph.addEdge(e1, "Alice", "Bob"); @@ -129,11 +129,11 @@ public void testExportToFile() throws IOException { @Test public void testXmlEscaping() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A&B"); g.addVertex("C"); - edge e = new edge("f", "A&B", "C"); + Edge e = new Edge("f", "A&B", "C"); e.setWeight(1.0f); g.addEdge(e, "A&B", "C"); @@ -148,14 +148,14 @@ public void testXmlEscaping() { @Test public void testEmptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); GexfExporter exporter = new GexfExporter(empty, new ArrayList<>()); String xml = exporter.exportToString(); assertTrue(xml.contains("")); assertTrue(xml.contains("")); - assertTrue(xml.contains("")); - assertTrue(xml.contains("")); + assertTrue(xml.contains("")); + assertTrue(xml.contains("")); } @Test diff --git a/Gvisual/test/gvisual/GraphAlgorithmAnimatorTest.java b/Gvisual/test/gvisual/GraphAlgorithmAnimatorTest.java index c119646..d6410d0 100644 --- a/Gvisual/test/gvisual/GraphAlgorithmAnimatorTest.java +++ b/Gvisual/test/gvisual/GraphAlgorithmAnimatorTest.java @@ -15,11 +15,11 @@ */ public class GraphAlgorithmAnimatorTest { - private Graph simpleGraph; - private Graph weightedGraph; - private Graph directedGraph; - private Graph singleNode; - private Graph disconnected; + private Graph simpleGraph; + private Graph weightedGraph; + private Graph directedGraph; + private Graph singleNode; + private Graph disconnected; @Before public void setUp() { @@ -29,10 +29,10 @@ public void setUp() { simpleGraph.addVertex("B"); simpleGraph.addVertex("C"); simpleGraph.addVertex("D"); - simpleGraph.addEdge(new edge("e", "A", "B"), "A", "B"); - simpleGraph.addEdge(new edge("e", "B", "C"), "B", "C"); - simpleGraph.addEdge(new edge("e", "C", "D"), "C", "D"); - simpleGraph.addEdge(new edge("e", "A", "C"), "A", "C"); + simpleGraph.addEdge(new Edge("e", "A", "B"), "A", "B"); + simpleGraph.addEdge(new Edge("e", "B", "C"), "B", "C"); + simpleGraph.addEdge(new Edge("e", "C", "D"), "C", "D"); + simpleGraph.addEdge(new Edge("e", "A", "C"), "A", "C"); // Weighted graph for Dijkstra/Kruskal weightedGraph = new UndirectedSparseGraph<>(); @@ -40,10 +40,10 @@ public void setUp() { weightedGraph.addVertex("B"); weightedGraph.addVertex("C"); weightedGraph.addVertex("D"); - edge e1 = new edge("e", "A", "B"); e1.setWeight(1); - edge e2 = new edge("e", "B", "C"); e2.setWeight(3); - edge e3 = new edge("e", "A", "C"); e3.setWeight(5); - edge e4 = new edge("e", "C", "D"); e4.setWeight(2); + Edge e1 = new Edge("e", "A", "B"); e1.setWeight(1); + Edge e2 = new Edge("e", "B", "C"); e2.setWeight(3); + Edge e3 = new Edge("e", "A", "C"); e3.setWeight(5); + Edge e4 = new Edge("e", "C", "D"); e4.setWeight(2); weightedGraph.addEdge(e1, "A", "B"); weightedGraph.addEdge(e2, "B", "C"); weightedGraph.addEdge(e3, "A", "C"); @@ -54,9 +54,9 @@ public void setUp() { directedGraph.addVertex("A"); directedGraph.addVertex("B"); directedGraph.addVertex("C"); - directedGraph.addEdge(new edge("e", "A", "B"), "A", "B"); - directedGraph.addEdge(new edge("e", "B", "C"), "B", "C"); - directedGraph.addEdge(new edge("e", "C", "A"), "C", "A"); + directedGraph.addEdge(new Edge("e", "A", "B"), "A", "B"); + directedGraph.addEdge(new Edge("e", "B", "C"), "B", "C"); + directedGraph.addEdge(new Edge("e", "C", "A"), "C", "A"); // Single node singleNode = new UndirectedSparseGraph<>(); @@ -67,7 +67,7 @@ public void setUp() { disconnected.addVertex("A"); disconnected.addVertex("B"); disconnected.addVertex("C"); - disconnected.addEdge(new edge("e", "A", "B"), "A", "B"); + disconnected.addEdge(new Edge("e", "A", "B"), "A", "B"); // C is isolated } diff --git a/Gvisual/test/gvisual/GraphAnnotationManagerTest.java b/Gvisual/test/gvisual/GraphAnnotationManagerTest.java index 68a34ba..243d4a4 100644 --- a/Gvisual/test/gvisual/GraphAnnotationManagerTest.java +++ b/Gvisual/test/gvisual/GraphAnnotationManagerTest.java @@ -267,15 +267,15 @@ public void testGetSummary() { @Test public void testAutoTagByDegree() { - Graph graph = new UndirectedSparseGraph<>(); + Graph graph = new UndirectedSparseGraph<>(); graph.addVertex("hub"); graph.addVertex("leaf1"); graph.addVertex("leaf2"); graph.addVertex("leaf3"); graph.addVertex("isolated"); - graph.addEdge(new edge("f", "hub", "leaf1"), "hub", "leaf1"); - graph.addEdge(new edge("f", "hub", "leaf2"), "hub", "leaf2"); - graph.addEdge(new edge("f", "hub", "leaf3"), "hub", "leaf3"); + graph.addEdge(new Edge("f", "hub", "leaf1"), "hub", "leaf1"); + graph.addEdge(new Edge("f", "hub", "leaf2"), "hub", "leaf2"); + graph.addEdge(new Edge("f", "hub", "leaf3"), "hub", "leaf3"); int count = manager.autoTagByDegree(graph, 3, 0); assertTrue(count > 0); @@ -285,11 +285,11 @@ public void testAutoTagByDegree() { @Test public void testAutoTagIsolated() { - Graph graph = new UndirectedSparseGraph<>(); + Graph graph = new UndirectedSparseGraph<>(); graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); int count = manager.autoTagIsolated(graph); assertEquals(1, count); diff --git a/Gvisual/test/gvisual/GraphAnomalyDetectorTest.java b/Gvisual/test/gvisual/GraphAnomalyDetectorTest.java index c546f1d..20edf2d 100644 --- a/Gvisual/test/gvisual/GraphAnomalyDetectorTest.java +++ b/Gvisual/test/gvisual/GraphAnomalyDetectorTest.java @@ -14,11 +14,11 @@ */ public class GraphAnomalyDetectorTest { - private Graph graph; + private Graph graph; /** Creates an edge with the given type and weight. */ - private edge makeEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); return e; } @@ -33,7 +33,7 @@ private edge makeEdge(String type, String v1, String v2, float weight) { */ @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); // Add hub String hub = "0"; @@ -45,7 +45,7 @@ public void setUp() { String node = String.valueOf(i); graph.addVertex(node); // Hub connects to each ring node with varying types - edge e = makeEdge(types[i - 1], hub, node, 1.0f); + Edge e = makeEdge(types[i - 1], hub, node, 1.0f); graph.addEdge(e, hub, node); } @@ -53,13 +53,13 @@ public void setUp() { for (int i = 1; i <= 8; i++) { String from = String.valueOf(i); String to = String.valueOf(i == 8 ? 1 : i + 1); - edge e = makeEdge("f", from, to, 1.0f); + Edge e = makeEdge("f", from, to, 1.0f); graph.addEdge(e, from, to); } // Leaf node graph.addVertex("9"); - edge leafEdge = makeEdge("s", "1", "9", 1.0f); + Edge leafEdge = makeEdge("s", "1", "9", 1.0f); graph.addEdge(leafEdge, "1", "9"); } @@ -92,22 +92,22 @@ public void testAnalyzeReturnsThis() { @Test(expected = IllegalStateException.class) public void testAnalyzeTooFewVertices() { - Graph tiny = new UndirectedSparseGraph(); + Graph tiny = new UndirectedSparseGraph(); tiny.addVertex("A"); tiny.addVertex("B"); - edge e = makeEdge("f", "A", "B", 1.0f); + Edge e = makeEdge("f", "A", "B", 1.0f); tiny.addEdge(e, "A", "B"); new GraphAnomalyDetector(tiny).analyze(); } @Test public void testAnalyzeThreeVerticesMinimum() { - Graph small = new UndirectedSparseGraph(); + Graph small = new UndirectedSparseGraph(); small.addVertex("A"); small.addVertex("B"); small.addVertex("C"); - edge e1 = makeEdge("f", "A", "B", 1.0f); - edge e2 = makeEdge("f", "B", "C", 1.0f); + Edge e1 = makeEdge("f", "A", "B", 1.0f); + Edge e2 = makeEdge("f", "B", "C", 1.0f); small.addEdge(e1, "A", "B"); small.addEdge(e2, "B", "C"); @@ -346,7 +346,7 @@ public void testHubHasHighDiversity() { GraphAnomalyDetector det = new GraphAnomalyDetector(graph).analyze(); GraphAnomalyDetector.AnomalyResult hub = det.getResult("0"); // Hub connects with 5 different edge types - assertTrue("Hub should have high edge diversity", + assertTrue("Hub should have high Edge diversity", hub.getEdgeDiversity() > 0.5); } @@ -437,14 +437,14 @@ public void testReanalyzeGivesSameResults() { @Test public void testUniformGraphLowScores() { // Ring graph: all nodes have degree 2, same clustering, same diversity - Graph ring = new UndirectedSparseGraph(); + Graph ring = new UndirectedSparseGraph(); for (int i = 0; i < 6; i++) { ring.addVertex(String.valueOf(i)); } for (int i = 0; i < 6; i++) { String from = String.valueOf(i); String to = String.valueOf((i + 1) % 6); - edge e = makeEdge("f", from, to, 1.0f); + Edge e = makeEdge("f", from, to, 1.0f); ring.addEdge(e, from, to); } @@ -460,12 +460,12 @@ public void testUniformGraphLowScores() { @Test public void testStarGraphHubIsAnomaly() { - Graph star = new UndirectedSparseGraph(); + Graph star = new UndirectedSparseGraph(); star.addVertex("center"); for (int i = 0; i < 10; i++) { String leaf = "leaf" + i; star.addVertex(leaf); - edge e = makeEdge("f", "center", leaf, 1.0f); + Edge e = makeEdge("f", "center", leaf, 1.0f); star.addEdge(e, "center", leaf); } @@ -480,14 +480,14 @@ public void testStarGraphHubIsAnomaly() { @Test public void testCompleteGraphAllSimilar() { - Graph complete = new UndirectedSparseGraph(); + Graph complete = new UndirectedSparseGraph(); String[] nodes = {"A", "B", "C", "D"}; for (String n : nodes) complete.addVertex(n); int edgeId = 0; for (int i = 0; i < nodes.length; i++) { for (int j = i + 1; j < nodes.length; j++) { - edge e = makeEdge("f", nodes[i], nodes[j], 1.0f); + Edge e = makeEdge("f", nodes[i], nodes[j], 1.0f); complete.addEdge(e, nodes[i], nodes[j]); } } diff --git a/Gvisual/test/gvisual/GraphAsciiRendererTest.java b/Gvisual/test/gvisual/GraphAsciiRendererTest.java index 5de1fb7..bdcd9d2 100644 --- a/Gvisual/test/gvisual/GraphAsciiRendererTest.java +++ b/Gvisual/test/gvisual/GraphAsciiRendererTest.java @@ -19,10 +19,10 @@ */ public class GraphAsciiRendererTest { - private Graph emptyGraph; - private Graph singleNodeGraph; - private Graph triangleGraph; - private Graph starGraph; + private Graph emptyGraph; + private Graph singleNodeGraph; + private Graph triangleGraph; + private Graph starGraph; @Before public void setUp() { @@ -36,11 +36,11 @@ public void setUp() { triangleGraph.addVertex("A"); triangleGraph.addVertex("B"); triangleGraph.addVertex("C"); - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "B", "C"); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("f", "C", "A"); + Edge e3 = new Edge("f", "C", "A"); e3.setWeight(1.5f); triangleGraph.addEdge(e1, "A", "B"); triangleGraph.addEdge(e2, "B", "C"); @@ -52,7 +52,7 @@ public void setUp() { for (int i = 1; i <= 4; i++) { String leaf = "Leaf" + i; starGraph.addVertex(leaf); - edge e = new edge("f", "Center", leaf); + Edge e = new Edge("f", "Center", leaf); e.setWeight(1.0f); starGraph.addEdge(e, "Center", leaf); } @@ -229,7 +229,7 @@ public void adjacencyListContainsAllVertices() { assertTrue(output.contains("B")); assertTrue(output.contains("C")); assertTrue(output.contains("3 nodes")); - assertTrue(output.contains("3 edges")); + assertTrue(output.contains("3 Edges")); } @Test @@ -328,12 +328,12 @@ public void minimalLayoutIterationsStillRenders() { @Test public void largeGraphRendersWithoutError() { - Graph large = new UndirectedSparseGraph<>(); + Graph large = new UndirectedSparseGraph<>(); for (int i = 0; i < 50; i++) { large.addVertex("N" + i); } for (int i = 0; i < 49; i++) { - edge e = new edge("f", "N" + i, "N" + (i + 1)); + Edge e = new Edge("f", "N" + i, "N" + (i + 1)); e.setWeight(1.0f); large.addEdge(e, "N" + i, "N" + (i + 1)); } diff --git a/Gvisual/test/gvisual/GraphBenchmarkSuiteTest.java b/Gvisual/test/gvisual/GraphBenchmarkSuiteTest.java index 16d145f..5982b20 100644 --- a/Gvisual/test/gvisual/GraphBenchmarkSuiteTest.java +++ b/Gvisual/test/gvisual/GraphBenchmarkSuiteTest.java @@ -17,7 +17,7 @@ public class GraphBenchmarkSuiteTest { assertTrue(bg.verify()); } @Test public void testZacharyKeyNodes() { - Graph g = suite.zacharyKarateClub().getGraph(); + Graph g = suite.zacharyKarateClub().getGraph(); assertTrue(g.containsVertex("1")); assertTrue(g.containsVertex("34")); assertTrue(g.degree("1") >= 16); @@ -32,7 +32,7 @@ public class GraphBenchmarkSuiteTest { assertTrue(bg.verify()); } @Test public void testPetersenThreeRegular() { - Graph g = suite.petersenGraph().getGraph(); + Graph g = suite.petersenGraph().getGraph(); for (String v : g.getVertices()) assertEquals(3, g.degree(v)); } @Test public void testPetersenNotHamiltonian() { @@ -45,12 +45,12 @@ public class GraphBenchmarkSuiteTest { assertTrue(bg.verify()); } @Test public void testFlorentineMediciHighest() { - Graph g = suite.florentineFamilies().getGraph(); + Graph g = suite.florentineFamilies().getGraph(); int md = g.degree("Medici"); for (String v : g.getVertices()) assertTrue(md >= g.degree(v)); } @Test public void testFlorentineNames() { - Graph g = suite.florentineFamilies().getGraph(); + Graph g = suite.florentineFamilies().getGraph(); assertTrue(g.containsVertex("Strozzi")); assertTrue(g.containsVertex("Albizzi")); } @@ -104,7 +104,7 @@ public class GraphBenchmarkSuiteTest { assertEquals(8, suite.friendshipGraph(4).getGraph().degree("0")); } @Test public void testFriendshipLeafDegree() { - Graph g = suite.friendshipGraph(3).getGraph(); + Graph g = suite.friendshipGraph(3).getGraph(); for (String v : g.getVertices()) if (!v.equals("0")) assertEquals(2, g.degree(v)); } diff --git a/Gvisual/test/gvisual/GraphCentralityCorrelatorTest.java b/Gvisual/test/gvisual/GraphCentralityCorrelatorTest.java index 52f675f..d484a8a 100644 --- a/Gvisual/test/gvisual/GraphCentralityCorrelatorTest.java +++ b/Gvisual/test/gvisual/GraphCentralityCorrelatorTest.java @@ -15,17 +15,17 @@ */ public class GraphCentralityCorrelatorTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helper methods --- - private edge addEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge addEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/GraphClusterQualityAnalyzerTest.java b/Gvisual/test/gvisual/GraphClusterQualityAnalyzerTest.java index 1f35419..34723ba 100644 --- a/Gvisual/test/gvisual/GraphClusterQualityAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphClusterQualityAnalyzerTest.java @@ -14,11 +14,11 @@ */ public class GraphClusterQualityAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // ── Helper methods ────────────────────────────────────────── @@ -26,7 +26,7 @@ public void setUp() { private void addEdge(String v1, String v2, String type) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge(type, v1, v2); + Edge e = new Edge(type, v1, v2); graph.addEdge(e, v1, v2); } diff --git a/Gvisual/test/gvisual/GraphColoringAnalyzerTest.java b/Gvisual/test/gvisual/GraphColoringAnalyzerTest.java index 0a4f28b..d9c8a60 100644 --- a/Gvisual/test/gvisual/GraphColoringAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphColoringAnalyzerTest.java @@ -11,16 +11,16 @@ /** * Tests for GraphColoringAnalyzer -- greedy coloring with multiple orderings, * DSatur, chromatic bounds, k-colorability, coloring verification, color - * class analysis, edge chromatic bounds, and report generation. + * class analysis, Edge chromatic bounds, and report generation. */ public class GraphColoringAnalyzerTest { - private Graph graph; + private Graph graph; private int edgeCounter; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); edgeCounter = 0; } @@ -618,7 +618,7 @@ public void testEdgeChromaticBoundsStar() { graph.addVertex("leaf" + i); addEdge("center", "leaf" + i); } - int[] bounds = new GraphColoringAnalyzer(graph).edgeChromaticBounds(); + int[] bounds = new GraphColoringAnalyzer(graph).EdgeChromaticBounds(); assertEquals(5, bounds[0]); assertEquals(6, bounds[1]); } @@ -858,7 +858,7 @@ public void testWelshPowellPrioritizesHighDegree() { // ========================================== private void addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setLabel("e" + (edgeCounter++)); graph.addEdge(e, v1, v2); } diff --git a/Gvisual/test/gvisual/GraphDiameterAnalyzerTest.java b/Gvisual/test/gvisual/GraphDiameterAnalyzerTest.java index a7111ed..46615f5 100644 --- a/Gvisual/test/gvisual/GraphDiameterAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphDiameterAnalyzerTest.java @@ -15,11 +15,11 @@ */ public class GraphDiameterAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } @Test(expected = IllegalArgumentException.class) @@ -60,9 +60,9 @@ public void linearGraph() { graph.addVertex("B"); graph.addVertex("C"); graph.addVertex("D"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); - graph.addEdge(new edge("f", "C", "D"), "C", "D"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "C", "D"), "C", "D"); GraphDiameterAnalyzer analyzer = new GraphDiameterAnalyzer(graph); analyzer.analyze(); @@ -85,7 +85,7 @@ public void completeGraph() { int edgeId = 0; for (int i = 0; i < verts.length; i++) { for (int j = i + 1; j < verts.length; j++) { - graph.addEdge(new edge("f", verts[i], verts[j]), verts[i], verts[j]); + graph.addEdge(new Edge("f", verts[i], verts[j]), verts[i], verts[j]); } } @@ -105,7 +105,7 @@ public void starGraph() { for (int i = 1; i <= 4; i++) { String leaf = "L" + i; graph.addVertex(leaf); - graph.addEdge(new edge("f", "H", leaf), "H", leaf); + graph.addEdge(new Edge("f", "H", leaf), "H", leaf); } GraphDiameterAnalyzer analyzer = new GraphDiameterAnalyzer(graph); @@ -127,9 +127,9 @@ public void disconnectedGraphUsesLargestComponent() { graph.addVertex("C"); graph.addVertex("X"); graph.addVertex("Y"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); - graph.addEdge(new edge("f", "X", "Y"), "X", "Y"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "X", "Y"), "X", "Y"); GraphDiameterAnalyzer analyzer = new GraphDiameterAnalyzer(graph); analyzer.analyze(); @@ -147,8 +147,8 @@ public void eccentricityValues() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); GraphDiameterAnalyzer analyzer = new GraphDiameterAnalyzer(graph); analyzer.analyze(); @@ -162,7 +162,7 @@ public void eccentricityValues() { public void summaryContainsKey() { graph.addVertex("A"); graph.addVertex("B"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); GraphDiameterAnalyzer analyzer = new GraphDiameterAnalyzer(graph); analyzer.analyze(); @@ -179,8 +179,8 @@ public void rankedByEccentricityIsSorted() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); GraphDiameterAnalyzer analyzer = new GraphDiameterAnalyzer(graph); analyzer.analyze(); diff --git a/Gvisual/test/gvisual/GraphDiffAnalyzerTest.java b/Gvisual/test/gvisual/GraphDiffAnalyzerTest.java index 1df4ea3..fb60bac 100644 --- a/Gvisual/test/gvisual/GraphDiffAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphDiffAnalyzerTest.java @@ -16,8 +16,8 @@ */ public class GraphDiffAnalyzerTest { - private Graph graphA; - private Graph graphB; + private Graph graphA; + private Graph graphB; @Before public void setUp() { @@ -25,10 +25,10 @@ public void setUp() { graphB = new UndirectedSparseGraph<>(); } - private void addEdge(Graph g, String v1, String v2) { + private void addEdge(Graph g, String v1, String v2) { if (!g.containsVertex(v1)) g.addVertex(v1); if (!g.containsVertex(v2)) g.addVertex(v2); - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); g.addEdge(e, v1, v2); } diff --git a/Gvisual/test/gvisual/GraphDistanceDistributionTest.java b/Gvisual/test/gvisual/GraphDistanceDistributionTest.java index b18d022..6debf8e 100644 --- a/Gvisual/test/gvisual/GraphDistanceDistributionTest.java +++ b/Gvisual/test/gvisual/GraphDistanceDistributionTest.java @@ -16,34 +16,34 @@ public class GraphDistanceDistributionTest { // --- helpers --- - private Graph makePath(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makePath(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) g.addVertex("v" + i); for (int i = 0; i < n - 1; i++) { - g.addEdge(new edge("e", "v" + i, "v" + (i + 1)), "v" + i, "v" + (i + 1)); + g.addEdge(new Edge("e", "v" + i, "v" + (i + 1)), "v" + i, "v" + (i + 1)); } return g; } - private Graph makeComplete(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makeComplete(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) g.addVertex("v" + i); int id = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { - g.addEdge(new edge("e" + id++, "v" + i, "v" + j), "v" + i, "v" + j); + g.addEdge(new Edge("e" + id++, "v" + i, "v" + j), "v" + i, "v" + j); } } return g; } - private Graph makeStar(int leaves) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makeStar(int leaves) { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("center"); for (int i = 0; i < leaves; i++) { String leaf = "leaf" + i; g.addVertex(leaf); - g.addEdge(new edge("e" + i, "center", leaf), "center", leaf); + g.addEdge(new Edge("e" + i, "center", leaf), "center", leaf); } return g; } @@ -65,7 +65,7 @@ public void testNotComputed() { @Test public void testEmptyGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); assertEquals(0.0, dd.getAveragePathLength(), 0.001); @@ -76,7 +76,7 @@ public void testEmptyGraph() { @Test public void testSingleVertex() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); @@ -177,11 +177,11 @@ public void testConnectedSeparation() { @Test public void testDisconnectedSeparation() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); - g.addEdge(new edge("e1", "a", "b"), "a", "b"); + g.addEdge(new Edge("e1", "a", "b"), "a", "b"); // c is isolated → 2 out of 3 pairs unreachable GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); @@ -201,7 +201,7 @@ public void testHarmonicMeanComplete() { @Test public void testHarmonicMeanDisconnected() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); g.addVertex("b"); // No edges → infinite harmonic mean @@ -247,7 +247,7 @@ public void testDistinctDistancesComplete() { @Test public void testUnreachableDistance() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); g.addVertex("b"); GraphDistanceDistribution dd = new GraphDistanceDistribution(g); @@ -266,7 +266,7 @@ public void testNonexistentVertex() { @Test public void testRemotenessIsolated() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); @@ -318,12 +318,12 @@ public void testHistogramJson() { @Test public void testDirectedGraph() { - Graph g = new DirectedSparseGraph<>(); + Graph g = new DirectedSparseGraph<>(); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); - g.addEdge(new edge("e1", "a", "b"), "a", "b"); - g.addEdge(new edge("e2", "b", "c"), "b", "c"); + g.addEdge(new Edge("e1", "a", "b"), "a", "b"); + g.addEdge(new Edge("e2", "b", "c"), "b", "c"); // a→b→c but no reverse GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); @@ -357,13 +357,13 @@ public void testRecompute() { @Test public void testTwoComponents() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); g.addVertex("b"); - g.addEdge(new edge("e1", "a", "b"), "a", "b"); + g.addEdge(new Edge("e1", "a", "b"), "a", "b"); g.addVertex("c"); g.addVertex("d"); - g.addEdge(new edge("e2", "c", "d"), "c", "d"); + g.addEdge(new Edge("e2", "c", "d"), "c", "d"); GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); assertEquals(1, dd.getDistance("a", "b")); @@ -379,7 +379,7 @@ public void testTwoComponents() { @Test public void testPercentileEmpty() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); @@ -390,11 +390,11 @@ public void testPercentileEmpty() { @Test public void testCycleGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 6; i++) g.addVertex("v" + i); for (int i = 0; i < 6; i++) { int j = (i + 1) % 6; - g.addEdge(new edge("e" + i, "v" + i, "v" + j), "v" + i, "v" + j); + g.addEdge(new Edge("e" + i, "v" + i, "v" + j), "v" + i, "v" + j); } GraphDistanceDistribution dd = new GraphDistanceDistribution(g); dd.compute(); diff --git a/Gvisual/test/gvisual/GraphEntropyAnalyzerTest.java b/Gvisual/test/gvisual/GraphEntropyAnalyzerTest.java index 82a813c..d73feee 100644 --- a/Gvisual/test/gvisual/GraphEntropyAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphEntropyAnalyzerTest.java @@ -14,7 +14,7 @@ */ public class GraphEntropyAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -23,12 +23,12 @@ public void setUp() { // --- Helpers --- - private edge addEdge(String v1, String v2) { + private Edge addEdge(String v1, String v2) { return addEdge(v1, v2, "f"); } - private edge addEdge(String v1, String v2, String type) { - edge e = new edge(type, v1, v2); + private Edge addEdge(String v1, String v2, String type) { + Edge e = new Edge(type, v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -36,12 +36,12 @@ private edge addEdge(String v1, String v2, String type) { return e; } - private Graph completeGraph(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph completeGraph(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 1; i <= n; i++) g.addVertex("N" + i); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { - edge e = new edge("f", "N" + i, "N" + j); + Edge e = new Edge("f", "N" + i, "N" + j); e.setWeight(1.0f); g.addEdge(e, "N" + i, "N" + j); } @@ -49,31 +49,31 @@ private Graph completeGraph(int n) { return g; } - private Graph pathGraph(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph pathGraph(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 1; i <= n; i++) g.addVertex("N" + i); for (int i = 1; i < n; i++) { - edge e = new edge("f", "N" + i, "N" + (i + 1)); + Edge e = new Edge("f", "N" + i, "N" + (i + 1)); e.setWeight(1.0f); g.addEdge(e, "N" + i, "N" + (i + 1)); } return g; } - private Graph cycleGraph(int n) { - Graph g = pathGraph(n); - edge e = new edge("f", "N" + n, "N1"); + private Graph cycleGraph(int n) { + Graph g = pathGraph(n); + Edge e = new Edge("f", "N" + n, "N1"); e.setWeight(1.0f); g.addEdge(e, "N" + n, "N1"); return g; } - private Graph starGraph(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph starGraph(int n) { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("C"); for (int i = 1; i <= n; i++) { g.addVertex("L" + i); - edge e = new edge("f", "C", "L" + i); + Edge e = new Edge("f", "C", "L" + i); e.setWeight(1.0f); g.addEdge(e, "C", "L" + i); } @@ -129,7 +129,7 @@ public void testNullGraphThrows() { @Test public void testDegreeEntropyRegularGraph() { - Graph g = cycleGraph(5); + Graph g = cycleGraph(5); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getDegreeEntropy(), 1e-10); @@ -137,7 +137,7 @@ public void testDegreeEntropyRegularGraph() { @Test public void testDegreeEntropyStarGraph() { - Graph g = starGraph(4); + Graph g = starGraph(4); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); // 1 vertex with degree 4, 4 vertices with degree 1 @@ -149,7 +149,7 @@ public void testDegreeEntropyStarGraph() { @Test public void testDegreeEntropyCompleteGraph() { - Graph g = completeGraph(5); + Graph g = completeGraph(5); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getDegreeEntropy(), 1e-10); @@ -164,7 +164,7 @@ public void testMaxDegreeEntropy() { @Test public void testNormalisedDegreeEntropyRegular() { - Graph g = cycleGraph(6); + Graph g = cycleGraph(6); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getNormalisedDegreeEntropy(), 1e-10); @@ -211,7 +211,7 @@ public void testVonNeumannTriangle() { @Test public void testVonNeumannPositive() { - Graph g = pathGraph(5); + Graph g = pathGraph(5); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertTrue(a.getVonNeumannEntropy() > 0); @@ -232,7 +232,7 @@ public void testVonNeumannCompleteHigherThanPath() { @Test public void testNeighbourhoodEntropyRegular() { - Graph g = cycleGraph(5); + Graph g = cycleGraph(5); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getAvgNeighbourhoodEntropy(), 1e-10); @@ -337,7 +337,7 @@ public void testEdgeTypeEntropyNoEdges() { @Test public void testTopoInfoContentComplete() { - Graph g = completeGraph(4); + Graph g = completeGraph(4); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getTopologicalInfoContent(), 1e-6); @@ -345,7 +345,7 @@ public void testTopoInfoContentComplete() { @Test public void testTopoInfoContentAllDifferent() { - Graph g = pathGraph(4); + Graph g = pathGraph(4); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertTrue(a.getTopologicalInfoContent() > 0); @@ -365,7 +365,7 @@ public void testTopoInfoContentSingleVertex() { @Test public void testRWEntropyRateRegular() { - Graph g = cycleGraph(6); + Graph g = cycleGraph(6); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); // C6: m=6, 2m=12, each d=2 for 6 vertices @@ -399,7 +399,7 @@ public void testRWEntropyRateNoEdges() { @Test public void testChromaticEntropyComplete() { - Graph g = completeGraph(4); + Graph g = completeGraph(4); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(Math.log(4) / Math.log(2), a.getChromaticEntropy(), 1e-10); @@ -407,7 +407,7 @@ public void testChromaticEntropyComplete() { @Test public void testChromaticEntropyBipartite() { - Graph g = pathGraph(4); + Graph g = pathGraph(4); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(1.0, a.getChromaticEntropy(), 1e-6); @@ -448,7 +448,7 @@ public void testDegreeCCMutualInfoSingleVertex() { @Test public void testDegreeCCMutualInfoRegular() { - Graph g = cycleGraph(6); + Graph g = cycleGraph(6); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getDegreeCCMutualInfo(), 1e-10); @@ -469,7 +469,7 @@ public void testComplexityTrivialEmpty() { public void testComplexityRegularLow() { // Cycle — all vertices have same degree, but Von Neumann entropy // is non-trivial so complexity is moderate, not low - Graph g = cycleGraph(6); + Graph g = cycleGraph(6); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); String c = a.getComplexityClass(); @@ -551,7 +551,7 @@ public void testLazyCompute() { @Test public void testCompleteGraphK10() { - Graph g = completeGraph(10); + Graph g = completeGraph(10); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertEquals(0, a.getDegreeEntropy(), 1e-10); @@ -561,7 +561,7 @@ public void testCompleteGraphK10() { @Test public void testPathGraph10() { - Graph g = pathGraph(10); + Graph g = pathGraph(10); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertTrue(a.getDegreeEntropy() > 0); @@ -571,7 +571,7 @@ public void testPathGraph10() { @Test public void testStarGraph10() { - Graph g = starGraph(10); + Graph g = starGraph(10); GraphEntropyAnalyzer a = new GraphEntropyAnalyzer(g); a.compute(); assertTrue(a.getDegreeEntropy() > 0); @@ -632,15 +632,15 @@ public void testStarHigherDegreeEntropyThanCycle() { @Test public void testEdgeTypeEntropyMonotonicity() { - Graph g1 = new UndirectedSparseGraph<>(); + Graph g1 = new UndirectedSparseGraph<>(); g1.addVertex("A"); g1.addVertex("B"); g1.addVertex("C"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1); g1.addEdge(e1, "A", "B"); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1); g1.addEdge(e2, "B", "C"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1); g1.addEdge(e1, "A", "B"); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1); g1.addEdge(e2, "B", "C"); - Graph g2 = new UndirectedSparseGraph<>(); + Graph g2 = new UndirectedSparseGraph<>(); g2.addVertex("A"); g2.addVertex("B"); g2.addVertex("C"); - edge e3 = new edge("f", "A", "B"); e3.setWeight(1); g2.addEdge(e3, "A", "B"); - edge e4 = new edge("c", "B", "C"); e4.setWeight(1); g2.addEdge(e4, "B", "C"); + Edge e3 = new Edge("f", "A", "B"); e3.setWeight(1); g2.addEdge(e3, "A", "B"); + Edge e4 = new Edge("c", "B", "C"); e4.setWeight(1); g2.addEdge(e4, "B", "C"); GraphEntropyAnalyzer a1 = new GraphEntropyAnalyzer(g1); a1.compute(); @@ -692,13 +692,13 @@ public void testWheelGraph() { graph.addVertex("C"); for (int i = 1; i <= 6; i++) { graph.addVertex("N" + i); - edge e = new edge("f", "C", "N" + i); + Edge e = new Edge("f", "C", "N" + i); e.setWeight(1.0f); graph.addEdge(e, "C", "N" + i); } for (int i = 1; i <= 6; i++) { int next = (i % 6) + 1; - edge e = new edge("f", "N" + i, "N" + next); + Edge e = new Edge("f", "N" + i, "N" + next); e.setWeight(1.0f); graph.addEdge(e, "N" + i, "N" + next); } diff --git a/Gvisual/test/gvisual/GraphGeneratorTest.java b/Gvisual/test/gvisual/GraphGeneratorTest.java index b078be4..595a050 100644 --- a/Gvisual/test/gvisual/GraphGeneratorTest.java +++ b/Gvisual/test/gvisual/GraphGeneratorTest.java @@ -64,7 +64,7 @@ public void complete_negativeNodes_throws() { @Test public void complete_allNodesConnected() { GraphGenerator.GeneratedGraph result = gen.complete(4); - Graph g = result.getGraph(); + Graph g = result.getGraph(); for (String v : g.getVertices()) { assertEquals(3, g.degree(v)); } @@ -110,7 +110,7 @@ public void star_tenNodes() { assertEquals(10, result.getNodeCount()); assertEquals(9, result.getEdgeCount()); // Hub has degree n-1, leaves have degree 1 - Graph g = result.getGraph(); + Graph g = result.getGraph(); assertEquals(9, g.degree("n0")); for (int i = 1; i < 10; i++) { assertEquals(1, g.degree("n" + i)); @@ -184,7 +184,7 @@ public void path_fiveNodes() { assertEquals(5, result.getNodeCount()); assertEquals(4, result.getEdgeCount()); // Endpoints have degree 1, interior nodes have degree 2 - Graph g = result.getGraph(); + Graph g = result.getGraph(); assertEquals(1, g.degree("n0")); assertEquals(2, g.degree("n2")); assertEquals(1, g.degree("n4")); @@ -298,7 +298,7 @@ public void scaleFreeBa_basic() { GraphGenerator.GeneratedGraph result = gen.scaleFreeBa(50, 2); assertEquals(50, result.getNodeCount()); // Initial: 3 nodes with 3 edges. Then 47 nodes × 2 edges = 94 - // Total: ~97 edges + // Total: ~97 Edges assertTrue(result.getEdgeCount() > 80); assertTrue(result.getEdgeCount() <= 100); } @@ -307,14 +307,14 @@ public void scaleFreeBa_basic() { public void scaleFreeBa_m1() { GraphGenerator.GeneratedGraph result = gen.scaleFreeBa(20, 1); assertEquals(20, result.getNodeCount()); - // Tree-like: ~19 edges + // Tree-like: ~19 Edges assertTrue(result.getEdgeCount() >= 18); } @Test public void scaleFreeBa_hasHubs() { GraphGenerator.GeneratedGraph result = gen.scaleFreeBa(100, 2); - Graph g = result.getGraph(); + Graph g = result.getGraph(); // Early nodes should have higher degree (preferential attachment) int maxDegree = 0; for (String v : g.getVertices()) { @@ -416,7 +416,7 @@ public void bipartite_pOne_complete() { @Test public void bipartite_noIntraGroupEdges() { GraphGenerator.GeneratedGraph result = gen.bipartite(5, 5, 1.0); - Graph g = result.getGraph(); + Graph g = result.getGraph(); // Group A: n0-n4, Group B: n5-n9 // No edges within group A for (int i = 0; i < 5; i++) { @@ -424,7 +424,7 @@ public void bipartite_noIntraGroupEdges() { assertNull(g.findEdge("n" + i, "n" + j)); } } - // No edges within group B + // No Edges within group B for (int i = 5; i < 10; i++) { for (int j = i + 1; j < 10; j++) { assertNull(g.findEdge("n" + i, "n" + j)); @@ -548,7 +548,7 @@ public void reproducibility_differentSeed_likelyDifferent() { @Test public void generatedGraphs_workWithExistingAnalyzers() { GraphGenerator.GeneratedGraph result = gen.scaleFreeBa(30, 2); - Graph g = result.getGraph(); + Graph g = result.getGraph(); // Should work with ShortestPathFinder ShortestPathFinder spf = new ShortestPathFinder(g); @@ -571,11 +571,11 @@ public void generatedGraphs_workWithExistingAnalyzers() { @Test public void generatedGraphs_workWithGraphStats() { GraphGenerator.GeneratedGraph result = gen.ring(10); - Graph g = result.getGraph(); + Graph g = result.getGraph(); // Build edge lists (all "f" type in generated graphs) - List allEdges = new ArrayList<>(g.getEdges()); - List empty = Collections.emptyList(); + List allEdges = new ArrayList<>(g.getEdges()); + List empty = Collections.emptyList(); GraphStats stats = new GraphStats(g, allEdges, empty, empty, empty, empty); assertEquals(10, stats.getNodeCount()); diff --git a/Gvisual/test/gvisual/GraphIsomorphismAnalyzerTest.java b/Gvisual/test/gvisual/GraphIsomorphismAnalyzerTest.java index 2064bb6..eb39b03 100644 --- a/Gvisual/test/gvisual/GraphIsomorphismAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphIsomorphismAnalyzerTest.java @@ -19,13 +19,13 @@ public class GraphIsomorphismAnalyzerTest { * Build an undirected graph from edge pairs. * Each edge is [vertex1, vertex2]. */ - private Graph buildGraph(String[][] edges) { - Graph g = new UndirectedSparseGraph(); + private Graph buildGraph(String[][] edges) { + Graph g = new UndirectedSparseGraph(); int edgeId = 0; for (String[] e : edges) { if (!g.containsVertex(e[0])) g.addVertex(e[0]); if (!g.containsVertex(e[1])) g.addVertex(e[1]); - edge ed = new edge("c", e[0], e[1]); + Edge ed = new Edge("c", e[0], e[1]); ed.setLabel("e" + edgeId++); g.addEdge(ed, e[0], e[1]); } @@ -35,8 +35,8 @@ private Graph buildGraph(String[][] edges) { /** * Build a graph with only isolated vertices. */ - private Graph buildIsolated(String... vertices) { - Graph g = new UndirectedSparseGraph(); + private Graph buildIsolated(String... vertices) { + Graph g = new UndirectedSparseGraph(); for (String v : vertices) g.addVertex(v); return g; } @@ -45,13 +45,13 @@ private Graph buildIsolated(String... vertices) { @Test(expected = IllegalArgumentException.class) public void constructor_nullGraph1_throws() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); new GraphIsomorphismAnalyzer(null, g); } @Test(expected = IllegalArgumentException.class) public void constructor_nullGraph2_throws() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); new GraphIsomorphismAnalyzer(g, null); } @@ -64,8 +64,8 @@ public void constructor_bothNull_throws() { @Test public void analyze_twoEmptyGraphs_isomorphic() { - Graph g1 = new UndirectedSparseGraph(); - Graph g2 = new UndirectedSparseGraph(); + Graph g1 = new UndirectedSparseGraph(); + Graph g2 = new UndirectedSparseGraph(); GraphIsomorphismAnalyzer analyzer = new GraphIsomorphismAnalyzer(g1, g2); GraphIsomorphismAnalyzer.IsomorphismResult result = analyzer.analyze(); @@ -79,8 +79,8 @@ public void analyze_twoEmptyGraphs_isomorphic() { @Test public void analyze_singleVertexEach_isomorphic() { - Graph g1 = buildIsolated("A"); - Graph g2 = buildIsolated("X"); + Graph g1 = buildIsolated("A"); + Graph g2 = buildIsolated("X"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); @@ -94,10 +94,10 @@ public void analyze_singleVertexEach_isomorphic() { @Test public void analyze_identicalTriangles_isomorphic() { - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"}, {"Z", "X"} }); @@ -113,11 +113,11 @@ public void analyze_identicalTriangles_isomorphic() { @Test public void analyze_identicalPaths_isomorphic() { // Path: A-B-C-D - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"} }); // Path: W-X-Y-Z - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"W", "X"}, {"X", "Y"}, {"Y", "Z"} }); @@ -131,11 +131,11 @@ public void analyze_identicalPaths_isomorphic() { @Test public void analyze_identicalStars_isomorphic() { // Star: center A connected to B, C, D, E - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"A", "D"}, {"A", "E"} }); // Star: center M connected to N, O, P, Q - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"M", "N"}, {"M", "O"}, {"M", "P"}, {"M", "Q"} }); @@ -148,11 +148,11 @@ public void analyze_identicalStars_isomorphic() { @Test public void analyze_completeK4_isomorphic() { - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"W", "X"}, {"W", "Y"}, {"W", "Z"}, {"X", "Y"}, {"X", "Z"}, {"Y", "Z"} }); @@ -168,10 +168,10 @@ public void analyze_completeK4_isomorphic() { @Test public void analyze_differentVertexCount_notIsomorphic() { - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"}, {"Z", "W"} }); @@ -185,17 +185,17 @@ public void analyze_differentVertexCount_notIsomorphic() { @Test public void analyze_differentEdgeCount_notIsomorphic() { // Triangle vs path of 3 - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"} }); g2.addVertex("W"); // add isolated vertex to match vertex count // g1: 3 vertices 3 edges, g2: 4 vertices 2 edges → vertex count diff // Let's make same vertex count - Graph g2b = buildGraph(new String[][]{ + Graph g2b = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"} }); // g1: 3v 3e, g2b: 3v 2e @@ -210,11 +210,11 @@ public void analyze_differentEdgeCount_notIsomorphic() { @Test public void analyze_differentDegreeSequence_notIsomorphic() { // Star: center A → B, C, D (degrees: 3,1,1,1) - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"A", "D"} }); // Path: X-Y-Z-W (degrees: 1,2,2,1) - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"}, {"Z", "W"} }); @@ -229,12 +229,12 @@ public void analyze_differentDegreeSequence_notIsomorphic() { public void analyze_sameDegreeSequence_butNotIsomorphic() { // Two graphs with degree sequence [2,2,2,2,2,2] but different structure // Cycle C6: A-B-C-D-E-F-A - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "E"}, {"E", "F"}, {"F", "A"} }); // Two triangles: X-Y-Z-X and P-Q-R-P - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"}, {"Z", "X"}, {"P", "Q"}, {"Q", "R"}, {"R", "P"} }); @@ -251,8 +251,8 @@ public void analyze_sameDegreeSequence_butNotIsomorphic() { @Test public void analyze_isolatedVertices_isomorphic() { - Graph g1 = buildIsolated("A", "B", "C"); - Graph g2 = buildIsolated("X", "Y", "Z"); + Graph g1 = buildIsolated("A", "B", "C"); + Graph g2 = buildIsolated("X", "Y", "Z"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); @@ -263,8 +263,8 @@ public void analyze_isolatedVertices_isomorphic() { @Test public void analyze_differentIsolatedCount_notIsomorphic() { - Graph g1 = buildIsolated("A", "B"); - Graph g2 = buildIsolated("X", "Y", "Z"); + Graph g1 = buildIsolated("A", "B"); + Graph g2 = buildIsolated("X", "Y", "Z"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); @@ -276,10 +276,10 @@ public void analyze_differentIsolatedCount_notIsomorphic() { @Test public void areIsomorphic_returns_true_for_matching_graphs() { - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"} }); @@ -288,10 +288,10 @@ public void areIsomorphic_returns_true_for_matching_graphs() { @Test public void areIsomorphic_returns_false_for_nonMatching() { - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"Y", "Z"} }); g2.addVertex("W"); @@ -303,10 +303,10 @@ public void areIsomorphic_returns_false_for_nonMatching() { @Test public void analyze_degreeSequencesReturned() { - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "B"}, {"A", "C"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"X", "Y"}, {"X", "Z"} }); @@ -323,12 +323,12 @@ public void analyze_degreeSequencesReturned() { public void analyze_petersenLike_isomorphic() { // Build two copies of the Petersen graph with different labels // Outer cycle: 0-1-2-3-4-0, inner star: 5-7-9-6-8-5 - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"0", "1"}, {"1", "2"}, {"2", "3"}, {"3", "4"}, {"4", "0"}, {"0", "5"}, {"1", "6"}, {"2", "7"}, {"3", "8"}, {"4", "9"}, {"5", "7"}, {"7", "9"}, {"9", "6"}, {"6", "8"}, {"8", "5"} }); - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "E"}, {"E", "A"}, {"A", "F"}, {"B", "G"}, {"C", "H"}, {"D", "I"}, {"E", "J"}, {"F", "H"}, {"H", "J"}, {"J", "G"}, {"G", "I"}, {"I", "F"} @@ -345,12 +345,12 @@ public void analyze_petersenLike_isomorphic() { @Test public void analyze_bipartiteK23_isomorphic() { // K2,3: {A,B} fully connected to {C,D,E} - Graph g1 = buildGraph(new String[][]{ + Graph g1 = buildGraph(new String[][]{ {"A", "C"}, {"A", "D"}, {"A", "E"}, {"B", "C"}, {"B", "D"}, {"B", "E"} }); // Same with different labels - Graph g2 = buildGraph(new String[][]{ + Graph g2 = buildGraph(new String[][]{ {"P", "R"}, {"P", "S"}, {"P", "T"}, {"Q", "R"}, {"Q", "S"}, {"Q", "T"} }); @@ -362,8 +362,8 @@ public void analyze_bipartiteK23_isomorphic() { @Test public void toString_isomorphic_showsMapping() { - Graph g1 = buildIsolated("A"); - Graph g2 = buildIsolated("X"); + Graph g1 = buildIsolated("A"); + Graph g2 = buildIsolated("X"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); @@ -374,8 +374,8 @@ public void toString_isomorphic_showsMapping() { @Test public void toString_notIsomorphic_showsReason() { - Graph g1 = buildIsolated("A", "B"); - Graph g2 = buildIsolated("X"); + Graph g1 = buildIsolated("A", "B"); + Graph g2 = buildIsolated("X"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); @@ -388,10 +388,10 @@ public void toString_notIsomorphic_showsReason() { @Test public void analyze_graphWithIsolatedAndConnected_isomorphic() { // Graph: A-B, C isolated - Graph g1 = buildGraph(new String[][]{{"A", "B"}}); + Graph g1 = buildGraph(new String[][]{{"A", "B"}}); g1.addVertex("C"); - Graph g2 = buildGraph(new String[][]{{"X", "Y"}}); + Graph g2 = buildGraph(new String[][]{{"X", "Y"}}); g2.addVertex("Z"); assertTrue(new GraphIsomorphismAnalyzer(g1, g2).areIsomorphic()); @@ -399,7 +399,7 @@ public void analyze_graphWithIsolatedAndConnected_isomorphic() { @Test public void analyze_selfIsomorphic() { - Graph g = buildGraph(new String[][]{ + Graph g = buildGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"} }); @@ -410,8 +410,8 @@ public void analyze_selfIsomorphic() { @Test(expected = UnsupportedOperationException.class) public void mapping_isUnmodifiable() { - Graph g1 = buildIsolated("A"); - Graph g2 = buildIsolated("X"); + Graph g1 = buildIsolated("A"); + Graph g2 = buildIsolated("X"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); result.getMapping().put("B", "Y"); @@ -419,8 +419,8 @@ public void mapping_isUnmodifiable() { @Test(expected = UnsupportedOperationException.class) public void degreeSequence_isUnmodifiable() { - Graph g1 = buildIsolated("A"); - Graph g2 = buildIsolated("X"); + Graph g1 = buildIsolated("A"); + Graph g2 = buildIsolated("X"); GraphIsomorphismAnalyzer.IsomorphismResult result = new GraphIsomorphismAnalyzer(g1, g2).analyze(); result.getDegreeSequence1().add(42); @@ -433,10 +433,10 @@ public void degreeSequence_isUnmodifiable() { * for every edge (u, v) in g1, (mapping[u], mapping[v]) must be * an edge in g2. */ - private void verifyMapping(Graph g1, - Graph g2, + private void verifyMapping(Graph g1, + Graph g2, Map mapping) { - for (edge e : g1.getEdges()) { + for (Edge e : g1.getEdges()) { String u1 = e.getVertex1(); String v1 = e.getVertex2(); // JUNG undirected edges might have endpoints in either order diff --git a/Gvisual/test/gvisual/GraphMLExporterTest.java b/Gvisual/test/gvisual/GraphMLExporterTest.java index 3ea7238..69aa59f 100644 --- a/Gvisual/test/gvisual/GraphMLExporterTest.java +++ b/Gvisual/test/gvisual/GraphMLExporterTest.java @@ -24,13 +24,13 @@ public class GraphMLExporterTest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); - private Graph graph; - private List allEdges; + private Graph graph; + private List allEdges; @Before public void setUp() { - graph = new UndirectedSparseGraph(); - allEdges = new ArrayList(); + graph = new UndirectedSparseGraph(); + allEdges = new ArrayList(); } // --- Constructor tests --- @@ -55,10 +55,10 @@ public void testEmptyGraphExport() { assertTrue(xml.contains("")); assertFalse(xml.contains("")); + assertTrue(xml.contains("")); assertTrue(xml.contains("f")); assertTrue(xml.contains("Friend")); assertTrue(xml.contains("42.5")); @@ -114,7 +114,7 @@ public void testEdgesExported() { @Test public void testEdgeLabelExported() { - edge e = new edge("c", "X", "Y"); + Edge e = new Edge("c", "X", "Y"); e.setWeight(10f); e.setLabel("Classmate"); allEdges.add(e); @@ -128,7 +128,7 @@ public void testEdgeLabelExported() { @Test public void testEdgeWithoutLabelOmitted() { - edge e = new edge("s", "X", "Y"); + Edge e = new Edge("s", "X", "Y"); e.setWeight(5f); allEdges.add(e); graph.addEdge(e, "X", "Y"); @@ -154,11 +154,11 @@ public void testAllEdgeTypeLabels() { @Test public void testMultipleEdgeTypesExported() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(10f); - edge e2 = new edge("fs", "B", "C"); e2.setWeight(5f); - edge e3 = new edge("c", "C", "D"); e3.setWeight(20f); - edge e4 = new edge("s", "D", "E"); e4.setWeight(3f); - edge e5 = new edge("sg", "E", "A"); e5.setWeight(15f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(10f); + Edge e2 = new Edge("fs", "B", "C"); e2.setWeight(5f); + Edge e3 = new Edge("c", "C", "D"); e3.setWeight(20f); + Edge e4 = new Edge("s", "D", "E"); e4.setWeight(3f); + Edge e5 = new Edge("sg", "E", "A"); e5.setWeight(15f); allEdges.add(e1); allEdges.add(e2); allEdges.add(e3); allEdges.add(e4); allEdges.add(e5); graph.addEdge(e1, "A", "B"); @@ -266,7 +266,7 @@ public void testVertexWithSpecialCharsEscaped() { @Test public void testExportToFile() throws IOException { - edge e = new edge("f", "X", "Y"); + Edge e = new Edge("f", "X", "Y"); e.setWeight(99f); allEdges.add(e); graph.addEdge(e, "X", "Y"); @@ -302,8 +302,8 @@ public void testVertexCount() { @Test public void testEdgeCountUsesAllEdges() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(10f); - edge e2 = new edge("c", "C", "D"); e2.setWeight(20f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(10f); + Edge e2 = new Edge("c", "C", "D"); e2.setWeight(20f); allEdges.add(e1); allEdges.add(e2); // Only add one to graph (simulating filter) @@ -317,10 +317,10 @@ public void testEdgeCountUsesAllEdges() { @Test public void testEdgeCountFallsBackToGraphEdges() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(10f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(10f); graph.addEdge(e1, "A", "B"); - GraphMLExporter exporter = new GraphMLExporter(graph, new ArrayList()); + GraphMLExporter exporter = new GraphMLExporter(graph, new ArrayList()); assertEquals(1, exporter.getEdgeCount()); } @@ -345,8 +345,8 @@ public void testKeyDefinitionsPresent() { @Test public void testExportVisibleOnly() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(10f); - edge e2 = new edge("c", "C", "D"); e2.setWeight(20f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(10f); + Edge e2 = new Edge("c", "C", "D"); e2.setWeight(20f); allEdges.add(e1); allEdges.add(e2); // Only e1 in graph @@ -378,7 +378,7 @@ public void testLargeGraphExport() { graph.addVertex("N" + i); } for (int i = 0; i < 99; i++) { - edge e = new edge("f", "N" + i, "N" + (i + 1)); + Edge e = new Edge("f", "N" + i, "N" + (i + 1)); e.setWeight(i * 1.5f); allEdges.add(e); graph.addEdge(e, "N" + i, "N" + (i + 1)); @@ -399,7 +399,7 @@ public void testLargeGraphExport() { @Test public void testEdgeWeightFormatting() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(3.14159f); allEdges.add(e); graph.addEdge(e, "A", "B"); @@ -413,7 +413,7 @@ public void testEdgeWeightFormatting() { @Test public void testZeroWeightEdge() { - edge e = new edge("s", "A", "B"); + Edge e = new Edge("s", "A", "B"); e.setWeight(0f); allEdges.add(e); graph.addEdge(e, "A", "B"); @@ -448,7 +448,7 @@ public void testGraphIdAndEdgeDefault() { @Test public void testEdgeWithEmptyLabelOmitted() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(10f); e.setLabel(""); allEdges.add(e); @@ -465,7 +465,7 @@ public void testEdgeWithEmptyLabelOmitted() { @Test public void testIsolatedVerticesExported() { graph.addVertex("Lonely"); - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(10f); allEdges.add(e); graph.addEdge(e, "A", "B"); @@ -481,7 +481,7 @@ public void testIsolatedVerticesExported() { @Test public void testDeterministicOutput() { - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(10f); allEdges.add(e); graph.addEdge(e, "A", "B"); @@ -546,7 +546,7 @@ public void testEscapeXml_mixedControlAndSpecial() { public void testExport_vertexWithControlCharsProducesValidXml() { graph.addVertex("node\0inject"); graph.addVertex("B"); - edge e = new edge("f", "node\0inject", "B"); + Edge e = new Edge("f", "node\0inject", "B"); allEdges.add(e); graph.addEdge(e, "node\0inject", "B"); diff --git a/Gvisual/test/gvisual/GraphMergerTest.java b/Gvisual/test/gvisual/GraphMergerTest.java index bea64d3..7689304 100644 --- a/Gvisual/test/gvisual/GraphMergerTest.java +++ b/Gvisual/test/gvisual/GraphMergerTest.java @@ -17,8 +17,8 @@ */ public class GraphMergerTest { - private Graph graphA; - private Graph graphB; + private Graph graphA; + private Graph graphB; @Before public void setUp() { @@ -27,9 +27,9 @@ public void setUp() { graphA.addVertex("A"); graphA.addVertex("B"); graphA.addVertex("C"); - edge ab = new edge("undirected", "A", "B"); + Edge ab = new Edge("undirected", "A", "B"); ab.setWeight(1.0f); - edge bc = new edge("undirected", "B", "C"); + Edge bc = new Edge("undirected", "B", "C"); bc.setWeight(1.0f); graphA.addEdge(ab, "A", "B"); graphA.addEdge(bc, "B", "C"); @@ -39,9 +39,9 @@ public void setUp() { graphB.addVertex("B"); graphB.addVertex("C"); graphB.addVertex("D"); - edge bc2 = new edge("undirected", "B", "C"); + Edge bc2 = new Edge("undirected", "B", "C"); bc2.setWeight(3.0f); - edge cd = new edge("undirected", "C", "D"); + Edge cd = new Edge("undirected", "C", "D"); cd.setWeight(2.0f); graphB.addEdge(bc2, "B", "C"); graphB.addEdge(cd, "C", "D"); @@ -58,7 +58,7 @@ public void testUnionMerge() { assertEquals(3, result.getMergedEdgeCount()); // A-B, B-C, C-D assertEquals(1, result.getConflictsResolved()); // B-C conflict - Graph merged = result.getMergedGraph(); + Graph merged = result.getMergedGraph(); assertTrue(merged.containsVertex("A")); assertTrue(merged.containsVertex("D")); } @@ -68,7 +68,7 @@ public void testUnionKeepLeftWeight() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.KEEP_LEFT); - edge bcEdge = result.getMergedGraph().findEdge("B", "C"); + Edge bcEdge = result.getMergedGraph().findEdge("B", "C"); assertNotNull(bcEdge); assertEquals(1.0f, bcEdge.getWeight(), 0.001f); // kept left (1.0) } @@ -78,7 +78,7 @@ public void testUnionKeepRightWeight() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.KEEP_RIGHT); - edge bcEdge = result.getMergedGraph().findEdge("B", "C"); + Edge bcEdge = result.getMergedGraph().findEdge("B", "C"); assertNotNull(bcEdge); assertEquals(3.0f, bcEdge.getWeight(), 0.001f); } @@ -88,7 +88,7 @@ public void testUnionSumWeight() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.SUM); - edge bcEdge = result.getMergedGraph().findEdge("B", "C"); + Edge bcEdge = result.getMergedGraph().findEdge("B", "C"); assertNotNull(bcEdge); assertEquals(4.0f, bcEdge.getWeight(), 0.001f); // 1+3 } @@ -98,7 +98,7 @@ public void testUnionAverageWeight() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.AVERAGE); - edge bcEdge = result.getMergedGraph().findEdge("B", "C"); + Edge bcEdge = result.getMergedGraph().findEdge("B", "C"); assertNotNull(bcEdge); assertEquals(2.0f, bcEdge.getWeight(), 0.001f); // (1+3)/2 } @@ -108,7 +108,7 @@ public void testUnionMaxWeight() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.MAX); - edge bcEdge = result.getMergedGraph().findEdge("B", "C"); + Edge bcEdge = result.getMergedGraph().findEdge("B", "C"); assertNotNull(bcEdge); assertEquals(3.0f, bcEdge.getWeight(), 0.001f); } @@ -118,7 +118,7 @@ public void testUnionMinWeight() { GraphMerger.MergeResult result = GraphMerger.merge(graphA, graphB, GraphMerger.Strategy.UNION, GraphMerger.EdgeConflict.MIN); - edge bcEdge = result.getMergedGraph().findEdge("B", "C"); + Edge bcEdge = result.getMergedGraph().findEdge("B", "C"); assertNotNull(bcEdge); assertEquals(1.0f, bcEdge.getWeight(), 0.001f); } @@ -134,7 +134,7 @@ public void testIntersectionMerge() { assertEquals(2, result.getMergedVertexCount()); assertEquals(1, result.getMergedEdgeCount()); - Graph merged = result.getMergedGraph(); + Graph merged = result.getMergedGraph(); assertTrue(merged.containsVertex("B")); assertTrue(merged.containsVertex("C")); assertFalse(merged.containsVertex("A")); @@ -152,7 +152,7 @@ public void testSymmetricDifferenceMerge() { // B-C is in both → excluded. assertEquals(2, result.getMergedEdgeCount()); // A-B, C-D - Graph merged = result.getMergedGraph(); + Graph merged = result.getMergedGraph(); assertTrue(merged.containsVertex("A")); assertTrue(merged.containsVertex("D")); } @@ -230,8 +230,8 @@ public void testSharedVertices() { @Test public void testMergeEmptyGraphs() { - Graph empty1 = new UndirectedSparseGraph<>(); - Graph empty2 = new UndirectedSparseGraph<>(); + Graph empty1 = new UndirectedSparseGraph<>(); + Graph empty2 = new UndirectedSparseGraph<>(); GraphMerger.MergeResult result = GraphMerger.merge(empty1, empty2); assertEquals(0, result.getMergedVertexCount()); diff --git a/Gvisual/test/gvisual/GraphMinorAnalyzerTest.java b/Gvisual/test/gvisual/GraphMinorAnalyzerTest.java index 3c5534e..0424efb 100644 --- a/Gvisual/test/gvisual/GraphMinorAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphMinorAnalyzerTest.java @@ -14,58 +14,58 @@ public class GraphMinorAnalyzerTest { // ── Helpers ───────────────────────────────────────────────────────── - private Graph makePath(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makePath(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) g.addVertex("v" + i); for (int i = 0; i < n - 1; i++) - g.addEdge(new edge("e" + i, "v" + i, "v" + (i + 1)), "v" + i, "v" + (i + 1)); + g.addEdge(new Edge("e" + i, "v" + i, "v" + (i + 1)), "v" + i, "v" + (i + 1)); return g; } - private Graph makeCycle(int n) { - Graph g = makePath(n); - g.addEdge(new edge("ec", "v" + (n - 1), "v0"), "v" + (n - 1), "v0"); + private Graph makeCycle(int n) { + Graph g = makePath(n); + g.addEdge(new Edge("ec", "v" + (n - 1), "v0"), "v" + (n - 1), "v0"); return g; } - private Graph makeComplete(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makeComplete(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) g.addVertex("v" + i); int id = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) - g.addEdge(new edge("e" + id++, "v" + i, "v" + j), "v" + i, "v" + j); + g.addEdge(new Edge("e" + id++, "v" + i, "v" + j), "v" + i, "v" + j); return g; } - private Graph makeK33() { - Graph g = new UndirectedSparseGraph<>(); + private Graph makeK33() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 3; i++) { g.addVertex("a" + i); g.addVertex("b" + i); } int id = 0; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) - g.addEdge(new edge("e" + id++, "a" + i, "b" + j), "a" + i, "b" + j); + g.addEdge(new Edge("e" + id++, "a" + i, "b" + j), "a" + i, "b" + j); return g; } - private Graph makeEmpty(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makeEmpty(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) g.addVertex("v" + i); return g; } - private Graph makePetersen() { - Graph g = new UndirectedSparseGraph<>(); + private Graph makePetersen() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 10; i++) g.addVertex("v" + i); // Outer cycle for (int i = 0; i < 5; i++) - g.addEdge(new edge("o" + i, "v" + i, "v" + ((i + 1) % 5)), "v" + i, "v" + ((i + 1) % 5)); + g.addEdge(new Edge("o" + i, "v" + i, "v" + ((i + 1) % 5)), "v" + i, "v" + ((i + 1) % 5)); // Inner pentagram for (int i = 0; i < 5; i++) - g.addEdge(new edge("i" + i, "v" + (i + 5), "v" + ((i + 2) % 5 + 5)), "v" + (i + 5), "v" + ((i + 2) % 5 + 5)); + g.addEdge(new Edge("i" + i, "v" + (i + 5), "v" + ((i + 2) % 5 + 5)), "v" + (i + 5), "v" + ((i + 2) % 5 + 5)); // Spokes for (int i = 0; i < 5; i++) - g.addEdge(new edge("s" + i, "v" + i, "v" + (i + 5)), "v" + i, "v" + (i + 5)); + g.addEdge(new Edge("s" + i, "v" + i, "v" + (i + 5)), "v" + i, "v" + (i + 5)); return g; } @@ -80,16 +80,16 @@ public void testNullGraph() { @Test public void testCopyPreservesStructure() { - Graph g = makeComplete(4); - Graph copy = GraphMinorAnalyzer.copyGraph(g); + Graph g = makeComplete(4); + Graph copy = GraphMinorAnalyzer.copyGraph(g); assertEquals(g.getVertexCount(), copy.getVertexCount()); assertEquals(g.getEdgeCount(), copy.getEdgeCount()); } @Test public void testCopyIsIndependent() { - Graph g = makeComplete(3); - Graph copy = GraphMinorAnalyzer.copyGraph(g); + Graph g = makeComplete(3); + Graph copy = GraphMinorAnalyzer.copyGraph(g); copy.removeVertex("v0"); assertEquals(3, g.getVertexCount()); assertEquals(2, copy.getVertexCount()); @@ -100,7 +100,7 @@ public void testCopyIsIndependent() { @Test public void testDeleteVertex() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makeComplete(4)); - Graph result = a.deleteVertex("v0"); + Graph result = a.deleteVertex("v0"); assertEquals(3, result.getVertexCount()); assertFalse(result.containsVertex("v0")); // K4 - v0 = K3 @@ -115,7 +115,7 @@ public void testDeleteVertexNotFound() { @Test public void testDeleteMultipleVertices() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makeComplete(5)); - Graph result = a.deleteVertices(Arrays.asList("v0", "v1")); + Graph result = a.deleteVertices(Arrays.asList("v0", "v1")); assertEquals(3, result.getVertexCount()); assertEquals(3, result.getEdgeCount()); // K3 } @@ -125,7 +125,7 @@ public void testDeleteMultipleVertices() { @Test public void testDeleteEdge() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makeComplete(3)); - Graph result = a.deleteEdge("v0", "v1"); + Graph result = a.deleteEdge("v0", "v1"); assertEquals(3, result.getVertexCount()); assertEquals(2, result.getEdgeCount()); assertNull(result.findEdge("v0", "v1")); @@ -142,7 +142,7 @@ public void testDeleteEdgeNotFound() { public void testContractEdgeReducesVertices() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makePath(3)); // v0--v1--v2, contract v0-v1 - Graph result = a.contractEdge("v0", "v1"); + Graph result = a.contractEdge("v0", "v1"); assertEquals(2, result.getVertexCount()); assertTrue(result.containsVertex("v0")); assertTrue(result.containsVertex("v2")); @@ -152,7 +152,7 @@ public void testContractEdgeReducesVertices() { @Test public void testContractEdgeInTriangle() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makeComplete(3)); - Graph result = a.contractEdge("v0", "v1"); + Graph result = a.contractEdge("v0", "v1"); // K3 contract → K2 (v0 and v2 with one edge) assertEquals(2, result.getVertexCount()); assertEquals(1, result.getEdgeCount()); @@ -161,7 +161,7 @@ public void testContractEdgeInTriangle() { @Test public void testContractEdgeK4ToK3() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makeComplete(4)); - Graph result = a.contractEdge("v0", "v1"); + Graph result = a.contractEdge("v0", "v1"); // K4 contract one edge → K3 assertEquals(3, result.getVertexCount()); assertEquals(3, result.getEdgeCount()); @@ -182,7 +182,7 @@ public void testMinorSequence() { GraphMinorAnalyzer.MinorOp.deleteVertex("v3"), GraphMinorAnalyzer.MinorOp.contract("v0", "v1") ); - Graph result = a.applySequence(ops); + Graph result = a.applySequence(ops); assertEquals(2, result.getVertexCount()); } @@ -297,7 +297,7 @@ public void testNoK33MinorInSmallGraph() { @Test public void testHadwigerEmpty() { - assertEquals(0, new GraphMinorAnalyzer(new UndirectedSparseGraph()).hadwigerNumber()); + assertEquals(0, new GraphMinorAnalyzer(new UndirectedSparseGraph()).hadwigerNumber()); } @Test @@ -331,16 +331,16 @@ public void testContractionDegeneracyConnected() { @Test public void testContractionDegeneracyDisconnected() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); - g.addEdge(new edge("e0", "a", "b"), "a", "b"); + g.addEdge(new Edge("e0", "a", "b"), "a", "b"); // c is isolated → 2 components assertEquals(2, new GraphMinorAnalyzer(g).contractionDegeneracy()); } @Test public void testContractionDegeneracyEmpty() { - assertEquals(0, new GraphMinorAnalyzer(new UndirectedSparseGraph()).contractionDegeneracy()); + assertEquals(0, new GraphMinorAnalyzer(new UndirectedSparseGraph()).contractionDegeneracy()); } // ── Subdivide edge ────────────────────────────────────────────────── @@ -348,7 +348,7 @@ public void testContractionDegeneracyEmpty() { @Test public void testSubdivideEdge() { GraphMinorAnalyzer a = new GraphMinorAnalyzer(makePath(2)); - Graph result = a.subdivideEdge("v0", "v1", "mid"); + Graph result = a.subdivideEdge("v0", "v1", "mid"); assertEquals(3, result.getVertexCount()); assertEquals(2, result.getEdgeCount()); assertNull(result.findEdge("v0", "v1")); diff --git a/Gvisual/test/gvisual/GraphNeighborhoodAnalyzerTest.java b/Gvisual/test/gvisual/GraphNeighborhoodAnalyzerTest.java index 2bc66d2..2cf141b 100644 --- a/Gvisual/test/gvisual/GraphNeighborhoodAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphNeighborhoodAnalyzerTest.java @@ -14,15 +14,15 @@ */ public class GraphNeighborhoodAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { graph = new UndirectedSparseGraph<>(); } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/GraphNetworkProfilerTest.java b/Gvisual/test/gvisual/GraphNetworkProfilerTest.java index 97b76ca..d751c0c 100644 --- a/Gvisual/test/gvisual/GraphNetworkProfilerTest.java +++ b/Gvisual/test/gvisual/GraphNetworkProfilerTest.java @@ -17,20 +17,20 @@ public class GraphNetworkProfilerTest { // ── Helpers ───────────────────────────────────────────────── - private static Graph emptyGraph() { + private static Graph emptyGraph() { return new UndirectedSparseGraph<>(); } private static int edgeCounter = 0; - private static void addEdge(Graph g, String v1, String v2) { - edge e = new edge("f", v1, v2); + private static void addEdge(Graph g, String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setLabel("e" + (edgeCounter++)); g.addEdge(e, v1, v2); } - private static Graph completeGraph(int n) { - Graph g = emptyGraph(); + private static Graph completeGraph(int n) { + Graph g = emptyGraph(); for (int i = 0; i < n; i++) g.addVertex("v" + i); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) @@ -38,8 +38,8 @@ private static Graph completeGraph(int n) { return g; } - private static Graph starGraph(int spokes) { - Graph g = emptyGraph(); + private static Graph starGraph(int spokes) { + Graph g = emptyGraph(); g.addVertex("hub"); for (int i = 0; i < spokes; i++) { String s = "s" + i; @@ -48,21 +48,21 @@ private static Graph starGraph(int spokes) { return g; } - private static Graph pathGraph(int n) { - Graph g = emptyGraph(); + private static Graph pathGraph(int n) { + Graph g = emptyGraph(); for (int i = 0; i < n; i++) g.addVertex("v" + i); for (int i = 0; i < n - 1; i++) addEdge(g, "v" + i, "v" + (i + 1)); return g; } - private static Graph ringGraph(int n) { - Graph g = pathGraph(n); + private static Graph ringGraph(int n) { + Graph g = pathGraph(n); addEdge(g, "v0", "v" + (n - 1)); return g; } - private static Graph gridGraph(int rows, int cols) { - Graph g = emptyGraph(); + private static Graph gridGraph(int rows, int cols) { + Graph g = emptyGraph(); for (int r = 0; r < rows; r++) for (int c = 0; c < cols; c++) g.addVertex(r + "," + c); @@ -87,7 +87,7 @@ public void testEmptyGraph() { @Test public void testSingleVertex() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("a"); GraphNetworkProfiler p = new GraphNetworkProfiler(g); p.analyze(); @@ -98,7 +98,7 @@ public void testSingleVertex() { @Test public void testTwoConnectedVertices() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); addEdge(g, "a", "b"); GraphNetworkProfiler p = new GraphNetworkProfiler(g); p.analyze(); @@ -152,7 +152,7 @@ public void testPathGraph() { p.analyze(); assertEquals(0.0, p.getGlobalClustering(), 0.01); assertTrue(p.getDensity() < 0.1); - // Path is tree-like: edges = n-1 + // Path is tree-like: Edges = n-1 assertEquals(1.0, p.getLargestComponentFraction(), 0.01); } @@ -182,7 +182,7 @@ public void testGridGraph() { @Test public void testDisconnectedGraph() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); addEdge(g, "a", "b"); addEdge(g, "c", "d"); g.addVertex("e"); // isolate @@ -369,7 +369,7 @@ public void testSmallWorldQuotientNonNegative() { @Test public void testLargeGraph() { // BA-style: start with K3, attach new nodes - Graph g = emptyGraph(); + Graph g = emptyGraph(); addEdge(g, "v0", "v1"); addEdge(g, "v1", "v2"); addEdge(g, "v0", "v2"); @@ -396,7 +396,7 @@ public void testLargeGraph() { @Test public void testDeterministicWithSeed() { - Graph g = gridGraph(5, 5); + Graph g = gridGraph(5, 5); GraphNetworkProfiler p1 = new GraphNetworkProfiler(g, new Random(42)); GraphNetworkProfiler p2 = new GraphNetworkProfiler(g, new Random(42)); p1.analyze(); @@ -428,7 +428,7 @@ public void testLargestComponentFractionSingle() { @Test public void testCorePeripheryShape() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); // Dense core of 5 nodes for (int i = 0; i < 5; i++) for (int j = i + 1; j < 5; j++) diff --git a/Gvisual/test/gvisual/GraphPartitionerTest.java b/Gvisual/test/gvisual/GraphPartitionerTest.java index aee49d0..1998636 100644 --- a/Gvisual/test/gvisual/GraphPartitionerTest.java +++ b/Gvisual/test/gvisual/GraphPartitionerTest.java @@ -10,11 +10,11 @@ /** * Tests for GraphPartitioner — BFS, Kernighan-Lin, and spectral - * partitioning strategies with balance, edge cut, and conductance metrics. + * partitioning strategies with balance, Edge cut, and conductance metrics. */ public class GraphPartitionerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -24,7 +24,7 @@ public void setUp() { // ---- Helpers ---- private void addEdge(String u, String v) { - edge e = new edge("f", u, v); + Edge e = new Edge("f", u, v); graph.addEdge(e, u, v); } @@ -208,7 +208,7 @@ public void testKLImprovesBFS() { GraphPartitioner p = new GraphPartitioner(graph); GraphPartitioner.PartitionResult bfs = p.partition(2, GraphPartitioner.Strategy.BFS); GraphPartitioner.PartitionResult kl = p.partition(2, GraphPartitioner.Strategy.KERNIGHAN_LIN); - // KL should have same or fewer edge cuts than BFS + // KL should have same or fewer Edge cuts than BFS assertTrue("KL cuts " + kl.getEdgeCuts() + " >= BFS cuts " + bfs.getEdgeCuts(), kl.getEdgeCuts() <= bfs.getEdgeCuts()); } @@ -416,7 +416,7 @@ public void testDefaultStrategyIsBFS() { public void testConductanceSinglePartition() { buildTriangle(); GraphPartitioner.PartitionResult result = new GraphPartitioner(graph).partition(1); - // Single partition: no external edges → conductance = 0 + // Single partition: no external Edges → conductance = 0 assertEquals(0.0, result.getPartitions().get(0).getConductance(), 1e-9); } diff --git a/Gvisual/test/gvisual/GraphQueryEngineTest.java b/Gvisual/test/gvisual/GraphQueryEngineTest.java index bffce7e..4b0f8f5 100644 --- a/Gvisual/test/gvisual/GraphQueryEngineTest.java +++ b/Gvisual/test/gvisual/GraphQueryEngineTest.java @@ -14,7 +14,7 @@ */ public class GraphQueryEngineTest { - private Graph graph; + private Graph graph; private GraphQueryEngine engine; @Before @@ -31,10 +31,10 @@ public void setUp() { graph.addVertex("D"); graph.addVertex("E"); - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "B", "C"); e2.setWeight(2.5f); - edge e3 = new edge("f", "C", "D"); e3.setWeight(0.5f); - edge e4 = new edge("s", "B", "D"); e4.setWeight(3.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(2.5f); + Edge e3 = new Edge("f", "C", "D"); e3.setWeight(0.5f); + Edge e4 = new Edge("s", "B", "D"); e4.setWeight(3.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -108,26 +108,26 @@ public void testEdgeOfType() { @Test public void testEdgeMinWeight() { - Set result = engine.edges().withMinWeight(2.0f).results(); + Set result = engine.edges().withMinWeight(2.0f).results(); assertEquals(2, result.size()); // c=2.5, s=3.0 } @Test public void testEdgeBetweenNodes() { Set subset = new HashSet<>(Arrays.asList("B", "C", "D")); - Set result = engine.edges().betweenNodes(subset).results(); + Set result = engine.edges().betweenNodes(subset).results(); assertEquals(3, result.size()); // B-C, C-D, B-D } @Test public void testEdgeIncidentTo() { - Set result = engine.edges().incidentTo("A").results(); + Set result = engine.edges().incidentTo("A").results(); assertEquals(1, result.size()); } @Test public void testEdgeSortedByWeight() { - List sorted = engine.edges().sortedByWeight(); + List sorted = engine.edges().sortedByWeight(); assertEquals(3.0f, sorted.get(0).getWeight(), 0.001f); } @@ -142,7 +142,7 @@ public void testEdgeTypeBreakdown() { @Test public void testChainedFilters() { // Edges of type "f" with weight >= 1.0 - Set result = engine.edges().ofType("f").withMinWeight(1.0f).results(); + Set result = engine.edges().ofType("f").withMinWeight(1.0f).results(); assertEquals(1, result.size()); // only A-B (w=1.0), C-D has w=0.5 } @@ -176,7 +176,7 @@ public void testEmptyResults() { @Test public void testTemporalEdgeQuery() { - edge te = new edge("f", "A", "E"); + Edge te = new Edge("f", "A", "E"); te.setTimestamp(1000L); te.setEndTimestamp(2000L); graph.addEdge(te, "A", "E"); diff --git a/Gvisual/test/gvisual/GraphResilienceAnalyzerTest.java b/Gvisual/test/gvisual/GraphResilienceAnalyzerTest.java index 7253b32..5bf9bc0 100644 --- a/Gvisual/test/gvisual/GraphResilienceAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphResilienceAnalyzerTest.java @@ -19,8 +19,8 @@ public class GraphResilienceAnalyzerTest { private int edgeCounter = 0; - private edge makeEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge makeEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setLabel("e" + (edgeCounter++)); return e; } @@ -28,8 +28,8 @@ private edge makeEdge(String v1, String v2) { /** * Creates a simple triangle graph: A—B—C—A. */ - private Graph createTriangle() { - Graph g = new UndirectedSparseGraph<>(); + private Graph createTriangle() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); @@ -42,8 +42,8 @@ private Graph createTriangle() { /** * Creates a star graph: center connected to N leaves. */ - private Graph createStar(int leaves) { - Graph g = new UndirectedSparseGraph<>(); + private Graph createStar(int leaves) { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("center"); for (int i = 0; i < leaves; i++) { String leaf = "leaf" + i; @@ -56,8 +56,8 @@ private Graph createStar(int leaves) { /** * Creates a path graph: v0—v1—v2—...—vN. */ - private Graph createPath(int length) { - Graph g = new UndirectedSparseGraph<>(); + private Graph createPath(int length) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i <= length; i++) { g.addVertex("v" + i); } @@ -70,8 +70,8 @@ private Graph createPath(int length) { /** * Creates a complete graph K_n. */ - private Graph createComplete(int n) { - Graph g = new UndirectedSparseGraph<>(); + private Graph createComplete(int n) { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < n; i++) { g.addVertex("v" + i); } @@ -337,7 +337,7 @@ public void testGlobalEfficiency_DecreasesWithRemovals() { @Test public void testSingleNode_NoCrash() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("alone"); GraphResilienceAnalyzer analyzer = new GraphResilienceAnalyzer(g); @@ -351,7 +351,7 @@ public void testSingleNode_NoCrash() { @Test public void testTwoNodes_OneEdge() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addEdge(makeEdge("A", "B"), "A", "B"); @@ -369,7 +369,7 @@ public void testTwoNodes_OneEdge() { @Test public void testDisconnectedGraph() { // Two disconnected triangles - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addVertex("E"); g.addVertex("F"); g.addEdge(makeEdge("A", "B"), "A", "B"); diff --git a/Gvisual/test/gvisual/GraphSamplerTest.java b/Gvisual/test/gvisual/GraphSamplerTest.java index 4824f45..6d131ee 100644 --- a/Gvisual/test/gvisual/GraphSamplerTest.java +++ b/Gvisual/test/gvisual/GraphSamplerTest.java @@ -13,17 +13,17 @@ */ public class GraphSamplerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } private void addEdge(String v1, String v2) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); graph.addEdge(e, v1, v2); } @@ -126,7 +126,7 @@ public void randomNode_halfSample_returnsCorrectCount() { GraphSampler.SampleResult result = sampler.randomNode(0.5); assertEquals(5, result.getNodeCount()); - assertTrue(result.getEdgeCount() <= 4); // at most 4 chain edges + assertTrue(result.getEdgeCount() <= 4); // at most 4 chain Edges } @Test diff --git a/Gvisual/test/gvisual/GraphSimilarityAnalyzerTest.java b/Gvisual/test/gvisual/GraphSimilarityAnalyzerTest.java index 99b60cb..81241e2 100644 --- a/Gvisual/test/gvisual/GraphSimilarityAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphSimilarityAnalyzerTest.java @@ -10,36 +10,36 @@ */ public class GraphSimilarityAnalyzerTest { - private Graph createTriangle() { - Graph g = new UndirectedSparseGraph<>(); + private Graph createTriangle() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - g.addEdge(new edge("friend", "A", "B"), "A", "B"); - g.addEdge(new edge("friend", "B", "C"), "B", "C"); - g.addEdge(new edge("friend", "A", "C"), "A", "C"); + g.addEdge(new Edge("friend", "A", "B"), "A", "B"); + g.addEdge(new Edge("friend", "B", "C"), "B", "C"); + g.addEdge(new Edge("friend", "A", "C"), "A", "C"); return g; } - private Graph createPath() { - Graph g = new UndirectedSparseGraph<>(); + private Graph createPath() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - g.addEdge(new edge("friend", "A", "B"), "A", "B"); - g.addEdge(new edge("friend", "B", "C"), "B", "C"); + g.addEdge(new Edge("friend", "A", "B"), "A", "B"); + g.addEdge(new Edge("friend", "B", "C"), "B", "C"); return g; } - private Graph createStar5() { - Graph g = new UndirectedSparseGraph<>(); + private Graph createStar5() { + Graph g = new UndirectedSparseGraph<>(); for (int i = 0; i < 5; i++) g.addVertex("V" + i); for (int i = 1; i < 5; i++) { - g.addEdge(new edge("friend", "V0", "V" + i), "V0", "V" + i); + g.addEdge(new Edge("friend", "V0", "V" + i), "V0", "V" + i); } return g; } @Test public void testIdenticalGraphs() { - Graph g1 = createTriangle(); - Graph g2 = createTriangle(); + Graph g1 = createTriangle(); + Graph g2 = createTriangle(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -52,8 +52,8 @@ public void testIdenticalGraphs() { @Test public void testDifferentGraphs() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -66,8 +66,8 @@ public void testDifferentGraphs() { @Test public void testJSDBounded() { - Graph g1 = createTriangle(); - Graph g2 = createPath(); + Graph g1 = createTriangle(); + Graph g2 = createPath(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -78,8 +78,8 @@ public void testJSDBounded() { @Test public void testVonNeumannNonNegative() { - Graph g1 = createPath(); - Graph g2 = createStar5(); + Graph g1 = createPath(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -89,8 +89,8 @@ public void testVonNeumannNonNegative() { @Test public void testEntropyProfiles() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -104,8 +104,8 @@ public void testEntropyProfiles() { @Test public void testEmptyGraphs() { - Graph g1 = new UndirectedSparseGraph<>(); - Graph g2 = new UndirectedSparseGraph<>(); + Graph g1 = new UndirectedSparseGraph<>(); + Graph g2 = new UndirectedSparseGraph<>(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -116,8 +116,8 @@ public void testEmptyGraphs() { @Test public void testReport() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -140,8 +140,8 @@ public void testNullGraph2() { @Test public void testSymmetry() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim12 = new GraphSimilarityAnalyzer(g1, g2); sim12.compute(); @@ -160,9 +160,9 @@ public void testSymmetry() { @Test public void testSingleVertexGraphs() { - Graph g1 = new UndirectedSparseGraph<>(); + Graph g1 = new UndirectedSparseGraph<>(); g1.addVertex("A"); - Graph g2 = new UndirectedSparseGraph<>(); + Graph g2 = new UndirectedSparseGraph<>(); g2.addVertex("X"); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); @@ -175,12 +175,12 @@ public void testSingleVertexGraphs() { @Test public void testSingleVertexVsEdge() { - Graph g1 = new UndirectedSparseGraph<>(); + Graph g1 = new UndirectedSparseGraph<>(); g1.addVertex("A"); - Graph g2 = new UndirectedSparseGraph<>(); + Graph g2 = new UndirectedSparseGraph<>(); g2.addVertex("A"); g2.addVertex("B"); - g2.addEdge(new edge("friend", "A", "B"), "A", "B"); + g2.addEdge(new Edge("friend", "A", "B"), "A", "B"); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -192,18 +192,18 @@ public void testSingleVertexVsEdge() { @Test public void testDisconnectedGraph() { // Two isolated components vs a connected graph - Graph disconnected = new UndirectedSparseGraph<>(); + Graph disconnected = new UndirectedSparseGraph<>(); disconnected.addVertex("A"); disconnected.addVertex("B"); disconnected.addVertex("C"); disconnected.addVertex("D"); - disconnected.addEdge(new edge("friend", "A", "B"), "A", "B"); - disconnected.addEdge(new edge("friend", "C", "D"), "C", "D"); + disconnected.addEdge(new Edge("friend", "A", "B"), "A", "B"); + disconnected.addEdge(new Edge("friend", "C", "D"), "C", "D"); - Graph connected = new UndirectedSparseGraph<>(); + Graph connected = new UndirectedSparseGraph<>(); connected.addVertex("A"); connected.addVertex("B"); connected.addVertex("C"); connected.addVertex("D"); - connected.addEdge(new edge("friend", "A", "B"), "A", "B"); - connected.addEdge(new edge("friend", "B", "C"), "B", "C"); - connected.addEdge(new edge("friend", "C", "D"), "C", "D"); + connected.addEdge(new Edge("friend", "A", "B"), "A", "B"); + connected.addEdge(new Edge("friend", "B", "C"), "B", "C"); + connected.addEdge(new Edge("friend", "C", "D"), "C", "D"); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(disconnected, connected); sim.compute(); @@ -216,8 +216,8 @@ public void testDisconnectedGraph() { @Test public void testDifferentSizedGraphs() { // Tests spectral padding: triangle (3 vertices) vs star5 (5 vertices) - Graph small = createTriangle(); - Graph large = createStar5(); + Graph small = createTriangle(); + Graph large = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(small, large); sim.compute(); @@ -234,8 +234,8 @@ public void testDifferentSizedGraphs() { @Test public void testLazyCompute() { // Calling getters should trigger compute() automatically - Graph g1 = createTriangle(); - Graph g2 = createPath(); + Graph g1 = createTriangle(); + Graph g2 = createPath(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); // DO NOT call compute() — ensureComputed should handle it @@ -248,8 +248,8 @@ public void testLazyCompute() { @Test public void testComputeIdempotency() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -265,8 +265,8 @@ public void testComputeIdempotency() { @Test public void testProfilesCloned() { // getProfile1/getProfile2 should return defensive copies - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -286,7 +286,7 @@ public void testProfilesCloned() { @Test public void testSimilarityScoreBounds() { // Test across multiple graph pairs that similarity is always in [0, 1] - Graph[] graphs = new Graph[]{ + Graph[] graphs = new Graph[]{ createTriangle(), createPath(), createStar5(), new UndirectedSparseGraph<>() }; @@ -309,9 +309,9 @@ public void testSimilarityScoreBounds() { @Test public void testEntropyProfileDistanceTriangleInequality() { // For a metric: d(A,C) <= d(A,B) + d(B,C) - Graph a = createTriangle(); - Graph b = createPath(); - Graph c = createStar5(); + Graph a = createTriangle(); + Graph b = createPath(); + Graph c = createStar5(); GraphSimilarityAnalyzer ab = new GraphSimilarityAnalyzer(a, b); ab.compute(); @@ -327,8 +327,8 @@ public void testEntropyProfileDistanceTriangleInequality() { @Test public void testReportContainsGraphSizes() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -342,8 +342,8 @@ public void testReportContainsGraphSizes() { @Test public void testReportContainsInterpretation() { - Graph g1 = createTriangle(); - Graph g2 = createTriangle(); + Graph g1 = createTriangle(); + Graph g2 = createTriangle(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -358,8 +358,8 @@ public void testReportContainsInterpretation() { @Test public void testReportContainsEntropyProfileTable() { - Graph g1 = createTriangle(); - Graph g2 = createPath(); + Graph g1 = createTriangle(); + Graph g2 = createPath(); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -376,15 +376,15 @@ public void testReportContainsEntropyProfileTable() { @Test public void testCompleteGraphVsEmpty() { // Complete graph K4 vs graph with only isolated vertices - Graph complete = new UndirectedSparseGraph<>(); + Graph complete = new UndirectedSparseGraph<>(); for (int i = 0; i < 4; i++) complete.addVertex("V" + i); for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { - complete.addEdge(new edge("friend", "V" + i, "V" + j), "V" + i, "V" + j); + complete.addEdge(new Edge("friend", "V" + i, "V" + j), "V" + i, "V" + j); } } - Graph isolated = new UndirectedSparseGraph<>(); + Graph isolated = new UndirectedSparseGraph<>(); for (int i = 0; i < 4; i++) isolated.addVertex("V" + i); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(complete, isolated); @@ -400,17 +400,17 @@ public void testCompleteGraphVsEmpty() { @Test public void testIsomorphicGraphsDifferentLabels() { // Two triangles with different vertex labels should be identical - Graph g1 = new UndirectedSparseGraph<>(); + Graph g1 = new UndirectedSparseGraph<>(); g1.addVertex("A"); g1.addVertex("B"); g1.addVertex("C"); - g1.addEdge(new edge("friend", "A", "B"), "A", "B"); - g1.addEdge(new edge("friend", "B", "C"), "B", "C"); - g1.addEdge(new edge("friend", "A", "C"), "A", "C"); + g1.addEdge(new Edge("friend", "A", "B"), "A", "B"); + g1.addEdge(new Edge("friend", "B", "C"), "B", "C"); + g1.addEdge(new Edge("friend", "A", "C"), "A", "C"); - Graph g2 = new UndirectedSparseGraph<>(); + Graph g2 = new UndirectedSparseGraph<>(); g2.addVertex("X"); g2.addVertex("Y"); g2.addVertex("Z"); - g2.addEdge(new edge("friend", "X", "Y"), "X", "Y"); - g2.addEdge(new edge("friend", "Y", "Z"), "Y", "Z"); - g2.addEdge(new edge("friend", "X", "Z"), "X", "Z"); + g2.addEdge(new Edge("friend", "X", "Y"), "X", "Y"); + g2.addEdge(new Edge("friend", "Y", "Z"), "Y", "Z"); + g2.addEdge(new Edge("friend", "X", "Z"), "X", "Z"); GraphSimilarityAnalyzer sim = new GraphSimilarityAnalyzer(g1, g2); sim.compute(); @@ -423,8 +423,8 @@ public void testIsomorphicGraphsDifferentLabels() { @Test public void testVonNeumannSymmetry() { - Graph g1 = createPath(); - Graph g2 = createStar5(); + Graph g1 = createPath(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim12 = new GraphSimilarityAnalyzer(g1, g2); sim12.compute(); @@ -438,8 +438,8 @@ public void testVonNeumannSymmetry() { @Test public void testEntropyProfileDistanceSymmetry() { - Graph g1 = createTriangle(); - Graph g2 = createStar5(); + Graph g1 = createTriangle(); + Graph g2 = createStar5(); GraphSimilarityAnalyzer sim12 = new GraphSimilarityAnalyzer(g1, g2); sim12.compute(); diff --git a/Gvisual/test/gvisual/GraphSparsificationAnalyzerTest.java b/Gvisual/test/gvisual/GraphSparsificationAnalyzerTest.java index bf70e81..a9733ab 100644 --- a/Gvisual/test/gvisual/GraphSparsificationAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphSparsificationAnalyzerTest.java @@ -9,55 +9,55 @@ public class GraphSparsificationAnalyzerTest { - private Graph triangle, path, star, complete5, disconnected, single, empty, weighted; + private Graph triangle, path, star, complete5, disconnected, single, empty, weighted; @Before public void setUp() { - triangle = new UndirectedSparseGraph(); + triangle = new UndirectedSparseGraph(); triangle.addVertex("A"); triangle.addVertex("B"); triangle.addVertex("C"); - triangle.addEdge(new edge("f", "A", "B"), "A", "B"); - triangle.addEdge(new edge("f", "B", "C"), "B", "C"); - triangle.addEdge(new edge("f", "A", "C"), "A", "C"); + triangle.addEdge(new Edge("f", "A", "B"), "A", "B"); + triangle.addEdge(new Edge("f", "B", "C"), "B", "C"); + triangle.addEdge(new Edge("f", "A", "C"), "A", "C"); - path = new UndirectedSparseGraph(); + path = new UndirectedSparseGraph(); for (String v : new String[]{"A","B","C","D"}) path.addVertex(v); - path.addEdge(new edge("f","A","B"),"A","B"); - path.addEdge(new edge("f","B","C"),"B","C"); - path.addEdge(new edge("f","C","D"),"C","D"); + path.addEdge(new Edge("f","A","B"),"A","B"); + path.addEdge(new Edge("f","B","C"),"B","C"); + path.addEdge(new Edge("f","C","D"),"C","D"); - star = new UndirectedSparseGraph(); + star = new UndirectedSparseGraph(); for (String v : new String[]{"A","B","C","D","E"}) star.addVertex(v); - star.addEdge(new edge("f","A","B"),"A","B"); - star.addEdge(new edge("f","A","C"),"A","C"); - star.addEdge(new edge("f","A","D"),"A","D"); - star.addEdge(new edge("f","A","E"),"A","E"); + star.addEdge(new Edge("f","A","B"),"A","B"); + star.addEdge(new Edge("f","A","C"),"A","C"); + star.addEdge(new Edge("f","A","D"),"A","D"); + star.addEdge(new Edge("f","A","E"),"A","E"); - complete5 = new UndirectedSparseGraph(); + complete5 = new UndirectedSparseGraph(); String[] k5 = {"A","B","C","D","E"}; for (String v : k5) complete5.addVertex(v); for (int i = 0; i < k5.length; i++) for (int j = i+1; j < k5.length; j++) { - edge e = new edge("f", k5[i], k5[j]); e.setWeight((float)(i+j)); + Edge e = new Edge("f", k5[i], k5[j]); e.setWeight((float)(i+j)); complete5.addEdge(e, k5[i], k5[j]); } - disconnected = new UndirectedSparseGraph(); + disconnected = new UndirectedSparseGraph(); for (String v : new String[]{"A","B","C","D"}) disconnected.addVertex(v); - disconnected.addEdge(new edge("f","A","B"),"A","B"); - disconnected.addEdge(new edge("f","C","D"),"C","D"); + disconnected.addEdge(new Edge("f","A","B"),"A","B"); + disconnected.addEdge(new Edge("f","C","D"),"C","D"); - single = new UndirectedSparseGraph(); + single = new UndirectedSparseGraph(); single.addVertex("A"); - empty = new UndirectedSparseGraph(); + empty = new UndirectedSparseGraph(); - weighted = new UndirectedSparseGraph(); + weighted = new UndirectedSparseGraph(); for (String v : new String[]{"A","B","C","D"}) weighted.addVertex(v); - edge e1=new edge("f","A","B"); e1.setWeight(1f); - edge e2=new edge("f","B","C"); e2.setWeight(5f); - edge e3=new edge("f","C","D"); e3.setWeight(3f); - edge e4=new edge("f","A","D"); e4.setWeight(2f); - edge e5=new edge("f","A","C"); e5.setWeight(4f); + Edge e1=new Edge("f","A","B"); e1.setWeight(1f); + Edge e2=new Edge("f","B","C"); e2.setWeight(5f); + Edge e3=new Edge("f","C","D"); e3.setWeight(3f); + Edge e4=new Edge("f","A","D"); e4.setWeight(2f); + Edge e5=new Edge("f","A","C"); e5.setWeight(4f); weighted.addEdge(e1,"A","B"); weighted.addEdge(e2,"B","C"); weighted.addEdge(e3,"C","D"); weighted.addEdge(e4,"A","D"); weighted.addEdge(e5,"A","C"); @@ -76,7 +76,7 @@ public void setUp() { // Edge Importance @Test public void testImportancePath() { - Map s = new GraphSparsificationAnalyzer(path).scoreEdgeImportance(); + Map s = new GraphSparsificationAnalyzer(path).scoreEdgeImportance(); assertEquals(3, s.size()); for (double v : s.values()) { assertTrue(v >= 0); assertTrue(v <= 1.0); } } @@ -87,14 +87,14 @@ public void setUp() { @Test public void testImportanceK5() { assertEquals(10, new GraphSparsificationAnalyzer(complete5).scoreEdgeImportance().size()); } // Spanning Tree - @Test public void testSTTriangle() { Graph st = new GraphSparsificationAnalyzer(triangle).spanningTreeSparsify(); assertEquals(3, st.getVertexCount()); assertEquals(2, st.getEdgeCount()); } + @Test public void testSTTriangle() { Graph st = new GraphSparsificationAnalyzer(triangle).spanningTreeSparsify(); assertEquals(3, st.getVertexCount()); assertEquals(2, st.getEdgeCount()); } @Test public void testSTK5() { assertEquals(4, new GraphSparsificationAnalyzer(complete5).spanningTreeSparsify().getEdgeCount()); } @Test public void testSTDisconnected() { assertEquals(2, new GraphSparsificationAnalyzer(disconnected).spanningTreeSparsify().getEdgeCount()); } @Test public void testSTSingle() { assertEquals(0, new GraphSparsificationAnalyzer(single).spanningTreeSparsify().getEdgeCount()); } // Random @Test public void testRandAll() { assertEquals(10, new GraphSparsificationAnalyzer(complete5).randomSparsify(1.0, 42).getEdgeCount()); } - @Test public void testRandNone() { Graph s = new GraphSparsificationAnalyzer(complete5).randomSparsify(0.0, 42); assertEquals(0, s.getEdgeCount()); assertEquals(5, s.getVertexCount()); } + @Test public void testRandNone() { Graph s = new GraphSparsificationAnalyzer(complete5).randomSparsify(0.0, 42); assertEquals(0, s.getEdgeCount()); assertEquals(5, s.getVertexCount()); } @Test public void testRandDeterministic() { GraphSparsificationAnalyzer a = new GraphSparsificationAnalyzer(complete5); assertEquals(a.randomSparsify(0.5,42).getEdgeCount(), a.randomSparsify(0.5,42).getEdgeCount()); } @Test(expected = IllegalArgumentException.class) public void testRandInvalid() { new GraphSparsificationAnalyzer(complete5).randomSparsify(1.5, 42); } @@ -104,7 +104,7 @@ public void setUp() { @Test public void testThresholdZero() { assertEquals(5, new GraphSparsificationAnalyzer(weighted).thresholdSparsify(0f).getEdgeCount()); } // Local - @Test public void testLocalK1() { Graph s = new GraphSparsificationAnalyzer(weighted).localSparsify(1); assertTrue(s.getEdgeCount() >= 1 && s.getEdgeCount() <= 4); } + @Test public void testLocalK1() { Graph s = new GraphSparsificationAnalyzer(weighted).localSparsify(1); assertTrue(s.getEdgeCount() >= 1 && s.getEdgeCount() <= 4); } @Test public void testLocalHighK() { assertEquals(5, new GraphSparsificationAnalyzer(weighted).localSparsify(100).getEdgeCount()); } @Test(expected = IllegalArgumentException.class) public void testLocalInvalid() { new GraphSparsificationAnalyzer(weighted).localSparsify(0); } @@ -118,13 +118,13 @@ public void setUp() { GraphSparsificationAnalyzer a = new GraphSparsificationAnalyzer(complete5); GraphSparsificationAnalyzer.SparsificationQuality q = a.evaluateQuality(a.spanningTreeSparsify()); assertEquals(5, q.originalVertices); assertEquals(10, q.originalEdges); assertEquals(4, q.sparseEdges); - assertTrue(q.connectivityPreserved); assertTrue(q.edgeReduction > 0.5); + assertTrue(q.connectivityPreserved); assertTrue(q.EdgeReduction > 0.5); } @Test public void testQualityBroken() { GraphSparsificationAnalyzer a = new GraphSparsificationAnalyzer(path); - Graph b = new UndirectedSparseGraph(); + Graph b = new UndirectedSparseGraph(); for (String v : path.getVertices()) b.addVertex(v); - b.addEdge(new edge("f","A","B"),"A","B"); b.addEdge(new edge("f","C","D"),"C","D"); + b.addEdge(new Edge("f","A","B"),"A","B"); b.addEdge(new Edge("f","C","D"),"C","D"); assertFalse(a.evaluateQuality(b).connectivityPreserved); } @Test(expected = IllegalArgumentException.class) public void testQualityNull() { new GraphSparsificationAnalyzer(triangle).evaluateQuality(null); } @@ -149,8 +149,8 @@ public void setUp() { @Test public void testReportBridges() { assertTrue(new GraphSparsificationAnalyzer(path).generateReport().contains("Bridge Edges")); } // Edge cases - @Test public void testSingleEdge() { Graph g = new UndirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addEdge(new edge("f","A","B"),"A","B"); GraphSparsificationAnalyzer a = new GraphSparsificationAnalyzer(g); assertEquals(1, a.findBridges().size()); assertEquals(1, a.spanningTreeSparsify().getEdgeCount()); } - @Test public void testWeightedST() { Graph st = new GraphSparsificationAnalyzer(weighted).spanningTreeSparsify(); assertEquals(3, st.getEdgeCount()); assertEquals(4, st.getVertexCount()); } + @Test public void testSingleEdge() { Graph g = new UndirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addEdge(new Edge("f","A","B"),"A","B"); GraphSparsificationAnalyzer a = new GraphSparsificationAnalyzer(g); assertEquals(1, a.findBridges().size()); assertEquals(1, a.spanningTreeSparsify().getEdgeCount()); } + @Test public void testWeightedST() { Graph st = new GraphSparsificationAnalyzer(weighted).spanningTreeSparsify(); assertEquals(3, st.getEdgeCount()); assertEquals(4, st.getVertexCount()); } @Test public void testLocalPreservesV() { assertEquals(5, new GraphSparsificationAnalyzer(complete5).localSparsify(2).getVertexCount()); } @Test public void testRandPreservesV() { assertEquals(5, new GraphSparsificationAnalyzer(complete5).randomSparsify(0.3, 123).getVertexCount()); } @Test public void testQualityDensity() { GraphSparsificationAnalyzer a = new GraphSparsificationAnalyzer(complete5); GraphSparsificationAnalyzer.SparsificationQuality q = a.evaluateQuality(a.spanningTreeSparsify()); assertEquals(1.0, q.originalDensity, 0.001); assertTrue(q.sparseDensity < q.originalDensity); } diff --git a/Gvisual/test/gvisual/GraphStatsTest.java b/Gvisual/test/gvisual/GraphStatsTest.java index 1a47ca2..06c0646 100644 --- a/Gvisual/test/gvisual/GraphStatsTest.java +++ b/Gvisual/test/gvisual/GraphStatsTest.java @@ -16,21 +16,21 @@ */ public class GraphStatsTest { - private Graph graph; - private Vector friendEdges; - private Vector fsEdges; - private Vector classmateEdges; - private Vector strangerEdges; - private Vector studyGEdges; + private Graph graph; + private Vector friendEdges; + private Vector fsEdges; + private Vector classmateEdges; + private Vector strangerEdges; + private Vector studyGEdges; @Before public void setUp() { - graph = new UndirectedSparseGraph(); - friendEdges = new Vector(); - fsEdges = new Vector(); - classmateEdges = new Vector(); - strangerEdges = new Vector(); - studyGEdges = new Vector(); + graph = new UndirectedSparseGraph(); + friendEdges = new Vector(); + fsEdges = new Vector(); + classmateEdges = new Vector(); + strangerEdges = new Vector(); + studyGEdges = new Vector(); } private GraphStats createStats() { @@ -40,13 +40,13 @@ private GraphStats createStats() { // ── Helper ────────────────────────────────────────────────── - private edge makeEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); return e; } - private void addToGraph(edge e) { + private void addToGraph(Edge e) { graph.addEdge(e, e.getVertex1(), e.getVertex2()); } @@ -106,7 +106,7 @@ public void testDensitySingleNode() { @Test public void testSingleEdge() { - edge e = makeEdge("f", "A", "B", 50.0f); + Edge e = makeEdge("f", "A", "B", 50.0f); friendEdges.add(e); addToGraph(e); @@ -121,7 +121,7 @@ public void testSingleEdge() { @Test public void testSingleEdge_density() { // 2 nodes, 1 edge: density = 2*1 / (2*1) = 1.0 - edge e = makeEdge("f", "A", "B", 10); + Edge e = makeEdge("f", "A", "B", 10); friendEdges.add(e); addToGraph(e); GraphStats stats = createStats(); @@ -131,7 +131,7 @@ public void testSingleEdge_density() { @Test public void testSingleEdge_averageDegree() { // 2 nodes, 1 edge: avg = 2*1/2 = 1.0 - edge e = makeEdge("f", "A", "B", 10); + Edge e = makeEdge("f", "A", "B", 10); friendEdges.add(e); addToGraph(e); GraphStats stats = createStats(); @@ -142,9 +142,9 @@ public void testSingleEdge_averageDegree() { @Test public void testDensityTriangle() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); - edge e3 = makeEdge("f", "A", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); + Edge e3 = makeEdge("f", "A", "C", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -155,9 +155,9 @@ public void testDensityTriangle() { @Test public void testTriangle_averageDegree() { // 3 nodes, 3 edges: avg = 2*3/3 = 2.0 - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); - edge e3 = makeEdge("f", "A", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); + Edge e3 = makeEdge("f", "A", "C", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -167,9 +167,9 @@ public void testTriangle_averageDegree() { @Test public void testTriangle_maxDegree() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); - edge e3 = makeEdge("f", "A", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); + Edge e3 = makeEdge("f", "A", "C", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -179,9 +179,9 @@ public void testTriangle_maxDegree() { @Test public void testTriangle_noIsolatedNodes() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); - edge e3 = makeEdge("f", "A", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); + Edge e3 = makeEdge("f", "A", "C", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -194,8 +194,8 @@ public void testTriangle_noIsolatedNodes() { @Test public void testAverageDegree() { // 3 nodes, 2 edges: degrees are 2, 1, 1 -> avg = 4/3 - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("c", "A", "C", 20); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("c", "A", "C", 20); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); classmateEdges.add(e2); @@ -207,9 +207,9 @@ public void testAverageDegree() { @Test public void testAverageDegree_fourNodesPath() { // A-B-C-D (path): 3 edges, 4 nodes, degrees: 1,2,2,1 avg = 6/4 = 1.5 - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); - edge e3 = makeEdge("f", "C", "D", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); + Edge e3 = makeEdge("f", "C", "D", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -221,9 +221,9 @@ public void testAverageDegree_fourNodesPath() { @Test public void testTopNodes() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "A", "C", 10); - edge e3 = makeEdge("f", "A", "D", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "A", "C", 10); + Edge e3 = makeEdge("f", "A", "D", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -236,7 +236,7 @@ public void testTopNodes() { @Test public void testTopNodes_requestMoreThanExist() { - edge e1 = makeEdge("f", "A", "B", 10); + Edge e1 = makeEdge("f", "A", "B", 10); addToGraph(e1); friendEdges.add(e1); @@ -247,7 +247,7 @@ public void testTopNodes_requestMoreThanExist() { @Test public void testTopNodes_requestZero() { - edge e1 = makeEdge("f", "A", "B", 10); + Edge e1 = makeEdge("f", "A", "B", 10); addToGraph(e1); friendEdges.add(e1); @@ -258,7 +258,7 @@ public void testTopNodes_requestZero() { @Test public void testTopNodes_requestNegative() { - edge e1 = makeEdge("f", "A", "B", 10); + Edge e1 = makeEdge("f", "A", "B", 10); addToGraph(e1); friendEdges.add(e1); @@ -269,8 +269,8 @@ public void testTopNodes_requestNegative() { @Test public void testTopNodes_requestOne() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "A", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "A", "C", 10); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); friendEdges.add(e2); @@ -284,9 +284,9 @@ public void testTopNodes_requestOne() { @Test public void testTopNodes_allSameDegree() { // Triangle: all have degree 2 - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); - edge e3 = makeEdge("f", "A", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); + Edge e3 = makeEdge("f", "A", "C", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -316,12 +316,12 @@ public void testTopNodes_onlyIsolatedNodes() { @Test public void testTopNodes_descending() { // Hub A connects to 4, B connects to 2, C connects to 1 - edge e1 = makeEdge("f", "A", "X", 10); - edge e2 = makeEdge("f", "A", "Y", 10); - edge e3 = makeEdge("f", "A", "Z", 10); - edge e4 = makeEdge("f", "A", "W", 10); - edge e5 = makeEdge("f", "B", "X", 10); - edge e6 = makeEdge("f", "B", "Y", 10); + Edge e1 = makeEdge("f", "A", "X", 10); + Edge e2 = makeEdge("f", "A", "Y", 10); + Edge e3 = makeEdge("f", "A", "Z", 10); + Edge e4 = makeEdge("f", "A", "W", 10); + Edge e5 = makeEdge("f", "B", "X", 10); + Edge e6 = makeEdge("f", "B", "Y", 10); addToGraph(e1); addToGraph(e2); addToGraph(e3); addToGraph(e4); addToGraph(e5); addToGraph(e6); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); @@ -350,7 +350,7 @@ public void testIsolatedNodes() { @Test public void testIsolatedNodes_mixedConnectivity() { // A-B connected, C and D isolated - edge e = makeEdge("f", "A", "B", 10); + Edge e = makeEdge("f", "A", "B", 10); addToGraph(e); friendEdges.add(e); graph.addVertex("C"); @@ -362,8 +362,8 @@ public void testIsolatedNodes_mixedConnectivity() { @Test public void testIsolatedNodes_noneIsolated() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "B", "C", 10); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "B", "C", 10); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); friendEdges.add(e2); @@ -375,8 +375,8 @@ public void testIsolatedNodes_noneIsolated() { @Test public void testAverageWeight() { - edge e1 = makeEdge("f", "A", "B", 30.0f); - edge e2 = makeEdge("s", "C", "D", 10.0f); + Edge e1 = makeEdge("f", "A", "B", 30.0f); + Edge e2 = makeEdge("s", "C", "D", 10.0f); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); strangerEdges.add(e2); @@ -386,7 +386,7 @@ public void testAverageWeight() { @Test public void testAverageWeight_singleEdge() { - edge e = makeEdge("f", "A", "B", 42.0f); + Edge e = makeEdge("f", "A", "B", 42.0f); addToGraph(e); friendEdges.add(e); @@ -396,8 +396,8 @@ public void testAverageWeight_singleEdge() { @Test public void testAverageWeight_zeroWeight() { - edge e1 = makeEdge("f", "A", "B", 0.0f); - edge e2 = makeEdge("f", "C", "D", 0.0f); + Edge e1 = makeEdge("f", "A", "B", 0.0f); + Edge e2 = makeEdge("f", "C", "D", 0.0f); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); friendEdges.add(e2); @@ -414,10 +414,10 @@ public void testAverageWeight_noEdges() { @Test public void testAverageWeight_multipleEdges() { - edge e1 = makeEdge("f", "A", "B", 10.0f); - edge e2 = makeEdge("f", "B", "C", 20.0f); - edge e3 = makeEdge("f", "C", "D", 30.0f); - edge e4 = makeEdge("f", "D", "E", 40.0f); + Edge e1 = makeEdge("f", "A", "B", 10.0f); + Edge e2 = makeEdge("f", "B", "C", 20.0f); + Edge e3 = makeEdge("f", "C", "D", 30.0f); + Edge e4 = makeEdge("f", "D", "E", 40.0f); addToGraph(e1); addToGraph(e2); addToGraph(e3); addToGraph(e4); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); friendEdges.add(e4); @@ -429,11 +429,11 @@ public void testAverageWeight_multipleEdges() { @Test public void testCategoryCountsIndependent() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("fs", "C", "D", 5); - edge e3 = makeEdge("c", "E", "F", 20); - edge e4 = makeEdge("s", "G", "H", 2); - edge e5 = makeEdge("sg", "I", "J", 15); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("fs", "C", "D", 5); + Edge e3 = makeEdge("c", "E", "F", 20); + Edge e4 = makeEdge("s", "G", "H", 2); + Edge e5 = makeEdge("sg", "I", "J", 15); friendEdges.add(e1); fsEdges.add(e2); @@ -457,9 +457,9 @@ public void testCategoryCountsIndependent() { @Test public void testCategoryCount_multipleFriends() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "C", "D", 20); - edge e3 = makeEdge("f", "E", "F", 30); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "C", "D", 20); + Edge e3 = makeEdge("f", "E", "F", 30); friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); addToGraph(e1); addToGraph(e2); addToGraph(e3); @@ -488,7 +488,7 @@ public void testCategoryCount_allZero() { @Test public void testDensity_sparseGraph() { // 4 nodes, 1 edge: density = 2*1 / (4*3) = 1/6 - edge e = makeEdge("f", "A", "B", 10); + Edge e = makeEdge("f", "A", "B", 10); addToGraph(e); friendEdges.add(e); graph.addVertex("C"); @@ -505,7 +505,7 @@ public void testDensity_completeK4() { int id = 0; for (int i = 0; i < nodes.length; i++) { for (int j = i + 1; j < nodes.length; j++) { - edge e = makeEdge("f", nodes[i], nodes[j], 10); + Edge e = makeEdge("f", nodes[i], nodes[j], 10); e.setLabel("e" + id++); addToGraph(e); friendEdges.add(e); @@ -521,7 +521,7 @@ public void testDensity_starGraph() { // Center connects to 5 others: 6 nodes, 5 edges // density = 2*5 / (6*5) = 10/30 = 1/3 for (int i = 1; i <= 5; i++) { - edge e = makeEdge("f", "center", "n" + i, 10); + Edge e = makeEdge("f", "center", "n" + i, 10); e.setLabel("e" + i); addToGraph(e); friendEdges.add(e); @@ -537,7 +537,7 @@ public void testDensity_starGraph() { public void testMaxDegree_starGraph() { // Center has degree 5 for (int i = 1; i <= 5; i++) { - edge e = makeEdge("f", "hub", "leaf" + i, 10); + Edge e = makeEdge("f", "hub", "leaf" + i, 10); e.setLabel("e" + i); addToGraph(e); friendEdges.add(e); @@ -565,8 +565,8 @@ public void testMaxDegree_onlyIsolated() { @Test public void testCaching_multipleCallsReturnSameResult() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("f", "A", "C", 20); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("f", "A", "C", 20); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); friendEdges.add(e2); @@ -585,8 +585,8 @@ public void testCaching_multipleCallsReturnSameResult() { @Test public void testCaching_weightMultipleCalls() { - edge e1 = makeEdge("f", "A", "B", 15.0f); - edge e2 = makeEdge("f", "C", "D", 25.0f); + Edge e1 = makeEdge("f", "A", "B", 15.0f); + Edge e2 = makeEdge("f", "C", "D", 25.0f); addToGraph(e1); addToGraph(e2); friendEdges.add(e1); friendEdges.add(e2); @@ -613,9 +613,9 @@ public void testFiltered_noEdgesVisible() { @Test public void testFiltered_partialVisible() { - edge e1 = makeEdge("f", "A", "B", 30); - edge e2 = makeEdge("f", "C", "D", 10); - edge e3 = makeEdge("f", "E", "F", 50); // not added to graph + Edge e1 = makeEdge("f", "A", "B", 30); + Edge e2 = makeEdge("f", "C", "D", 10); + Edge e3 = makeEdge("f", "E", "F", 50); // not added to graph friendEdges.add(e1); friendEdges.add(e2); friendEdges.add(e3); addToGraph(e1); addToGraph(e2); @@ -632,7 +632,7 @@ public void testFiltered_partialVisible() { public void testLargerGraph_tenNodes() { // Build a star: node0 connects to nodes 1-9 for (int i = 1; i <= 9; i++) { - edge e = makeEdge("f", "n0", "n" + i, i * 10.0f); + Edge e = makeEdge("f", "n0", "n" + i, i * 10.0f); e.setLabel("e" + i); addToGraph(e); friendEdges.add(e); @@ -663,7 +663,7 @@ public void testLargerGraph_tenNodes() { public void testLargerGraph_chainOf10() { // Linear chain: n0-n1-n2-...-n9 for (int i = 0; i < 9; i++) { - edge e = makeEdge("f", "n" + i, "n" + (i + 1), 10); + Edge e = makeEdge("f", "n" + i, "n" + (i + 1), 10); e.setLabel("e" + i); addToGraph(e); friendEdges.add(e); @@ -681,7 +681,7 @@ public void testLargerGraph_chainOf10() { @Test public void testNodeCount_verticesFromEdgesOnly() { // Vertices only added implicitly through edges - edge e = makeEdge("f", "X", "Y", 5); + Edge e = makeEdge("f", "X", "Y", 5); addToGraph(e); friendEdges.add(e); @@ -694,7 +694,7 @@ public void testNodeCount_mixedExplicitAndEdge() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - edge e = makeEdge("f", "A", "B", 10); + Edge e = makeEdge("f", "A", "B", 10); addToGraph(e); friendEdges.add(e); @@ -708,11 +708,11 @@ public void testNodeCount_mixedExplicitAndEdge() { @Test public void testMixedCategories_allInGraph() { - edge e1 = makeEdge("f", "A", "B", 10); - edge e2 = makeEdge("fs", "C", "D", 20); - edge e3 = makeEdge("c", "E", "F", 30); - edge e4 = makeEdge("s", "G", "H", 40); - edge e5 = makeEdge("sg", "I", "J", 50); + Edge e1 = makeEdge("f", "A", "B", 10); + Edge e2 = makeEdge("fs", "C", "D", 20); + Edge e3 = makeEdge("c", "E", "F", 30); + Edge e4 = makeEdge("s", "G", "H", 40); + Edge e5 = makeEdge("sg", "I", "J", 50); e1.setLabel("e1"); e2.setLabel("e2"); e3.setLabel("e3"); e4.setLabel("e4"); e5.setLabel("e5"); addToGraph(e1); addToGraph(e2); addToGraph(e3); diff --git a/Gvisual/test/gvisual/GraphSummarizerTest.java b/Gvisual/test/gvisual/GraphSummarizerTest.java index 1229aa0..e2b6510 100644 --- a/Gvisual/test/gvisual/GraphSummarizerTest.java +++ b/Gvisual/test/gvisual/GraphSummarizerTest.java @@ -13,27 +13,27 @@ */ public class GraphSummarizerTest { - private Graph graph; - private List friends, fs, classmates, strangers, studyG; + private Graph graph; + private List friends, fs, classmates, strangers, studyG; @Before public void setUp() { - graph = new UndirectedSparseGraph(); - friends = new ArrayList(); - fs = new ArrayList(); - classmates = new ArrayList(); - strangers = new ArrayList(); - studyG = new ArrayList(); + graph = new UndirectedSparseGraph(); + friends = new ArrayList(); + fs = new ArrayList(); + classmates = new ArrayList(); + strangers = new ArrayList(); + studyG = new ArrayList(); } private GraphSummarizer makeSummarizer() { return new GraphSummarizer(graph, friends, fs, classmates, strangers, studyG); } - private edge addEdge(String v1, String v2, String typeCode) { + private Edge addEdge(String v1, String v2, String typeCode) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge(typeCode, v1, v2); + Edge e = new Edge(typeCode, v1, v2); e.setWeight(50.0f); graph.addEdge(e, v1, v2); return e; @@ -63,7 +63,7 @@ public void testEmptyGraphOneLiner() { @Test public void testSmallNetwork() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); GraphSummarizer s = makeSummarizer(); String overview = s.getOverviewSection(); @@ -78,7 +78,7 @@ public void testMediumNetwork() { graph.addVertex("N" + i); } for (int i = 0; i < 19; i++) { - edge e = addEdge("N" + i, "N" + (i + 1), "c"); + Edge e = addEdge("N" + i, "N" + (i + 1), "c"); classmates.add(e); } GraphSummarizer s = makeSummarizer(); @@ -87,9 +87,9 @@ public void testMediumNetwork() { @Test public void testDensitySection() { - edge e1 = addEdge("A", "B", "f"); - edge e2 = addEdge("B", "C", "f"); - edge e3 = addEdge("A", "C", "f"); + Edge e1 = addEdge("A", "B", "f"); + Edge e2 = addEdge("B", "C", "f"); + Edge e3 = addEdge("A", "C", "f"); friends.add(e1); friends.add(e2); friends.add(e3); @@ -102,7 +102,7 @@ public void testDensitySection() { @Test public void testConnectivitySingleComponent() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); GraphSummarizer s = makeSummarizer(); String conn = s.getConnectivitySection(); @@ -111,7 +111,7 @@ public void testConnectivitySingleComponent() { @Test public void testConnectivityMultipleComponents() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); graph.addVertex("C"); // isolated GraphSummarizer s = makeSummarizer(); @@ -122,7 +122,7 @@ public void testConnectivityMultipleComponents() { @Test public void testCompositionAllFriends() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); GraphSummarizer s = makeSummarizer(); String comp = s.getCompositionSection(); @@ -132,9 +132,9 @@ public void testCompositionAllFriends() { @Test public void testCompositionMixed() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); - edge e2 = addEdge("B", "C", "s"); + Edge e2 = addEdge("B", "C", "s"); strangers.add(e2); GraphSummarizer s = makeSummarizer(); String comp = s.getCompositionSection(); @@ -152,9 +152,9 @@ public void testCompositionEmpty() { @Test public void testHubSection() { - edge e1 = addEdge("Hub", "A", "f"); - edge e2 = addEdge("Hub", "B", "f"); - edge e3 = addEdge("Hub", "C", "f"); + Edge e1 = addEdge("Hub", "A", "f"); + Edge e2 = addEdge("Hub", "B", "f"); + Edge e3 = addEdge("Hub", "C", "f"); friends.add(e1); friends.add(e2); friends.add(e3); @@ -174,9 +174,9 @@ public void testHubSectionEmpty() { @Test public void testStructuralObservationsTree() { // 4-node tree: A-B, B-C, C-D (3 edges, 4 nodes, connected) - edge e1 = addEdge("A", "B", "f"); - edge e2 = addEdge("B", "C", "f"); - edge e3 = addEdge("C", "D", "f"); + Edge e1 = addEdge("A", "B", "f"); + Edge e2 = addEdge("B", "C", "f"); + Edge e3 = addEdge("C", "D", "f"); friends.add(e1); friends.add(e2); friends.add(e3); @@ -188,11 +188,11 @@ public void testStructuralObservationsTree() { @Test public void testStructuralObservationsNearComplete() { // 4-node near-complete: 5 out of 6 edges → density 0.833 - edge e1 = addEdge("A", "B", "f"); - edge e2 = addEdge("A", "C", "f"); - edge e3 = addEdge("A", "D", "f"); - edge e4 = addEdge("B", "C", "f"); - edge e5 = addEdge("B", "D", "f"); + Edge e1 = addEdge("A", "B", "f"); + Edge e2 = addEdge("A", "C", "f"); + Edge e3 = addEdge("A", "D", "f"); + Edge e4 = addEdge("B", "C", "f"); + Edge e5 = addEdge("B", "D", "f"); friends.add(e1); friends.add(e2); friends.add(e3); friends.add(e4); friends.add(e5); GraphSummarizer s = makeSummarizer(); @@ -202,7 +202,7 @@ public void testStructuralObservationsNearComplete() { @Test public void testFullSummaryContainsAllSections() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); GraphSummarizer s = makeSummarizer(); String full = s.generateSummary(); @@ -222,7 +222,7 @@ public void testNullEdgeListsHandledGracefully() { @Test public void testOneLinerFormat() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); GraphSummarizer s = makeSummarizer(); String line = s.getOneLiner(); @@ -234,7 +234,7 @@ public void testOneLinerFormat() { @Test public void testAverageWeightObservation() { - edge e1 = addEdge("A", "B", "f"); + Edge e1 = addEdge("A", "B", "f"); friends.add(e1); GraphSummarizer s = makeSummarizer(); String obs = s.getStructuralObservations(); diff --git a/Gvisual/test/gvisual/GraphSymmetryAnalyzerTest.java b/Gvisual/test/gvisual/GraphSymmetryAnalyzerTest.java index 94fc8f8..ec3880b 100644 --- a/Gvisual/test/gvisual/GraphSymmetryAnalyzerTest.java +++ b/Gvisual/test/gvisual/GraphSymmetryAnalyzerTest.java @@ -14,15 +14,15 @@ */ public class GraphSymmetryAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { graph = new UndirectedSparseGraph<>(); } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -159,7 +159,7 @@ public void cycleC5_vertexTransitive() { } @Test - public void cycleC5_edgeTransitive() { + public void cycleC5_EdgeTransitive() { buildCycle(5); GraphSymmetryAnalyzer a = new GraphSymmetryAnalyzer(graph); assertTrue(a.isEdgeTransitive()); @@ -278,7 +278,7 @@ public void petersen_vertexTransitive() { } @Test - public void petersen_edgeTransitive() { + public void petersen_EdgeTransitive() { buildPetersen(); GraphSymmetryAnalyzer a = new GraphSymmetryAnalyzer(graph); assertTrue(a.isEdgeTransitive()); diff --git a/Gvisual/test/gvisual/GraphUtilsTest.java b/Gvisual/test/gvisual/GraphUtilsTest.java index ce34c65..3ecaf52 100644 --- a/Gvisual/test/gvisual/GraphUtilsTest.java +++ b/Gvisual/test/gvisual/GraphUtilsTest.java @@ -15,7 +15,7 @@ */ public class GraphUtilsTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -45,7 +45,7 @@ public void setUp() { private int edgeCounter = 0; private void addEdge(String v1, String v2, String type, float weight) { - edge e = new edge(type, v1, v2); + Edge e = new Edge(type, v1, v2); e.setWeight(weight); e.setLabel(v1 + "-" + v2); graph.addEdge(e, v1, v2); @@ -56,19 +56,19 @@ private void addEdge(String v1, String v2, String type, float weight) { @Test public void getOtherEnd_fromVertex1_returnsVertex2() { - edge e = new edge("f", "X", "Y"); + Edge e = new Edge("f", "X", "Y"); assertEquals("Y", GraphUtils.getOtherEnd(e, "X")); } @Test public void getOtherEnd_fromVertex2_returnsVertex1() { - edge e = new edge("f", "X", "Y"); + Edge e = new Edge("f", "X", "Y"); assertEquals("X", GraphUtils.getOtherEnd(e, "Y")); } @Test public void getOtherEnd_notEndpoint_returnsNull() { - edge e = new edge("f", "X", "Y"); + Edge e = new Edge("f", "X", "Y"); assertNull(GraphUtils.getOtherEnd(e, "Z")); } @@ -109,7 +109,7 @@ public void buildAdjacencyMap_subset() { @Test public void buildAdjacencyMap_emptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); Map> adj = GraphUtils.buildAdjacencyMap(empty); assertTrue(adj.isEmpty()); } @@ -166,7 +166,7 @@ public void findComponents_twoComponents() { @Test public void findComponents_emptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); List> comps = GraphUtils.findComponents(empty); assertTrue(comps.isEmpty()); } @@ -182,7 +182,7 @@ public void findLargestComponent_returnsLargest() { @Test public void findLargestComponent_emptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); Set largest = GraphUtils.findLargestComponent(empty); assertTrue(largest.isEmpty()); } @@ -284,7 +284,7 @@ public void cycleRank_withCycle() { @Test public void copyGraph_preservesStructure() { - Graph copy = GraphUtils.copyGraph(graph); + Graph copy = GraphUtils.copyGraph(graph); assertEquals(graph.getVertexCount(), copy.getVertexCount()); assertEquals(graph.getEdgeCount(), copy.getEdgeCount()); @@ -295,7 +295,7 @@ public void copyGraph_preservesStructure() { @Test public void copyGraph_independent() { - Graph copy = GraphUtils.copyGraph(graph); + Graph copy = GraphUtils.copyGraph(graph); copy.removeVertex("A"); // Original should be unaffected assertTrue(graph.containsVertex("A")); @@ -305,8 +305,8 @@ public void copyGraph_independent() { @Test public void copyGraph_preservesEdgeProperties() { - Graph copy = GraphUtils.copyGraph(graph); - for (edge e : copy.getEdges()) { + Graph copy = GraphUtils.copyGraph(graph); + for (Edge e : copy.getEdges()) { assertNotNull(e.getType()); assertNotNull(e.getVertex1()); assertNotNull(e.getVertex2()); @@ -333,14 +333,14 @@ public void computeBetweenness_nonEmpty() { @Test public void computeBetweenness_emptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); Map bc = GraphUtils.computeBetweenness(empty); assertTrue(bc.isEmpty()); } @Test public void computeBetweenness_singleNode() { - Graph single = new UndirectedSparseGraph<>(); + Graph single = new UndirectedSparseGraph<>(); single.addVertex("X"); Map bc = GraphUtils.computeBetweenness(single); assertEquals(1, bc.size()); @@ -350,12 +350,12 @@ public void computeBetweenness_singleNode() { @Test public void computeBetweenness_lineGraph() { // A -- B -- C: B has betweenness = 1 (on path A-C) - Graph line = new UndirectedSparseGraph<>(); + Graph line = new UndirectedSparseGraph<>(); line.addVertex("A"); line.addVertex("B"); line.addVertex("C"); - edge e1 = new edge("f", "A", "B"); - edge e2 = new edge("f", "B", "C"); + Edge e1 = new Edge("f", "A", "B"); + Edge e2 = new Edge("f", "B", "C"); line.addEdge(e1, "A", "B"); line.addEdge(e2, "B", "C"); @@ -369,13 +369,13 @@ public void computeBetweenness_lineGraph() { @Test public void globalEfficiency_completeTriangle() { - Graph tri = new UndirectedSparseGraph<>(); + Graph tri = new UndirectedSparseGraph<>(); tri.addVertex("A"); tri.addVertex("B"); tri.addVertex("C"); - tri.addEdge(new edge("f", "A", "B"), "A", "B"); - tri.addEdge(new edge("f", "B", "C"), "B", "C"); - tri.addEdge(new edge("f", "A", "C"), "A", "C"); + tri.addEdge(new Edge("f", "A", "B"), "A", "B"); + tri.addEdge(new Edge("f", "B", "C"), "B", "C"); + tri.addEdge(new Edge("f", "A", "C"), "A", "C"); double eff = GraphUtils.globalEfficiency(tri); // Complete graph: all distances = 1, efficiency = 1.0 @@ -384,7 +384,7 @@ public void globalEfficiency_completeTriangle() { @Test public void globalEfficiency_singleNode() { - Graph single = new UndirectedSparseGraph<>(); + Graph single = new UndirectedSparseGraph<>(); single.addVertex("X"); assertEquals(0.0, GraphUtils.globalEfficiency(single), 0.001); } @@ -392,7 +392,7 @@ public void globalEfficiency_singleNode() { @Test public void globalEfficiency_disconnected() { // Two isolated nodes: distance infinite, sum = 0 - Graph disc = new UndirectedSparseGraph<>(); + Graph disc = new UndirectedSparseGraph<>(); disc.addVertex("A"); disc.addVertex("B"); assertEquals(0.0, GraphUtils.globalEfficiency(disc), 0.001); @@ -402,12 +402,12 @@ public void globalEfficiency_disconnected() { public void globalEfficiency_lineGraph() { // A-B-C: d(A,B)=1, d(A,C)=2, d(B,C)=1 // sum = 1/1 + 1/2 + 1/1 = 2.5; E = 2*2.5/(3*2) = 5/6 ≈ 0.833 - Graph line = new UndirectedSparseGraph<>(); + Graph line = new UndirectedSparseGraph<>(); line.addVertex("A"); line.addVertex("B"); line.addVertex("C"); - line.addEdge(new edge("f", "A", "B"), "A", "B"); - line.addEdge(new edge("f", "B", "C"), "B", "C"); + line.addEdge(new Edge("f", "A", "B"), "A", "B"); + line.addEdge(new Edge("f", "B", "C"), "B", "C"); double eff = GraphUtils.globalEfficiency(line); assertEquals(5.0 / 6.0, eff, 0.001); diff --git a/Gvisual/test/gvisual/GrowthRateAnalyzerTest.java b/Gvisual/test/gvisual/GrowthRateAnalyzerTest.java index 9af3bbd..19217cb 100644 --- a/Gvisual/test/gvisual/GrowthRateAnalyzerTest.java +++ b/Gvisual/test/gvisual/GrowthRateAnalyzerTest.java @@ -12,33 +12,33 @@ /** * Comprehensive tests for GrowthRateAnalyzer. * Covers: constructor validation, analyze() snapshots, edgeGrowthRate() - * linear regression, density, clustering coefficient, edge cases. + * linear regression, density, clustering coefficient, Edge cases. */ public class GrowthRateAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // ─── Helper methods ─── - private edge makeEdge(String type, String v1, String v2, long start, long end) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, long start, long end) { + Edge e = new Edge(type, v1, v2); e.setTimestamp(start); e.setEndTimestamp(end); return e; } - private edge makeEdge(String type, String v1, String v2, long timestamp) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, long timestamp) { + Edge e = new Edge(type, v1, v2); e.setTimestamp(timestamp); return e; } - private void addEdge(Graph g, edge e) { + private void addEdge(Graph g, Edge e) { String v1 = e.getVertex1(); String v2 = e.getVertex2(); if (!g.containsVertex(v1)) g.addVertex(v1); @@ -67,7 +67,7 @@ public void testConstructor_negativeWindows() { @Test public void testConstructor_validArguments() { - edge e = makeEdge("f", "A", "B", 100L, 200L); + Edge e = makeEdge("f", "A", "B", 100L, 200L); addEdge(graph, e); TemporalGraph tg = new TemporalGraph(graph); GrowthRateAnalyzer analyzer = new GrowthRateAnalyzer(tg, 3); @@ -76,7 +76,7 @@ public void testConstructor_validArguments() { @Test public void testConstructor_singleWindow() { - edge e = makeEdge("f", "A", "B", 100L, 200L); + Edge e = makeEdge("f", "A", "B", 100L, 200L); addEdge(graph, e); TemporalGraph tg = new TemporalGraph(graph); GrowthRateAnalyzer analyzer = new GrowthRateAnalyzer(tg, 1); @@ -87,7 +87,7 @@ public void testConstructor_singleWindow() { @Test public void testAnalyze_singleWindowSingleEdge() { - edge e = makeEdge("f", "A", "B", 100L, 200L); + Edge e = makeEdge("f", "A", "B", 100L, 200L); addEdge(graph, e); TemporalGraph tg = new TemporalGraph(graph); GrowthRateAnalyzer analyzer = new GrowthRateAnalyzer(tg, 1); @@ -101,9 +101,9 @@ public void testAnalyze_singleWindowSingleEdge() { @Test public void testAnalyze_multipleWindows() { // Build a growing graph: edges appear at different times - edge e1 = makeEdge("f", "A", "B", 100L, 500L); - edge e2 = makeEdge("f", "B", "C", 200L, 500L); - edge e3 = makeEdge("f", "C", "D", 300L, 500L); + Edge e1 = makeEdge("f", "A", "B", 100L, 500L); + Edge e2 = makeEdge("f", "B", "C", 200L, 500L); + Edge e3 = makeEdge("f", "C", "D", 300L, 500L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -123,8 +123,8 @@ public void testAnalyze_multipleWindows() { @Test public void testAnalyze_snapshotsAreOrdered() { - edge e1 = makeEdge("f", "A", "B", 100L, 400L); - edge e2 = makeEdge("f", "C", "D", 200L, 400L); + Edge e1 = makeEdge("f", "A", "B", 100L, 400L); + Edge e2 = makeEdge("f", "C", "D", 200L, 400L); addEdge(graph, e1); addEdge(graph, e2); @@ -140,11 +140,11 @@ public void testAnalyze_snapshotsAreOrdered() { @Test public void testAnalyze_growingNetwork() { // Phase 1: 1 edge (t=0..1000) - edge e1 = makeEdge("f", "A", "B", 0L, 1000L); + Edge e1 = makeEdge("f", "A", "B", 0L, 1000L); addEdge(graph, e1); // Phase 2: 2 more edges (t=500..1000) - edge e2 = makeEdge("f", "B", "C", 500L, 1000L); - edge e3 = makeEdge("f", "C", "A", 500L, 1000L); + Edge e2 = makeEdge("f", "B", "C", 500L, 1000L); + Edge e3 = makeEdge("f", "C", "A", 500L, 1000L); addEdge(graph, e2); addEdge(graph, e3); @@ -162,9 +162,9 @@ public void testAnalyze_growingNetwork() { @Test public void testAnalyze_densityOfCompleteTriangle() { // Triangle: 3 nodes, 3 edges → density = 3/3 = 1.0 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); - edge e3 = makeEdge("f", "A", "C", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e3 = makeEdge("f", "A", "C", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -179,8 +179,8 @@ public void testAnalyze_densityOfCompleteTriangle() { @Test public void testAnalyze_densityOfPath() { // Path A-B-C: 3 nodes, 2 edges → density = 2/3 ≈ 0.667 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); @@ -194,7 +194,7 @@ public void testAnalyze_densityOfPath() { @Test public void testAnalyze_densityOfSingleEdge() { // 2 nodes, 1 edge → density = 1/1 = 1.0 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); addEdge(graph, e1); TemporalGraph tg = new TemporalGraph(graph); @@ -209,9 +209,9 @@ public void testAnalyze_densityOfSingleEdge() { @Test public void testAnalyze_clusteringOfTriangle() { // Complete triangle: all neighbors are connected → clustering = 1.0 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); - edge e3 = makeEdge("f", "A", "C", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e3 = makeEdge("f", "A", "C", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -228,8 +228,8 @@ public void testAnalyze_clusteringOfPath() { // Path A-B-C: B has 2 neighbors not connected → clustering(B) = 0 // A and C each have 1 neighbor → clustering = 0 // Average = 0 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); @@ -244,10 +244,10 @@ public void testAnalyze_clusteringOfPath() { public void testAnalyze_clusteringOfStar() { // Star: A connected to B,C,D,E but no connections among B,C,D,E // clustering(A) = 0 (no triangles), others have degree 1 (skip) - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "A", "C", 100L, 200L); - edge e3 = makeEdge("f", "A", "D", 100L, 200L); - edge e4 = makeEdge("f", "A", "E", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "A", "C", 100L, 200L); + Edge e3 = makeEdge("f", "A", "D", 100L, 200L); + Edge e4 = makeEdge("f", "A", "E", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -265,10 +265,10 @@ public void testAnalyze_clusteringOfStar() { @Test public void testEdgeGrowthRate_growingNetwork() { // Edges appearing over time: should have positive growth rate - edge e1 = makeEdge("f", "A", "B", 0L, 1000L); - edge e2 = makeEdge("f", "B", "C", 250L, 1000L); - edge e3 = makeEdge("f", "C", "D", 500L, 1000L); - edge e4 = makeEdge("f", "D", "E", 750L, 1000L); + Edge e1 = makeEdge("f", "A", "B", 0L, 1000L); + Edge e2 = makeEdge("f", "B", "C", 250L, 1000L); + Edge e3 = makeEdge("f", "C", "D", 500L, 1000L); + Edge e4 = makeEdge("f", "D", "E", 750L, 1000L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -284,9 +284,9 @@ public void testEdgeGrowthRate_growingNetwork() { @Test public void testEdgeGrowthRate_shrinkingNetwork() { // Edges disappearing over time: should have negative growth rate - edge e1 = makeEdge("f", "A", "B", 0L, 1000L); - edge e2 = makeEdge("f", "B", "C", 0L, 250L); - edge e3 = makeEdge("f", "C", "D", 0L, 500L); + Edge e1 = makeEdge("f", "A", "B", 0L, 1000L); + Edge e2 = makeEdge("f", "B", "C", 0L, 250L); + Edge e3 = makeEdge("f", "C", "D", 0L, 500L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -301,9 +301,9 @@ public void testEdgeGrowthRate_shrinkingNetwork() { @Test public void testEdgeGrowthRate_stableNetwork() { // All edges active for entire duration: constant count → rate ≈ 0 - edge e1 = makeEdge("f", "A", "B", 0L, 1000L); - edge e2 = makeEdge("f", "B", "C", 0L, 1000L); - edge e3 = makeEdge("f", "C", "A", 0L, 1000L); + Edge e1 = makeEdge("f", "A", "B", 0L, 1000L); + Edge e2 = makeEdge("f", "B", "C", 0L, 1000L); + Edge e3 = makeEdge("f", "C", "A", 0L, 1000L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -318,7 +318,7 @@ public void testEdgeGrowthRate_stableNetwork() { @Test public void testEdgeGrowthRate_singleWindow() { // With only 1 window, can't compute regression → returns 0 - edge e = makeEdge("f", "A", "B", 100L, 200L); + Edge e = makeEdge("f", "A", "B", 100L, 200L); addEdge(graph, e); TemporalGraph tg = new TemporalGraph(graph); @@ -358,8 +358,8 @@ public void testMetricSnapshot_fields() { @Test public void testAnalyze_disconnectedComponents() { // Two disconnected edges at same time - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "C", "D", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "C", "D", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); @@ -376,9 +376,9 @@ public void testAnalyze_disconnectedComponents() { @Test public void testAnalyze_edgesWithDifferentTypes() { // Multiple edge types shouldn't affect metric computation - edge e1 = makeEdge("friendship", "A", "B", 100L, 200L); - edge e2 = makeEdge("work", "B", "C", 100L, 200L); - edge e3 = makeEdge("family", "C", "A", 100L, 200L); + Edge e1 = makeEdge("friendship", "A", "B", 100L, 200L); + Edge e2 = makeEdge("work", "B", "C", 100L, 200L); + Edge e3 = makeEdge("family", "C", "A", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -396,10 +396,10 @@ public void testAnalyze_edgesWithDifferentTypes() { public void testAnalyze_windowWithNoEdges() { // Edge only active in first half of time range // Last windows should have 0 edges - edge e1 = makeEdge("f", "A", "B", 0L, 100L); + Edge e1 = makeEdge("f", "A", "B", 0L, 100L); addEdge(graph, e1); // Add another edge later to extend time range - edge e2 = makeEdge("f", "C", "D", 900L, 1000L); + Edge e2 = makeEdge("f", "C", "D", 900L, 1000L); addEdge(graph, e2); TemporalGraph tg = new TemporalGraph(graph); @@ -426,7 +426,7 @@ public void testAnalyze_k4CompleteGraph() { int id = 0; for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { - edge e = makeEdge("f", verts[i], verts[j], 100L, 200L); + Edge e = makeEdge("f", verts[i], verts[j], 100L, 200L); addEdge(graph, e); id++; } @@ -446,8 +446,8 @@ public void testAnalyze_k4CompleteGraph() { @Test public void testAnalyze_manyWindows() { // Test with many windows (10) - edge e1 = makeEdge("f", "A", "B", 0L, 1000L); - edge e2 = makeEdge("f", "B", "C", 500L, 1000L); + Edge e1 = makeEdge("f", "A", "B", 0L, 1000L); + Edge e2 = makeEdge("f", "B", "C", 500L, 1000L); addEdge(graph, e1); addEdge(graph, e2); @@ -465,20 +465,20 @@ public void testEdgeGrowthRate_linearGrowth() { String v1 = "V" + i; String v2 = "V" + (i + 1); long start = i * 100L; - edge e = makeEdge("f", v1, v2, start, 1000L); + Edge e = makeEdge("f", v1, v2, start, 1000L); addEdge(graph, e); } TemporalGraph tg = new TemporalGraph(graph); GrowthRateAnalyzer analyzer = new GrowthRateAnalyzer(tg, 10); - double rate = analyzer.edgeGrowthRate(); + double rate = analyzer.EdgeGrowthRate(); assertTrue("Linear growth should have positive rate", rate > 0); } @Test public void testAnalyze_snapshotCountMatchesWindowCount() { - edge e = makeEdge("f", "A", "B", 0L, 100L); + Edge e = makeEdge("f", "A", "B", 0L, 100L); addEdge(graph, e); TemporalGraph tg = new TemporalGraph(graph); @@ -493,9 +493,9 @@ public void testAnalyze_snapshotCountMatchesWindowCount() { public void testEdgeGrowthRate_twoWindows() { // 2 windows: window 1 has 1 edge, window 2 has 3 edges // slope = (3-1)/1 = 2.0 - edge e1 = makeEdge("f", "A", "B", 0L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); - edge e3 = makeEdge("f", "C", "D", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 0L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e3 = makeEdge("f", "C", "D", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -510,8 +510,8 @@ public void testEdgeGrowthRate_twoWindows() { @Test public void testAnalyze_densityWithEmptyWindow() { // Windows with 0 or 1 nodes should have density 0 - edge e1 = makeEdge("f", "A", "B", 0L, 50L); - edge e2 = makeEdge("f", "C", "D", 950L, 1000L); + Edge e1 = makeEdge("f", "A", "B", 0L, 50L); + Edge e2 = makeEdge("f", "C", "D", 950L, 1000L); addEdge(graph, e1); addEdge(graph, e2); @@ -530,10 +530,10 @@ public void testAnalyze_densityWithEmptyWindow() { public void testAnalyze_clusteringWithPartialTriangles() { // Square: A-B-C-D-A (4 nodes, 4 edges, no diagonals) // Each node has degree 2, neighbors not connected → clustering = 0 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); - edge e3 = makeEdge("f", "C", "D", 100L, 200L); - edge e4 = makeEdge("f", "D", "A", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e3 = makeEdge("f", "C", "D", 100L, 200L); + Edge e4 = makeEdge("f", "D", "A", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); @@ -555,11 +555,11 @@ public void testAnalyze_clusteringWithOneDiagonal() { // C: neighbors A,B,D; pairs: (A,B)=yes, (A,D)=yes, (B,D)=no → 2/3 // D: neighbors A,C; pair (A,C)=yes → 1/1 = 1.0 // Average = (2/3 + 1 + 2/3 + 1) / 4 = (10/3) / 4 ≈ 0.833 - edge e1 = makeEdge("f", "A", "B", 100L, 200L); - edge e2 = makeEdge("f", "B", "C", 100L, 200L); - edge e3 = makeEdge("f", "C", "D", 100L, 200L); - edge e4 = makeEdge("f", "D", "A", 100L, 200L); - edge e5 = makeEdge("f", "A", "C", 100L, 200L); + Edge e1 = makeEdge("f", "A", "B", 100L, 200L); + Edge e2 = makeEdge("f", "B", "C", 100L, 200L); + Edge e3 = makeEdge("f", "C", "D", 100L, 200L); + Edge e4 = makeEdge("f", "D", "A", 100L, 200L); + Edge e5 = makeEdge("f", "A", "C", 100L, 200L); addEdge(graph, e1); addEdge(graph, e2); addEdge(graph, e3); diff --git a/Gvisual/test/gvisual/HamiltonianAnalyzerTest.java b/Gvisual/test/gvisual/HamiltonianAnalyzerTest.java index 1845307..f5a974d 100644 --- a/Gvisual/test/gvisual/HamiltonianAnalyzerTest.java +++ b/Gvisual/test/gvisual/HamiltonianAnalyzerTest.java @@ -15,7 +15,7 @@ public class HamiltonianAnalyzerTest { private HamiltonianAnalyzer analyzer; - private Graph graph; + private Graph graph; private int edgeId; @Before @@ -25,8 +25,8 @@ public void setUp() { edgeId = 0; } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); e.setLabel("e" + (edgeId++)); if (!graph.containsVertex(v1)) graph.addVertex(v1); diff --git a/Gvisual/test/gvisual/HierarchicalLayoutTest.java b/Gvisual/test/gvisual/HierarchicalLayoutTest.java index 0782931..695bb04 100644 --- a/Gvisual/test/gvisual/HierarchicalLayoutTest.java +++ b/Gvisual/test/gvisual/HierarchicalLayoutTest.java @@ -12,50 +12,50 @@ public class HierarchicalLayoutTest { // ── Helpers ────────────────────────────────────────────────────── - private Graph linearDAG(int n) { - Graph g = new DirectedSparseGraph(); + private Graph linearDAG(int n) { + Graph g = new DirectedSparseGraph(); for (int i = 0; i < n; i++) g.addVertex("n" + i); for (int i = 0; i < n - 1; i++) { - edge e = new edge("d", "n" + i, "n" + (i + 1)); + Edge e = new Edge("d", "n" + i, "n" + (i + 1)); g.addEdge(e, "n" + i, "n" + (i + 1)); } return g; } - private Graph diamondDAG() { + private Graph diamondDAG() { // A // / \ // B C // \ / // D - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); for (String v : new String[]{"A", "B", "C", "D"}) g.addVertex(v); - g.addEdge(new edge("d", "A", "B"), "A", "B"); - g.addEdge(new edge("d", "A", "C"), "A", "C"); - g.addEdge(new edge("d", "B", "D"), "B", "D"); - g.addEdge(new edge("d", "C", "D"), "C", "D"); + g.addEdge(new Edge("d", "A", "B"), "A", "B"); + g.addEdge(new Edge("d", "A", "C"), "A", "C"); + g.addEdge(new Edge("d", "B", "D"), "B", "D"); + g.addEdge(new Edge("d", "C", "D"), "C", "D"); return g; } - private Graph wideDAG(int width) { + private Graph wideDAG(int width) { // root -> child0, child1, ..., child(width-1) - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("root"); for (int i = 0; i < width; i++) { String child = "c" + i; g.addVertex(child); - g.addEdge(new edge("d", "root", child), "root", child); + g.addEdge(new Edge("d", "root", child), "root", child); } return g; } - private Graph cycleGraph(int n) { - Graph g = new DirectedSparseGraph(); + private Graph cycleGraph(int n) { + Graph g = new DirectedSparseGraph(); for (int i = 0; i < n; i++) g.addVertex("n" + i); for (int i = 0; i < n; i++) { String from = "n" + i; String to = "n" + ((i + 1) % n); - g.addEdge(new edge("d", from, to), from, to); + g.addEdge(new Edge("d", from, to), from, to); } return g; } @@ -117,7 +117,7 @@ public void toSVG_beforeCompute() { @Test public void emptyGraph() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); HierarchicalLayout layout = new HierarchicalLayout(g).compute(); assertTrue(layout.getPositions().isEmpty()); @@ -132,7 +132,7 @@ public void emptyGraph() { @Test public void singleNode() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("solo"); HierarchicalLayout layout = new HierarchicalLayout(g).compute(); @@ -240,10 +240,10 @@ public void cycleGraph_handledGracefully() { @Test public void selfLoop_handled() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); - g.addEdge(new edge("d", "A", "B"), "A", "B"); + g.addEdge(new Edge("d", "A", "B"), "A", "B"); HierarchicalLayout layout = new HierarchicalLayout(g).compute(); assertEquals(2, layout.getPositions().size()); @@ -292,7 +292,7 @@ public void toSVG_containsElements() { @Test public void toSVG_emptyGraph() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); String svg = new HierarchicalLayout(g).compute().toSVG(800, 600, 15); assertTrue(svg.contains(" g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); - g.addEdge(new edge("d", "A", "B"), "A", "B"); - g.addEdge(new edge("d", "C", "D"), "C", "D"); + g.addEdge(new Edge("d", "A", "B"), "A", "B"); + g.addEdge(new Edge("d", "C", "D"), "C", "D"); HierarchicalLayout layout = new HierarchicalLayout(g).compute(); @@ -383,7 +383,7 @@ public void disconnectedComponents() { @Test public void isolatedVertices() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); @@ -401,13 +401,13 @@ public void isolatedVertices() { @Test public void crossingDetection_knownCase() { // Create X-crossing pattern: A->D, B->C where A,B in layer 0 and C,D in layer 1 - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); - g.addEdge(new edge("d", "A", "D"), "A", "D"); - g.addEdge(new edge("d", "B", "C"), "B", "C"); + g.addEdge(new Edge("d", "A", "D"), "A", "D"); + g.addEdge(new Edge("d", "B", "C"), "B", "C"); // With enough crossing sweeps, should minimize crossings HierarchicalLayout layout = new HierarchicalLayout( @@ -459,16 +459,16 @@ public void complexDAG_multiplePathsToSink() { // E F // \ / // G - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); for (String v : new String[]{"A","B","C","D","E","F","G"}) g.addVertex(v); - g.addEdge(new edge("d","A","B"), "A", "B"); - g.addEdge(new edge("d","A","C"), "A", "C"); - g.addEdge(new edge("d","A","D"), "A", "D"); - g.addEdge(new edge("d","B","E"), "B", "E"); - g.addEdge(new edge("d","C","E"), "C", "E"); - g.addEdge(new edge("d","D","F"), "D", "F"); - g.addEdge(new edge("d","E","G"), "E", "G"); - g.addEdge(new edge("d","F","G"), "F", "G"); + g.addEdge(new Edge("d","A","B"), "A", "B"); + g.addEdge(new Edge("d","A","C"), "A", "C"); + g.addEdge(new Edge("d","A","D"), "A", "D"); + g.addEdge(new Edge("d","B","E"), "B", "E"); + g.addEdge(new Edge("d","C","E"), "C", "E"); + g.addEdge(new Edge("d","D","F"), "D", "F"); + g.addEdge(new Edge("d","E","G"), "E", "G"); + g.addEdge(new Edge("d","F","G"), "F", "G"); HierarchicalLayout layout = new HierarchicalLayout(g).compute(); @@ -502,7 +502,7 @@ public void criticalPath_unmodifiable() { @Test(expected = UnsupportedOperationException.class) public void reversedEdges_unmodifiable() { HierarchicalLayout layout = new HierarchicalLayout(cycleGraph(3)).compute(); - layout.getReversedEdges().add(new edge("d", "x", "y")); + layout.getReversedEdges().add(new Edge("d", "x", "y")); } // ── Recompute ──────────────────────────────────────────────────── @@ -520,7 +520,7 @@ public void compute_canCallTwice() { @Test public void largeGraph_completes() { // Build a moderately large DAG (100 nodes, ~200 edges) - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); for (int i = 0; i < 100; i++) g.addVertex("v" + i); Random rng = new Random(42); @@ -531,11 +531,11 @@ public void largeGraph_completes() { if (j < 100) { String from = "v" + i; String to = "v" + j; - edge e = new edge("d", from, to); + Edge e = new Edge("d", from, to); try { g.addEdge(e, from, to); } catch (Exception ex) { - // duplicate edge, skip + // duplicate Edge, skip } } } diff --git a/Gvisual/test/gvisual/IndependentSetAnalyzerTest.java b/Gvisual/test/gvisual/IndependentSetAnalyzerTest.java index eabe2a1..ef309b8 100644 --- a/Gvisual/test/gvisual/IndependentSetAnalyzerTest.java +++ b/Gvisual/test/gvisual/IndependentSetAnalyzerTest.java @@ -14,16 +14,16 @@ */ public class IndependentSetAnalyzerTest { - private Graph emptyGraph; - private Graph singleVertex; - private Graph singleEdge; - private Graph triangle; - private Graph path4; // A-B-C-D - private Graph star5; // center connected to 4 leaves - private Graph cycle5; // 5-cycle - private Graph complete4; - private Graph bipartite; // K_{2,3} - private Graph petersen; // Petersen graph approx + private Graph emptyGraph; + private Graph singleVertex; + private Graph singleEdge; + private Graph triangle; + private Graph path4; // A-B-C-D + private Graph star5; // center connected to 4 leaves + private Graph cycle5; // 5-cycle + private Graph complete4; + private Graph bipartite; // K_{2,3} + private Graph petersen; // Petersen graph approx @Before public void setUp() { @@ -38,48 +38,48 @@ public void setUp() { singleEdge = new UndirectedSparseGraph<>(); singleEdge.addVertex("A"); singleEdge.addVertex("B"); - singleEdge.addEdge(new edge("e1", "A", "B"), "A", "B"); + singleEdge.addEdge(new Edge("e1", "A", "B"), "A", "B"); // Triangle triangle = new UndirectedSparseGraph<>(); for (String v : new String[]{"A", "B", "C"}) triangle.addVertex(v); - triangle.addEdge(new edge("e1", "A", "B"), "A", "B"); - triangle.addEdge(new edge("e2", "B", "C"), "B", "C"); - triangle.addEdge(new edge("e3", "A", "C"), "A", "C"); + triangle.addEdge(new Edge("e1", "A", "B"), "A", "B"); + triangle.addEdge(new Edge("e2", "B", "C"), "B", "C"); + triangle.addEdge(new Edge("e3", "A", "C"), "A", "C"); // Path: A-B-C-D path4 = new UndirectedSparseGraph<>(); for (String v : new String[]{"A", "B", "C", "D"}) path4.addVertex(v); - path4.addEdge(new edge("e1", "A", "B"), "A", "B"); - path4.addEdge(new edge("e2", "B", "C"), "B", "C"); - path4.addEdge(new edge("e3", "C", "D"), "C", "D"); + path4.addEdge(new Edge("e1", "A", "B"), "A", "B"); + path4.addEdge(new Edge("e2", "B", "C"), "B", "C"); + path4.addEdge(new Edge("e3", "C", "D"), "C", "D"); // Star: center=X, leaves=A,B,C,D star5 = new UndirectedSparseGraph<>(); for (String v : new String[]{"X", "A", "B", "C", "D"}) star5.addVertex(v); - star5.addEdge(new edge("e1", "X", "A"), "X", "A"); - star5.addEdge(new edge("e2", "X", "B"), "X", "B"); - star5.addEdge(new edge("e3", "X", "C"), "X", "C"); - star5.addEdge(new edge("e4", "X", "D"), "X", "D"); + star5.addEdge(new Edge("e1", "X", "A"), "X", "A"); + star5.addEdge(new Edge("e2", "X", "B"), "X", "B"); + star5.addEdge(new Edge("e3", "X", "C"), "X", "C"); + star5.addEdge(new Edge("e4", "X", "D"), "X", "D"); // 5-cycle: A-B-C-D-E-A cycle5 = new UndirectedSparseGraph<>(); for (String v : new String[]{"A", "B", "C", "D", "E"}) cycle5.addVertex(v); - cycle5.addEdge(new edge("e1", "A", "B"), "A", "B"); - cycle5.addEdge(new edge("e2", "B", "C"), "B", "C"); - cycle5.addEdge(new edge("e3", "C", "D"), "C", "D"); - cycle5.addEdge(new edge("e4", "D", "E"), "D", "E"); - cycle5.addEdge(new edge("e5", "E", "A"), "E", "A"); + cycle5.addEdge(new Edge("e1", "A", "B"), "A", "B"); + cycle5.addEdge(new Edge("e2", "B", "C"), "B", "C"); + cycle5.addEdge(new Edge("e3", "C", "D"), "C", "D"); + cycle5.addEdge(new Edge("e4", "D", "E"), "D", "E"); + cycle5.addEdge(new Edge("e5", "E", "A"), "E", "A"); // K4 complete4 = new UndirectedSparseGraph<>(); for (String v : new String[]{"A", "B", "C", "D"}) complete4.addVertex(v); - complete4.addEdge(new edge("e1", "A", "B"), "A", "B"); - complete4.addEdge(new edge("e2", "A", "C"), "A", "C"); - complete4.addEdge(new edge("e3", "A", "D"), "A", "D"); - complete4.addEdge(new edge("e4", "B", "C"), "B", "C"); - complete4.addEdge(new edge("e5", "B", "D"), "B", "D"); - complete4.addEdge(new edge("e6", "C", "D"), "C", "D"); + complete4.addEdge(new Edge("e1", "A", "B"), "A", "B"); + complete4.addEdge(new Edge("e2", "A", "C"), "A", "C"); + complete4.addEdge(new Edge("e3", "A", "D"), "A", "D"); + complete4.addEdge(new Edge("e4", "B", "C"), "B", "C"); + complete4.addEdge(new Edge("e5", "B", "D"), "B", "D"); + complete4.addEdge(new Edge("e6", "C", "D"), "C", "D"); // K_{2,3}: {A,B} x {C,D,E} bipartite = new UndirectedSparseGraph<>(); @@ -87,7 +87,7 @@ public void setUp() { int eid = 0; for (String l : new String[]{"A", "B"}) { for (String r : new String[]{"C", "D", "E"}) { - bipartite.addEdge(new edge("e" + (eid++), l, r), l, r); + bipartite.addEdge(new Edge("e" + (eid++), l, r), l, r); } } } @@ -387,7 +387,7 @@ public void testKernelOnEmptyGraph() { @Test public void testKernelOnIsolatedVertices() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); IndependentSetAnalyzer a = new IndependentSetAnalyzer(g); IndependentSetAnalyzer.KernelResult kr = a.kernelReduction(); @@ -555,7 +555,7 @@ public void testPolynomialOnPath4() { @Test(expected = IllegalStateException.class) public void testPolynomialTooLargeThrows() { - Graph big = new UndirectedSparseGraph<>(); + Graph big = new UndirectedSparseGraph<>(); for (int i = 0; i < 25; i++) big.addVertex("V" + i); IndependentSetAnalyzer a = new IndependentSetAnalyzer(big); a.independencePolynomial(); // > 20 vertices @@ -579,7 +579,7 @@ public void testMaxCliqueOnPath4() { @Test public void testMaxCliqueOnIndependentVertices() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); IndependentSetAnalyzer a = new IndependentSetAnalyzer(g); Set clique = a.maximumCliqueViaComplement(); @@ -658,11 +658,11 @@ public void testReportSummaryContainsVertexCount() { @Test public void testDisconnectedGraph() { // Two components: triangle + isolated vertex - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); - g.addEdge(new edge("e1", "A", "B"), "A", "B"); - g.addEdge(new edge("e2", "B", "C"), "B", "C"); - g.addEdge(new edge("e3", "A", "C"), "A", "C"); + g.addEdge(new Edge("e1", "A", "B"), "A", "B"); + g.addEdge(new Edge("e2", "B", "C"), "B", "C"); + g.addEdge(new Edge("e3", "A", "C"), "A", "C"); IndependentSetAnalyzer a = new IndependentSetAnalyzer(g); Set mis = a.exactMaximumIndependentSet(); assertEquals(2, mis.size()); // 1 from triangle + D @@ -671,10 +671,10 @@ public void testDisconnectedGraph() { @Test public void testTwoDisconnectedEdges() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); - g.addEdge(new edge("e1", "A", "B"), "A", "B"); - g.addEdge(new edge("e2", "C", "D"), "C", "D"); + g.addEdge(new Edge("e1", "A", "B"), "A", "B"); + g.addEdge(new Edge("e2", "C", "D"), "C", "D"); IndependentSetAnalyzer a = new IndependentSetAnalyzer(g); assertEquals(2, a.exactMaximumIndependentSet().size()); } diff --git a/Gvisual/test/gvisual/InfluenceSpreadSimulatorTest.java b/Gvisual/test/gvisual/InfluenceSpreadSimulatorTest.java index 72d3313..d0fee73 100644 --- a/Gvisual/test/gvisual/InfluenceSpreadSimulatorTest.java +++ b/Gvisual/test/gvisual/InfluenceSpreadSimulatorTest.java @@ -15,16 +15,16 @@ */ public class InfluenceSpreadSimulatorTest { - private Graph graph; + private Graph graph; private InfluenceSpreadSimulator simulator; @Before public void setUp() { graph = new UndirectedSparseGraph<>(); - graph.addEdge(new edge("c", "A", "B"), "A", "B"); - graph.addEdge(new edge("c", "A", "C"), "A", "C"); - graph.addEdge(new edge("c", "A", "D"), "A", "D"); - graph.addEdge(new edge("c", "A", "E"), "A", "E"); + graph.addEdge(new Edge("c", "A", "B"), "A", "B"); + graph.addEdge(new Edge("c", "A", "C"), "A", "C"); + graph.addEdge(new Edge("c", "A", "D"), "A", "D"); + graph.addEdge(new Edge("c", "A", "E"), "A", "E"); simulator = new InfluenceSpreadSimulator(graph, 42L); } @@ -332,7 +332,7 @@ public void testFindTopKSeeds() { @Test public void testFindTopKSeedsEmptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); InfluenceSpreadSimulator sim = new InfluenceSpreadSimulator(empty, 42L); List seeds = sim.findTopKSeeds(3, @@ -404,10 +404,10 @@ public void testVaccinationToString() { @Test public void testEdgeWeightAsInfluenceProbability() { - Graph wg = new UndirectedSparseGraph<>(); - edge e1 = new edge("c", "X", "Y"); + Graph wg = new UndirectedSparseGraph<>(); + Edge e1 = new Edge("c", "X", "Y"); e1.setWeight(1.0f); - edge e2 = new edge("c", "X", "Z"); + Edge e2 = new Edge("c", "X", "Z"); e2.setWeight(0.0f); wg.addEdge(e1, "X", "Y"); wg.addEdge(e2, "X", "Z"); @@ -423,9 +423,9 @@ public void testEdgeWeightAsInfluenceProbability() { @Test public void testDirectedGraphIC() { - Graph dg = new DirectedSparseGraph<>(); - dg.addEdge(new edge("c", "A", "B"), "A", "B"); - dg.addEdge(new edge("c", "A", "C"), "A", "C"); + Graph dg = new DirectedSparseGraph<>(); + dg.addEdge(new Edge("c", "A", "B"), "A", "B"); + dg.addEdge(new Edge("c", "A", "C"), "A", "C"); InfluenceSpreadSimulator sim = new InfluenceSpreadSimulator(dg, 42L); InfluenceSpreadSimulator.SimulationResult result = @@ -435,8 +435,8 @@ public void testDirectedGraphIC() { @Test public void testDirectedGraphNoBackPropagation() { - Graph dg = new DirectedSparseGraph<>(); - dg.addEdge(new edge("c", "A", "B"), "A", "B"); + Graph dg = new DirectedSparseGraph<>(); + dg.addEdge(new Edge("c", "A", "B"), "A", "B"); InfluenceSpreadSimulator sim = new InfluenceSpreadSimulator(dg, 42L); InfluenceSpreadSimulator.SimulationResult result = @@ -448,11 +448,11 @@ public void testDirectedGraphNoBackPropagation() { @Test public void testChainGraphPropagation() { - Graph chain = new UndirectedSparseGraph<>(); - chain.addEdge(new edge("c", "1", "2"), "1", "2"); - chain.addEdge(new edge("c", "2", "3"), "2", "3"); - chain.addEdge(new edge("c", "3", "4"), "3", "4"); - chain.addEdge(new edge("c", "4", "5"), "4", "5"); + Graph chain = new UndirectedSparseGraph<>(); + chain.addEdge(new Edge("c", "1", "2"), "1", "2"); + chain.addEdge(new Edge("c", "2", "3"), "2", "3"); + chain.addEdge(new Edge("c", "3", "4"), "3", "4"); + chain.addEdge(new Edge("c", "4", "5"), "4", "5"); InfluenceSpreadSimulator sim = new InfluenceSpreadSimulator(chain, 42L); InfluenceSpreadSimulator.SimulationResult result = @@ -465,8 +465,8 @@ public void testChainGraphPropagation() { @Test public void testDisconnectedGraphLimitsSpread() { - Graph dg = new UndirectedSparseGraph<>(); - dg.addEdge(new edge("c", "A", "B"), "A", "B"); + Graph dg = new UndirectedSparseGraph<>(); + dg.addEdge(new Edge("c", "A", "B"), "A", "B"); dg.addVertex("C"); InfluenceSpreadSimulator sim = new InfluenceSpreadSimulator(dg, 42L); diff --git a/Gvisual/test/gvisual/InteractiveHtmlExporterTest.java b/Gvisual/test/gvisual/InteractiveHtmlExporterTest.java index 2e2a8af..78d666a 100644 --- a/Gvisual/test/gvisual/InteractiveHtmlExporterTest.java +++ b/Gvisual/test/gvisual/InteractiveHtmlExporterTest.java @@ -14,7 +14,7 @@ */ public class InteractiveHtmlExporterTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -24,19 +24,19 @@ public void setUp() { graph.addVertex("Carol"); graph.addVertex("Dave"); - edge e1 = new edge("f", "Alice", "Bob"); + Edge e1 = new Edge("f", "Alice", "Bob"); e1.setWeight(1.0f); graph.addEdge(e1, "Alice", "Bob"); - edge e2 = new edge("c", "Bob", "Carol"); + Edge e2 = new Edge("c", "Bob", "Carol"); e2.setWeight(0.5f); graph.addEdge(e2, "Bob", "Carol"); - edge e3 = new edge("sg", "Alice", "Carol"); + Edge e3 = new Edge("sg", "Alice", "Carol"); e3.setWeight(2.0f); graph.addEdge(e3, "Alice", "Carol"); - edge e4 = new edge("fs", "Carol", "Dave"); + Edge e4 = new Edge("fs", "Carol", "Dave"); e4.setWeight(1.0f); graph.addEdge(e4, "Carol", "Dave"); } @@ -174,7 +174,7 @@ public void testExportToFile() throws Exception { @Test public void testEmptyGraph() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); InteractiveHtmlExporter exporter = new InteractiveHtmlExporter(empty); String html = exporter.exportToString(); assertTrue(html.contains("")); @@ -184,7 +184,7 @@ public void testEmptyGraph() { @Test public void testSingleNodeGraph() { - Graph single = new UndirectedSparseGraph<>(); + Graph single = new UndirectedSparseGraph<>(); single.addVertex("Lonely"); InteractiveHtmlExporter exporter = new InteractiveHtmlExporter(single); String html = exporter.exportToString(); diff --git a/Gvisual/test/gvisual/JsonGraphExporterTest.java b/Gvisual/test/gvisual/JsonGraphExporterTest.java index 33579f2..908d1ac 100644 --- a/Gvisual/test/gvisual/JsonGraphExporterTest.java +++ b/Gvisual/test/gvisual/JsonGraphExporterTest.java @@ -23,7 +23,7 @@ public void testNullGraphThrows() { @Test public void testNullEdgeListAccepted() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); JsonGraphExporter exporter = new JsonGraphExporter(g, null); String json = exporter.exportToString(); assertNotNull(json); @@ -33,8 +33,8 @@ public void testNullEdgeListAccepted() { @Test public void testEmptyGraphJson() { - Graph g = new UndirectedSparseGraph<>(); - JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); + Graph g = new UndirectedSparseGraph<>(); + JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); exporter.setTimestamp("2011-03-15"); String json = exporter.exportToString(); @@ -47,15 +47,15 @@ public void testEmptyGraphJson() { @Test public void testSingleEdgeGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(2.5f); e.setLabel("friends"); g.addEdge(e, "A", "B"); - List edges = new ArrayList<>(); + List edges = new ArrayList<>(); edges.add(e); JsonGraphExporter exporter = new JsonGraphExporter(g, edges); @@ -74,12 +74,12 @@ public void testSingleEdgeGraph() { @Test public void testStatsIncluded() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - edge e1 = new edge("f", "A", "B"); - edge e2 = new edge("c", "B", "C"); + Edge e1 = new Edge("f", "A", "B"); + Edge e2 = new Edge("c", "B", "C"); g.addEdge(e1, "A", "B"); g.addEdge(e2, "B", "C"); @@ -94,11 +94,11 @@ public void testStatsIncluded() { @Test public void testStatsDisabled() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("X"); - edge e = new edge("s", "X", "X"); + Edge e = new Edge("s", "X", "X"); // self-loop won't work in undirected sparse, just test empty stats - JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); + JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); exporter.setIncludeStats(false); String json = exporter.exportToString(); @@ -108,9 +108,9 @@ public void testStatsDisabled() { @Test public void testCompactOutput() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); - JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); + JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); exporter.setPrettyPrint(false); String json = exporter.exportToString(); @@ -120,10 +120,10 @@ public void testCompactOutput() { @Test public void testTimestampOnEdge() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setTimestamp(1300000000000L); e.setEndTimestamp(1300100000000L); g.addEdge(e, "A", "B"); @@ -137,9 +137,9 @@ public void testTimestampOnEdge() { @Test public void testSpecialCharactersEscaped() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("node\"1"); - JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); + JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); String json = exporter.exportToString(); assertTrue(json.contains("node\\\"1")); @@ -147,10 +147,10 @@ public void testSpecialCharactersEscaped() { @Test public void testFileExport() throws IOException { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); g.addEdge(e, "A", "B"); JsonGraphExporter exporter = new JsonGraphExporter(g, Arrays.asList(e)); @@ -166,12 +166,12 @@ public void testFileExport() throws IOException { @Test public void testEdgeTypesPerNode() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - edge e1 = new edge("f", "A", "B"); - edge e2 = new edge("c", "A", "C"); + Edge e1 = new Edge("f", "A", "B"); + Edge e2 = new Edge("c", "A", "C"); g.addEdge(e1, "A", "B"); g.addEdge(e2, "A", "C"); @@ -186,8 +186,8 @@ public void testEdgeTypesPerNode() { @Test public void testDescriptionInMetadata() { - Graph g = new UndirectedSparseGraph<>(); - JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); + Graph g = new UndirectedSparseGraph<>(); + JsonGraphExporter exporter = new JsonGraphExporter(g, new ArrayList()); exporter.setDescription("Test graph for unit testing"); String json = exporter.exportToString(); diff --git a/Gvisual/test/gvisual/KCoreDecompositionTest.java b/Gvisual/test/gvisual/KCoreDecompositionTest.java index 15676f6..898da1c 100644 --- a/Gvisual/test/gvisual/KCoreDecompositionTest.java +++ b/Gvisual/test/gvisual/KCoreDecompositionTest.java @@ -16,17 +16,17 @@ */ public class KCoreDecompositionTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helpers --- - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/KTrussAnalyzerTest.java b/Gvisual/test/gvisual/KTrussAnalyzerTest.java index 69e84ab..796de69 100644 --- a/Gvisual/test/gvisual/KTrussAnalyzerTest.java +++ b/Gvisual/test/gvisual/KTrussAnalyzerTest.java @@ -15,15 +15,15 @@ */ public class KTrussAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { graph = new UndirectedSparseGraph<>(); } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); graph.addEdge(e, v1, v2); return e; @@ -46,9 +46,9 @@ public void testSingleEdge_noTriangle() { @Test public void testTriangle() { - edge ab = addEdge("A", "B"); - edge bc = addEdge("B", "C"); - edge ac = addEdge("A", "C"); + Edge ab = addEdge("A", "B"); + Edge bc = addEdge("B", "C"); + Edge ac = addEdge("A", "C"); KTrussAnalyzer analyzer = new KTrussAnalyzer(graph); // A triangle: each edge has 1 triangle support → 3-truss @@ -81,7 +81,7 @@ public void testGetKTruss() { addEdge("C", "D"); // no triangle KTrussAnalyzer analyzer = new KTrussAnalyzer(graph); - Graph truss3 = analyzer.getKTruss(3); + Graph truss3 = analyzer.getKTruss(3); // The 3-truss should contain only the triangle edges assertTrue(truss3.getEdgeCount() <= 3); @@ -107,7 +107,7 @@ public void testTrussHierarchy() { addEdge("C", "D"); KTrussAnalyzer analyzer = new KTrussAnalyzer(graph); - Map> hierarchy = analyzer.getTrussHierarchy(); + Map> hierarchy = analyzer.getTrussHierarchy(); assertFalse(hierarchy.isEmpty()); } diff --git a/Gvisual/test/gvisual/LaplacianBuilderTest.java b/Gvisual/test/gvisual/LaplacianBuilderTest.java index 927cb32..864a433 100644 --- a/Gvisual/test/gvisual/LaplacianBuilderTest.java +++ b/Gvisual/test/gvisual/LaplacianBuilderTest.java @@ -14,7 +14,7 @@ */ public class LaplacianBuilderTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -22,7 +22,7 @@ public void setUp() { } private void addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); graph.addEdge(e, v1, v2); diff --git a/Gvisual/test/gvisual/LineGraphAnalyzerTest.java b/Gvisual/test/gvisual/LineGraphAnalyzerTest.java index 70497f4..7549b6a 100644 --- a/Gvisual/test/gvisual/LineGraphAnalyzerTest.java +++ b/Gvisual/test/gvisual/LineGraphAnalyzerTest.java @@ -11,58 +11,58 @@ */ public class LineGraphAnalyzerTest { - private Graph makeGraph(String[][] edges) { - Graph g = new UndirectedSparseGraph(); + private Graph makeGraph(String[][] edges) { + Graph g = new UndirectedSparseGraph(); for (String[] e : edges) { g.addVertex(e[0]); g.addVertex(e[1]); - edge ed = new edge("e", e[0], e[1]); + Edge ed = new Edge("e", e[0], e[1]); ed.setLabel(e[0] + "-" + e[1]); g.addEdge(ed, e[0], e[1]); } return g; } - private Graph emptyGraph() { - return new UndirectedSparseGraph(); + private Graph emptyGraph() { + return new UndirectedSparseGraph(); } - private Graph singleVertex() { - Graph g = new UndirectedSparseGraph(); + private Graph singleVertex() { + Graph g = new UndirectedSparseGraph(); g.addVertex("A"); return g; } - private Graph singleEdge() { + private Graph singleEdge() { return makeGraph(new String[][]{{"A", "B"}}); } - private Graph path3() { + private Graph path3() { return makeGraph(new String[][]{{"A", "B"}, {"B", "C"}}); } - private Graph triangle() { + private Graph triangle() { return makeGraph(new String[][]{{"A", "B"}, {"B", "C"}, {"A", "C"}}); } - private Graph k4() { + private Graph k4() { return makeGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"A", "D"}, {"B", "C"}, {"B", "D"}, {"C", "D"} }); } - private Graph star4() { + private Graph star4() { return makeGraph(new String[][]{{"A", "B"}, {"A", "C"}, {"A", "D"}}); } - private Graph cycle4() { + private Graph cycle4() { return makeGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"} }); } - private Graph cycle5() { + private Graph cycle5() { return makeGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "E"}, {"E", "A"} }); @@ -241,7 +241,7 @@ public void testWhitneyEmpty() { @Test public void testWhitneyDisconnected() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); assertTrue(new LineGraphAnalyzer(g).whitneyTheoremCheck().contains("disconnected")); } @@ -261,14 +261,14 @@ public void testWhitneyDisconnected() { public void testMatchDisjoint() { LineGraphAnalyzer a = new LineGraphAnalyzer(k4()); Set m = a.maximalMatchingViaLineGraph(); - Graph lg = a.getLineGraph(); + Graph lg = a.getLineGraph(); List ml = new ArrayList(m); for (int i = 0; i < ml.size(); i++) for (int j = i + 1; j < ml.size(); j++) assertFalse(lg.isNeighbor(ml.get(i), ml.get(j))); } - // ── Vertex edge-cliques ───────────────────────────────────────── + // ── Vertex Edge-cliques ───────────────────────────────────────── @Test public void testCliquesK4Size() { diff --git a/Gvisual/test/gvisual/LinkPredictionAnalyzerTest.java b/Gvisual/test/gvisual/LinkPredictionAnalyzerTest.java index 2d9edf0..4272f21 100644 --- a/Gvisual/test/gvisual/LinkPredictionAnalyzerTest.java +++ b/Gvisual/test/gvisual/LinkPredictionAnalyzerTest.java @@ -14,11 +14,11 @@ */ public class LinkPredictionAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } @Test(expected = IllegalArgumentException.class) @@ -41,8 +41,8 @@ public void testTrianglePrediction() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -60,8 +60,8 @@ public void testJaccardScoring() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -79,11 +79,11 @@ public void testPreferentialAttachment() { graph.addVertex("C"); graph.addVertex("D"); graph.addVertex("E"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "A", "D"), "A", "D"); - graph.addEdge(new edge("f", "D", "E"), "D", "E"); - graph.addEdge(new edge("f", "C", "E"), "C", "E"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "D"), "A", "D"); + graph.addEdge(new Edge("f", "D", "E"), "D", "E"); + graph.addEdge(new Edge("f", "C", "E"), "C", "E"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -103,10 +103,10 @@ public void testAdamicAdar() { graph.addVertex("B"); graph.addVertex("C"); graph.addVertex("D"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "B", "D"), "B", "D"); - graph.addEdge(new edge("f", "C", "D"), "C", "D"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "B", "D"), "B", "D"); + graph.addEdge(new Edge("f", "C", "D"), "C", "D"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -124,8 +124,8 @@ public void testEnsemblePrediction() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -140,9 +140,9 @@ public void testCompleteGraphNoPredictions() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -157,7 +157,7 @@ public void testDensityCalculation() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -171,7 +171,7 @@ public void testDensityCalculation() { public void testSummaryNotNull() { graph.addVertex("A"); graph.addVertex("B"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); graph.addVertex("C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); @@ -221,8 +221,8 @@ public void testIsolatedVerticesInLargerGraph() { graph.addVertex("B"); graph.addVertex("C"); graph.addVertex("isolated"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -242,12 +242,12 @@ public void testDisconnectedComponents() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); // Component 2: D-E graph.addVertex("D"); graph.addVertex("E"); - graph.addEdge(new edge("f", "D", "E"), "D", "E"); + graph.addEdge(new Edge("f", "D", "E"), "D", "E"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -271,10 +271,10 @@ public void testTopKLimitsResults() { graph.addVertex("C"); graph.addVertex("D"); graph.addVertex("E"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "A", "D"), "A", "D"); - graph.addEdge(new edge("f", "A", "E"), "A", "E"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "D"), "A", "D"); + graph.addEdge(new Edge("f", "A", "E"), "A", "E"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -289,8 +289,8 @@ public void testTopKZero() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -309,11 +309,11 @@ public void testResultsSortedByScoreDescending() { graph.addVertex("C"); graph.addVertex("D"); graph.addVertex("E"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "A", "D"), "A", "D"); - graph.addEdge(new edge("f", "A", "E"), "A", "E"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "D"), "A", "D"); + graph.addEdge(new Edge("f", "A", "E"), "A", "E"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -340,11 +340,11 @@ public void testJaccardWithDifferentSizedNeighborhoods() { graph.addVertex("D"); graph.addVertex("E"); graph.addVertex("F"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "A", "D"), "A", "D"); - graph.addEdge(new edge("f", "A", "E"), "A", "E"); - graph.addEdge(new edge("f", "B", "F"), "B", "F"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "D"), "A", "D"); + graph.addEdge(new Edge("f", "A", "E"), "A", "E"); + graph.addEdge(new Edge("f", "B", "F"), "B", "F"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -371,8 +371,8 @@ public void testAdamicAdarScoreValue() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -390,10 +390,10 @@ public void testAdamicAdarMultipleCommonNeighbors() { graph.addVertex("B"); graph.addVertex("C"); graph.addVertex("D"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "D", "B"), "D", "B"); - graph.addEdge(new edge("f", "D", "C"), "D", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "D", "B"), "D", "B"); + graph.addEdge(new Edge("f", "D", "C"), "D", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -421,11 +421,11 @@ public void testPreferentialAttachmentScoreValue() { graph.addVertex("C"); graph.addVertex("D"); graph.addVertex("E"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "A", "D"), "A", "D"); - graph.addEdge(new edge("f", "D", "E"), "D", "E"); - graph.addEdge(new edge("f", "C", "E"), "C", "E"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "D"), "A", "D"); + graph.addEdge(new Edge("f", "D", "E"), "D", "E"); + graph.addEdge(new Edge("f", "C", "E"), "C", "E"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -451,8 +451,8 @@ public void testPredictionResultMetadata() { graph.addVertex("B"); graph.addVertex("C"); graph.addVertex("D"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -482,9 +482,9 @@ public void testDensityOneForCompleteGraph() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "B", "C"), "B", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "B", "C"), "B", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -500,8 +500,8 @@ public void testPredictedLinkToString() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -522,9 +522,9 @@ public void testEnsembleReturnsNormalizedScores() { graph.addVertex("B"); graph.addVertex("C"); graph.addVertex("D"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "A", "D"), "A", "D"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "D"), "A", "D"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -554,8 +554,8 @@ public void testSummaryContainsKey() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -578,10 +578,10 @@ public void testCommonNeighborsCorrect() { graph.addVertex("C"); graph.addVertex("D"); // A--B, A--C, D--B, D--C → predict A-D, common = {B, C} - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); - graph.addEdge(new edge("f", "D", "B"), "D", "B"); - graph.addEdge(new edge("f", "D", "C"), "D", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "D", "B"), "D", "B"); + graph.addEdge(new Edge("f", "D", "C"), "D", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -604,8 +604,8 @@ public void testCommonNeighborsUnmodifiable() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = @@ -619,8 +619,8 @@ public void testPredictionsListUnmodifiable() { graph.addVertex("A"); graph.addVertex("B"); graph.addVertex("C"); - graph.addEdge(new edge("f", "A", "B"), "A", "B"); - graph.addEdge(new edge("f", "A", "C"), "A", "C"); + graph.addEdge(new Edge("f", "A", "B"), "A", "B"); + graph.addEdge(new Edge("f", "A", "C"), "A", "C"); LinkPredictionAnalyzer analyzer = new LinkPredictionAnalyzer(graph); LinkPredictionAnalyzer.PredictionResult result = diff --git a/Gvisual/test/gvisual/LouvainCommunityDetectorTest.java b/Gvisual/test/gvisual/LouvainCommunityDetectorTest.java index c20328b..f485038 100644 --- a/Gvisual/test/gvisual/LouvainCommunityDetectorTest.java +++ b/Gvisual/test/gvisual/LouvainCommunityDetectorTest.java @@ -12,17 +12,17 @@ */ public class LouvainCommunityDetectorTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } private void addEdge(String type, String v1, String v2, float weight) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge(type, v1, v2); + Edge e = new Edge(type, v1, v2); e.setWeight(weight); graph.addEdge(e, v1, v2); } @@ -317,7 +317,7 @@ public void testDeterministic() { @Test public void testZeroWeightEdge() { graph.addVertex("A"); graph.addVertex("B"); - edge e = new edge("f", "A", "B"); e.setWeight(0.0f); + Edge e = new Edge("f", "A", "B"); e.setWeight(0.0f); graph.addEdge(e, "A", "B"); LouvainCommunityDetector.LouvainResult r = new LouvainCommunityDetector(graph).detect(); assertEquals(r.getNodeToCommunity().get("A"), r.getNodeToCommunity().get("B")); diff --git a/Gvisual/test/gvisual/MaxCutAnalyzerTest.java b/Gvisual/test/gvisual/MaxCutAnalyzerTest.java index ba3c6ba..5974824 100644 --- a/Gvisual/test/gvisual/MaxCutAnalyzerTest.java +++ b/Gvisual/test/gvisual/MaxCutAnalyzerTest.java @@ -14,20 +14,20 @@ */ public class MaxCutAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } private void addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); graph.addEdge(e, v1, v2); } private void addWeightedEdge(String v1, String v2, float weight) { - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setWeight(weight); graph.addEdge(e, v1, v2); } @@ -289,7 +289,7 @@ public void testCutResultSetsAreUnmodifiable() { @Test public void testCutEdgesUnmodifiable() { addEdge("A","B"); - try { new MaxCutAnalyzer(graph).computeExact().getCutEdges().add(new edge("f","X","Y")); fail(); } + try { new MaxCutAnalyzer(graph).computeExact().getCutEdges().add(new Edge("f","X","Y")); fail(); } catch (UnsupportedOperationException e) { /* expected */ } } diff --git a/Gvisual/test/gvisual/MetricDimensionAnalyzerTest.java b/Gvisual/test/gvisual/MetricDimensionAnalyzerTest.java index d639464..ded91f7 100644 --- a/Gvisual/test/gvisual/MetricDimensionAnalyzerTest.java +++ b/Gvisual/test/gvisual/MetricDimensionAnalyzerTest.java @@ -15,41 +15,41 @@ public class MetricDimensionAnalyzerTest { // ── Graph builders ────────────────────────────────────────────── - private Graph makeGraph(String[][] edges) { - Graph g = new UndirectedSparseGraph(); + private Graph makeGraph(String[][] edges) { + Graph g = new UndirectedSparseGraph(); for (String[] e : edges) { g.addVertex(e[0]); g.addVertex(e[1]); - edge ed = new edge("e", e[0], e[1]); + Edge ed = new Edge("e", e[0], e[1]); ed.setLabel(e[0] + "-" + e[1]); g.addEdge(ed, e[0], e[1]); } return g; } - private Graph emptyGraph() { - return new UndirectedSparseGraph(); + private Graph emptyGraph() { + return new UndirectedSparseGraph(); } - private Graph singleVertex() { - Graph g = new UndirectedSparseGraph(); + private Graph singleVertex() { + Graph g = new UndirectedSparseGraph(); g.addVertex("A"); return g; } - private Graph path(String... nodes) { - Graph g = new UndirectedSparseGraph(); + private Graph path(String... nodes) { + Graph g = new UndirectedSparseGraph(); for (String v : nodes) g.addVertex(v); for (int i = 0; i < nodes.length - 1; i++) { - edge e = new edge("e", nodes[i], nodes[i + 1]); + Edge e = new Edge("e", nodes[i], nodes[i + 1]); e.setLabel(nodes[i] + "-" + nodes[i + 1]); g.addEdge(e, nodes[i], nodes[i + 1]); } return g; } - private Graph cycle(int n) { - Graph g = new UndirectedSparseGraph(); + private Graph cycle(int n) { + Graph g = new UndirectedSparseGraph(); String[] v = new String[n]; for (int i = 0; i < n; i++) { v[i] = String.valueOf((char) ('A' + i)); @@ -57,15 +57,15 @@ private Graph cycle(int n) { } for (int i = 0; i < n; i++) { String a = v[i], b = v[(i + 1) % n]; - edge e = new edge("e", a, b); + Edge e = new Edge("e", a, b); e.setLabel(a + "-" + b); g.addEdge(e, a, b); } return g; } - private Graph complete(int n) { - Graph g = new UndirectedSparseGraph(); + private Graph complete(int n) { + Graph g = new UndirectedSparseGraph(); String[] v = new String[n]; for (int i = 0; i < n; i++) { v[i] = String.valueOf((char) ('A' + i)); @@ -73,7 +73,7 @@ private Graph complete(int n) { } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { - edge e = new edge("e", v[i], v[j]); + Edge e = new Edge("e", v[i], v[j]); e.setLabel(v[i] + "-" + v[j]); g.addEdge(e, v[i], v[j]); } @@ -81,41 +81,41 @@ private Graph complete(int n) { return g; } - private Graph star(int leaves) { - Graph g = new UndirectedSparseGraph(); + private Graph star(int leaves) { + Graph g = new UndirectedSparseGraph(); g.addVertex("C"); for (int i = 0; i < leaves; i++) { String v = "L" + i; g.addVertex(v); - edge e = new edge("e", "C", v); + Edge e = new Edge("e", "C", v); e.setLabel("C-" + v); g.addEdge(e, "C", v); } return g; } - private Graph petersen() { + private Graph petersen() { // Petersen graph: outer cycle 0-4, inner pentagram 5-9 - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); for (int i = 0; i < 10; i++) g.addVertex("V" + i); // Outer cycle: 0-1-2-3-4-0 int[][] outer = {{0,1},{1,2},{2,3},{3,4},{4,0}}; for (int[] e : outer) { - edge ed = new edge("e", "V" + e[0], "V" + e[1]); + Edge ed = new Edge("e", "V" + e[0], "V" + e[1]); ed.setLabel("V" + e[0] + "-V" + e[1]); g.addEdge(ed, "V" + e[0], "V" + e[1]); } // Inner pentagram: 5-7, 7-9, 9-6, 6-8, 8-5 int[][] inner = {{5,7},{7,9},{9,6},{6,8},{8,5}}; for (int[] e : inner) { - edge ed = new edge("e", "V" + e[0], "V" + e[1]); + Edge ed = new Edge("e", "V" + e[0], "V" + e[1]); ed.setLabel("V" + e[0] + "-V" + e[1]); g.addEdge(ed, "V" + e[0], "V" + e[1]); } // Spokes: 0-5, 1-6, 2-7, 3-8, 4-9 int[][] spokes = {{0,5},{1,6},{2,7},{3,8},{4,9}}; for (int[] e : spokes) { - edge ed = new edge("e", "V" + e[0], "V" + e[1]); + Edge ed = new Edge("e", "V" + e[0], "V" + e[1]); ed.setLabel("V" + e[0] + "-V" + e[1]); g.addEdge(ed, "V" + e[0], "V" + e[1]); } @@ -258,7 +258,7 @@ public void testDistanceMatrixPath() { @Test public void testDistanceMatrixDisconnected() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); MetricDimensionAnalyzer a = new MetricDimensionAnalyzer(g); @@ -527,11 +527,11 @@ public void testSummaryEmptyGraph() { @Test public void testDisconnectedGraph() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - edge e = new edge("e", "A", "B"); + Edge e = new Edge("e", "A", "B"); e.setLabel("A-B"); g.addEdge(e, "A", "B"); // C is isolated — disconnected graph @@ -543,7 +543,7 @@ public void testDisconnectedGraph() { @Test public void testTwoIsolatedVertices() { - Graph g = new UndirectedSparseGraph(); + Graph g = new UndirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); MetricDimensionAnalyzer a = new MetricDimensionAnalyzer(g); diff --git a/Gvisual/test/gvisual/MinimumSpanningTreeTest.java b/Gvisual/test/gvisual/MinimumSpanningTreeTest.java index d23459a..9662d09 100644 --- a/Gvisual/test/gvisual/MinimumSpanningTreeTest.java +++ b/Gvisual/test/gvisual/MinimumSpanningTreeTest.java @@ -14,11 +14,11 @@ */ public class MinimumSpanningTreeTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // ========================================== @@ -83,7 +83,7 @@ public void testTwoDisconnectedVertices() { @Test public void testSingleEdge() { - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(5.0f); graph.addEdge(e1, "A", "B"); @@ -105,11 +105,11 @@ public void testSingleEdge() { @Test public void testTrianglePicksLightestTwoEdges() { // Triangle: A-B(1), B-C(2), A-C(3) → MST = A-B(1) + B-C(2) = weight 3 - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("f", "A", "C"); + Edge e3 = new Edge("f", "A", "C"); e3.setWeight(3.0f); graph.addEdge(e1, "A", "B"); @@ -133,11 +133,11 @@ public void testSquareGraphSelectsCorrectEdges() { // Square: A-B(1), B-C(4), C-D(2), A-D(3) // Also diagonal: A-C(5) // MST = A-B(1) + C-D(2) + A-D(3) = weight 6 - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "B", "C"); e2.setWeight(4.0f); - edge e3 = new edge("f", "C", "D"); e3.setWeight(2.0f); - edge e4 = new edge("s", "A", "D"); e4.setWeight(3.0f); - edge e5 = new edge("fs", "A", "C"); e5.setWeight(5.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(4.0f); + Edge e3 = new Edge("f", "C", "D"); e3.setWeight(2.0f); + Edge e4 = new Edge("s", "A", "D"); e4.setWeight(3.0f); + Edge e5 = new Edge("fs", "A", "C"); e5.setWeight(5.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -160,7 +160,7 @@ public void testMstHasNMinus1Edges() { float w = 1.0f; for (int i = 0; i < nodes.length; i++) { for (int j = i + 1; j < nodes.length; j++) { - edge e = new edge("f", nodes[i], nodes[j]); + Edge e = new Edge("f", nodes[i], nodes[j]); e.setWeight(w); graph.addEdge(e, nodes[i], nodes[j]); w += 1.0f; @@ -181,13 +181,13 @@ public void testMstHasNMinus1Edges() { @Test public void testDisconnectedGraphProducesForest() { // Component 1: A-B(1), B-C(2) - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); // Component 2: D-E(3) - edge e3 = new edge("c", "D", "E"); e3.setWeight(3.0f); + Edge e3 = new Edge("c", "D", "E"); e3.setWeight(3.0f); graph.addEdge(e3, "D", "E"); MinimumSpanningTree mst = new MinimumSpanningTree(graph); @@ -202,13 +202,13 @@ public void testDisconnectedGraphProducesForest() { @Test public void testForestComponentBreakdown() { // Component 1: A-B(1), B-C(2) - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); // Component 2: D-E(5) - edge e3 = new edge("c", "D", "E"); e3.setWeight(5.0f); + Edge e3 = new Edge("c", "D", "E"); e3.setWeight(5.0f); graph.addEdge(e3, "D", "E"); // Isolated vertex @@ -250,9 +250,9 @@ public void testIsolatedVerticesAsSingletonComponents() { @Test public void testEqualWeightsProducesValidMst() { // All edges weight 1 — any spanning tree is MST - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1.0f); - edge e3 = new edge("f", "A", "C"); e3.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1.0f); + Edge e3 = new Edge("f", "A", "C"); e3.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -268,8 +268,8 @@ public void testEqualWeightsProducesValidMst() { @Test public void testZeroWeightEdges() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(0.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(0.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(0.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(0.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -283,8 +283,8 @@ public void testZeroWeightEdges() { @Test public void testLargeWeights() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1000000.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(999999.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1000000.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(999999.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -302,10 +302,10 @@ public void testLargeWeights() { @Test public void testEdgeTypeDistribution() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("f", "C", "D"); e3.setWeight(3.0f); - edge e4 = new edge("s", "D", "E"); e4.setWeight(4.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(2.0f); + Edge e3 = new Edge("f", "C", "D"); e3.setWeight(3.0f); + Edge e4 = new Edge("s", "D", "E"); e4.setWeight(4.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -331,8 +331,8 @@ public void testEdgeTypeDistributionEmpty() { @Test public void testEdgeTypeDistributionAllSameType() { - edge e1 = new edge("sg", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("sg", "B", "C"); e2.setWeight(2.0f); + Edge e1 = new Edge("sg", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("sg", "B", "C"); e2.setWeight(2.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -351,9 +351,9 @@ public void testEdgeTypeDistributionAllSameType() { @Test public void testHeaviestEdge() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(5.0f); - edge e3 = new edge("f", "C", "D"); e3.setWeight(3.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(5.0f); + Edge e3 = new Edge("f", "C", "D"); e3.setWeight(3.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -376,9 +376,9 @@ public void testHeaviestEdgeEmpty() { @Test public void testLightestEdge() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(3.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(1.0f); - edge e3 = new edge("f", "C", "D"); e3.setWeight(5.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(3.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(1.0f); + Edge e3 = new Edge("f", "C", "D"); e3.setWeight(5.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -401,9 +401,9 @@ public void testLightestEdgeEmpty() { @Test public void testAverageWeight() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(2.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(4.0f); - edge e3 = new edge("f", "C", "D"); e3.setWeight(6.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(2.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(4.0f); + Edge e3 = new Edge("f", "C", "D"); e3.setWeight(6.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -425,8 +425,8 @@ public void testAverageWeightEmpty() { @Test public void testGetSummaryConnected() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -443,7 +443,7 @@ public void testGetSummaryConnected() { @Test public void testGetSummaryForest() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addVertex("C"); @@ -462,13 +462,13 @@ public void testGetSummaryForest() { @Test public void testComponentWeights() { // Comp1: A-B(1) B-C(2) → weight 3 - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); // Comp2: D-E(7) - edge e3 = new edge("c", "D", "E"); e3.setWeight(7.0f); + Edge e3 = new Edge("c", "D", "E"); e3.setWeight(7.0f); graph.addEdge(e3, "D", "E"); MinimumSpanningTree mst = new MinimumSpanningTree(graph); @@ -489,9 +489,9 @@ public void testComponentWeights() { @Test public void testComponentDominantType() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("c", "C", "D"); e3.setWeight(3.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); + Edge e3 = new Edge("c", "C", "D"); e3.setWeight(3.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -516,7 +516,7 @@ public void testComponentDominantTypeNull() { @Test public void testComponentIds() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); graph.addVertex("C"); graph.addVertex("D"); @@ -546,13 +546,13 @@ public void testLargerGraph() { // 4 3 5 2 // | / | / // D--7--E--8--F - edge[] edges = { + Edge[] edges = { makeEdge("f", "A", "B", 1), makeEdge("c", "A", "D", 4), makeEdge("f", "B", "D", 3), makeEdge("s", "B", "E", 5), makeEdge("f", "B", "C", 6), makeEdge("c", "C", "E", 2), makeEdge("sg", "D", "E", 7), makeEdge("f", "E", "F", 8) }; - for (edge e : edges) { + for (Edge e : edges) { graph.addEdge(e, e.getVertex1(), e.getVertex2()); } @@ -569,7 +569,7 @@ public void testLargerGraph() { public void testStarGraph() { // Hub (A) connected to 5 leaves for (int i = 0; i < 5; i++) { - edge e = new edge("f", "A", "L" + i); + Edge e = new Edge("f", "A", "L" + i); e.setWeight(i + 1.0f); graph.addEdge(e, "A", "L" + i); } @@ -586,7 +586,7 @@ public void testStarGraph() { public void testLinearChain() { // A-B-C-D-E (chain) for (int i = 0; i < 4; i++) { - edge e = new edge("f", "N" + i, "N" + (i + 1)); + Edge e = new Edge("f", "N" + i, "N" + (i + 1)); e.setWeight((i + 1) * 2.0f); graph.addEdge(e, "N" + i, "N" + (i + 1)); } @@ -611,7 +611,7 @@ public void testCompleteGraphK4() { }; for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { - edge e = new edge("f", nodes[i], nodes[j]); + Edge e = new Edge("f", nodes[i], nodes[j]); e.setWeight(weights[i][j]); graph.addEdge(e, nodes[i], nodes[j]); } @@ -632,9 +632,9 @@ public void testCompleteGraphK4() { @Test public void testMultipleComputesSameResult() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("f", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("f", "A", "C"); e3.setWeight(3.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("f", "B", "C"); e2.setWeight(2.0f); + Edge e3 = new Edge("f", "A", "C"); e3.setWeight(3.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -652,14 +652,14 @@ public void testMultipleComputesSameResult() { @Test public void testResultIsUnmodifiable() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); MinimumSpanningTree mst = new MinimumSpanningTree(graph); MinimumSpanningTree.MSTResult result = mst.compute(); try { - result.getEdges().add(new edge("f", "X", "Y")); + result.getEdges().add(new Edge("f", "X", "Y")); fail("Should not be able to modify edges list"); } catch (UnsupportedOperationException expected) { // pass @@ -668,7 +668,7 @@ public void testResultIsUnmodifiable() { @Test public void testComponentsUnmodifiable() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); graph.addEdge(e1, "A", "B"); MinimumSpanningTree mst = new MinimumSpanningTree(graph); @@ -688,11 +688,11 @@ public void testComponentsUnmodifiable() { @Test public void testMixedEdgeTypes() { - edge e1 = new edge("f", "A", "B"); e1.setWeight(1.0f); - edge e2 = new edge("c", "B", "C"); e2.setWeight(2.0f); - edge e3 = new edge("s", "C", "D"); e3.setWeight(3.0f); - edge e4 = new edge("fs", "D", "E"); e4.setWeight(4.0f); - edge e5 = new edge("sg", "A", "E"); e5.setWeight(10.0f); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.0f); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(2.0f); + Edge e3 = new Edge("s", "C", "D"); e3.setWeight(3.0f); + Edge e4 = new Edge("fs", "D", "E"); e4.setWeight(4.0f); + Edge e5 = new Edge("sg", "A", "E"); e5.setWeight(10.0f); graph.addEdge(e1, "A", "B"); graph.addEdge(e2, "B", "C"); @@ -705,7 +705,7 @@ public void testMixedEdgeTypes() { assertEquals(4, result.getEdgeCount()); assertEquals(10.0f, result.getTotalWeight(), 0.001f); // 1+2+3+4 - // sg edge (weight 10) should NOT be in MST + // sg Edge (weight 10) should NOT be in MST assertFalse(result.getEdges().contains(e5)); Map dist = result.getEdgeTypeDistribution(); @@ -768,8 +768,8 @@ public void testUnionFindSelfUnion() { // Helper // ========================================== - private edge makeEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); return e; } diff --git a/Gvisual/test/gvisual/MotifAnalyzerTest.java b/Gvisual/test/gvisual/MotifAnalyzerTest.java index d324db6..2bfe3aa 100644 --- a/Gvisual/test/gvisual/MotifAnalyzerTest.java +++ b/Gvisual/test/gvisual/MotifAnalyzerTest.java @@ -14,17 +14,17 @@ */ public class MotifAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helpers --- - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -187,7 +187,7 @@ public void testStarOf3HasWedges() { makeStar("H", "A", "B", "C"); MotifAnalyzer ma = new MotifAnalyzer(graph).compute(); // C(3,2) = 3 wedges centered on H - assertEquals(3, ma.getWedgeCount()); + assertEquals(3, ma.getWEdgeCount()); assertEquals(0, ma.getTriangleCount()); } diff --git a/Gvisual/test/gvisual/NetworkFlowAnalyzerTest.java b/Gvisual/test/gvisual/NetworkFlowAnalyzerTest.java index c72b7cc..234f8a3 100644 --- a/Gvisual/test/gvisual/NetworkFlowAnalyzerTest.java +++ b/Gvisual/test/gvisual/NetworkFlowAnalyzerTest.java @@ -16,17 +16,17 @@ */ public class NetworkFlowAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helpers --- - private edge addEdge(String v1, String v2, float weight) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2, float weight) { + Edge e = new Edge("f", v1, v2); e.setWeight(weight); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -34,7 +34,7 @@ private edge addEdge(String v1, String v2, float weight) { return e; } - private edge addEdge(String v1, String v2) { + private Edge addEdge(String v1, String v2) { return addEdge(v1, v2, 1.0f); } @@ -201,7 +201,7 @@ public void testTriangleGraph() { @Test public void testDefaultWeight() { // Unweighted edges default to capacity 1.0 - edge e = new edge("f", "A", "B"); + Edge e = new Edge("f", "A", "B"); e.setWeight(0); if (!graph.containsVertex("A")) graph.addVertex("A"); if (!graph.containsVertex("B")) graph.addVertex("B"); @@ -285,7 +285,7 @@ public void testMinCutSingleEdge() { addEdge("A", "B", 5.0f); NetworkFlowAnalyzer nfa = new NetworkFlowAnalyzer(graph); nfa.compute("A", "B"); - List cut = nfa.getMinCut(); + List cut = nfa.getMinCut(); assertEquals(1, cut.size()); } @@ -295,7 +295,7 @@ public void testMinCutDisconnected() { graph.addVertex("B"); NetworkFlowAnalyzer nfa = new NetworkFlowAnalyzer(graph); nfa.compute("A", "B"); - List cut = nfa.getMinCut(); + List cut = nfa.getMinCut(); assertEquals(0, cut.size()); } @@ -304,9 +304,9 @@ public void testMinCutUnmodifiable() { addEdge("A", "B", 5.0f); NetworkFlowAnalyzer nfa = new NetworkFlowAnalyzer(graph); nfa.compute("A", "B"); - List cut = nfa.getMinCut(); + List cut = nfa.getMinCut(); try { - cut.add(new edge("f", "X", "Y")); + cut.add(new Edge("f", "X", "Y")); fail("Should throw on modification"); } catch (UnsupportedOperationException e) { // expected @@ -363,7 +363,7 @@ public void testBottleneckEdges() { NetworkFlowAnalyzer nfa = new NetworkFlowAnalyzer(graph); nfa.compute("A", "C"); // A-B is bottleneck (capacity 3, flow 3) - List bottlenecks = nfa.getBottleneckEdges(); + List bottlenecks = nfa.getBottleneckEdges(); assertTrue(bottlenecks.size() >= 1); } @@ -372,9 +372,9 @@ public void testBottleneckEdgesUnmodifiable() { addEdge("A", "B", 5.0f); NetworkFlowAnalyzer nfa = new NetworkFlowAnalyzer(graph); nfa.compute("A", "B"); - List bottlenecks = nfa.getBottleneckEdges(); + List bottlenecks = nfa.getBottleneckEdges(); try { - bottlenecks.add(new edge("f", "X", "Y")); + bottlenecks.add(new Edge("f", "X", "Y")); fail("Should throw on modification"); } catch (UnsupportedOperationException e) { // expected diff --git a/Gvisual/test/gvisual/NetworkReportGeneratorTest.java b/Gvisual/test/gvisual/NetworkReportGeneratorTest.java index 409f65c..84932b6 100644 --- a/Gvisual/test/gvisual/NetworkReportGeneratorTest.java +++ b/Gvisual/test/gvisual/NetworkReportGeneratorTest.java @@ -16,27 +16,27 @@ */ public class NetworkReportGeneratorTest { - private Graph graph; - private List friendEdges; - private List fsEdges; - private List classmateEdges; - private List strangerEdges; - private List studyGEdges; + private Graph graph; + private List friendEdges; + private List fsEdges; + private List classmateEdges; + private List strangerEdges; + private List studyGEdges; @Before public void setUp() { - graph = new UndirectedSparseGraph(); - friendEdges = new ArrayList(); - fsEdges = new ArrayList(); - classmateEdges = new ArrayList(); - strangerEdges = new ArrayList(); - studyGEdges = new ArrayList(); + graph = new UndirectedSparseGraph(); + friendEdges = new ArrayList(); + fsEdges = new ArrayList(); + classmateEdges = new ArrayList(); + strangerEdges = new ArrayList(); + studyGEdges = new ArrayList(); } - private edge addEdge(String v1, String v2, String type) { + private Edge addEdge(String v1, String v2, String type) { if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); - edge e = new edge(type, v1, v2); + Edge e = new Edge(type, v1, v2); e.setWeight(1.0f); graph.addEdge(e, v1, v2); return e; @@ -80,7 +80,7 @@ public void testContainsSvgCharts() { assertTrue("Should contain SVG elements", html.contains("Covers: classification pipeline, role assignment rules, adaptive thresholds, - * report generation, edge cases (empty graph, single node, disconnected nodes, + * report generation, Edge cases (empty graph, single node, disconnected nodes, * complete graph), and all structural role archetypes.

      * * @author zalenix @@ -21,13 +21,13 @@ public class NetworkRoleClassifierTest { // ── Helper methods ────────────────────────────────────────── - private static Graph emptyGraph() { + private static Graph emptyGraph() { return new UndirectedSparseGraph<>(); } - private static void addEdge(Graph g, String v1, String v2) { + private static void addEdge(Graph g, String v1, String v2) { String id = v1 + "-" + v2; - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setLabel(id); g.addEdge(e, v1, v2); } @@ -35,8 +35,8 @@ private static void addEdge(Graph g, String v1, String v2) { /** * Builds a star graph: center connected to all spokes, no spoke-spoke edges. */ - private static Graph starGraph(int spokes) { - Graph g = emptyGraph(); + private static Graph starGraph(int spokes) { + Graph g = emptyGraph(); g.addVertex("center"); for (int i = 1; i <= spokes; i++) { String spoke = "s" + i; @@ -48,8 +48,8 @@ private static Graph starGraph(int spokes) { /** * Builds a bridge topology: two cliques connected by a single bridge node. */ - private static Graph bridgeGraph() { - Graph g = emptyGraph(); + private static Graph bridgeGraph() { + Graph g = emptyGraph(); String[] cliqueA = {"A1", "A2", "A3", "A4"}; for (int i = 0; i < cliqueA.length; i++) { for (int j = i + 1; j < cliqueA.length; j++) { @@ -71,8 +71,8 @@ private static Graph bridgeGraph() { /** * Builds a complete graph of n nodes (K_n). */ - private static Graph completeGraph(int n) { - Graph g = emptyGraph(); + private static Graph completeGraph(int n) { + Graph g = emptyGraph(); for (int i = 1; i <= n; i++) g.addVertex("N" + i); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { @@ -113,7 +113,7 @@ public void distribution_emptyGraph_allZeros() { @Test public void classify_singleIsolatedNode() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("alone"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); @@ -127,7 +127,7 @@ public void classify_singleIsolatedNode() { @Test public void classify_disconnectedNodes_allIsolates() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("X"); g.addVertex("Y"); g.addVertex("Z"); @@ -143,7 +143,7 @@ public void classify_disconnectedNodes_allIsolates() { @Test public void classify_starGraph_centerIsNotPeripheral() { - Graph g = starGraph(8); + Graph g = starGraph(8); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); NetworkRoleClassifier.NodeRole centerRole = c.getRole("center"); @@ -155,7 +155,7 @@ public void classify_starGraph_centerIsNotPeripheral() { @Test public void classify_starGraph_spokesArePeripheral() { - Graph g = starGraph(8); + Graph g = starGraph(8); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); for (int i = 1; i <= 8; i++) { @@ -169,7 +169,7 @@ public void classify_starGraph_spokesArePeripheral() { @Test public void classify_bridgeGraph_XHighBetweenness() { - Graph g = bridgeGraph(); + Graph g = bridgeGraph(); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); NetworkRoleClassifier.NodeRole xRole = c.getRole("X"); @@ -181,7 +181,7 @@ public void classify_bridgeGraph_XHighBetweenness() { @Test public void classify_bridgeGraph_cliqueNodesNotIsolate() { - Graph g = bridgeGraph(); + Graph g = bridgeGraph(); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); for (String v : new String[]{"A1", "A2", "B1", "B2"}) { @@ -194,7 +194,7 @@ public void classify_bridgeGraph_cliqueNodesNotIsolate() { @Test public void classify_completeGraph_allSameRole() { - Graph g = completeGraph(6); + Graph g = completeGraph(6); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); Set seenRoles = new HashSet<>(); @@ -211,7 +211,7 @@ public void classify_completeGraph_allSameRole() { @Test public void getNodesByRole_returnsCorrectNodes() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("X"); g.addVertex("Y"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); @@ -224,7 +224,7 @@ public void getNodesByRole_returnsCorrectNodes() { @Test public void getNodesByRole_isSorted() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("Z"); g.addVertex("A"); g.addVertex("M"); @@ -236,7 +236,7 @@ public void getNodesByRole_isSorted() { @Test public void getNodesByRole_emptyForUnusedRole() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("A"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); @@ -247,7 +247,7 @@ public void getNodesByRole_emptyForUnusedRole() { @Test public void distribution_countsMatchTotal() { - Graph g = starGraph(6); + Graph g = starGraph(6); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); NetworkRoleClassifier.RoleDistribution dist = c.getRoleDistribution(); @@ -261,7 +261,7 @@ public void distribution_countsMatchTotal() { @Test public void distribution_percentagesSumTo100() { - Graph g = bridgeGraph(); + Graph g = bridgeGraph(); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); NetworkRoleClassifier.RoleDistribution dist = c.getRoleDistribution(); @@ -276,7 +276,7 @@ public void distribution_percentagesSumTo100() { @Test(expected = IllegalArgumentException.class) public void topByImportance_zeroThrows() { - Graph g = starGraph(3); + Graph g = starGraph(3); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); c.topByImportance(0); @@ -284,7 +284,7 @@ public void topByImportance_zeroThrows() { @Test public void topByImportance_starGraph_centerFirst() { - Graph g = starGraph(6); + Graph g = starGraph(6); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); List top = c.topByImportance(3); @@ -294,7 +294,7 @@ public void topByImportance_starGraph_centerFirst() { @Test public void topByImportance_limitsToN() { - Graph g = starGraph(10); + Graph g = starGraph(10); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); assertEquals(2, c.topByImportance(2).size()); @@ -302,7 +302,7 @@ public void topByImportance_limitsToN() { @Test public void topByImportance_requestMoreThanExists() { - Graph g = starGraph(3); + Graph g = starGraph(3); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); List top = c.topByImportance(100); @@ -313,7 +313,7 @@ public void topByImportance_requestMoreThanExists() { @Test public void generateReport_containsHeader() { - Graph g = starGraph(3); + Graph g = starGraph(3); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); String report = c.generateReport(); @@ -324,7 +324,7 @@ public void generateReport_containsHeader() { @Test public void generateReport_listsAllNodes() { - Graph g = starGraph(4); + Graph g = starGraph(4); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); String report = c.generateReport(); @@ -347,7 +347,7 @@ public void generateReport_emptyGraph_noErrors() { @Test(expected = IllegalStateException.class) public void getRole_beforeClassify_throws() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("A"); new NetworkRoleClassifier(g).getRole("A"); } @@ -382,7 +382,7 @@ public void generateReport_beforeClassify_throws() { @Test public void reclassify_resetsRoles() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("A"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); @@ -397,7 +397,7 @@ public void reclassify_resetsRoles() { @Test public void nodeRole_toString_includesAllFields() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("solo"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); @@ -454,7 +454,7 @@ public void percentile_100th_returnsMax() { @Test public void metrics_pairGraph_symmetric() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); addEdge(g, "A", "B"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); @@ -470,7 +470,7 @@ public void metrics_pairGraph_symmetric() { @Test public void metrics_triangleGraph_fullClustering() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "A", "C"); @@ -484,7 +484,7 @@ public void metrics_triangleGraph_fullClustering() { @Test public void metrics_pathGraph_zeroClustering() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); @@ -497,7 +497,7 @@ public void metrics_pathGraph_zeroClustering() { @Test public void classify_mixedTopology_multipleRoles() { - Graph g = bridgeGraph(); + Graph g = bridgeGraph(); addEdge(g, "A1", "leaf1"); addEdge(g, "B1", "leaf2"); @@ -515,7 +515,7 @@ public void classify_mixedTopology_multipleRoles() { @Test public void getRole_nonexistentNode_returnsNull() { - Graph g = emptyGraph(); + Graph g = emptyGraph(); g.addVertex("A"); NetworkRoleClassifier c = new NetworkRoleClassifier(g); c.classify(); diff --git a/Gvisual/test/gvisual/NodeCentralityAnalyzerTest.java b/Gvisual/test/gvisual/NodeCentralityAnalyzerTest.java index 8166a1f..6e4a98e 100644 --- a/Gvisual/test/gvisual/NodeCentralityAnalyzerTest.java +++ b/Gvisual/test/gvisual/NodeCentralityAnalyzerTest.java @@ -15,17 +15,17 @@ */ public class NodeCentralityAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helper methods --- - private edge addEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge addEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); diff --git a/Gvisual/test/gvisual/NodeSimilarityAnalyzerTest.java b/Gvisual/test/gvisual/NodeSimilarityAnalyzerTest.java index bce3cd6..83cb8e2 100644 --- a/Gvisual/test/gvisual/NodeSimilarityAnalyzerTest.java +++ b/Gvisual/test/gvisual/NodeSimilarityAnalyzerTest.java @@ -13,17 +13,17 @@ */ public class NodeSimilarityAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } private void addEdge(String v1, String v2, String type) { graph.addVertex(v1); graph.addVertex(v2); - edge e = new edge(type, v1, v2); + Edge e = new Edge(type, v1, v2); graph.addEdge(e, v1, v2); } diff --git a/Gvisual/test/gvisual/PageRankAnalyzerTest.java b/Gvisual/test/gvisual/PageRankAnalyzerTest.java index a709fe1..463d1fd 100644 --- a/Gvisual/test/gvisual/PageRankAnalyzerTest.java +++ b/Gvisual/test/gvisual/PageRankAnalyzerTest.java @@ -15,17 +15,17 @@ */ public class PageRankAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helper methods --- - private edge addEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge addEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -33,7 +33,7 @@ private edge addEdge(String type, String v1, String v2, float weight) { return e; } - private edge addEdge(String v1, String v2) { + private Edge addEdge(String v1, String v2) { return addEdge("f", v1, v2, 1.0f); } diff --git a/Gvisual/test/gvisual/PlanarGraphAnalyzerTest.java b/Gvisual/test/gvisual/PlanarGraphAnalyzerTest.java index cd9db0d..ff87274 100644 --- a/Gvisual/test/gvisual/PlanarGraphAnalyzerTest.java +++ b/Gvisual/test/gvisual/PlanarGraphAnalyzerTest.java @@ -17,13 +17,13 @@ public class PlanarGraphAnalyzerTest { private int edgeId = 0; - private Graph newGraph() { + private Graph newGraph() { edgeId = 0; - return new UndirectedSparseGraph(); + return new UndirectedSparseGraph(); } - private void addEdge(Graph g, String v1, String v2) { - edge e = new edge("f", v1, v2); + private void addEdge(Graph g, String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setLabel("e" + (edgeId++)); g.addEdge(e, v1, v2); } @@ -32,7 +32,7 @@ private void addEdge(Graph g, String v1, String v2) { @Test public void testEmptyGraphIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); PlanarGraphAnalyzer.PlanarityResult r = PlanarGraphAnalyzer.testPlanarity(g); assertTrue(r.isPlanar()); assertEquals(0, r.getVertices()); @@ -41,7 +41,7 @@ public void testEmptyGraphIsPlanar() { @Test public void testSingleVertexIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); g.addVertex("A"); PlanarGraphAnalyzer.PlanarityResult r = PlanarGraphAnalyzer.testPlanarity(g); assertTrue(r.isPlanar()); @@ -50,7 +50,7 @@ public void testSingleVertexIsPlanar() { @Test public void testSingleEdgeIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); PlanarGraphAnalyzer.PlanarityResult r = PlanarGraphAnalyzer.testPlanarity(g); assertTrue(r.isPlanar()); @@ -60,7 +60,7 @@ public void testSingleEdgeIsPlanar() { @Test public void testTriangleIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -70,7 +70,7 @@ public void testTriangleIsPlanar() { @Test public void testK4IsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -83,7 +83,7 @@ public void testK4IsPlanar() { @Test public void testK5IsNotPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -96,7 +96,7 @@ public void testK5IsNotPlanar() { @Test public void testK33IsNotPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); String[] left = {"L1", "L2", "L3"}; String[] right = {"R1", "R2", "R3"}; for (String l : left) @@ -108,7 +108,7 @@ public void testK33IsNotPlanar() { @Test public void testPathGraphIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); for (int i = 0; i < 10; i++) addEdge(g, "V" + i, "V" + (i + 1)); assertTrue(PlanarGraphAnalyzer.testPlanarity(g).isPlanar()); @@ -116,7 +116,7 @@ public void testPathGraphIsPlanar() { @Test public void testCycleGraphIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); int n = 8; for (int i = 0; i < n; i++) addEdge(g, "V" + i, "V" + ((i + 1) % n)); @@ -126,7 +126,7 @@ public void testCycleGraphIsPlanar() { @Test public void testWheelGraphIsPlanar() { // Wheel W5: center + 5-cycle, always planar - Graph g = newGraph(); + Graph g = newGraph(); g.addVertex("C"); for (int i = 0; i < 5; i++) { addEdge(g, "V" + i, "V" + ((i + 1) % 5)); @@ -137,7 +137,7 @@ public void testWheelGraphIsPlanar() { @Test public void testDisconnectedPlanarGraph() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "D", "E"); @@ -149,7 +149,7 @@ public void testDisconnectedPlanarGraph() { @Test public void testPetersenGraphIsNotPlanar() { // Petersen graph: 10 vertices, 15 edges, non-planar - Graph g = newGraph(); + Graph g = newGraph(); // Outer cycle for (int i = 0; i < 5; i++) addEdge(g, "O" + i, "O" + ((i + 1) % 5)); @@ -164,7 +164,7 @@ public void testPetersenGraphIsNotPlanar() { @Test public void testComponentCount() { - Graph g = newGraph(); + Graph g = newGraph(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); @@ -181,7 +181,7 @@ public void testNullGraphThrows() { @Test public void testExpectedFacesEulerFormula() { // Triangle: V=3, E=3, C=1 → F = 3-3+1+1 = 2 - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -193,7 +193,7 @@ public void testExpectedFacesEulerFormula() { @Test public void testTriangleFaces() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -204,7 +204,7 @@ public void testTriangleFaces() { @Test public void testK4Faces() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -217,7 +217,7 @@ public void testK4Faces() { @Test public void testFacesOfNonPlanarReturnsNull() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -227,7 +227,7 @@ public void testFacesOfNonPlanarReturnsNull() { @Test public void testFaceHasOuterMarker() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -241,7 +241,7 @@ public void testFaceHasOuterMarker() { @Test public void testFaceIds() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -253,7 +253,7 @@ public void testFaceIds() { @Test public void testSquareFaces() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -265,7 +265,7 @@ public void testSquareFaces() { @Test public void testSingleEdgeFaces() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); List faces = PlanarGraphAnalyzer.enumerateFaces(g); assertNotNull(faces); @@ -277,7 +277,7 @@ public void testSingleEdgeFaces() { @Test public void testTriangleDualGraph() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -288,7 +288,7 @@ public void testTriangleDualGraph() { @Test public void testK4DualGraph() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -300,7 +300,7 @@ public void testK4DualGraph() { @Test public void testNonPlanarDualReturnsNull() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -310,7 +310,7 @@ public void testNonPlanarDualReturnsNull() { @Test public void testDualGraphSymmetry() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -326,7 +326,7 @@ public void testDualGraphSymmetry() { @Test public void testDualEdgeCount() { // Triangle dual: 2 nodes, should have edges between them - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -338,7 +338,7 @@ public void testDualEdgeCount() { @Test public void testK5KuratowskiSubgraph() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -352,7 +352,7 @@ public void testK5KuratowskiSubgraph() { @Test public void testK33KuratowskiSubgraph() { - Graph g = newGraph(); + Graph g = newGraph(); String[] left = {"L1", "L2", "L3"}; String[] right = {"R1", "R2", "R3"}; for (String l : left) @@ -368,7 +368,7 @@ public void testK33KuratowskiSubgraph() { @Test public void testPlanarGraphHasNoKuratowski() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -377,7 +377,7 @@ public void testPlanarGraphHasNoKuratowski() { @Test public void testKuratowskiHasPaths() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -392,7 +392,7 @@ public void testKuratowskiHasPaths() { @Test public void testPlanarReport() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -406,7 +406,7 @@ public void testPlanarReport() { @Test public void testNonPlanarReport() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -421,7 +421,7 @@ public void testNonPlanarReport() { @Test public void testReportToText() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -433,7 +433,7 @@ public void testReportToText() { @Test public void testNonPlanarReportToText() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -445,7 +445,7 @@ public void testNonPlanarReportToText() { @Test public void testGenusOfK5() { - Graph g = newGraph(); + Graph g = newGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < v.length; i++) for (int j = i + 1; j < v.length; j++) @@ -457,7 +457,7 @@ public void testGenusOfK5() { @Test public void testTreeIsPlanar() { // Binary tree - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "1", "2"); addEdge(g, "1", "3"); addEdge(g, "2", "4"); @@ -469,7 +469,7 @@ public void testTreeIsPlanar() { @Test public void testStarGraphIsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); for (int i = 0; i < 10; i++) addEdge(g, "C", "V" + i); assertTrue(PlanarGraphAnalyzer.testPlanarity(g).isPlanar()); @@ -477,7 +477,7 @@ public void testStarGraphIsPlanar() { @Test public void testTreeFaces() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "B", "D"); @@ -490,7 +490,7 @@ public void testTreeFaces() { @Test public void testIsolatedVerticesPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); for (int i = 0; i < 5; i++) g.addVertex("V" + i); PlanarGraphAnalyzer.PlanarityResult r = PlanarGraphAnalyzer.testPlanarity(g); assertTrue(r.isPlanar()); @@ -499,7 +499,7 @@ public void testIsolatedVerticesPlanar() { @Test public void testSquareWithDiagonalPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -511,7 +511,7 @@ public void testSquareWithDiagonalPlanar() { @Test public void testSquareWithBothDiagonalsPlanar() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -525,7 +525,7 @@ public void testSquareWithBothDiagonalsPlanar() { @Test public void testCubeGraphIsPlanar() { // Q3 (3-cube / hypercube) has 8 vertices, 12 edges — planar - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "000", "001"); addEdge(g, "000", "010"); addEdge(g, "000", "100"); addEdge(g, "001", "011"); addEdge(g, "001", "101"); addEdge(g, "010", "011"); addEdge(g, "010", "110"); @@ -538,7 +538,7 @@ public void testCubeGraphIsPlanar() { @Test public void testFaceVerticesNotNull() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -551,7 +551,7 @@ public void testFaceVerticesNotNull() { @Test public void testDualFacesMatchEnumeratedFaces() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "A"); @@ -562,7 +562,7 @@ public void testDualFacesMatchEnumeratedFaces() { @Test public void testPlanarReportHasCorrectVertexCount() { - Graph g = newGraph(); + Graph g = newGraph(); addEdge(g, "A", "B"); addEdge(g, "B", "C"); addEdge(g, "C", "D"); @@ -575,7 +575,7 @@ public void testPlanarReportHasCorrectVertexCount() { @Test public void testOctahedronIsPlanar() { // Octahedron: 6 vertices, 12 edges, planar - Graph g = newGraph(); + Graph g = newGraph(); // Top and bottom + mid ring String[] mid = {"A", "B", "C", "D"}; for (int i = 0; i < 4; i++) { diff --git a/Gvisual/test/gvisual/RandomWalkAnalyzerTest.java b/Gvisual/test/gvisual/RandomWalkAnalyzerTest.java index 9d4d700..3e7e1eb 100644 --- a/Gvisual/test/gvisual/RandomWalkAnalyzerTest.java +++ b/Gvisual/test/gvisual/RandomWalkAnalyzerTest.java @@ -14,15 +14,15 @@ */ public class RandomWalkAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { graph = new UndirectedSparseGraph<>(); } - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); graph.addEdge(e, v1, v2); diff --git a/Gvisual/test/gvisual/RichClubAnalyzerTest.java b/Gvisual/test/gvisual/RichClubAnalyzerTest.java index c254124..eba72ca 100644 --- a/Gvisual/test/gvisual/RichClubAnalyzerTest.java +++ b/Gvisual/test/gvisual/RichClubAnalyzerTest.java @@ -16,10 +16,10 @@ */ public class RichClubAnalyzerTest { - private Graph starGraph; - private Graph completeGraph; - private Graph bipartiteGraph; - private Graph hubAndSpoke; + private Graph starGraph; + private Graph completeGraph; + private Graph bipartiteGraph; + private Graph hubAndSpoke; @Before public void setUp() { @@ -29,7 +29,7 @@ public void setUp() { for (int i = 1; i <= 5; i++) { String leaf = "L" + i; starGraph.addVertex(leaf); - edge e = new edge("c", "center", leaf); + Edge e = new Edge("c", "center", leaf); starGraph.addEdge(e, "center", leaf); } @@ -40,7 +40,7 @@ public void setUp() { int eid = 0; for (int i = 0; i < nodes.length; i++) { for (int j = i + 1; j < nodes.length; j++) { - edge e = new edge("c", nodes[i], nodes[j]); + Edge e = new Edge("c", nodes[i], nodes[j]); completeGraph.addEdge(e, nodes[i], nodes[j]); } } @@ -54,24 +54,24 @@ public void setUp() { String b = "B" + i; bipartiteGraph.addVertex(a); bipartiteGraph.addVertex(b); - bipartiteGraph.addEdge(new edge("c", "H1", a), "H1", a); - bipartiteGraph.addEdge(new edge("c", "H2", b), "H2", b); + bipartiteGraph.addEdge(new Edge("c", "H1", a), "H1", a); + bipartiteGraph.addEdge(new Edge("c", "H2", b), "H2", b); } - bipartiteGraph.addEdge(new edge("c", "H1", "H2"), "H1", "H2"); + bipartiteGraph.addEdge(new Edge("c", "H1", "H2"), "H1", "H2"); // Hub-and-spoke with interconnected hubs hubAndSpoke = new UndirectedSparseGraph<>(); for (int h = 1; h <= 3; h++) hubAndSpoke.addVertex("Hub" + h); // Connect hubs to each other - hubAndSpoke.addEdge(new edge("c", "Hub1", "Hub2"), "Hub1", "Hub2"); - hubAndSpoke.addEdge(new edge("c", "Hub2", "Hub3"), "Hub2", "Hub3"); - hubAndSpoke.addEdge(new edge("c", "Hub1", "Hub3"), "Hub1", "Hub3"); + hubAndSpoke.addEdge(new Edge("c", "Hub1", "Hub2"), "Hub1", "Hub2"); + hubAndSpoke.addEdge(new Edge("c", "Hub2", "Hub3"), "Hub2", "Hub3"); + hubAndSpoke.addEdge(new Edge("c", "Hub1", "Hub3"), "Hub1", "Hub3"); // Add spokes for (int h = 1; h <= 3; h++) { for (int s = 1; s <= 4; s++) { String spoke = "S" + h + "_" + s; hubAndSpoke.addVertex(spoke); - hubAndSpoke.addEdge(new edge("c", "Hub" + h, spoke), "Hub" + h, spoke); + hubAndSpoke.addEdge(new Edge("c", "Hub" + h, spoke), "Hub" + h, spoke); } } } @@ -198,7 +198,7 @@ public void testAssortativityComplete() { @Test public void testAssortativityStar() { RichClubAnalyzer rca = new RichClubAnalyzer(starGraph); - // Star: all edges connect degree-5 center to degree-1 leaves + // Star: all Edges connect degree-5 center to degree-1 leaves // Zero variance on one side, so correlation is 0 (degenerate case) double a = rca.degreeAssortativity(); // Just verify it returns a finite value @@ -311,10 +311,10 @@ public void testJsonExport() { @Test public void testSingleEdgeGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("X"); g.addVertex("Y"); - g.addEdge(new edge("c", "X", "Y"), "X", "Y"); + g.addEdge(new Edge("c", "X", "Y"), "X", "Y"); RichClubAnalyzer rca = new RichClubAnalyzer(g); double phi = rca.richClubCoefficient(0); assertEquals(1.0, phi, 0.001); // 2 nodes, 1 edge, φ = 2*1/(2*1) = 1 @@ -322,11 +322,11 @@ public void testSingleEdgeGraph() { @Test public void testDisconnectedNodes() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - g.addEdge(new edge("c", "A", "B"), "A", "B"); + g.addEdge(new Edge("c", "A", "B"), "A", "B"); // C is isolated (degree 0) RichClubAnalyzer rca = new RichClubAnalyzer(g); List members = rca.getRichClubMembers(0); @@ -362,21 +362,21 @@ public void testDeterministicWithSameSeed() { @Test public void testLargerGraphPerformance() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); // Build a scale-free-ish graph: 50 nodes, preferential attachment for (int i = 0; i < 50; i++) g.addVertex("N" + i); Random r = new Random(99); // Connect in a ring first for (int i = 0; i < 50; i++) { String a = "N" + i, b = "N" + ((i + 1) % 50); - g.addEdge(new edge("c", a, b), a, b); + g.addEdge(new Edge("c", a, b), a, b); } // Add some hub edges for (int i = 0; i < 30; i++) { String hub = "N" + (i % 3); // nodes 0-2 become hubs String target = "N" + (3 + r.nextInt(47)); if (!g.isNeighbor(hub, target)) { - g.addEdge(new edge("c", hub, target), hub, target); + g.addEdge(new Edge("c", hub, target), hub, target); } } diff --git a/Gvisual/test/gvisual/ShortestPathFinderTest.java b/Gvisual/test/gvisual/ShortestPathFinderTest.java index f4e5432..0f2515d 100644 --- a/Gvisual/test/gvisual/ShortestPathFinderTest.java +++ b/Gvisual/test/gvisual/ShortestPathFinderTest.java @@ -16,15 +16,15 @@ */ public class ShortestPathFinderTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } - private edge makeEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); return e; } @@ -60,7 +60,7 @@ public void testSameSourceAndTarget() { public void testDirectConnection() { graph.addVertex("A"); graph.addVertex("B"); - edge e = makeEdge("f", "A", "B", 5.0f); + Edge e = makeEdge("f", "A", "B", 5.0f); graph.addEdge(e, "A", "B"); ShortestPathFinder finder = new ShortestPathFinder(graph); @@ -286,7 +286,7 @@ public void testAreConnectedSelf() { public void testPathResultToString() { graph.addVertex("A"); graph.addVertex("B"); - edge e = makeEdge("f", "A", "B", 5.0f); + Edge e = makeEdge("f", "A", "B", 5.0f); graph.addEdge(e, "A", "B"); ShortestPathFinder finder = new ShortestPathFinder(graph); diff --git a/Gvisual/test/gvisual/SignedGraphAnalyzerTest.java b/Gvisual/test/gvisual/SignedGraphAnalyzerTest.java index 5ac7a39..e9f5f59 100644 --- a/Gvisual/test/gvisual/SignedGraphAnalyzerTest.java +++ b/Gvisual/test/gvisual/SignedGraphAnalyzerTest.java @@ -14,33 +14,33 @@ */ public class SignedGraphAnalyzerTest { - private Graph emptyGraph; - private Graph singleVertex; - private Graph allPositive; // triangle with all + edges - private Graph balanced; // balanced: A-B+, B-C+, A-C- (two groups) - private Graph unbalanced; // triangle with 2+ and 1- (ppn) - private Graph allNegative; // triangle with all - edges - private Graph path3; // A--B--C with mixed signs - private Graph square; // 4-cycle - private Graph largeBalanced; // larger balanced graph + private Graph emptyGraph; + private Graph singleVertex; + private Graph allPositive; // triangle with all + edges + private Graph balanced; // balanced: A-B+, B-C+, A-C- (two groups) + private Graph unbalanced; // triangle with 2+ and 1- (ppn) + private Graph allNegative; // triangle with all - edges + private Graph path3; // A--B--C with mixed signs + private Graph square; // 4-cycle + private Graph largeBalanced; // larger balanced graph private int edgeCounter = 0; - private edge makeEdge(String v1, String v2, float weight) { - edge e = new edge("e", v1, v2); + private Edge makeEdge(String v1, String v2, float weight) { + Edge e = new Edge("e", v1, v2); e.setWeight(weight); e.setLabel(weight < 0 ? "-" : "+"); return e; } - private edge makeLabelEdge(String v1, String v2, String label) { - edge e = new edge("e", v1, v2); + private Edge makeLabelEdge(String v1, String v2, String label) { + Edge e = new Edge("e", v1, v2); e.setLabel(label); return e; } @Before public void setUp() { - edgeCounter = 0; + EdgeCounter = 0; // Empty graph emptyGraph = new UndirectedSparseGraph<>(); @@ -115,7 +115,7 @@ public void testNullGraph() { @Test public void testIsNegativeByWeight() { - edge e = makeEdge("A","B",-1); + Edge e = makeEdge("A","B",-1); SignedGraphAnalyzer a = new SignedGraphAnalyzer(emptyGraph); assertTrue(a.isNegative(e)); assertFalse(a.isPositive(e)); @@ -123,7 +123,7 @@ public void testIsNegativeByWeight() { @Test public void testIsPositiveByWeight() { - edge e = makeEdge("A","B",1); + Edge e = makeEdge("A","B",1); SignedGraphAnalyzer a = new SignedGraphAnalyzer(emptyGraph); assertFalse(a.isNegative(e)); assertTrue(a.isPositive(e)); @@ -131,21 +131,21 @@ public void testIsPositiveByWeight() { @Test public void testIsNegativeByLabel() { - edge e = makeLabelEdge("A","B","-"); + Edge e = makeLabelEdge("A","B","-"); SignedGraphAnalyzer a = new SignedGraphAnalyzer(emptyGraph); assertTrue(a.isNegative(e)); } @Test public void testIsNegativeByLabelWord() { - edge e = makeLabelEdge("A","B","negative"); + Edge e = makeLabelEdge("A","B","negative"); SignedGraphAnalyzer a = new SignedGraphAnalyzer(emptyGraph); assertTrue(a.isNegative(e)); } @Test public void testZeroWeightIsPositive() { - edge e = makeEdge("A","B",0); + Edge e = makeEdge("A","B",0); e.setLabel(null); SignedGraphAnalyzer a = new SignedGraphAnalyzer(emptyGraph); assertTrue(a.isPositive(e)); @@ -442,7 +442,7 @@ public void testFrustratedEdgesBalanced() { @Test public void testFrustratedEdgesUnbalanced() { - List frustrated = new SignedGraphAnalyzer(unbalanced).findFrustratedEdges(); + List frustrated = new SignedGraphAnalyzer(unbalanced).findFrustratedEdges(); assertFalse(frustrated.isEmpty()); } @@ -460,7 +460,7 @@ public void testPredictSignNoMutual() { public void testPredictSignPositive() { // All-positive triangle: A-C exists, but predict via B // Need a graph where A-C doesn't exist but they share neighbors - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addEdge(makeEdge("A","B",1), "A", "B"); g.addEdge(makeEdge("B","C",1), "B", "C"); @@ -479,7 +479,7 @@ public void testPredictSignInvalidVertex() { @Test public void testPredictSignNoEvidence() { // Two disconnected vertices - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); assertEquals(0, new SignedGraphAnalyzer(g).predictSign("A", "B")); } @@ -554,7 +554,7 @@ public void testTriangleCensusToString() { @Test public void testSingleEdgePositive() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addEdge(makeEdge("A","B",1), "A", "B"); SignedGraphAnalyzer a = new SignedGraphAnalyzer(g); @@ -565,7 +565,7 @@ public void testSingleEdgePositive() { @Test public void testSingleEdgeNegative() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addEdge(makeEdge("A","B",-1), "A", "B"); SignedGraphAnalyzer a = new SignedGraphAnalyzer(g); @@ -576,7 +576,7 @@ public void testSingleEdgeNegative() { @Test public void testDisconnectedComponents() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); g.addEdge(makeEdge("A","B",1), "A", "B"); g.addEdge(makeEdge("C","D",-1), "C", "D"); diff --git a/Gvisual/test/gvisual/SmallWorldAnalyzerTest.java b/Gvisual/test/gvisual/SmallWorldAnalyzerTest.java index b61946e..4f8a513 100644 --- a/Gvisual/test/gvisual/SmallWorldAnalyzerTest.java +++ b/Gvisual/test/gvisual/SmallWorldAnalyzerTest.java @@ -15,7 +15,7 @@ */ public class SmallWorldAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -23,7 +23,7 @@ public void setUp() { } private void addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); graph.addEdge(e, v1, v2); } @@ -280,7 +280,7 @@ public void testDisconnected_classification() { @Test public void testSparse_classification() { - // Tree: n=5, edges=4, mean degree < 2 + // Tree: n=5, Edges=4, mean degree < 2 addEdge("A", "B"); addEdge("A", "C"); addEdge("A", "D"); diff --git a/Gvisual/test/gvisual/SpectralAnalyzerTest.java b/Gvisual/test/gvisual/SpectralAnalyzerTest.java index 9dad706..cf55a1e 100644 --- a/Gvisual/test/gvisual/SpectralAnalyzerTest.java +++ b/Gvisual/test/gvisual/SpectralAnalyzerTest.java @@ -15,17 +15,17 @@ */ public class SpectralAnalyzerTest { - private Graph graph; + private Graph graph; @Before public void setUp() { - graph = new UndirectedSparseGraph(); + graph = new UndirectedSparseGraph(); } // --- Helpers --- - private edge addEdge(String v1, String v2) { - edge e = new edge("f", v1, v2); + private Edge addEdge(String v1, String v2) { + Edge e = new Edge("f", v1, v2); e.setWeight(1.0f); if (!graph.containsVertex(v1)) graph.addVertex(v1); if (!graph.containsVertex(v2)) graph.addVertex(v2); @@ -33,13 +33,13 @@ private edge addEdge(String v1, String v2) { return e; } - private Graph completeGraph(int n) { - Graph g = new UndirectedSparseGraph(); + private Graph completeGraph(int n) { + Graph g = new UndirectedSparseGraph(); for (int i = 1; i <= n; i++) g.addVertex("N" + i); int edgeId = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { - edge e = new edge("f", "N" + i, "N" + j); + Edge e = new Edge("f", "N" + i, "N" + j); e.setWeight(1.0f); g.addEdge(e, "N" + i, "N" + j); edgeId++; @@ -48,20 +48,20 @@ private Graph completeGraph(int n) { return g; } - private Graph pathGraph(int n) { - Graph g = new UndirectedSparseGraph(); + private Graph pathGraph(int n) { + Graph g = new UndirectedSparseGraph(); for (int i = 1; i <= n; i++) g.addVertex("N" + i); for (int i = 1; i < n; i++) { - edge e = new edge("f", "N" + i, "N" + (i + 1)); + Edge e = new Edge("f", "N" + i, "N" + (i + 1)); e.setWeight(1.0f); g.addEdge(e, "N" + i, "N" + (i + 1)); } return g; } - private Graph cycleGraph(int n) { - Graph g = pathGraph(n); - edge e = new edge("f", "N" + n, "N1"); + private Graph cycleGraph(int n) { + Graph g = pathGraph(n); + Edge e = new Edge("f", "N" + n, "N1"); e.setWeight(1.0f); g.addEdge(e, "N" + n, "N1"); return g; diff --git a/Gvisual/test/gvisual/SteinerTreeAnalyzerTest.java b/Gvisual/test/gvisual/SteinerTreeAnalyzerTest.java index 9bedb05..6ab0d3a 100644 --- a/Gvisual/test/gvisual/SteinerTreeAnalyzerTest.java +++ b/Gvisual/test/gvisual/SteinerTreeAnalyzerTest.java @@ -16,29 +16,29 @@ public class SteinerTreeAnalyzerTest { private int edgeId = 0; - private edge addEdge(Graph g, String u, String v, float w) { - edge e = new edge("e", u, v); + private Edge addEdge(Graph g, String u, String v, float w) { + Edge e = new Edge("e", u, v); e.setWeight(w); e.setLabel("e" + (edgeId++)); g.addEdge(e, u, v); return e; } - private edge addEdge(Graph g, String u, String v) { + private Edge addEdge(Graph g, String u, String v) { return addEdge(g, u, v, 1.0f); } // ── Simple graphs ───────────────────────────────────────────── - private Graph makePath(String... vertices) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makePath(String... vertices) { + Graph g = new UndirectedSparseGraph<>(); for (String v : vertices) g.addVertex(v); for (int i = 0; i < vertices.length - 1; i++) addEdge(g, vertices[i], vertices[i + 1]); return g; } - private Graph makeStar(String center, String... leaves) { - Graph g = new UndirectedSparseGraph<>(); + private Graph makeStar(String center, String... leaves) { + Graph g = new UndirectedSparseGraph<>(); g.addVertex(center); for (String l : leaves) { g.addVertex(l); addEdge(g, center, l); } return g; @@ -55,7 +55,7 @@ public void testNullGraph() { @Test public void testValidateTerminals() { - Graph g = makePath("A", "B", "C"); + Graph g = makePath("A", "B", "C"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); Set valid = sa.validateTerminals(new HashSet<>(Arrays.asList("A", "C", "X"))); assertEquals(new HashSet<>(Arrays.asList("A", "C")), valid); @@ -63,7 +63,7 @@ public void testValidateTerminals() { @Test public void testValidateTerminalsAllInvalid() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); assertTrue(sa.validateTerminals(new HashSet<>(Arrays.asList("X", "Y"))).isEmpty()); } @@ -72,14 +72,14 @@ public void testValidateTerminalsAllInvalid() { @Test public void testTerminalsConnected() { - Graph g = makePath("A", "B", "C", "D"); + Graph g = makePath("A", "B", "C", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); assertTrue(sa.areTerminalsConnected(new HashSet<>(Arrays.asList("A", "D")))); } @Test public void testTerminalsDisconnected() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); addEdge(g, "A", "B"); addEdge(g, "C", "D"); @@ -89,7 +89,7 @@ public void testTerminalsDisconnected() { @Test public void testTerminalComponents() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); addEdge(g, "A", "B"); addEdge(g, "C", "D"); @@ -100,7 +100,7 @@ public void testTerminalComponents() { @Test public void testSingleTerminalAlwaysConnected() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); assertTrue(sa.areTerminalsConnected(Collections.singleton("A"))); } @@ -109,7 +109,7 @@ public void testSingleTerminalAlwaysConnected() { @Test public void testSPHeuristicSimplePath() { - Graph g = makePath("A", "B", "C"); + Graph g = makePath("A", "B", "C"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.shortestPathHeuristic( new HashSet<>(Arrays.asList("A", "C"))); @@ -120,7 +120,7 @@ public void testSPHeuristicSimplePath() { @Test public void testSPHeuristicStar() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.shortestPathHeuristic( new HashSet<>(Arrays.asList("A", "B", "D"))); @@ -130,7 +130,7 @@ public void testSPHeuristicStar() { @Test public void testSPHeuristicSingleTerminal() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.shortestPathHeuristic(Collections.singleton("A")); assertEquals(0, r.totalWeight, 0.001); @@ -139,19 +139,19 @@ public void testSPHeuristicSingleTerminal() { @Test(expected = IllegalArgumentException.class) public void testSPHeuristicNullTerminals() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); new SteinerTreeAnalyzer(g).shortestPathHeuristic(null); } @Test(expected = IllegalArgumentException.class) public void testSPHeuristicEmptyTerminals() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); new SteinerTreeAnalyzer(g).shortestPathHeuristic(Collections.emptySet()); } @Test public void testSPHeuristicWeightedGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D")) g.addVertex(v); addEdge(g, "A", "B", 1); addEdge(g, "B", "C", 1); @@ -167,7 +167,7 @@ public void testSPHeuristicWeightedGraph() { @Test public void testMSTHeuristicSimplePath() { - Graph g = makePath("A", "B", "C"); + Graph g = makePath("A", "B", "C"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.mstHeuristic( new HashSet<>(Arrays.asList("A", "C"))); @@ -176,7 +176,7 @@ public void testMSTHeuristicSimplePath() { @Test public void testMSTHeuristicStar() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.mstHeuristic( new HashSet<>(Arrays.asList("A", "B", "D"))); @@ -185,7 +185,7 @@ public void testMSTHeuristicStar() { @Test public void testMSTHeuristicSingleTerminal() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.mstHeuristic(Collections.singleton("A")); assertEquals(0, r.totalWeight, 0.001); @@ -195,7 +195,7 @@ public void testMSTHeuristicSingleTerminal() { @Test public void testExactSimplePath() { - Graph g = makePath("A", "B", "C"); + Graph g = makePath("A", "B", "C"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.exact( new HashSet<>(Arrays.asList("A", "C"))); @@ -206,7 +206,7 @@ public void testExactSimplePath() { @Test public void testExactStar() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.exact( new HashSet<>(Arrays.asList("A", "B", "D"))); @@ -216,7 +216,7 @@ public void testExactStar() { @Test public void testExactTwoTerminals() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C")) g.addVertex(v); addEdge(g, "A", "B", 5); addEdge(g, "A", "C", 2); @@ -229,7 +229,7 @@ public void testExactTwoTerminals() { @Test public void testExactSingleTerminal() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.exact(Collections.singleton("A")); assertEquals(0, r.totalWeight, 0.001); @@ -238,7 +238,7 @@ public void testExactSingleTerminal() { @Test(expected = IllegalArgumentException.class) public void testExactTooManyTerminals() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); Set terms = new HashSet<>(); for (int i = 0; i < 16; i++) { String v = "V" + i; @@ -251,7 +251,7 @@ public void testExactTooManyTerminals() { @Test public void testExactWeightedDiamond() { // Diamond: A-B(1), A-C(1), B-D(1), C-D(1), A-D(10) - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D")) g.addVertex(v); addEdge(g, "A", "B", 1); addEdge(g, "A", "C", 1); @@ -268,7 +268,7 @@ public void testExactWeightedDiamond() { @Test public void testBestHeuristic() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.bestHeuristic( new HashSet<>(Arrays.asList("A", "B", "D"))); @@ -279,7 +279,7 @@ public void testBestHeuristic() { @Test public void testSolveSmallUsesExact() { - Graph g = makePath("A", "B", "C"); + Graph g = makePath("A", "B", "C"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.solve( new HashSet<>(Arrays.asList("A", "C"))); @@ -290,7 +290,7 @@ public void testSolveSmallUsesExact() { @Test public void testBottleneckEdge() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C")) g.addVertex(v); addEdge(g, "A", "B", 1); addEdge(g, "B", "C", 5); @@ -304,7 +304,7 @@ public void testBottleneckEdge() { @Test public void testBottleneckEdgeEmpty() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.shortestPathHeuristic(Collections.singleton("A")); @@ -316,7 +316,7 @@ public void testBottleneckEdgeEmpty() { @Test public void testSteinerRatioNoSteinerPoints() { // When all terminals are adjacent, ratio should be ~1 - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C")) g.addVertex(v); addEdge(g, "A", "B", 1); addEdge(g, "B", "C", 1); @@ -331,7 +331,7 @@ public void testSteinerRatioNoSteinerPoints() { @Test public void testSteinerRatioWithSteinerPoints() { // Star topology: terminals at leaves, center is Steiner point - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D", "center")) g.addVertex(v); addEdge(g, "center", "A", 1); addEdge(g, "center", "B", 1); @@ -352,7 +352,7 @@ public void testSteinerRatioWithSteinerPoints() { @Test public void testSteinerPointImportance() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.shortestPathHeuristic( new HashSet<>(Arrays.asList("A", "B", "D"))); @@ -363,7 +363,7 @@ public void testSteinerPointImportance() { @Test public void testSteinerPointImportanceNoSteinerPoints() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); addEdge(g, "A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); @@ -376,7 +376,7 @@ public void testSteinerPointImportanceNoSteinerPoints() { @Test public void testTerminalMSTCost() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C")) g.addVertex(v); addEdge(g, "A", "B", 3); addEdge(g, "B", "C", 4); @@ -387,7 +387,7 @@ public void testTerminalMSTCost() { @Test public void testTerminalMSTCostSingle() { - Graph g = makePath("A", "B"); + Graph g = makePath("A", "B"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); assertEquals(0, sa.terminalMSTCost(Collections.singleton("A")), 0.001); } @@ -396,7 +396,7 @@ public void testTerminalMSTCostSingle() { @Test public void testAnalyze() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerReport report = sa.analyze( new HashSet<>(Arrays.asList("A", "B", "D"))); @@ -406,7 +406,7 @@ public void testAnalyze() { @Test public void testTextReport() { - Graph g = makeStar("C", "A", "B", "D"); + Graph g = makeStar("C", "A", "B", "D"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); String report = sa.textReport(new HashSet<>(Arrays.asList("A", "B", "D"))); assertTrue(report.contains("STEINER TREE ANALYSIS")); @@ -455,7 +455,7 @@ public void testResultAllVertices() { @Test public void testGridGraph() { // 3x3 grid with unit weights - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (int r = 0; r < 3; r++) for (int c = 0; c < 3; c++) g.addVertex(r + "," + c); @@ -475,7 +475,7 @@ public void testGridGraph() { @Test public void testWeightedGraphPrefersCheaperPaths() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D", "E")) g.addVertex(v); addEdge(g, "A", "B", 10); addEdge(g, "A", "D", 1); @@ -490,7 +490,7 @@ public void testWeightedGraphPrefersCheaperPaths() { @Test public void testTwoAdjacentTerminals() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); addEdge(g, "A", "B", 3); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); @@ -502,7 +502,7 @@ public void testTwoAdjacentTerminals() { @Test public void testAllVerticesAreTerminals() { - Graph g = makePath("A", "B", "C"); + Graph g = makePath("A", "B", "C"); SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); SteinerTreeAnalyzer.SteinerTreeResult r = sa.solve( new HashSet<>(Arrays.asList("A", "B", "C"))); @@ -512,7 +512,7 @@ public void testAllVerticesAreTerminals() { @Test public void testSavingsAnalysis() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "S")) g.addVertex(v); addEdge(g, "S", "A", 1); addEdge(g, "S", "B", 1); @@ -529,7 +529,7 @@ public void testSavingsAnalysis() { @Test public void testDisconnectedTerminals() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); // No edges SteinerTreeAnalyzer sa = new SteinerTreeAnalyzer(g); @@ -538,7 +538,7 @@ public void testDisconnectedTerminals() { @Test public void testCompleteGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D")) g.addVertex(v); addEdge(g, "A", "B", 1); addEdge(g, "A", "C", 1); @@ -554,7 +554,7 @@ public void testCompleteGraph() { @Test public void testHeuristicsVsExact() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D", "E")) g.addVertex(v); addEdge(g, "A", "D", 1); addEdge(g, "D", "B", 1); diff --git a/Gvisual/test/gvisual/StronglyConnectedComponentsAnalyzerTest.java b/Gvisual/test/gvisual/StronglyConnectedComponentsAnalyzerTest.java index 5637877..13eef4f 100644 --- a/Gvisual/test/gvisual/StronglyConnectedComponentsAnalyzerTest.java +++ b/Gvisual/test/gvisual/StronglyConnectedComponentsAnalyzerTest.java @@ -16,30 +16,30 @@ public class StronglyConnectedComponentsAnalyzerTest { // ── Helper methods ────────────────────────────────────────── - private Graph buildDirectedGraph(String[][] edges) { - Graph g = new DirectedSparseGraph(); + private Graph buildDirectedGraph(String[][] edges) { + Graph g = new DirectedSparseGraph(); int edgeId = 0; for (String[] e : edges) { String from = e[0]; String to = e[1]; if (!g.containsVertex(from)) g.addVertex(from); if (!g.containsVertex(to)) g.addVertex(to); - edge ed = new edge("link", from, to); + Edge ed = new Edge("link", from, to); ed.setLabel("e" + edgeId++); g.addEdge(ed, from, to); } return g; } - private Graph buildDirectedGraphWithIsolated(String[][] edges, String[] isolated) { - Graph g = buildDirectedGraph(edges); + private Graph buildDirectedGraphWithIsolated(String[][] edges, String[] isolated) { + Graph g = buildDirectedGraph(edges); for (String v : isolated) { if (!g.containsVertex(v)) g.addVertex(v); } return g; } - private void assertBothAlgorithmsAgree(Graph g, int expectedComponents) { + private void assertBothAlgorithmsAgree(Graph g, int expectedComponents) { StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); StronglyConnectedComponentsAnalyzer.SCCResult tarjan = analyzer.tarjan(); StronglyConnectedComponentsAnalyzer.SCCResult kosaraju = analyzer.kosaraju(); @@ -68,7 +68,7 @@ public void testNullGraph() { @Test public void testEmptyGraph() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); StronglyConnectedComponentsAnalyzer.SCCResult result = analyzer.tarjan(); assertEquals(0, result.getComponentCount()); @@ -79,7 +79,7 @@ public void testEmptyGraph() { @Test public void testSingleVertex() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); assertBothAlgorithmsAgree(g, 1); @@ -93,7 +93,7 @@ public void testSingleVertex() { @Test public void testTwoVerticesOneEdge() { - Graph g = buildDirectedGraph(new String[][]{{"A", "B"}}); + Graph g = buildDirectedGraph(new String[][]{{"A", "B"}}); assertBothAlgorithmsAgree(g, 2); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); @@ -107,7 +107,7 @@ public void testTwoVerticesOneEdge() { @Test public void testSimpleCycle() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"} }); assertBothAlgorithmsAgree(g, 1); @@ -124,7 +124,7 @@ public void testSimpleCycle() { @Test public void testTwoSCCs() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"}, // SCC1: {A,B} {"C", "D"}, {"D", "C"}, // SCC2: {C,D} {"B", "C"} // bridge @@ -143,7 +143,7 @@ public void testTwoSCCs() { @Test public void testDAG() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"B", "D"}, {"C", "D"} }); assertBothAlgorithmsAgree(g, 4); @@ -157,7 +157,7 @@ public void testDAG() { @Test public void testIsolatedVertices() { - Graph g = buildDirectedGraphWithIsolated( + Graph g = buildDirectedGraphWithIsolated( new String[][]{{"A", "B"}, {"B", "A"}}, new String[]{"X", "Y"} ); @@ -169,7 +169,7 @@ public void testIsolatedVertices() { @Test public void testComplexGraph() { // 3 SCCs: {A,B,C}, {D,E}, {F} - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"}, // SCC1 {"D", "E"}, {"E", "D"}, // SCC2 {"C", "D"}, {"E", "F"} // bridges @@ -188,7 +188,7 @@ public void testComplexGraph() { @Test public void testClassification() { // source -> intermediate -> sink - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"}, // source SCC {"C", "D"}, {"D", "C"}, // intermediate SCC {"E", "F"}, {"F", "E"}, // sink SCC @@ -214,7 +214,7 @@ public void testClassification() { @Test public void testCondensationDAG() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"}, {"C", "D"}, {"D", "C"}, {"B", "C"} @@ -222,7 +222,7 @@ public void testCondensationDAG() { StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); StronglyConnectedComponentsAnalyzer.SCCResult result = analyzer.tarjan(); - Graph condensation = result.getCondensation(); + Graph condensation = result.getCondensation(); assertEquals(2, condensation.getVertexCount()); assertEquals(1, condensation.getEdgeCount()); } @@ -231,7 +231,7 @@ public void testCondensationDAG() { @Test public void testLargestComponent() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "D"}, {"D", "A"}, // size 4 {"E", "F"}, {"F", "E"} // size 2 }); @@ -245,7 +245,7 @@ public void testLargestComponent() { @Test public void testVertexLookup() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"} }); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); @@ -260,7 +260,7 @@ public void testVertexLookup() { @Test public void testSelfLoop() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); // Self-loops in JUNG DirectedSparseGraph may not be supported, // but the vertex should still be in its own SCC @@ -274,14 +274,14 @@ public void testSelfLoop() { @Test public void testMinEdgesToConnect() { // Already strongly connected - Graph g1 = buildDirectedGraph(new String[][]{ + Graph g1 = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"} }); StronglyConnectedComponentsAnalyzer a1 = new StronglyConnectedComponentsAnalyzer(g1); assertEquals(0, a1.minEdgesToStronglyConnect(a1.tarjan())); // Chain: A->B->C (3 SCCs, 1 source, 1 sink) => need max(1,1) = 1 edge - Graph g2 = buildDirectedGraph(new String[][]{ + Graph g2 = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"} }); StronglyConnectedComponentsAnalyzer a2 = new StronglyConnectedComponentsAnalyzer(g2); @@ -292,7 +292,7 @@ public void testMinEdgesToConnect() { @Test public void testReportGeneration() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"}, {"C", "D"} }); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); @@ -318,7 +318,7 @@ public void testCompleteGraph() { } } } - Graph g = buildDirectedGraph(edges.toArray(new String[0][])); + Graph g = buildDirectedGraph(edges.toArray(new String[0][])); assertBothAlgorithmsAgree(g, 1); } @@ -330,7 +330,7 @@ public void testLongChain() { for (int i = 0; i < 9; i++) { edges[i] = new String[]{"N" + i, "N" + (i + 1)}; } - Graph g = buildDirectedGraph(edges); + Graph g = buildDirectedGraph(edges); assertBothAlgorithmsAgree(g, 10); // each node is its own SCC } @@ -343,7 +343,7 @@ public void testLongCycle() { for (int i = 0; i < n; i++) { edges[i] = new String[]{"N" + i, "N" + ((i + 1) % n)}; } - Graph g = buildDirectedGraph(edges); + Graph g = buildDirectedGraph(edges); assertBothAlgorithmsAgree(g, 1); // all in one SCC } @@ -351,7 +351,7 @@ public void testLongCycle() { @Test public void testDiamondPattern() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"B", "D"}, {"C", "D"}, {"D", "A"} // back edge creates one big SCC }); @@ -362,7 +362,7 @@ public void testDiamondPattern() { @Test public void testMultipleSourcesSinks() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "C"}, {"B", "C"}, {"C", "D"}, {"C", "E"} }); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); @@ -377,7 +377,7 @@ public void testMultipleSourcesSinks() { @Test public void testConnectivityNonExistent() { - Graph g = buildDirectedGraph(new String[][]{{"A", "B"}}); + Graph g = buildDirectedGraph(new String[][]{{"A", "B"}}); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); StronglyConnectedComponentsAnalyzer.SCCResult result = analyzer.tarjan(); @@ -390,7 +390,7 @@ public void testConnectivityNonExistent() { @Test public void testNestedCycles() { // Inner cycle A-B-C-A, outer cycle A-D-E-C - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"}, {"A", "D"}, {"D", "E"}, {"E", "C"} }); @@ -406,7 +406,7 @@ public void testNestedCycles() { @Test public void testParallelBridgeEdges() { // Two SCCs with multiple edges between them - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"}, {"C", "D"}, {"D", "C"}, {"A", "C"}, {"B", "D"} // two bridge edges @@ -424,7 +424,7 @@ public void testParallelBridgeEdges() { @Test public void testComponentToString() { - Graph g = buildDirectedGraph(new String[][]{{"A", "B"}, {"B", "A"}}); + Graph g = buildDirectedGraph(new String[][]{{"A", "B"}, {"B", "A"}}); StronglyConnectedComponentsAnalyzer analyzer = new StronglyConnectedComponentsAnalyzer(g); StronglyConnectedComponentsAnalyzer.SCCResult result = analyzer.tarjan(); @@ -437,7 +437,7 @@ public void testComponentToString() { @Test public void testStarTopology() { // Hub A with outgoing edges to B,C,D,E - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"A", "C"}, {"A", "D"}, {"A", "E"} }); assertBothAlgorithmsAgree(g, 5); @@ -447,7 +447,7 @@ public void testStarTopology() { @Test public void testBidirectionalStar() { - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "A"}, {"A", "C"}, {"C", "A"}, {"A", "D"}, {"D", "A"} @@ -461,7 +461,7 @@ public void testBidirectionalStar() { @Test public void testFigureEight() { // Two cycles sharing vertex C - Graph g = buildDirectedGraph(new String[][]{ + Graph g = buildDirectedGraph(new String[][]{ {"A", "B"}, {"B", "C"}, {"C", "A"}, {"C", "D"}, {"D", "E"}, {"E", "C"} }); @@ -472,7 +472,7 @@ public void testFigureEight() { @Test public void testMinEdgesMultipleIsolated() { - Graph g = new DirectedSparseGraph(); + Graph g = new DirectedSparseGraph(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); diff --git a/Gvisual/test/gvisual/StructuralHoleAnalyzerTest.java b/Gvisual/test/gvisual/StructuralHoleAnalyzerTest.java index bdf0a3b..29916ae 100644 --- a/Gvisual/test/gvisual/StructuralHoleAnalyzerTest.java +++ b/Gvisual/test/gvisual/StructuralHoleAnalyzerTest.java @@ -15,43 +15,43 @@ public class StructuralHoleAnalyzerTest { // ── Graph builders ────────────────────────────────────────── - private Graph emptyGraph() { + private Graph emptyGraph() { return new UndirectedSparseGraph<>(); } - private Graph singleVertex() { - Graph g = new UndirectedSparseGraph<>(); + private Graph singleVertex() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); return g; } - private Graph singleEdge() { - Graph g = new UndirectedSparseGraph<>(); + private Graph singleEdge() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); - g.addEdge(new edge("f", "A", "B"), "A", "B"); + g.addEdge(new Edge("f", "A", "B"), "A", "B"); return g; } /** Triangle: A-B, B-C, A-C — fully connected, no structural holes */ - private Graph triangle() { - Graph g = new UndirectedSparseGraph<>(); + private Graph triangle() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); - g.addEdge(new edge("f", "A", "B"), "A", "B"); - g.addEdge(new edge("f", "B", "C"), "B", "C"); - g.addEdge(new edge("f", "A", "C"), "A", "C"); + g.addEdge(new Edge("f", "A", "B"), "A", "B"); + g.addEdge(new Edge("f", "B", "C"), "B", "C"); + g.addEdge(new Edge("f", "A", "C"), "A", "C"); return g; } /** Star: center connected to A, B, C, D — spokes not connected */ - private Graph star() { - Graph g = new UndirectedSparseGraph<>(); + private Graph star() { + Graph g = new UndirectedSparseGraph<>(); g.addVertex("center"); g.addVertex("A"); g.addVertex("B"); g.addVertex("C"); g.addVertex("D"); - g.addEdge(new edge("f", "center", "A"), "center", "A"); - g.addEdge(new edge("f", "center", "B"), "center", "B"); - g.addEdge(new edge("f", "center", "C"), "center", "C"); - g.addEdge(new edge("f", "center", "D"), "center", "D"); + g.addEdge(new Edge("f", "center", "A"), "center", "A"); + g.addEdge(new Edge("f", "center", "B"), "center", "B"); + g.addEdge(new Edge("f", "center", "C"), "center", "C"); + g.addEdge(new Edge("f", "center", "D"), "center", "D"); return g; } @@ -59,56 +59,56 @@ private Graph star() { * Bow-tie: two triangles connected by a single bridge node. * A-B-C triangle, C-D-E triangle, C is the broker. */ - private Graph bowTie() { - Graph g = new UndirectedSparseGraph<>(); + private Graph bowTie() { + Graph g = new UndirectedSparseGraph<>(); for (String v : new String[]{"A", "B", "C", "D", "E"}) g.addVertex(v); - g.addEdge(new edge("f", "A", "B"), "A", "B"); - g.addEdge(new edge("f", "A", "C"), "A", "C"); - g.addEdge(new edge("f", "B", "C"), "B", "C"); - g.addEdge(new edge("f", "C", "D"), "C", "D"); - g.addEdge(new edge("f", "C", "E"), "C", "E"); - g.addEdge(new edge("f", "D", "E"), "D", "E"); + g.addEdge(new Edge("f", "A", "B"), "A", "B"); + g.addEdge(new Edge("f", "A", "C"), "A", "C"); + g.addEdge(new Edge("f", "B", "C"), "B", "C"); + g.addEdge(new Edge("f", "C", "D"), "C", "D"); + g.addEdge(new Edge("f", "C", "E"), "C", "E"); + g.addEdge(new Edge("f", "D", "E"), "D", "E"); return g; } /** Path: A-B-C-D — B and C are brokers between endpoints */ - private Graph path() { - Graph g = new UndirectedSparseGraph<>(); + private Graph path() { + Graph g = new UndirectedSparseGraph<>(); for (String v : new String[]{"A", "B", "C", "D"}) g.addVertex(v); - g.addEdge(new edge("f", "A", "B"), "A", "B"); - g.addEdge(new edge("f", "B", "C"), "B", "C"); - g.addEdge(new edge("f", "C", "D"), "C", "D"); + g.addEdge(new Edge("f", "A", "B"), "A", "B"); + g.addEdge(new Edge("f", "B", "C"), "B", "C"); + g.addEdge(new Edge("f", "C", "D"), "C", "D"); return g; } /** Complete K4 — fully connected, maximum redundancy */ - private Graph complete4() { - Graph g = new UndirectedSparseGraph<>(); + private Graph complete4() { + Graph g = new UndirectedSparseGraph<>(); String[] vs = {"A", "B", "C", "D"}; for (String v : vs) g.addVertex(v); for (int i = 0; i < vs.length; i++) { for (int j = i + 1; j < vs.length; j++) { - g.addEdge(new edge("f", vs[i], vs[j]), vs[i], vs[j]); + g.addEdge(new Edge("f", vs[i], vs[j]), vs[i], vs[j]); } } return g; } /** Two cliques connected by a single bridge */ - private Graph twoClusters() { - Graph g = new UndirectedSparseGraph<>(); + private Graph twoClusters() { + Graph g = new UndirectedSparseGraph<>(); // Cluster 1: A, B, C (triangle) for (String v : new String[]{"A", "B", "C"}) g.addVertex(v); - g.addEdge(new edge("f", "A", "B"), "A", "B"); - g.addEdge(new edge("f", "A", "C"), "A", "C"); - g.addEdge(new edge("f", "B", "C"), "B", "C"); + g.addEdge(new Edge("f", "A", "B"), "A", "B"); + g.addEdge(new Edge("f", "A", "C"), "A", "C"); + g.addEdge(new Edge("f", "B", "C"), "B", "C"); // Cluster 2: D, E, F (triangle) for (String v : new String[]{"D", "E", "F"}) g.addVertex(v); - g.addEdge(new edge("f", "D", "E"), "D", "E"); - g.addEdge(new edge("f", "D", "F"), "D", "F"); - g.addEdge(new edge("f", "E", "F"), "E", "F"); + g.addEdge(new Edge("f", "D", "E"), "D", "E"); + g.addEdge(new Edge("f", "D", "F"), "D", "F"); + g.addEdge(new Edge("f", "E", "F"), "E", "F"); // Bridge: C -- D - g.addEdge(new edge("f", "C", "D"), "C", "D"); + g.addEdge(new Edge("f", "C", "D"), "C", "D"); return g; } @@ -567,7 +567,7 @@ public void testPathEfficiency() { @Test public void testConstraintNonnegative() { - for (Graph g : Arrays.asList(star(), triangle(), bowTie(), path(), complete4())) { + for (Graph g : Arrays.asList(star(), triangle(), bowTie(), path(), complete4())) { StructuralHoleAnalyzer a = new StructuralHoleAnalyzer(g); for (StructuralHoleAnalyzer.VertexMetrics vm : a.analyzeAll()) { assertTrue("Constraint should be non-negative for " + vm.getVertex(), @@ -578,7 +578,7 @@ public void testConstraintNonnegative() { @Test public void testEfficiencyBetweenZeroAndOne() { - for (Graph g : Arrays.asList(star(), triangle(), bowTie(), path(), complete4())) { + for (Graph g : Arrays.asList(star(), triangle(), bowTie(), path(), complete4())) { StructuralHoleAnalyzer a = new StructuralHoleAnalyzer(g); for (StructuralHoleAnalyzer.VertexMetrics vm : a.analyzeAll()) { if (vm.getDegree() > 0) { diff --git a/Gvisual/test/gvisual/SubgraphExtractorTest.java b/Gvisual/test/gvisual/SubgraphExtractorTest.java index e496e44..1a31dc8 100644 --- a/Gvisual/test/gvisual/SubgraphExtractorTest.java +++ b/Gvisual/test/gvisual/SubgraphExtractorTest.java @@ -22,19 +22,19 @@ */ public class SubgraphExtractorTest { - private Graph graph; - private List edges; + private Graph graph; + private List edges; /** Helper to create an edge with type, vertices, weight, and optional timestamps. */ - private edge makeEdge(String type, String v1, String v2, float weight) { - edge e = new edge(type, v1, v2); + private Edge makeEdge(String type, String v1, String v2, float weight) { + Edge e = new Edge(type, v1, v2); e.setWeight(weight); return e; } - private edge makeTimedEdge(String type, String v1, String v2, float weight, + private Edge makeTimedEdge(String type, String v1, String v2, float weight, long start, long end) { - edge e = makeEdge(type, v1, v2, weight); + Edge e = makeEdge(type, v1, v2, weight); e.setTimestamp(start); e.setEndTimestamp(end); return e; @@ -51,17 +51,17 @@ public void setUp() { graph = new UndirectedSparseGraph<>(); edges = new ArrayList<>(); - edge e1 = makeEdge("f", "A", "B", 3.0f); - edge e2 = makeEdge("c", "B", "C", 1.0f); - edge e3 = makeEdge("f", "C", "D", 5.0f); - edge e4 = makeEdge("s", "D", "E", 2.0f); - edge e5 = makeEdge("c", "A", "C", 4.0f); - edge e6 = makeEdge("f", "B", "D", 2.0f); + Edge e1 = makeEdge("f", "A", "B", 3.0f); + Edge e2 = makeEdge("c", "B", "C", 1.0f); + Edge e3 = makeEdge("f", "C", "D", 5.0f); + Edge e4 = makeEdge("s", "D", "E", 2.0f); + Edge e5 = makeEdge("c", "A", "C", 4.0f); + Edge e6 = makeEdge("f", "B", "D", 2.0f); for (String v : Arrays.asList("A", "B", "C", "D", "E")) { graph.addVertex(v); } - for (edge e : Arrays.asList(e1, e2, e3, e4, e5, e6)) { + for (Edge e : Arrays.asList(e1, e2, e3, e4, e5, e6)) { graph.addEdge(e, e.getVertex1(), e.getVertex2()); edges.add(e); } @@ -238,14 +238,14 @@ public void testFilterByNodesWithNonExistentNodesIgnoresThem() { @Test public void testFilterByTimeWindow() { // Replace edges with timed ones - List timedEdges = new ArrayList<>(); + List timedEdges = new ArrayList<>(); timedEdges.add(makeTimedEdge("f", "A", "B", 3.0f, 100, 200)); timedEdges.add(makeTimedEdge("c", "B", "C", 1.0f, 300, 400)); timedEdges.add(makeTimedEdge("f", "C", "D", 5.0f, 150, 250)); - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); for (String v : Arrays.asList("A", "B", "C", "D")) g.addVertex(v); - for (edge e : timedEdges) g.addEdge(e, e.getVertex1(), e.getVertex2()); + for (Edge e : timedEdges) g.addEdge(e, e.getVertex1(), e.getVertex2()); SubgraphExtractor.Result result = new SubgraphExtractor(g, timedEdges) .filterByTimeWindow(100, 200) @@ -303,7 +303,7 @@ public void testDensityCalculation() { @Test public void testDensityWithSingleNode() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("X"); SubgraphExtractor.Result result = new SubgraphExtractor(g, Collections.emptyList()) .extract(); @@ -312,7 +312,7 @@ public void testDensityWithSingleNode() { @Test public void testRetentionOnEmptySourceGraph() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("X"); SubgraphExtractor.Result result = new SubgraphExtractor(g, Collections.emptyList()) .extract(); diff --git a/Gvisual/test/gvisual/SubgraphPatternMatcherTest.java b/Gvisual/test/gvisual/SubgraphPatternMatcherTest.java index 8fa9002..f9015f6 100644 --- a/Gvisual/test/gvisual/SubgraphPatternMatcherTest.java +++ b/Gvisual/test/gvisual/SubgraphPatternMatcherTest.java @@ -15,33 +15,33 @@ public class SubgraphPatternMatcherTest { // ── Helpers ───────────────────────────────────────────────── - private Graph emptyGraph() { + private Graph emptyGraph() { return new UndirectedSparseGraph<>(); } - private void addEdge(Graph g, String v1, String v2) { + private void addEdge(Graph g, String v1, String v2) { if (!g.containsVertex(v1)) g.addVertex(v1); if (!g.containsVertex(v2)) g.addVertex(v2); - g.addEdge(new edge(null, v1, v2), v1, v2); + g.addEdge(new Edge(null, v1, v2), v1, v2); } - private void addTypedEdge(Graph g, String v1, String v2, + private void addTypedEdge(Graph g, String v1, String v2, String type) { if (!g.containsVertex(v1)) g.addVertex(v1); if (!g.containsVertex(v2)) g.addVertex(v2); - g.addEdge(new edge(type, v1, v2), v1, v2); + g.addEdge(new Edge(type, v1, v2), v1, v2); } - private Graph makeTriangle(String a, String b, String c) { - Graph g = emptyGraph(); + private Graph makeTriangle(String a, String b, String c) { + Graph g = emptyGraph(); addEdge(g, a, b); addEdge(g, b, c); addEdge(g, a, c); return g; } - private Graph makeK4() { - Graph g = emptyGraph(); + private Graph makeK4() { + Graph g = emptyGraph(); String[] v = {"A", "B", "C", "D"}; for (int i = 0; i < 4; i++) { for (int j = i + 1; j < 4; j++) { @@ -51,8 +51,8 @@ private Graph makeK4() { return g; } - private Graph makePath(String... nodes) { - Graph g = emptyGraph(); + private Graph makePath(String... nodes) { + Graph g = emptyGraph(); for (int i = 0; i < nodes.length - 1; i++) { addEdge(g, nodes[i], nodes[i + 1]); } @@ -74,7 +74,7 @@ public void testNullPattern() { @Test(expected = IllegalArgumentException.class) public void testPatternTooSmall() { - Graph tiny = emptyGraph(); + Graph tiny = emptyGraph(); tiny.addVertex("X"); new SubgraphPatternMatcher.Builder(emptyGraph(), tiny).build(); } @@ -90,7 +90,7 @@ public void testMaxMatchesZero() { @Test public void testNoMatchInEmptyTarget() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); SubgraphPatternMatcher.MatchResult r = m.findMatches(); @@ -100,7 +100,7 @@ public void testNoMatchInEmptyTarget() { @Test public void testNoMatchPatternLargerThanTarget() { - Graph target = makePath("A", "B"); + Graph target = makePath("A", "B"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.squarePattern()).build(); assertEquals(0, m.findMatches().getMatchCount()); @@ -108,7 +108,7 @@ public void testNoMatchPatternLargerThanTarget() { @Test public void testNoTriangleInTree() { - Graph tree = emptyGraph(); + Graph tree = emptyGraph(); addEdge(tree, "A", "B"); addEdge(tree, "A", "C"); addEdge(tree, "B", "D"); @@ -122,7 +122,7 @@ public void testNoTriangleInTree() { @Test public void testSingleTriangleFound() { - Graph target = makeTriangle("A", "B", "C"); + Graph target = makeTriangle("A", "B", "C"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); SubgraphPatternMatcher.MatchResult r = m.findMatches(); @@ -138,7 +138,7 @@ public void testSingleTriangleFound() { @Test public void testTwoDisjointTriangles() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "A", "B"); addEdge(target, "B", "C"); addEdge(target, "A", "C"); @@ -153,7 +153,7 @@ public void testTwoDisjointTriangles() { @Test public void testTrianglesInK4() { - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); // K4 contains C(4,3) = 4 triangles @@ -164,8 +164,8 @@ public void testTrianglesInK4() { @Test public void testPathInChain() { - Graph target = makePath("A", "B", "C", "D", "E"); - Graph pattern = SubgraphPatternMatcher.pathPattern(2); + Graph target = makePath("A", "B", "C", "D", "E"); + Graph pattern = SubgraphPatternMatcher.pathPattern(2); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, pattern).build(); SubgraphPatternMatcher.MatchResult r = m.findMatches(); @@ -175,8 +175,8 @@ public void testPathInChain() { @Test public void testPathLength1() { - Graph target = makePath("A", "B", "C"); - Graph pattern = SubgraphPatternMatcher.pathPattern(1); + Graph target = makePath("A", "B", "C"); + Graph pattern = SubgraphPatternMatcher.pathPattern(1); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, pattern).build(); // Two edges: A-B and B-C @@ -187,13 +187,13 @@ public void testPathLength1() { @Test public void testStarInHub() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "hub", "A"); addEdge(target, "hub", "B"); addEdge(target, "hub", "C"); addEdge(target, "hub", "D"); - Graph pattern = SubgraphPatternMatcher.starPattern(3); + Graph pattern = SubgraphPatternMatcher.starPattern(3); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, pattern).build(); // 4 leaves choose 3 = 4 star-3 patterns @@ -209,7 +209,7 @@ public void testStarPatternMinLeaves() { @Test public void testSquareFound() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "A", "B"); addEdge(target, "B", "C"); addEdge(target, "C", "D"); @@ -222,7 +222,7 @@ public void testSquareFound() { @Test public void testNoSquareInTriangle() { - Graph target = makeTriangle("A", "B", "C"); + Graph target = makeTriangle("A", "B", "C"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.squarePattern()).build(); assertEquals(0, m.findMatches().getMatchCount()); @@ -237,7 +237,7 @@ public void testDiamondInK4() { // But dedup by node set: all cover {A,B,C,D} = only 1 unique set. // Actually no — diamond is a specific subgraph structure, not just // a node set. With dedup by node set, K4 yields 1 match. - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.diamondPattern()).build(); // All 4 nodes form a single set → 1 unique match @@ -246,7 +246,7 @@ public void testDiamondInK4() { @Test public void testDiamondPattern() { - Graph p = SubgraphPatternMatcher.diamondPattern(); + Graph p = SubgraphPatternMatcher.diamondPattern(); assertEquals(4, p.getVertexCount()); assertEquals(5, p.getEdgeCount()); } @@ -255,14 +255,14 @@ public void testDiamondPattern() { @Test public void testBowtiePattern() { - Graph p = SubgraphPatternMatcher.bowtiePattern(); + Graph p = SubgraphPatternMatcher.bowtiePattern(); assertEquals(5, p.getVertexCount()); assertEquals(6, p.getEdgeCount()); } @Test public void testBowtieFound() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); // Two triangles sharing node C addEdge(target, "A", "B"); addEdge(target, "B", "C"); @@ -282,7 +282,7 @@ public void testBowtieFound() { @Test public void testCompletePattern() { - Graph p = SubgraphPatternMatcher.completePattern(4); + Graph p = SubgraphPatternMatcher.completePattern(4); assertEquals(4, p.getVertexCount()); assertEquals(6, p.getEdgeCount()); } @@ -294,7 +294,7 @@ public void testCompletePatternMinNodes() { @Test public void testK4InK5() { - Graph k5 = emptyGraph(); + Graph k5 = emptyGraph(); String[] v = {"A", "B", "C", "D", "E"}; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { @@ -311,14 +311,14 @@ public void testK4InK5() { @Test public void testHousePattern() { - Graph p = SubgraphPatternMatcher.housePattern(); + Graph p = SubgraphPatternMatcher.housePattern(); assertEquals(5, p.getVertexCount()); assertEquals(6, p.getEdgeCount()); } @Test public void testHouseFound() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "A", "B"); addEdge(target, "B", "C"); addEdge(target, "C", "D"); @@ -335,7 +335,7 @@ public void testHouseFound() { @Test public void testMaxMatchesLimit() { - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()) .maxMatches(2).build(); @@ -350,13 +350,13 @@ public void testMaxMatchesLimit() { public void testDegreeConstrainedReducesMatches() { // Star hub has degree 4, pattern hub has degree 3 // With degree constraint, hub must have degree >= 3 - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "H", "A"); addEdge(target, "H", "B"); addEdge(target, "H", "C"); addEdge(target, "H", "D"); - Graph pattern = SubgraphPatternMatcher.starPattern(3); + Graph pattern = SubgraphPatternMatcher.starPattern(3); // Without degree constraint SubgraphPatternMatcher m1 = new SubgraphPatternMatcher.Builder( @@ -376,7 +376,7 @@ public void testDegreeConstrainedReducesMatches() { @Test public void testEdgeTypeFilter() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addTypedEdge(target, "A", "B", "friend"); addTypedEdge(target, "B", "C", "friend"); addTypedEdge(target, "A", "C", "colleague"); @@ -390,7 +390,7 @@ public void testEdgeTypeFilter() { @Test public void testEdgeTypeFilterFindsMatch() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addTypedEdge(target, "A", "B", "friend"); addTypedEdge(target, "B", "C", "friend"); addTypedEdge(target, "A", "C", "friend"); @@ -463,7 +463,7 @@ public void testMatchToString() { @Test public void testCoverage() { - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "A", "B"); addEdge(target, "B", "C"); addEdge(target, "A", "C"); @@ -479,7 +479,7 @@ public void testCoverage() { @Test public void testNodeParticipation() { - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); SubgraphPatternMatcher.MatchResult r = m.findMatches(); @@ -492,7 +492,7 @@ public void testNodeParticipation() { @Test public void testTopParticipants() { - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); List> top = @@ -503,7 +503,7 @@ public void testTopParticipants() { @Test public void testAverageOverlapNoMatches() { - Graph target = makePath("A", "B", "C"); + Graph target = makePath("A", "B", "C"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); assertEquals(0, m.findMatches().getAverageOverlap(), 0.001); @@ -511,7 +511,7 @@ public void testAverageOverlapNoMatches() { @Test public void testAverageOverlapOneMatch() { - Graph target = makeTriangle("A", "B", "C"); + Graph target = makeTriangle("A", "B", "C"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); assertEquals(0, m.findMatches().getAverageOverlap(), 0.001); @@ -519,7 +519,7 @@ public void testAverageOverlapOneMatch() { @Test public void testAverageOverlapMultipleMatches() { - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); SubgraphPatternMatcher.MatchResult r = m.findMatches(); @@ -531,7 +531,7 @@ public void testAverageOverlapMultipleMatches() { @Test public void testReport() { - Graph target = makeK4(); + Graph target = makeK4(); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); String report = m.findMatches().generateReport(); @@ -544,7 +544,7 @@ public void testReport() { @Test public void testReportEmpty() { - Graph target = makePath("A", "B"); + Graph target = makePath("A", "B"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, SubgraphPatternMatcher.trianglePattern()).build(); String report = m.findMatches().generateReport(); @@ -556,14 +556,14 @@ public void testReportEmpty() { @Test public void testCustomPattern() { // Custom pattern: 4-clique with one pendant (tail) - Graph pattern = emptyGraph(); + Graph pattern = emptyGraph(); addEdge(pattern, "A", "B"); addEdge(pattern, "A", "C"); addEdge(pattern, "B", "C"); addEdge(pattern, "C", "D"); // pendant // Target: triangle + pendant - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "X", "Y"); addEdge(target, "Y", "Z"); addEdge(target, "X", "Z"); @@ -580,9 +580,9 @@ public void testCustomPattern() { @Test public void testDeduplicated() { // Path P0-P1 can match A-B in two orientations but should dedup - Graph target = emptyGraph(); + Graph target = emptyGraph(); addEdge(target, "A", "B"); - Graph pattern = SubgraphPatternMatcher.pathPattern(1); + Graph pattern = SubgraphPatternMatcher.pathPattern(1); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( target, pattern).build(); assertEquals(1, m.findMatches().getMatchCount()); @@ -592,7 +592,7 @@ public void testDeduplicated() { @Test public void testIsolatedNodesIgnored() { - Graph target = makeTriangle("A", "B", "C"); + Graph target = makeTriangle("A", "B", "C"); target.addVertex("D"); target.addVertex("E"); SubgraphPatternMatcher m = new SubgraphPatternMatcher.Builder( diff --git a/Gvisual/test/gvisual/SvgExporterTest.java b/Gvisual/test/gvisual/SvgExporterTest.java index 8e54eb6..403f805 100644 --- a/Gvisual/test/gvisual/SvgExporterTest.java +++ b/Gvisual/test/gvisual/SvgExporterTest.java @@ -12,7 +12,7 @@ */ public class SvgExporterTest { - private Graph graph; + private Graph graph; @Before public void setUp() { @@ -22,19 +22,19 @@ public void setUp() { graph.addVertex("C"); graph.addVertex("D"); - edge e1 = new edge("f", "A", "B"); + Edge e1 = new Edge("f", "A", "B"); e1.setWeight(1.5f); graph.addEdge(e1, "A", "B"); - edge e2 = new edge("c", "B", "C"); + Edge e2 = new Edge("c", "B", "C"); e2.setWeight(2.0f); graph.addEdge(e2, "B", "C"); - edge e3 = new edge("s", "A", "C"); + Edge e3 = new Edge("s", "A", "C"); e3.setWeight(0.5f); graph.addEdge(e3, "A", "C"); - edge e4 = new edge("sg", "C", "D"); + Edge e4 = new Edge("sg", "C", "D"); e4.setWeight(3.0f); graph.addEdge(e4, "C", "D"); } @@ -81,7 +81,7 @@ public void svgContainsNodeCount() { SvgExporter exporter = new SvgExporter(graph); String svg = exporter.exportToString(); assertTrue(svg.contains("4 nodes")); - assertTrue(svg.contains("4 edges")); + assertTrue(svg.contains("4 Edges")); } @Test @@ -143,7 +143,7 @@ public void darkThemeIsDefault() { @Test public void emptyGraphProducesSvg() { - Graph empty = new UndirectedSparseGraph<>(); + Graph empty = new UndirectedSparseGraph<>(); SvgExporter exporter = new SvgExporter(empty); String svg = exporter.exportToString(); assertTrue(svg.contains(" single = new UndirectedSparseGraph<>(); + Graph single = new UndirectedSparseGraph<>(); single.addVertex("X"); SvgExporter exporter = new SvgExporter(single); String svg = exporter.exportToString(); @@ -180,10 +180,10 @@ public void customTypeColor() { @Test public void xmlSpecialCharsEscaped() { - Graph g = new UndirectedSparseGraph<>(); + Graph g = new UndirectedSparseGraph<>(); g.addVertex("