diff options
author | Ian Valentin Christensen <valentianchristensen@gmail.com> | 2025-04-29 13:18:29 +0200 |
---|---|---|
committer | Ian Valentin Christensen <valentianchristensen@gmail.com> | 2025-04-29 13:18:29 +0200 |
commit | ff91bbbfaeb9000197c615c822cf3040590912d6 (patch) | |
tree | 7638fc0f722faa7a1b8e3233b849f0b306401073 /src | |
parent | d2a7db8a16bcc97a720a3721a1888c59e80f2f34 (diff) |
add comments and avoid processing same pair of groups twice
Diffstat (limited to 'src')
-rw-r--r-- | src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java index 8782569..ec4a35d 100644 --- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java +++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java @@ -221,14 +221,15 @@ public final class Graph { final ArrayList<Set<Vertex>> sets, final AbstractGraph g ) { AbstractGraph h = new AdjListGraph(); - Map<Set<Vertex>, String> label = new HashMap<>(); + Map<Set<Vertex>, String> groupLabel = new HashMap<>(); for (Set<Vertex> groupSet : sets) { - // canonical string name - strings sortes alphabetically + // create a string for each group of module selections String name = groupSet.stream() .map(Vertex::toString) .sorted() // avoid differently sorted duplicates - .collect(Collectors.joining(",", "{", "}")); - label.put(groupSet, name); + .collect(Collectors.joining(", ", "{", "}")); + // formatting of groups as vertices + groupLabel.put(groupSet, name); // map group to name of group } for (Set<Vertex> s: sets) { @@ -236,6 +237,9 @@ public final class Graph { if (t == s) { continue; } + if (s.hashCode() > t.hashCode()) { + continue; // process each pair no more than once + } int sum = 0; for (Vertex v: s) { // students with this choice @@ -248,7 +252,7 @@ public final class Graph { } } h.insertEdge( - label.get(s), label.get(t), sum); + groupLabel.get(s), groupLabel.get(t), sum); } } |