File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 11import random
2- from functools import reduce
2+ from datarepresentation . movie import Movie
33
44
55class Solution :
@@ -13,12 +13,15 @@ def __str__(self):
1313 for s in self .solution :
1414 res += str (s .ids ) + "->["
1515 for m in self .solution [s ]:
16- res += str (m )
16+ res += str (m ) + " "
1717 res += "], "
1818 return res
1919
2020 def random_neighbour (self , radius ):
2121
22+ if radius == 0 :
23+ return self
24+
2225 acceptable_ops = [(s , f )
2326 for s in self .data .servers
2427 for f in self .data .movies
@@ -27,7 +30,14 @@ def random_neighbour(self, radius):
2730 op = random .choice (acceptable_ops )
2831 s = op [0 ]
2932 f = op [1 ]
30- return self .solution [s ].remove (f ) if f in self .solution [s ] else self .solution [s ].append (f )
33+
34+ res = Solution (self .data , self .solution )
35+ if f in self .solution [s ]:
36+ res .solution [s ].remove (f )
37+ else :
38+ res .solution [s ].append (f )
39+
40+ return res .random_neighbour (radius - 1 )
3141
3242 def free_space (self , server ):
3343 return 899 - sum ([f .size for f in self .solution [server ]])
You can’t perform that action at this time.
0 commit comments