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

Function test_cost

tests/test_CostEvaluator.py:123–143  ·  view source on GitHub ↗

This test asserts that the cost is computed correctly for feasible solutions, and is a large value (representing infinity) for infeasible solutions.

(ok_small)

Source from the content-addressed store, hash-verified

121
122
123def test_cost(ok_small):
124 """
125 This test asserts that the cost is computed correctly for feasible
126 solutions, and is a large value (representing infinity) for infeasible
127 solutions.
128 """
129 default_cost_evaluator = CostEvaluator([0], 0, 0)
130 cost_evaluator = CostEvaluator([20], 6, 0)
131
132 feas_sol = Solution(ok_small, [[1, 2], [3], [4]]) # feasible solution
133 distance = feas_sol.distance()
134
135 assert_equal(cost_evaluator.cost(feas_sol), distance)
136 assert_equal(default_cost_evaluator.cost(feas_sol), distance)
137
138 infeas_sol = Solution(ok_small, [[1, 2, 3, 4]]) # infeasible solution
139 assert_(not infeas_sol.is_feasible())
140
141 infeas_cost = np.iinfo(np.int64).max
142 assert_equal(cost_evaluator.cost(infeas_sol), infeas_cost)
143 assert_equal(default_cost_evaluator.cost(infeas_sol), infeas_cost)
144
145
146def test_cost_with_prizes(prize_collecting):

Callers

nothing calls this directly

Calls 5

distanceMethod · 0.95
costMethod · 0.95
CostEvaluatorClass · 0.90
SolutionClass · 0.90
is_feasibleMethod · 0.80

Tested by

no test coverage detected