Coder Social home page Coder Social logo

mtsp_aco's Introduction

MTSP_ACO

This repository is the repository which implements mTSP (multi Traveling Salesman Problem) with ant colony optimization. Referenced paper is here.

Algorithm

This mTSP will try to solve multi salesman problem with ant colony optimization.

n: cities (1 is a start node(default))

m: number of salesman

This mTSP will start num_of_ants ant's will start node. And, each ant will make m paths that, each path will contain (n-1) / m cities. So, each ant will make m-salesman path, each path has different nodes.

For example, if n = 10, m = 3, k(num_of_ants) = 6,

ant_1 = [[1, 2, 3, 4], [1, 5, 6, 10], [1, 7, 8, 9]] ant_2 = [[1, 4, 10, 3], [1, 5, 7, 8], [1, 2, 6, 9]] ... ant_6 = [...]

And num_of_ants made the each m paths, we score the length in each path, and as usually, we make pheromones and accumulate it on the path ant routes.

This repository doesn't use MMAS, so

  • mTSP
  • 2-opt

use as techniques.

How to use

main.py

import tsplib95
import matplotlib.pyplot as plt
import networkx as nx
import random

from colony import Colony
from solver import Solver

problem = tsplib95.load_problem('bays29.tsp')
G = problem.get_graph()

solver = Solver()
colony = Colony(1, 3)

# num of sales
sales = 5

# start is the start node, and limit is max cycles, opt2 is times how to try opt2
# if opt2 is None, don't try opt2.
ans = solver.solve(G, colony, sales, start=13, limit=50, opt2=20)
print(sum(s.cost for s in ans), ans)

# draw
colors = ['black', 'blue', 'green', 'red', 'pink', 'orange']
plt.figure(dpi=300)
_, ax = plt.subplots()
pos = problem.display_data or problem.node_coords
nx.draw_networkx_nodes(G, pos=pos, ax=ax, node_color=(0.4157, 0.3529, 0.3490))
nx.draw_networkx_labels(G, pos=pos, labels={i: str(i) for i in range(1, len(G.nodes) + 1)}, font_size=8, font_color='white')
for i in range(len(ans)):
    solution = ans[i]
    path = solution.path
    nx.draw_networkx_edges(G, pos=pos, edgelist=path, arrows=True, edge_color=colors[i])
    # nx.draw_networkx_edges(G, pos=pos, edgelist=path, arrows=True, edge_color=[random.random() for i in range(3)])

# If this doesn't exsit, x_axis and y_axis's numbers are not there.
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True)
plt.show()

Thanks

This repository refers to acopy. Please read this documentation and implemantiaon.

If MTSP_ACO has bad implementation or issue, please feel free to contact me and issue.

mtsp_aco's People

Contributors

dependabot[bot] avatar ganyariya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mtsp_aco's Issues

About the number of ants~~~

What's the number of ants in the MTSP-ACO? The same number as salesman? Which parameter in the code represents the number of ants?
thanks~~~

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.