iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Graph.Dense.TSP

Synopsis

Documentation

data TSPResult a Source #

Constructors

TSPResult 

Fields

runTSP Source #

Arguments

:: (Unbox w, Num w, Eq w, Ord w) 
=> w

inf (2 * inf <= maxBound)

-> DenseGraph w 
-> TSPResult w 

Traveling Salesman Problem

O(n^2 2^n)

>>> resultTSP . runTSP 0x3f3f3f3f $ fromListDG @Int [[0,1,999],[999,0,2],[4,999,0]]
7
>>> resultTSP . runTSP 0x3f3f3f3f $ fromListDG @Int [[0,1,1],[1,0,8],[1,999,0]]
10
>>> resultTSP . runTSP 0x3f3f3f3f $ fromListDG @Int [[0]]
0
>>> resultTSP . runTSP 999 $ fromListDG @Int [[0,-1,999],[999,0,1],[1,999,0]]
1
>>> resultTSP . runTSP 999 $ fromListDG @Int [[0,-1,999],[999,0,-1],[999,999,0]]
997

reconstructTSP :: (Unbox w, Num w, Eq w) => DenseGraph w -> TSPResult w -> Vector Int Source #

O(n^2)

>>> let gr = fromListDG @Int [[0,1,999],[999,0,2],[4,999,0]]
>>> reconstructTSP gr $ runTSP gr
[2,0,1,2]