MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_distance_calculation

Function test_distance_calculation

tests/test_Solution.py:409–433  ·  view source on GitHub ↗

Tests that route distance calculations are correct, and that the overall Solution's distance is the sum of the route distances.

(ok_small)

Source from the content-addressed store, hash-verified

407
408
409def test_distance_calculation(ok_small):
410 """
411 Tests that route distance calculations are correct, and that the overall
412 Solution's distance is the sum of the route distances.
413 """
414 sol = Solution(ok_small, [[1, 2], [3], [4]])
415 routes = sol.routes()
416
417 # Solution is feasible, so all its routes should also be feasible.
418 assert_(sol.is_feasible())
419 assert_(all(route.is_feasible() for route in routes))
420
421 # Solution distance should be equal to all routes' distances. These we
422 # check separately.
423 assert_equal(sol.distance(), sum(route.distance() for route in routes))
424
425 distances = ok_small.distance_matrix(profile=0)
426 expected = distances[0, 1] + distances[1, 2] + distances[2, 0]
427 assert_equal(routes[0].distance(), expected)
428
429 expected = distances[0, 3] + distances[3, 0]
430 assert_equal(routes[1].distance(), expected)
431
432 expected = distances[0, 4] + distances[4, 0]
433 assert_equal(routes[2].distance(), expected)
434
435
436def test_excess_load_calculation(ok_small):

Callers

nothing calls this directly

Calls 4

distanceMethod · 0.95
SolutionClass · 0.90
is_feasibleMethod · 0.80
distanceMethod · 0.45

Tested by

no test coverage detected