MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / distance

Function distance

graphs/ant_colony_optimization_algorithms.py:102–112  ·  view source on GitHub ↗

Calculate the distance between two coordinate points >>> distance([0, 0], [3, 4] ) 5.0 >>> distance([0, 0], [-3, 4] ) 5.0 >>> distance([0, 0], [-3, -4] ) 5.0

(city1: list[int], city2: list[int])

Source from the content-addressed store, hash-verified

100
101
102def distance(city1: list[int], city2: list[int]) -> float:
103 """
104 Calculate the distance between two coordinate points
105 >>> distance([0, 0], [3, 4] )
106 5.0
107 >>> distance([0, 0], [-3, 4] )
108 5.0
109 >>> distance([0, 0], [-3, -4] )
110 5.0
111 """
112 return (((city1[0] - city2[0]) ** 2) + ((city1[1] - city2[1]) ** 2)) ** 0.5
113
114
115def pheromone_update(

Callers 2

pheromone_updateFunction · 0.70
city_selectFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected