Coder Social home page Coder Social logo

astrodynamic / classical-tsp-in-postgresql Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 3 KB

This project solves the classical Traveling Salesman Problem (TSP) using PostgreSQL. It creates a table of cities with associated costs and finds the cheapest route that visits all cities and returns to the starting point.

License: MIT License

database graph learning optimization postgresql recursive-queries routing-algorithm travelling-salesman-problem tsp tsp-problem tsp-solver

classical-tsp-in-postgresql's Introduction

Classical TSP in Postgresql

This project focuses on solving the classical Traveling Salesman Problem (TSP) using PostgreSQL. The goal is to find the cheapest route that visits all cities and returns to the starting point.

Exercise 00: Classical TSP

Turn-in Directory

ex00

Files to Turn-in

  • ex00.sql: DDL for table creation with INSERTs of data; SQL DML statement

Allowed

  • Language: ANSI SQL
  • SQL Syntax Pattern: Recursive Query

Problem Description

Please refer to the graph on the left. It represents four cities (a, b, c, and d) connected by arcs with associated costs (or taxation). The cost between cities (a,b) is equal to the cost between (b,a).

Your task is to create a table named "nodes" with the following structure: {point1, point2, cost}. Fill the table with data based on the given picture, considering both direct and reverse paths between two nodes.

Write a single SQL statement that returns all tours (paths) with the minimum traveling cost if we start from city "a". The tours should be sorted by total_cost and then by tour.

Example output data:

total_cost | tour
-----------+-----------------
80         | {a,b,d,c,a}
...        | ...

Exercise 01: Opposite TSP

Turn-in Directory

ex01

Files to Turn-in

  • ex01.sql: SQL DML statement

Allowed

  • Language: ANSI SQL
  • SQL Syntax Pattern: Recursive Query

Problem Description

In this exercise, you need to modify the SQL query from the previous exercise to include additional rows with the highest cost. The sample output data below demonstrates the expected result, sorted by total_cost and then by tour.

Example output data:

total_cost | tour
-----------+-----------------
80         | {a,b,d,c,a}
...        | ...
95         | {a,d,c,b,a}

classical-tsp-in-postgresql's People

Contributors

astrodynamic avatar

Watchers

 avatar  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.