@@ -8,7 +8,8 @@ class AlgorithmUtils:
88 def random_solution (data ):
99 res = dict ()
1010 for ids in range (data .amount_of_cache_servers ):
11- res [ids ] = [0 ]
11+ random_video = random .randint (0 , len (data .videos_sizes )- 1 )
12+ res [ids ] = [random_video ] if data .videos_sizes [random_video ] <= data .cache_size else []
1213 return res
1314
1415 @staticmethod
@@ -18,7 +19,7 @@ def print_solution_pool(pool):
1819 @staticmethod
1920 def random_neighbour (data , solution , radius ):
2021
21- res = solution . copy ( )
22+ res = AlgorithmUtils . solution_copy ( solution )
2223 if radius == 0 :
2324 return res
2425
@@ -43,9 +44,19 @@ def best_in_neighbourhood(data, solution, radius, number_of_bees):
4344 neighbours = []
4445 for _ in range (number_of_bees ):
4546 neighbours .append (AlgorithmUtils .random_neighbour (data , solution , radius ))
46- best_neighbour = min (neighbours , key = lambda s : calculate_score (data , s ))
47- return best_neighbour if calculate_score (data , best_neighbour ) < calculate_score (data , solution ) else solution
47+ best_neighbour = max (neighbours , key = lambda s : calculate_score (data , s ))
48+ return best_neighbour if calculate_score (data , best_neighbour ) > calculate_score (data , solution ) else solution
4849
4950 @staticmethod
5051 def free_space (data , server , solution ):
51- return 999
52+ res = data .cache_size
53+ for v in solution [server ]:
54+ res -= data .videos_sizes [v ]
55+ return res
56+
57+ @staticmethod
58+ def solution_copy (solution ):
59+ res = dict ()
60+ for s in solution :
61+ res [s ] = solution [s ][:]
62+ return res
0 commit comments