Code Monkey home page Code Monkey logo

essa-tsp-metaheuristics's Introduction

essa-tsp-metaheuristics

Contents

  1. πŸ“Š About
  2. πŸ“‹ Requirements
  3. ⭐ Features
  4. πŸ“ Examples
  5. πŸ‘¨β€πŸ’» Contributing
  6. πŸ“‚ Directory Structure
  7. πŸ“… Development schedule
  8. πŸ“§ Contact
  9. πŸ“„ License

πŸ“Š About

A repository containing heuristics for the traveling salesman problem (TSP) is a collection of algorithms and techniques that can be used to approximately solve the TSP. The TSP is a classic optimization problem in computer science that involves finding the shortest possible route that visits a given set of cities and returns to the starting city. The problem is NP-hard, meaning that it is very difficult to find an exact solution, particularly for large sets of cities. Heuristics are methods that can quickly find a good, but not necessarily optimal, solution to the TSP. These methods are useful for real-world applications where finding the exact solution may be impractical due to time or resource constraints. The repository contains a variety of heuristics, such as nearest neighbor, hill climbing and genetic algorithm.

πŸ“‹ Requirements

  1. The library works under Python 3.9+
  2. Algorithms need distance matrix to solve the problem. A distance matrix is a table that lists the distances between pairs of objects. In the context of this repository, a distance matrix is an excel file that specifies the distances between every pair of cities in the TSP. The distance matrix is used to define the TSP, as it specifies the cost of traveling from one city to another.

Distance matrix examples:

  • Example Problem

https://www.thecrazyprogrammer.com/2017/05/travelling-salesman-problem.html

  • Format supported by the repository

⭐ Features

  • Parallel Multistart for algorithms except Genetic Algorithm
  • GridSearch running in parallel for Genetic Algorithm

⭐ Parallel Multistart

from src.utils import load_data, PathPlotter, BenchmarkPlotter, DistanceHistoryPlotter
from src.algos import *
import os

distances = load_data(os.path.join("data", "Data_TSP_127.xlsx"))

result = MultistartAlgorithm()(HillClimbing, distances, n_starts=NUM_STARTS, only_best=True, verbose=False, n_jobs=-1, n_iter=25)
print(result)

⭐ GridSearch

from src.utils import *
from src.algos import *
import os

distances = load_data(os.path.join("data", "Data_TSP_29.xlsx"))

param_grid = {
    "POP_SIZE": [500],
    "N_ITERS": [100],
    "SELECTION_METHOD": ["truncation", "roulette", "tournament"], # "truncation", "roulette", "tournament"
    "CROSSOVER_METHOD": ["pmx", "ox"], # "ox", "pmx"
    "ELITE_SIZE": [0, ],
    "MATING_POOL_SIZE": [.5],
    "MUTATION_RATE": [.15],
    "NEIGH_TYPE": ["inversion", "insertion", "swap"], # "inversion", "insertion", "swap"
    "VERBOSE": [True]
}

gg = GridSearchGA(param_grid=param_grid, n_jobs=-1)
result = gg.solve(distances)
print(result)

πŸ“ Examples

Example 1. Run Nearest Neighbor Algorithm

The nearest neighbor algorithm is a heuristic for solving the traveling salesman problem (TSP). It is a simple and efficient method that can be used to quickly find a good, although not necessarily optimal, solution to the TSP. The algorithm works by iteratively adding the nearest unvisited city to the current tour until all cities have been visited.

from src.utils import load_data
from src.algos import *
import os

distances = load_data(os.path.join("data", "Data_TSP_127.xlsx"))

n = NearestNeighbour(verbose=False)
result = n.solve(distances, start_order=14) # we start from 14th city
print(result)

πŸ‘¨β€πŸ’» Contributing

πŸ“‚ Directory Structure

β”œβ”€β”€β”€.github
|   └───workflows
β”œβ”€β”€β”€assets
β”œβ”€β”€β”€data
β”œβ”€β”€β”€notebooks
└───src
    β”œβ”€β”€β”€algos
    └───utils
        └───genetic

πŸ“… Development Schedule

Version 1.0.0

  • Nearest Neighbour Algorithm
  • Hill Climbing Algorithm
  • Tabu Search Algorithm
  • Simulated Annealing Algorithm
  • Genetic Algorithm
  • Parallel Multistart for algorithms except Genetic Algorithm
  • GridSearch running in parallel for Genetic Algorithm
  • Python package

Version 2.0.0

  • Rework Multistart feature
  • Code optimization
  • More data load possibilities

πŸŽ“ Learning Materials

πŸ“§ Contact

πŸ“„ License

essa-tsp-metaheuristics's People

Contributors

pannorek avatar

Watchers

 avatar

Forkers

sewcio543

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.