Skip to content
/ TSP Public

The Traveling Salesman Problem (TSP) aims for the most efficient route across cities. This Python project, employing Tkinter and the Model-View-Controller (MVC) architecture, visualizes TSP solutions. It generates random cities, utilizes the nearest neighbor algorithm, and presents the optimal path with a Tkinter-based GUI.

License

Notifications You must be signed in to change notification settings

nsswifter/TSP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traveling Salesman Problem (TSP) Visualization

This Python project uses Tkinter for creating a GUI to visualize the Traveling Salesman Problem (TSP) solution, following the Model-View-Controller (MVC) architecture.

Demo

Table of Contents

Introduction

The project aims to visualize the TSP solution (using a Tkinter-based graphical user interface). It generates a specified number of random cities, applies the nearest neighbor algorithm to find the optimal path, and visualizes the results.

MVC Architecture

The project's code is organized into three main classes, following the Model-View-Controller (MVC) architecture:

  • Model (TSPSolver):

    • Implements the nearest neighbor algorithm to solve the TSP.
    • Represents the model in the MVC architecture, handling data and business logic, such as calculating the TSP solution.
  • View (TSPView):

    • Takes care of drawing cities and the TSP solution on the canvas.
    • Acts as the view in the MVC architecture, dealing with the user interface and visualization.
  • Controller (TSPController):

    • Initializes the Tkinter window.
    • Manages the GUI components such as the canvas, sliders, and labels.
    • Handles city initialization, TSP solving, and GUI updates.
    • Acts as the controller in the MVC architecture, managing user input, updating the model, and triggering visual updates on the view.
Project's Source Tree
.
├── LICENSE
├── README.md
│
├── controller
│   └── tspController.py
├── main.py
├── model
│   ├── city.py
│   └── tspSolver.py
└── view
    ├── tspView.py
    └── view.py

Dependencies

To run this project, ensure you have the following dependencies installed:

  1. Python 3.x: If you don't have Python installed, download and install it from the official Python website. Make sure to add Python to your system PATH during installation.

  2. Tkinter: Tkinter is included with most Python installations. To check if Tkinter is available on your system, open a terminal or command prompt and run the following command:

    python -m tkinter

    If Tkinter is installed, a Tkinter window should appear. If not, you may need to install Tkinter separately.

    • On Ubuntu or Debian-based systems, you can install Tkinter using:

      sudo apt-get install python3-tk
    • On Fedora or Red Hat-based systems, use:

      sudo dnf install python3-tkinter
    • On macOS, Tkinter is included with the default Python installation.

    • For Windows users, Tkinter is typically included with Python, so no additional steps are needed.

Usage

To use the program:

Execute the main.py script to start the TSP visualization:

python main.py

Contributing

Your contributions are greatly valued! Feel free to contribute to the project.

License

This project is licensed under the MIT - see the LICENSE file for details.

About

The Traveling Salesman Problem (TSP) aims for the most efficient route across cities. This Python project, employing Tkinter and the Model-View-Controller (MVC) architecture, visualizes TSP solutions. It generates random cities, utilizes the nearest neighbor algorithm, and presents the optimal path with a Tkinter-based GUI.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages