Beispiel #1
0
 def test_Solver_solution_ex357_10(self):
     solver = Solver(self.ex357_equ_wt_candts, 10)
     solver.solve_branch_and_bound()
     expected = set([WeightProfitTuple(3,3), WeightProfitTuple(7,7)])
     actual = set(solver.solution)
     #actual = set(solver._current_best_solution)
     self.assertEqual(expected, actual)
Beispiel #2
0
 def test_Solver_branch_13(self):
     new_candidates = [WeightProfitTuple(5,5),
                       WeightProfitTuple(3,3),
                       WeightProfitTuple(7,7)]
     solver = Solver(new_candidates, 13)
     solver.solve_branch_and_bound()
     # The current best solution should have been updated.
     expected = set([WeightProfitTuple(5,5),
                     WeightProfitTuple(7,7)])
     actual = set(solver._current_best_solution)
     self.assertEqual(expected, actual)
Beispiel #3
0
 def test_Solver_branch_10_5(self):
     solver = Solver(self.ex357_equ_wt_candts, 10)
     solver._current_best_solution = [WeightProfitTuple(7,7)]
     total_weight_so_far = 10
     total_profit_so_far = 10
     items_so_far = [WeightProfitTuple(7,7)]
     remaining_candidates = [WeightProfitTuple(5,5)]
     solver.branch(total_weight_so_far, total_profit_so_far, items_so_far,
                   remaining_candidates)
     # The current best solution should not have been updated.
     expected = set([WeightProfitTuple(7,7)])
     actual = set(solver._current_best_solution)
     self.assertEqual(expected, actual)
Beispiel #4
0
 def test_Solver_empty_solution(self):
     solver = Solver(self.ex357_equ_wt_candts, 2)
     solver.solve_branch_and_bound()
     expected = []
     actual = solver.solution
     self.assertEqual(expected, actual)
Beispiel #5
0
 def test_Solver(self):
     assert Solver(self.ex357_equ_wt_candts, 10) is not None