Ejemplo n.º 1
0
 def test_1(self):
     value = 100
     purities = [100, 50, 25, 20, 10, 5]
     random.shuffle(purities)  # the order should not matter
     max_weight = np.infty
     bank = SameValuesBank()
     bank.setup(value=value, purities=purities)
     values_solution = bank.values
     weights_solution = bank.weights
     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))
Ejemplo n.º 2
0
 def test_2(self):
     value = 100
     purities = [100, 50, 25, 20, 10, 5]
     random.shuffle(purities)  # the order should not matter
     max_weight = 1
     bank = SameValuesBank()
     bank.setup(value=value, purities=purities)
     values_greedy_solution = [100]
     weights_greedy_solution = [1]
     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))
Ejemplo n.º 3
0
 def test_1(self):
     value = 100
     purities = [100, 50, 25, 20, 10, 5]
     random.shuffle(purities)  # the order should not matter
     max_weight = np.infty
     bank = SameValuesBank()
     bank.setup(value=value, purities=purities)
     values_solution = bank.values
     weights_solution = bank.weights
     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))
Ejemplo n.º 4
0
 def test_7(self):
     value = 100
     purities = [100, 50, 25, 20, 10, 5]
     random.shuffle(purities)  # the order should not matter
     max_weight = 45
     bank = SameValuesBank()
     bank.setup(value=value, purities=purities)
     values_greedy_solution = [value, value, value, value, value, value]
     weights_greedy_solution = [1, 2, 4, 5, 10, 20]
     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))