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

Function test_data_warns_about_scaling_issues

tests/test_Model.py:438–460  ·  view source on GitHub ↗

Tests that the modelling interface warns when an edge is added whose distance or duration values are too large. This situation is likely caused by scaling issues, so a warning is appropriate.

(recwarn)

Source from the content-addressed store, hash-verified

436
437
438def test_data_warns_about_scaling_issues(recwarn):
439 """
440 Tests that the modelling interface warns when an edge is added whose
441 distance or duration values are too large. This situation is likely caused
442 by scaling issues, so a warning is appropriate.
443 """
444 model = Model()
445 model.add_vehicle_type(capacity=0, num_available=1)
446 depot = model.add_depot(0, 0)
447 client = model.add_client(1, 1)
448
449 # Normal distance sizes; should all be OK.
450 for distance in [1, 10, 100, 1_000, 10_000, 100_000, MAX_VALUE]:
451 model.add_edge(client, depot, distance=distance)
452 assert_equal(len(recwarn), 0)
453
454 # But a value exceeding the maximum value is not OK. This should warn (both
455 # for distance and/or duration).
456 with pytest.warns(ScalingWarning):
457 model.add_edge(depot, client, distance=MAX_VALUE + 1)
458
459 with pytest.warns(ScalingWarning):
460 model.add_edge(depot, client, distance=0, duration=MAX_VALUE + 1)
461
462
463def test_model_solves_instance_with_zero_or_one_clients():

Callers

nothing calls this directly

Calls 5

add_vehicle_typeMethod · 0.95
add_depotMethod · 0.95
add_clientMethod · 0.95
add_edgeMethod · 0.95
ModelClass · 0.90

Tested by

no test coverage detected