atagunay / travel_salesman

Solve Travel Salesman Problem. Give best route and route cost.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table of Contents

Table of Contents

Installation

Installation is pretty standard:

$ gem install travel_salesman

or with using Bundler, add this line to your Gemfile

gem 'travel_salesman'

Documentation

Finding best route cost

Route start and end at first index of the 2D array. This 2D array is your distance matrix

  distance_matrix = [
    [0, 10, 15, 20],
    [5, 0, 9, 10],
    [6, 13, 0, 12],
    [8, 8, 9, 0]
]

TravelSalesman.new(distance_matrix).get_tour_distance
# => 35 

Finding best route

Route start and end at first index of the 2D array. This 2D array is your distance matrix

distance_matrix = [
  [0, 10, 15, 20],
  [5, 0, 9, 10],
  [6, 13, 0, 12],
  [8, 8, 9, 0]
]

puts TravelSalesman.new(distance_matrix).get_tour_route
# => [0, 1, 3, 2, 0]

Contributing

People behind the 💻


Ata Günay

About

Solve Travel Salesman Problem. Give best route and route cost.


Languages

Language:Ruby 100.0%