Package edu.ucsb.cs.scaffold.services
Class ConceptGraphService
java.lang.Object
edu.ucsb.cs.scaffold.services.ConceptGraphService
Graph algorithms for the prerequisite structure of a course's top-level concepts (subconcepts
have no position in this graph). Prerequisite edges only ever connect top-level concepts, so
every method here operates on that subgraph.
reset(java.util.List<edu.ucsb.cs.scaffold.entity.Concept>, java.util.List<edu.ucsb.cs.scaffold.entity.ConceptEdge>) is the analysis run by POST /api/course/scaffold/reset: it detects
cycles (flagging their edges rather than processing them further), removes edges that are
redundant given the graph's transitive structure, ranks concepts by longest path from a root, and
lays out each level's x,y position. It is a pure function of its inputs — no repository access —
so the controller owns loading input and persisting the result.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final record -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncolorForLevel(int level) The color assigned to a top-level concept at the given longest-path level (1-based).reset(List<Concept> topLevelConcepts, List<ConceptEdge> edges) Runs the full scaffold reset analysis: cycle detection, transitive reduction, longest-path leveling, and layout.Likereset(List, List), but sorts each level by the given prior x values instead of each concept's own x column.booleanwouldCreateCycle(List<ConceptEdge> existingEdges, Long sourceId, Long targetId) True if adding an edge sourceId -> targetId would create a cycle, i.e. targetId can already reach sourceId via existingEdges.
-
Field Details
-
LEVEL_COLORS
-
CYCLE_EDGE_COLOR
- See Also:
-
MIN_HORIZONTAL_SEPARATION
public static final int MIN_HORIZONTAL_SEPARATION- See Also:
-
VERTICAL_LEVEL_SEPARATION
public static final int VERTICAL_LEVEL_SEPARATION- See Also:
-
-
Constructor Details
-
ConceptGraphService
public ConceptGraphService()
-
-
Method Details
-
colorForLevel
The color assigned to a top-level concept at the given longest-path level (1-based). -
wouldCreateCycle
True if adding an edge sourceId -> targetId would create a cycle, i.e. targetId can already reach sourceId via existingEdges. Used to reject new prerequisite edges at creation time, before a cycle can ever be persisted. -
reset
public ConceptGraphService.ResetResult reset(List<Concept> topLevelConcepts, List<ConceptEdge> edges) Runs the full scaffold reset analysis: cycle detection, transitive reduction, longest-path leveling, and layout. Does not mutate concepts or edges or read/write any repository; the caller appliesConceptGraphService.ResetResultto persistent entities.- Parameters:
topLevelConcepts- every top-level concept in the course (used for their id/x, to sort and lay out concepts with no edges at all, and as the node set for the graph algorithms)edges- every prerequisite edge in the course
-
reset
public ConceptGraphService.ResetResult reset(List<Concept> topLevelConcepts, List<ConceptEdge> edges, Map<Long, Integer> priorXByConceptId) Likereset(List, List), but sorts each level by the given prior x values instead of each concept's own x column. Used by the controller to sort by the requesting user's private, unsaved drag positions where they exist, falling back to the concept's persisted x otherwise — seePOST /api/course/scaffold/reset.
-