-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluator.py
More file actions
47 lines (37 loc) · 1.88 KB
/
evaluator.py
File metadata and controls
47 lines (37 loc) · 1.88 KB
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
45
46
47
from __future__ import annotations
from typing import Callable
from allocatorunit import AllocatorUnit
#----------------------------------------------------------------------------------------
def avg_slots(ind: AllocatorUnit) -> float:
return ind.get_avg_slot_num()
#----------------------------------------------------------------------------------------
def max_slots(ind: AllocatorUnit) -> int:
return ind.get_max_slot_num()
#----------------------------------------------------------------------------------------
def edges(ind: AllocatorUnit) -> int:
return ind.get_total_communication_flow_edges()
#----------------------------------------------------------------------------------------
def boards(ind: AllocatorUnit) -> int:
return ind.board_num_to_be_routed()
#----------------------------------------------------------------------------------------
def avg_hops(ind: AllocatorUnit) -> float:
return ind.average_hops()
#----------------------------------------------------------------------------------------
class Evaluator:
__funcs: list[tuple[str, Callable[[AllocatorUnit], float | int], float]] = [
('avg # of slots', avg_slots, -1.0),
("# of flows' edges", edges, -1.0),
('# of routed bords', boards, -1.0)
]
##-----------------------------------------------------------------------------------
@classmethod
def eval_list(cls) -> list[str]:
return [func[0] for func in cls.__funcs]
##-----------------------------------------------------------------------------------
@classmethod
def evaluate(cls, individual: AllocatorUnit) -> list[float | int]:
return [func[1](individual) for func in cls.__funcs]
##-----------------------------------------------------------------------------------
@classmethod
def weights(cls) -> tuple[float]:
return tuple(func[2] for func in cls.__funcs)