This test asserts that the cost is computed correctly for feasible solutions, and is a large value (representing infinity) for infeasible solutions.
(ok_small)
| 121 | |
| 122 | |
| 123 | def 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 | |
| 146 | def test_cost_with_prizes(prize_collecting): |
nothing calls this directly
no test coverage detected