GithubHelp home page GithubHelp logo

vsg-root / routexplorer Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 3.92 MB

RouteXplorer is a lib developed to optimize routes in Complete Graphs.

License: MIT License

Python 100.00%
graph hamiltonian-cycles python travelling-salesman-problem

routexplorer's Introduction



Python License: MIT Development Status PyPI for pypop7

RouteXplorer is a Python library developed to solve the Traveling Salesman Problem (TSP) in complete graphs. Its goal is to find the most efficient sequence of visiting nodes in a graph, minimizing the total distance traveled.

Install

$ pip install routexplorer
Try your first RouteXplorer program
# Create a .py file
$ echo > PythonFile.py
$ open PythonFile.py

With this piece of code you can read a input file, convert it into a graph and calculate the best path using the brute force algorithm.

>>> from routexplorer.utils.input_reader import InputReader
>>> from routexplorer.algorithms.BruteForceSearch import BruteForceSearch

>>> # Datas of graph
>>> graph = InputReader.read_file(input("Enter file path: ")) 

>>> # Calculation of the best path and distance
>>> best_path, best_distance = BruteForceSearch.find_best_path(graph, show_load=True, show_result=True)

Alternatively you can get the input directly with the final user and omit the loading process.

>>> from routexplorer.utils.input_reader import InputReader
>>> from routexplorer.utils.Graph import Graph
>>> from routexplorer.algorithms.BruteForceSearch import BruteForceSearch

>>> # Datas of graph
>>> graph = Graph(InputReader.get_vertices(InputReader.get_map_size(input()), input_function=input))

>>> # Calculation of the best path and distance
>>> best_path, _ = BruteForceSearch.find_best_path(graph)

>>> path_length = len(best_path)
>>> for i in range(path_length):
>>>     print(best_path[i], end=" " if i < path_length - 1 else "\n")
Create a .txt file

If you want, you can create a input file to facilitate the graph creation. This step can be achieved alternatively using other methods without the need to create a input file.

$ echo > file.txt
$ open file.txt

The file must have the following format:

4 5
0 0 0 0 D
0 A 0 0 0
0 0 0 0 C
R 0 B 0 0

The first row represents the size of the map and the following rows represents the map itself. each one of the characters is a cell, the 0's are empty cell's, you can change these characters for anything you want, as long as it isn't a letter, the letters represents a node.

Run your project
$ python RouteXplorer.py
Enter file path: your/txt/file/path/file.txt
100% [■■■■■■■■■■] - Generating permutations
100% [■■■■■■■■■■] - Checking paths
Best path: ['A', 'D', 'C', 'B'] 
Shorter distance: (14)

Or if you have chosed the second code example:

$ python RouteXplorer.py
4 5
0 0 0 0 D
0 A 0 0 0
0 0 0 0 C
R 0 B 0 0
A D C B

Library Architecture

---
title: Packet Diagram
---
flowchart TD
RouteXplorer(<b>RouteXplorer</b>\nRoot directory of the project) --> Algorithms(<b>algorithms</b>\nImplementations of the project's algorithms)
RouteXplorer --> Utils(<b>Utils</b>\nAuxiliary functions)
Utils --> Graph[<b>Graph</b>\nGraph creation]
Utils --> utils[<b>utils</b>\nStorage of utility functions]
Utils --> input_reader[<b>input_reader</b>\nInput data function]
Algorithms --> IAlgorithm[<b>IAlgorithm</b>\nAbstract Algorithm class]
Algorithms --> BruteForceSearch[<b>BruteForceSearch</b>\nBrute force algorithm]

Loading

Key Features

  • Efficient Algorithms: RouteXplorer implements a variety of optimized algorithms to solve the Traveling Salesman Problem, allowing you to find solutions quickly and efficiently.

  • Flexible Customization: The library offers flexible options to customize the algorithm settings, allowing you to adapt the optimization process to the specific needs of your project.

  • Simple Integration: The library is easy to integrate into your existing Python projects, allowing you to leverage its powerful functionality without complications.

Contribution

RouteXplorer is an open source project and we encourage community contributions. If you want to contribute, please follow the guidelines outlined in the repository's CONTRIBUTING.md file.

License

RouteXplorer is distributed under the MIT license. For more information, see the LICENSE.md file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.