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

Function test_partial_distance_duration_matrix

tests/test_Model.py:408–435  ·  view source on GitHub ↗

Tests that adding a full distance or duration matrix is not required. Any "missing" arcs are given default values.

(missing_value)

Source from the content-addressed store, hash-verified

406
407@pytest.mark.parametrize("missing_value", [5, 100, MAX_VALUE, MAX_VALUE + 1])
408def test_partial_distance_duration_matrix(missing_value):
409 """
410 Tests that adding a full distance or duration matrix is not required. Any
411 "missing" arcs are given default values.
412 """
413 model = Model()
414 model.add_vehicle_type()
415
416 depot = model.add_depot(0, 0)
417 clients = [model.add_client(0, 1), model.add_client(1, 0)]
418
419 # Only a subset of all possible edges exist. The model should be able to
420 # handle that.
421 model.add_edge(depot, clients[0], distance=1)
422 model.add_edge(clients[0], clients[1], distance=2)
423 model.add_edge(clients[1], depot, distance=1)
424
425 # Edges that were not explicitly set should default to the missing value
426 # argument, or MAX_VALUE, whichever is smaller.
427 data = model.data(missing_value)
428 distances = data.distance_matrix(profile=0)
429 assert_equal(distances[0, 2], min(missing_value, MAX_VALUE))
430 assert_equal(distances[1, 0], min(missing_value, MAX_VALUE))
431
432 res = model.solve(MaxIterations(100), seed=4, missing_value=missing_value)
433 assert_equal(res.best.num_routes(), 1)
434 assert_equal(res.cost(), 4) # depot -> client 1 -> client 2 -> depot
435 assert_(res.is_feasible())
436
437
438def test_data_warns_about_scaling_issues(recwarn):

Callers

nothing calls this directly

Calls 10

add_vehicle_typeMethod · 0.95
add_depotMethod · 0.95
add_clientMethod · 0.95
add_edgeMethod · 0.95
dataMethod · 0.95
solveMethod · 0.95
ModelClass · 0.90
MaxIterationsClass · 0.90
is_feasibleMethod · 0.80
costMethod · 0.45

Tested by

no test coverage detected