Skip to main content

This package(Christofides) provides a way to implement Christofides algorithm for solving Travelling Saleman Problem(TSP) to obtain an approximate solution on an undirected graph(Distance Matrix) provided as an upper Triangular matrix. The Distance from a node on to itself is assumed 0.

Usage

Use the compute() function which takes as input a distance_matrix and returns a Christofides solution as follows:

from Christofides import christofides
TSP = christofides.compute(distance_matrix)

or:

import Christofides
TSP = Christofides.christofides.compute(distance_matrix)

The Distance Matrix is an upper Triangular matrix with distance from a node on to itself 0, since Christofides algorithm could only be applied for undirected graphs. Also the distance between a node on to itself is practically 0. Example for distance_matrix is as follows, distance_matrix =

[[0,45,65,15],
 [0,0,56,12],
 [0,0,0,89],
 [0,0,0,0]]

The above distance_matrix should be provided as an input to christofides.compute(), when we want to calculate TSP for distance =

[[0,45,65,15],
[45,0,56,12],
[65,56,0,89],
[15,12,89,0]]
christofides.compute(distance_matrix) returns a Dictionary with following Keys:

Christofides_Solution, Travel_Cost, MST, Odd_Vertices Indexes, Multigraph, Euler_Tour

  • Christofides_Solution: A list consisting of approximate tour for TSP.

    Use: TSP[‘Chistofides_Solution’]

  • Travel_Cost: The cost of TSP tour generated.

    Use: TSP[‘Travel_Cost’]

  • MST: The minimum spanning tree generated during the Christofides algorithm.

    Use: TSP[‘MST’]

  • Odd_Vertices: A list of odd vertices of minimum spanning tree.

    Use: TSP[‘Odd_Vertices’]

  • Indexes: List of edges from minimum cost perfect matching of odd vertices.

    Use: TSP[‘Indexes’]

  • Multigraph: Edges of multigraph formed after Indexing.

    Use: TSP[‘Multigraph’]

  • Euler_Tour: The Euler Tour of the Multigraph.

    Use: TSP[‘Euler_Tour’]

Support Functions in christofides

  • _csr_gen_triples(csr_matrix)

  • _odd_vertices_of_MST(distance_matrix, number_of_nodes)

  • min_Munkres(distance_matrix, bipartitie_graphs)

  • Munkres_cost(indexes, bipartite_graph)

  • bipartite_Graph(distance_matrix, bipartite_set, odd_vertices)

  • create_Multigraph(distance_matrix, MST, indexes, odd_vertices)

  • Euler_Tour(multigraph)

  • shortcut_Euler_Tour(tour)

  • cost(christofides_tour, distance_matrix)

Install

python setup.py install

Additional Packages

scipy, numpy, networkx, munkres

Metadata

Release files for Christofides 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Christofides 1.0.1
File Size Uploaded
Christofides-1.0.1.tar.gz 5.8 kB Details

Release files / Christofides-1.0.1.tar.gz

Download URL Christofides-1.0.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
411696f665cdffec63e709f3f4cd4338fd2014ffd5420f4ba1bfb5aca94dafd6
BLAKE2b-256 checksum
How to use checksums
0f6e93158e316b513d06515442cebdf096b7ad13e6b4204f0cf0950f8279f3ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

0.2.0

0.1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page