コード例 #1
0
 def test_5(self):
     values_bank = [60, 100, 120, 100, 80]
     weights_bank = [10, 20, 30, 50, 80]
     max_weight = 200
     bank = ManualBank()
     bank.setup(values_bank, weights_bank)
     values_greedy_solution = [60, 100, 120, 100, 80]
     weights_greedy_solution = [10, 20, 30, 50, 80]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight, knapsack_alg='greedy')
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_greedy_solution, weights_greedy_solution))
コード例 #2
0
 def test_2(self):
     values_bank = [60, 100, 120]
     weights_bank = [10, 20, 30]
     max_weight = np.infty  # carry as much as you want
     bank = ManualBank()
     bank.setup(values_bank, weights_bank)
     values_greedy_solution = values_bank
     weights_greedy_solution = weights_bank
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight, knapsack_alg='greedy')
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_greedy_solution, weights_greedy_solution))
コード例 #3
0
 def test_6(self):
     values_bank = [10, 100, 120, 100, 80]
     weights_bank = [10, 20, 30, 50, 80]
     max_weight = 120
     bank = ManualBank()
     bank.setup(values_bank, weights_bank)
     values_solution = [10, 100, 120, 100]
     weights_solution = [10, 20, 30, 50]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight, knapsack_alg=method)
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_solution, weights_solution))
コード例 #4
0
 def test_6(self):
     values_bank = [10, 100, 120, 100, 80]
     weights_bank = [10, 20, 30, 50, 80]
     max_weight = 120
     bank = ManualBank()
     bank.setup(values_bank, weights_bank)
     values_solution = [10, 100, 120, 100]
     weights_solution = [10, 20, 30, 50]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight,
                                              knapsack_alg=method)
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_solution, weights_solution))
コード例 #5
0
 def test_2(self):
     values_bank = [60, 100, 120]
     weights_bank = [10, 20, 30]
     max_weight = np.infty  # carry as much as you want
     bank = ManualBank()
     bank.setup(values_bank, weights_bank)
     values_solution = values_bank
     weights_solution = weights_bank
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight,
                                              knapsack_alg=method)
     self.assertCountEqual(zip(values_robbed, weights_robbed),
                           zip(values_solution, weights_solution))
コード例 #6
0
 def test_5(self):
     values_bank = [60, 100, 120, 100, 80]
     weights_bank = [10, 20, 30, 50, 80]
     max_weight = 200
     bank = ManualBank()
     bank.setup(values_bank, weights_bank)
     values_greedy_solution = [60, 100, 120, 100, 80]
     weights_greedy_solution = [10, 20, 30, 50, 80]
     values_robbed, weights_robbed = bank.rob(max_weight=max_weight,
                                              knapsack_alg='greedy')
     self.assertCountEqual(
         zip(values_robbed, weights_robbed),
         zip(values_greedy_solution, weights_greedy_solution))