aboutsummaryrefslogtreecommitdiff
path: root/dk/abcdefghijklmnopqrstuvxyzæøå
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-21 12:43:57 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-21 13:58:38 +0200
commitaa16fc2be9cce83f20f2e35804956ac7cb5d5603 (patch)
tree5701dc51839c7ecfb00fa48a16403c063239b30c /dk/abcdefghijklmnopqrstuvxyzæøå
parent83f8ff7091ad51198d23de053d3ebae3f992fea2 (diff)
use class MatrixGraph
Diffstat (limited to 'dk/abcdefghijklmnopqrstuvxyzæøå')
-rw-r--r--dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/model/Combi.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/model/Combi.java b/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/model/Combi.java
index cf2fe91..6feea62 100644
--- a/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/model/Combi.java
+++ b/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/model/Combi.java
@@ -6,6 +6,7 @@ package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.model;
import com.example.portfolio3.AdjListGraph;
import com.example.portfolio3.Graph;
import com.example.portfolio3.GraphAlgorithms;
+import com.example.portfolio3.MatrixGraph;
/// Combi - static sample dataset of course combinations
///
@@ -23,9 +24,30 @@ public final class Combi {
/// @param path path to data file
private Combi(final String path) {
- g = new AdjListGraph();
+ // read into temporary graph to resolve vertice count
+ //
+ // use Adjacency List Representation:
+ // * cheap to bootstrap (done once)
+ // * simple to count vertices (done once): O(1)
+ Graph _g = new AdjListGraph();
+ GraphAlgorithms.readGraph(_g, path);
+ Integer _vertice_count = _g.vertices().size();
+
+ // read into final graph
+ //
+ // use Adjacency Matrix Representation:
+ // * expensive to bootstrap (done once)
+ // * simple to add edges but needs vertice count
+ // * simple to get edges (done repeatedly): O(1)
+ //
+ // TODO: avoid reading and parsing file twice
+ Graph g = new MatrixGraph(_vertice_count);
GraphAlgorithms.readGraph(g, path);
GraphAlgorithms.printGraph(g);
+
+ // release temporary variables for garbage collection
+ _g = null;
+ _vertice_count = null;
}
/// JVM entry point