GithubHelp home page GithubHelp logo

xavier-mayiming / tabu-search Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 88 KB

Tabu search for traveling salesman problem (TSP)

Python 100.00%
combinatorial-optimization metaheuristic python tabu-search traveling-salesman-problem

tabu-search's Introduction

Tabu Search

Reference: Glover, Fred. Tabu Search-- Part I.[J]. ORSA Journal on Computing, 1989.
The tabu search for the traveling salesman problem
Variables Meaning
x The x coordinates of cities (list)
y The y coordinates of cities (list)
iter The maximum number of iterations
city_num The number of cities
na The number of actions
dis The distance matrix, dis[i][j] denotes the distances between city i and city j
TC The tabu counter (list)
TL The tabu length
gbest The length of the global best path
gbest_path The global best path (list)
iter_best The length of the global best path of each iteration (list)
con_iter The last iteration number when "gbest" is updated

Example

if __name__ == '__main__':
    min_coord = 0
    max_coord = 10
    city_num = 30
    iter = 50
    x = [random.uniform(min_coord, max_coord) for _ in range(city_num)]
    y = [random.uniform(min_coord, max_coord) for _ in range(city_num)]
    print(main(x, y, iter))
Output:

The TS converges at its 20-th iteration, and the global best value is 46.273638987858966.

{
    'best length': 46.273638987858966, 
    'best path': [16, 6, 15, 20, 24, 25, 5, 21, 12, 22, 18, 28, 14, 4, 0, 26, 2, 27, 7, 10, 9, 17, 11, 19, 23, 3, 29, 13, 1, 8], 
    'convergence iteration': 20
}

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.