| | import networkx as nx |
| | import json |
| | from typing import Dict, List |
| |
|
| |
|
| | class SingleDstPath(Dict): |
| | partition: int |
| | edges: List[List] |
| |
|
| |
|
| | class BroadCastTopology: |
| | def __init__(self, src: str, dsts: List[str], num_partitions: int = 4, paths: Dict[str, SingleDstPath] = None): |
| | self.src = src |
| | self.dsts = dsts |
| | self.num_partitions = num_partitions |
| |
|
| | |
| | |
| | if paths is not None: |
| | self.paths = paths |
| | self.set_graph() |
| | else: |
| | self.paths = {dst: SingleDstPath().fromkeys(range(num_partitions)) for dst in dsts} |
| |
|
| | def get_paths(self): |
| | print(f"now the set path is: {self.paths}") |
| | return self.paths |
| |
|
| | def set_num_partitions(self, num_partitions: int): |
| | self.num_partitions = num_partitions |
| |
|
| | def set_dst_partition_paths(self, dst: str, partition: int, paths: List[List]): |
| | """ |
| | Set paths for partition = partition to reach dst |
| | """ |
| | partition = str(partition) |
| | self.paths[dst][partition] = paths |
| |
|
| | def append_dst_partition_path(self, dst: str, partition: int, path: List): |
| | """ |
| | Append path for partition = partition to reach dst |
| | """ |
| | partition = str(partition) |
| | if self.paths[dst][partition] is None: |
| | self.paths[dst][partition] = [] |
| | self.paths[dst][partition].append(path) |
| |
|