How shakibim/traveling-salesman-problem-tsp-with-java-swing works
1. Repository shape
- This is a small Java desktop application built with Maven.
- The entire application appears to live in a single source file: TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java.
- The target/ directory is just Maven build output and is not part of the runtime architecture.
2. Primary boundary: Swing UI on the JVM
- The app is a Java Swing GUI, not a web app or service.
- All user interaction happens in a desktop window: adding vertices, adding edges, auto-generating graphs, and triggering TSP solving.
3. Single-process, in-memory application
- There is no evidence of a database, filesystem persistence, or external API integration.
- Graph state, weights, and solution results are managed in memory and reset with the UI’s clear action.
4. Core domain model: graph + TSP route state
- The application centers on an editable graph of cities/vertices and weighted edges.
- It supports both directed and undirected graph behavior, based on the README examples.
- The solver works on the current graph state rather than loading data from elsewhere.
5. Graph editing subsystem
- Users can:
- create vertices by clicking,
- add edges manually,
- enter weights,
- and use Auto Connect to generate a complete or near-complete weighted graph automatically.
- This subsystem is responsible for building the problem instance that the TSP algorithms consume.
6. TSP algorithm subsystem
- Three solvers are implemented:
- Naive / brute force: exhaustive search, optimal but factorial-time.
- Dynamic Programming: memoized optimal solver for smaller to medium graphs.
- Greedy: nearest-neighbor heuristic, fast but not guaranteed optimal.
- These are the computational core of the app and are selected from the GUI.
7. Result flow
- User selects a graph and an algorithm.
- The solver computes a route and total cost.
- The UI then displays the result visually and in a details view.
- This is the main data flow: UI input → graph state → algorithm execution → highlighted solution + cost display.
8. Visualization subsystem
- The app renders the graph and solution route directly in Swing.
- It can emphasize the chosen path and optionally hide non-optimal edges.
- The README’s screenshots suggest custom drawing of nodes, edges, and directional arrows.
9. Performance/behavior tradeoff built into the architecture
- The app is intentionally designed to compare algorithms:
- Naive and DP are used for correctness/optimality on small graphs.
- Greedy is used for large graphs where exact methods become impractical.
- Large inputs can freeze the UI when exact solvers are used, which implies the computations run on the same desktop thread flow rather than in a separate job system.
10. No backend layering
- There is no separate service layer, persistence layer, or network boundary visible from the repo layout.
- The architecture is effectively a monolithic Swing application with UI, model, rendering, and algorithms concentrated in one class/file.
11. Build/tooling boundary
- Maven handles compilation and packaging.
- The compiled classes under target/classes indicate a standard Java build pipeline, but no additional runtime infrastructure.
12. How to diagram it
- The most accurate architecture diagram would show:
- Swing UI / event handlers
- Graph editor state
- TSP solver algorithms
- Graph rendering/output panel
- All of these are internal components of one desktop process, with no external system dependencies.
Main entry points: TSPSolver.java Graph editor · tspsolver Compiled app · pom.xml Maven build
Components 14
Desktop app
Single-process Swing application runtime
- Swing UI · Main window and user interactions for editing graphs and running solvers
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Graph view · Draws vertices, edges, arrows, and highlighted routes
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Graph editor · Holds the editable graph, vertices, edges, and weights
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Mouse input · Handles clicks and UI actions for creating and modifying the graph
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Auto Connect · Builds dense or complete weighted graphs automatically
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Solver select · Chooses brute force, dynamic programming, or greedy solving
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Naive search · Brute-force TSP solver for exact results on small graphs
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Dynamic prog · Memoized exact TSP solver for small to medium graphs
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Greedy TSP · Nearest-neighbor style fast approximation solver
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Route result · Stores the chosen route, total cost, and highlighted path
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Details view · Shows the computed route and cost to the user
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java - Clear graph · Resets the current graph and solution state
TSPSolver/src/main/java/com/mycompany/tspsolver/TSPSolver.java
Build
Maven compilation and packaged output
- Maven build · Compiles and packages the Java application
TSPSolver/pom.xml - Compiled app · Generated class files under target/classes
TSPSolver/target/classes/com/mycompany/tspsolver
Connections 20
- Mouse input → Graph editor: edit graph · User clicks create and connect vertices through the UI
- Mouse input → Auto Connect: generate · UI triggers automatic graph generation
- Auto Connect → Graph editor: populate · Generated vertices and weighted edges are written into the graph state
- Swing UI → Solver select: run solver · User selects an algorithm from the GUI
- Solver select → Naive search: brute force · Routes small graphs through exhaustive search
- Solver select → Dynamic prog: dynamic programming · Routes small and medium graphs through memoized exact solving
- Solver select → Greedy TSP: heuristic · Routes larger graphs through nearest-neighbor style solving
- Graph editor → Naive search: graph input · Exact solvers consume the current weighted graph
- Graph editor → Dynamic prog: graph input · Exact solvers consume the current weighted graph
- Graph editor → Greedy TSP: graph input · Heuristic solver consumes the current weighted graph
- Naive search → Route result: route + cost · Brute force returns the best tour and total weight
- Dynamic prog → Route result: route + cost · Dynamic programming returns the optimal tour and total weight
- Greedy TSP → Route result: route + cost · Greedy solver returns an approximate tour and total weight
- Route result → Details view: display · Solution summary is shown in the details panel
- Route result → Graph view: highlight · Chosen path is emphasized in the drawing surface
- Graph editor → Graph view: render graph · Current graph state is painted in Swing
- Clear graph → Graph editor: reset · Clears vertices, edges, and weights
- Clear graph → Route result: clear result · Removes the previous route and cost display
- Maven build → Compiled app: compile · Maven produces the compiled application classes
- Compiled app → Swing UI: run · Compiled classes contain the desktop application entrypoint