aboutsummaryrefslogtreecommitdiff
path: root/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/model/Combi.java
blob: 6feea623f840117e54e99efaa138629cfd28f60a (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.model;
  4. import com.example.portfolio3.AdjListGraph;
  5. import com.example.portfolio3.Graph;
  6. import com.example.portfolio3.GraphAlgorithms;
  7. import com.example.portfolio3.MatrixGraph;
  8. /// Combi - static sample dataset of course combinations
  9. ///
  10. /// Slurps and parses data from upstream-provided comma-separated file.
  11. ///
  12. /// @version 0.0.1
  13. /// @see <https://moodle.ruc.dk/mod/assign/view.php?id=523186>
  14. public final class Combi {
  15. /// data about combinations as a Graph
  16. private Graph g;
  17. /// Default constructor
  18. ///
  19. /// @param path path to data file
  20. private Combi(final String path) {
  21. // read into temporary graph to resolve vertice count
  22. //
  23. // use Adjacency List Representation:
  24. // * cheap to bootstrap (done once)
  25. // * simple to count vertices (done once): O(1)
  26. Graph _g = new AdjListGraph();
  27. GraphAlgorithms.readGraph(_g, path);
  28. Integer _vertice_count = _g.vertices().size();
  29. // read into final graph
  30. //
  31. // use Adjacency Matrix Representation:
  32. // * expensive to bootstrap (done once)
  33. // * simple to add edges but needs vertice count
  34. // * simple to get edges (done repeatedly): O(1)
  35. //
  36. // TODO: avoid reading and parsing file twice
  37. Graph g = new MatrixGraph(_vertice_count);
  38. GraphAlgorithms.readGraph(g, path);
  39. GraphAlgorithms.printGraph(g);
  40. // release temporary variables for garbage collection
  41. _g = null;
  42. _vertice_count = null;
  43. }
  44. /// JVM entry point
  45. ///
  46. /// @param args command-line arguments
  47. public static void main(final String[] args) {
  48. // first argument, if provided, is the data file path;
  49. // else use upstream named file in current directory.
  50. String path = (args.length > 0)
  51. ? args[0]
  52. : "combi.txt";
  53. Combi combi = new Combi(path);
  54. }
  55. }