This project is a React + TypeScript + Vite application that teaches Dijkstra's Algorithm through a restaurant meeting-point problem.
Two friends start on opposite sides of a coordinate grid. Several restaurants are placed between them. The app runs Dijkstra from each friend, visualizes how shortest-path estimates change over time, and then compares restaurants to choose the best meeting point by combined travel distance.
- SVG-based weighted graph visualization
- Hidden coordinate grid used for layout and edge distance calculation
- Visible graph nodes limited to:
Friend AFriend B- restaurants
- Step-by-step Dijkstra replay from both friends
- Educational explanation panel with:
- how to read the visualization
- current algorithm explanation
- live distance table
- Restaurant scoring phase after both shortest-path runs complete
- Final recommended restaurant highlight with shortest paths
- React 18
- TypeScript
- Vite
- Plain SVG rendering
- Inline style objects in
src/styles/styles.ts
src/App.tsxMain orchestration for graph generation, replay, and scoring phases.src/components/Controls.tsxGenerate, run, and reset controls.src/components/GraphView.tsxSVG graph rendering, live distance badges, node states, and final path highlights.src/components/InfoPanel.tsxEducational explanation panel and distance / scoring tables.src/logic/generator.tsGraph generation for the two friends and restaurant nodes.src/logic/dijkstra.tsDijkstra implementation, replay snapshots, and path reconstruction helpers.src/logic/scoring.tsRestaurant ranking and best-candidate selection.src/types/graph.tsShared graph, replay, and scoring types.src/styles/styles.tsShared colors and visual styles.
- The app uses a fixed
12 x 8coordinate grid as a spatial reference. Friend Ais placed near the left side.Friend Bis placed near the right side.4to7restaurants are placed in the middle region.- Edges are explicitly defined between nodes.
- Edge weights use Euclidean distance.
Important:
- The background grid is not the graph.
- Only connected nodes can be traversed.
- Nearby nodes are not automatically connected.
The app runs Dijkstra twice:
- Phase A: from
Friend A - Phase B: from
Friend B
During replay:
- unexplored nodes stay neutral
- discovered nodes are highlighted red
- finalized nodes are highlighted green
- the active edge is highlighted blue
- live shortest-known distances are shown beside each visible node
After both shortest-path runs finish:
- each restaurant is scored using
distance from A + distance from B - restaurants are compared one by one
- the restaurant with the smallest total is selected
The final state highlights:
- the chosen restaurant
- the final shortest paths
- the total score comparison result
- Node.js
20.x
This project includes:
.nvmrcpackage.jsonengine constraint:>=20 <21
If you use nvm:
nvm usenpm installnpm run devVite is configured to use:
- dev server:
127.0.0.1:5173 - preview server:
127.0.0.1:4173
npm run buildnpm run previewThis repo includes a .gitignore for:
node_modules/dist/*.tsbuildinfo.DS_Store
That keeps git add . fast and prevents generated files from being committed by mistake.
- The current UI assumes exactly two friends:
AandB. - Restaurant selection currently uses combined-distance sum mode in the main app.
- The project is educational and replay-driven, so the animation intentionally favors clarity over speed.
- add a UI toggle for
sumvsminimaxscoring - add automated tests for graph generation, Dijkstra replay snapshots, and scoring
- update
PROJECT_STATUS.mdso it matches the current visible-node-only graph model