Giter Club home page Giter Club logo

cpp-triang-tsp's Introduction

C++ TSP library

This library includes C++ implementation of different algs for computing triangulations and TSP approximations.

There are in fact 3 libraries: geometry, triangulation computing, TSP approximations computing.

Examples

Triangulation

triang

TSP tour (Cheapest edges approximation)

tsp

MST (based on the trianguation)

mst

Algorithms

  1. Bowyer-Watson algorithm for computing Delaunay Triangulation.
  2. Cheapest Link Algorithm
  3. Kruskal's Algorithm
  4. 2-approximation algorithm.
  5. Cheapest Edges + DFS approximation.
  6. Delaunay Triangulation + Iterative Point Addition

Performance

Name Result Time Memory Optimality
B-W Triangulation O(VlogV) O(VlogV) Optimal
CLA (pointset) TSP tour O(VlogV) O(V^2) 1.5 Optimal
Kruskal (pointset) MST O(VlogV) O(V^2) Optimal
2-approximation (pointset) TSP tour O(VlogV) O(V^2) 2 Optimal
2-approximation (triangulation) TSP tour O(VlogV) O(VlogV) ?
CE + DFS TSP tour O(VlogV) O(VlogV) ?
DT + IPA TSP tour O(VlogV) O(VlogV) ?

Usage

The library works with text files.

input.txt (coordinates of points)

316.83673906150904 2202.34070733524
4377.40597216624 336.602082171235
3454.15819771172 2820.0530112481106
4688.099297634771 2935.89805580997
1010.6969517482901 3236.75098902635
...

Triangulation

main.cpp

#include "triangulation.h"
#include "geometry.h"

using namespace std;

int main() {
    BowyerWatson bw;
    // reading points from a file with coordinates
    bw.fromCoords("input.txt");
    // computing the triangulation
    bw.compute();
    // writing to a file
    bw.toEdges("triang.txt");
}

triang.txt (edges of triangulation; each number represents a point according to the input sequence)

197338 88708
88708 20109
88708 12785
88708 123994
88708 123616
...

TSP

main.cpp

#include "geometry.h"
#include "tsp.h"
#include <bits/stdc++.h>

using namespace std;

int main()
{
    // read coordinates from file
    vector<Point> coords = toPoints("input.txt");
    TSP tsp(toEdges("triang.txt", coords, 3));
    // creating an edge subset for faster solution finding
    tsp.toSmallestEdges();
    // computing the tour
    tsp.fromMST();
    // writing to file
    tsp.toFile("output.txt");
    return 0;
}

output.txt (resulting tour)

0
78934
111804
52086
18295
...

References and inspirations

  1. Bowyer-Watson algorithm and improvements: http://www.gdmc.nl/publications/2002/Bowyer_Watson_algorithm.pdf
  2. O(nlogn) Euristic for Eucledian TSP: https://www.researchgate.net/publication/215753374_An_On_log_n_Heuristic_for_the_Euclidean_Traveling_Salesman_Problem
  3. Images are generated from a dataset from this Kaggle competition.

cpp-triang-tsp's People

Stargazers

 avatar  avatar

Watchers

 avatar

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.