pycellga.problems.single_objective.discrete.permutation package

Submodules

pycellga.problems.single_objective.discrete.permutation.tsp module

class pycellga.problems.single_objective.discrete.permutation.tsp.Tsp[source]

Bases: AbstractProblem

Represents the Traveling Salesman Problem (TSP).

This class solves the TSP using geographical distances (GEO) for node coordinates.

Notes

#### burma14.tsp ######################################## # EDGE_WEIGHT_TYPE: GEO, use gographical_dist function # Length of chromosomes = 14 # Known Best Route = [] # Minumum Fitness Value = 3323 #########################################################

euclidean_dist(a: list, b: list) float[source]

Computes the Euclidean distance between two nodes.

Parameters:
  • a (list) – Coordinates of the first node.

  • b (list) – Coordinates of the second node.

Returns:

The Euclidean distance between the two nodes, rounded to one decimal place.

Return type:

float

f(x: list) float[source]

Evaluates the fitness of a given chromosome (route) for the TSP.

This method calculates the total distance of the given route using geographical distances.

Parameters:

x (list) – A list representing the route (chromosome), where each element is a node index.

Returns:

The total distance of the route, rounded to one decimal place.

Return type:

float

gographical_dist(a: list, b: list) float[source]

Computes the geographical distance between two nodes using the geodesic distance.

Parameters:
  • a (list) – Coordinates of the first node.

  • b (list) – Coordinates of the second node.

Returns:

The geographical distance between the two nodes, rounded to one decimal place.

Return type:

float

Module contents