A C# .NET 8 console application that solves the Traveling Salesman Problem (TSP) using three different graph search algorithms — Depth-First Search, Least-Cost Search, and A* Search — and compares their performance on various graph inputs.
- Solve TSP using three algorithms: DFS, Least-Cost Search, and A*
- Compare algorithm results side-by-side (path, cost, execution time)
- Build graphs manually via adjacency matrices or generate them randomly
- Extensible architecture using interfaces (
IGraph,IGraphBuilder,ITSPGraphTraversalAlgorithm)
- .NET 8 SDK or later
dotnet run- Open
HomeworkAssignmentAI.slnin Visual Studio 2022+ - Press
F5or click Start
The entry point is Program.cs. To change the graph or algorithms being used:
-
Choose a graph builder:
ManualMatrixGraphBuilder— provide your own adjacency matrixRandomMatrixGraphBuilder(nodeCount, minWeight, maxWeight)— generate a random graph
-
Choose algorithms by adding them to the dictionary passed to
TravelingSalesmanProblem:1→ Depth-First Search2→ Least-Cost Search3→ A* Search
-
Run an algorithm by calling
tsp.SelectAlgorithmAndRun(id)with the desired algorithm ID.
Algorithm: A* Search
Path:
(0, 1) , (1, 3) , (3, 2) , (2, 0) Cost: 80
Run Time: 11 ms
├── Program.cs # Entry point — configures graphs and algorithms
├── TravelingSalesmanProblem.cs # Orchestrator — runs selected algorithm and displays results
│
├── IGraph.cs # Interface for graph representation
├── AdjacencyMatrixGraph.cs # Adjacency matrix implementation of IGraph
│
├── IGraphBuilder.cs # Interface for graph construction
├── ManualMatrixGraphBuilder.cs # Builds a graph from a user-defined matrix
├── RandomMatrixGraphBuilder.cs # Builds a graph with random edge weights
│
├── ITSPGraphTraversalAlgorithm.cs # Interface for TSP solving algorithms
├── AStar.cs # A* Search implementation
├── DepthFirstSearch.cs # Depth-First Search implementation
├── LeastCostSearch.cs # Least-Cost Search implementation
│
├── State.cs # Search state used by algorithms
├── IDisplayResults.cs # Interface for result display
├── DisplayResults.cs # Console output of algorithm results
│
├── HomeworkAssignmentAI.csproj # .NET 8 project file
└── HomeworkAssignmentAI.sln # Visual Studio solution file
This project is licensed under the MIT License — see the LICENSE file for details.