GithubHelp home page GithubHelp logo

chkwon / lkh.jl Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 2.0 55 KB

A Julia wrapper for the Lin-Kernighan-Helsgaun (LKH) solver.

License: Other

Julia 100.00%
tsp tsp-solver lin-kernighan-heuristic travelling-salesman-problem

lkh.jl's Introduction

LKH.jl

Build Status codecov

This package provides a Julia wrapper for the LKH-3 library for solving Traveling Salesman Problems (TSP) and various Vehicle Routing Problems (VRPs).

While this Julia package is under MIT License, the underlying LKH library comes in a different license. Check with the LKH library homepage.

Installation

] add LKH

Usage for TSP

Using a distance matrix

using LKH
M = [
    0  16   7  14
   16   0   3   5
    7   3   0  16
   14   5  16   0 
]
opt_tour, opt_len = solve_tsp(M)

The distance matrix M can be either symmetric or asymmetric, but must be integer-valued.

Using coordinates

using LKH
n_nodes = 10
x = rand(n_nodes) .* 10000
y = rand(n_nodes) .* 10000
opt_tour, opt_len = solve_tsp(x, y; dist="EUC_2D")
opt_tour, opt_len = solve_tsp(x, y; dist="MAN_2D")
opt_tour, opt_len = solve_tsp(x, y; dist="MAX_2D")
opt_tour, opt_len = solve_tsp(x, y; dist="GEO")

Available dist functions are listed in TSPLIB_DOC.pdf. (Some may not be implemented in this package.)

Using a TSPLIB format file input

Using the TSPLIB format:

using LKH
opt_tour, opt_len = solve_tsp("gr17.tsp")

Passing solver parameters

In all cases, solver parameters are passed as keyword arguments.

opt_tour, opt_len = solve_tsp(M; INITIAL_TOUR_ALGORITHM="GREEDY", RUNS=5, TIME_LIMIT=10.0)

Usage for VRPs

For example, for the Capacitated Vehicle Routing Problem (CVRP):

using CVRPLIB, LKH
cvrp, vrp_file_path, solution_file_path = readCVRP("E-n101-k14")
@time opt_tour, opt_len = solve_tsp(vrp_file_path, TIME_LIMIT=1.0)

Related Projects

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.