-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathBenchmark.py
45 lines (33 loc) · 978 Bytes
/
Benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import abc
class Benchmark(abc.ABC):
@abc.abstractmethod
def goal(self, solution):
pass
@abc.abstractmethod
def mutate(self):
pass
@abc.abstractmethod
def mutates(self):
pass
@abc.abstractmethod
def apply(self, mutations):
pass
@abc.abstractmethod
def reach_go(self):
pass
@property
def current_solution(self):
return self._current_solution
@current_solution.setter
def current_solution(self, current_solution):
self._current_solution=current_solution
@staticmethod
def benchmark_factory(class_name, *args):
print(all_subclasses(Benchmark))
for cls in all_subclasses(Benchmark):
if cls.__name__.lower()==class_name.lower():
return cls(*args)
return None
def all_subclasses(cls):
return set(cls.__subclasses__()).\
union([s for c in cls.__subclasses__() for s in all_subclasses(c)])