def run_test(self, combinations: List = None): for combination in combinations: # origin method solver: Solver = Solver( nx_graph=self.graph, flows=self.flows[:], topo_strategy=None, routing_strategy=combination['routing_strategy'], scheduling_strategy=combination['scheduling_strategy'], allocating_strategy=combination['allocating_strategy'], reliability_strategy=combination['reliability_strategy']) self.solution = solver.generate_init_solution() solver.draw_gantt_chart(self.solution) # draw gantt chart solution_name: str = self.solution.generate_solution_name( prefix='b_n4_f10_') solver.save_solution(solution=self.solution) # save solution # create network tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename=solution_name, enhancement_enable=config. XML_CONFIG['enhancement-tsn-switch-enable']) self.tsn_network = tsn_network self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info # create test scenario ConfigFileGenerator.create_test_scenario( tsn_network=self.tsn_network, solution=self.solution, node_edge_mac_info=self.node_edge_mac_info)
def test_flow_size(self, topo_strategy_entities: List, combinations: List = None): for topo_strategy_entity in topo_strategy_entities: # set topology strategy self.topo_generator.topo_strategy = TopoStrategyFactory.get_instance( **topo_strategy_entity) # generate topology graph: nx.Graph = self.topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG['edge-node-num'] attached_edge_nodes: List[ NodeId] = self.topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) self.topo_generator.draw(graph) # generate flows flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_edge_nodes, graph=graph, flow_num=config.TESTING['flow-size'][1]) for combination in combinations: for i in range(config.TESTING['flow-size'][0], config.TESTING['flow-size'][1] + 1, config.TESTING['x-axis-gap']): solver: Solver = Solver( nx_graph=graph, flows=flows[:i], topo_strategy=topo_strategy_entity['strategy'], routing_strategy=combination['routing_strategy'], scheduling_strategy=combination['scheduling_strategy'], allocating_strategy=combination['allocating_strategy'], reliability_strategy=combination[ 'reliability_strategy']) # origin method solution = solver.generate_init_solution( ) # get initial solution solution.generate_solution_name( prefix='b_fz_t{}_n{}_'.format( self.test_round, len(solution.graph.nodes))) Analyzer.analyze_flow_size(solution, target_filename=os.path.join( config.flow_size_res_dir, solution.solution_name)) # solution.generate_solution_name( # prefix='b_fz_t{}_n{}_f{}_'.format(self.test_round, len(solution.graph.nodes), i)) # Analyzer.analyze_flow_routes_repetition_degree( # solution, # target_filename=os.path.join(config.flow_routes_repetition_degree_dir, # solution.solution_name)) # optimized method if config.OPTIMIZATION['enable'] is False: continue solution = solver.optimize() # optimize solution.generate_solution_name( prefix='o_fz_t{}_n{}_'.format( self.test_round, len(solution.graph.nodes))) Analyzer.analyze_flow_size(solution, target_filename=os.path.join( config.flow_size_res_dir, solution.solution_name))
def setUp(self): edges: List[Tuple[int, int]] = [(1, 5), (2, 6), (3, 8), (4, 11), (5, 6), (5, 9), (6, 7), (7, 9), (7, 8), (8, 9), (8, 11), (9, 10), (10, 11)] self.graph: nx.Graph = nx.Graph() self.graph.add_edges_from(edges) self.graph = self.graph.to_directed() TopoGenerator.draw(self.graph) config.TESTING['generate-flow'] = True # whether enable flow generation or not config.FLOW_CONFIG['reliability-set'] = [0.5] config.FLOW_CONFIG['redundancy_degree'] = 2 if config.TESTING['generate-flow']: attached_nodes: List[NodeId] = [1, 2, 3, 4] config.FLOW_CONFIG['dest-num-set'] = [1, 2, 3] config.FLOW_CONFIG['flow-num'] = 10 self.flows: List[Flow] = FlowGenerator.generate_flows(edge_nodes=attached_nodes, graph=self.graph) FlowGenerator.save_flows(self.flows) else: self.flows: List[Flow] = FlowGenerator.load_flows() config.FLOW_CONFIG['redundancy_degree'] = 5 config.GRAPH_CONFIG['routing_strategy'] = ROUTING_STRATEGY.BACKTRACKING_REDUNDANT_ROUTING_STRATEGY # config.GRAPH_CONFIG['routing_strategy'] = ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY config.GRAPH_CONFIG['scheduling_strategy'] = SCHEDULING_STRATEGY.LRF_REDUNDANT_SCHEDULING_STRATEGY config.GRAPH_CONFIG['allocating_strategy'] = ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY config.GRAPH_CONFIG['reliability-strategy'] = RELIABILITY_STRATEGY.ENUMERATION_METHOD_RELIABILITY_STRATEGY solver: Solver = Solver(nx_graph=self.graph, flows=self.flows, topo_strategy=None, routing_strategy=config.GRAPH_CONFIG['routing_strategy'], scheduling_strategy=config.GRAPH_CONFIG['scheduling_strategy'], allocating_strategy=config.GRAPH_CONFIG['allocating_strategy'], reliability_strategy=config.GRAPH_CONFIG['reliability-strategy']) self.solution = solver.generate_init_solution() solver.draw_gantt_chart(self.solution) # draw gantt chart solution_name: str = solver.generate_solution_name(solution=self.solution, prefix='n7_f10_r6_') import os filename: str = os.path.join(config.res_dir, solution_name) solver.analyze(solution=self.solution, target_filename=filename) # analyze solution config.OPTIMIZATION['enable'] = False if config.OPTIMIZATION['enable'] is True: # optimized method self.solution = solver.optimize() # optimize solver.draw_gantt_chart(self.solution) # draw gantt chart solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='o_n7_f10_r5_') filename: str = os.path.join(config.res_dir, solution_name) solver.analyze(solution=self.solution, target_filename=filename) solver.save_solution(solution=self.solution) # save solution tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename=solution_name, enhancement_enable=config.XML_CONFIG['enhancement-tsn-switch-enable']) self.tsn_network = tsn_network self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info
def test_routing_strategy(self): solver: Solver = Solver( nx_graph=self.graph, flows=self.flows, topo_strategy=None, routing_strategy=ROUTING_STRATEGY. BACKTRACKING_REDUNDANT_ROUTING_STRATEGY, scheduling_strategy=SCHEDULING_STRATEGY. LRF_REDUNDANT_SCHEDULING_STRATEGY, allocating_strategy=ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY, reliability_strategy=RELIABILITY_STRATEGY. ENUMERATION_METHOD_RELIABILITY_STRATEGY) self.solution = solver.generate_init_solution()
def test_allocation_methods(self, topo_strategy_entities: List, combinations: List = None): for topo_strategy_entity in topo_strategy_entities: for i in range(config.GRAPH_CONFIG['core-node-num'][0], config.GRAPH_CONFIG['core-node-num'][1] + 1, config.TESTING['x-axis-gap']): # set topology strategy topo_strategy_entity['n'] = i self.topo_generator.topo_strategy = TopoStrategyFactory.get_instance(**topo_strategy_entity) # generate topology graph: nx.Graph = self.topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG['edge-node-num'] attached_edge_nodes: List[NodeId] = self.topo_generator.attach_edge_nodes(graph, attached_edge_nodes_num) # self.topo_generator.draw(graph) # generate flows flows: List[Flow] = FlowGenerator.generate_flows(edge_nodes=attached_edge_nodes, graph=graph, flow_num=config.TESTING['flow-size'][1]) for combination in combinations: solver: Solver = Solver(nx_graph=graph, flows=flows, topo_strategy=topo_strategy_entity['strategy'], routing_strategy=combination['routing_strategy'], scheduling_strategy=combination['scheduling_strategy'], allocating_strategy=combination['allocating_strategy'], reliability_strategy=combination['reliability_strategy']) # origin method solution = solver.generate_init_solution() # get initial solution solution.generate_solution_name( prefix='b_gz_t{}_f{}_'.format(self.test_round, len(flows))) Analyzer.analyze_flow_size( solution, target_filename=os.path.join(config.graph_size_res_dir, solution.solution_name)) if config.TESTING['draw-gantt-chart'] is True: solver.draw_gantt_chart(solution) logger.info('Native Objective: ' + str(solver.objective_function(solution))) # optimized method if config.OPTIMIZATION['enable'] is False or \ combination['allocating_strategy'] == ALLOCATING_STRATEGY.AEAPBF_ALLOCATING_STRATEGY or \ combination['allocating_strategy'] == ALLOCATING_STRATEGY.AEAPWF_ALLOCATING_STRATEGY or \ combination['routing_strategy'] == ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY: continue solution = solver.optimize() # optimize solution.generate_solution_name( prefix='o_gz_t{}_f{}_'.format(self.test_round, len(flows))) Analyzer.analyze_flow_size( solution, target_filename=os.path.join(config.graph_size_res_dir, solution.solution_name)) if config.TESTING['draw-gantt-chart'] is True: solver.draw_gantt_chart(solution) logger.info('Optimal Objective: ' + str(solver.objective_function(solution)))
def setUp(self): edges: List[Tuple[int, int]] = [(1, 2), (2, 3), (2, 4), (3, 4), (3, 5), (4, 5), (3, 8), (5, 6), (5, 7)] self.graph: nx.Graph = nx.Graph() self.graph.add_edges_from(edges) self.graph = self.graph.to_directed() TopoGenerator.draw(self.graph) config.TESTING[ 'generate-flow'] = False # whether enable flow generation or not if config.TESTING['generate-flow']: attached_nodes: List[NodeId] = [1, 6, 7, 8] config.FLOW_CONFIG['dest-num-set'] = [1, 2, 3] config.FLOW_CONFIG['flow-num'] = 5 self.flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_nodes, graph=self.graph) FlowGenerator.save_flows(self.flows) else: self.flows: List[Flow] = FlowGenerator.load_flows() config.GRAPH_CONFIG[ 'routing_strategy'] = ROUTING_STRATEGY.BACKTRACKING_REDUNDANT_ROUTING_STRATEGY # config.GRAPH_CONFIG['routing_strategy'] = ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY config.GRAPH_CONFIG[ 'scheduling_strategy'] = SCHEDULING_STRATEGY.LRF_REDUNDANT_SCHEDULING_STRATEGY config.GRAPH_CONFIG[ 'allocating_strategy'] = ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY solver: Solver = Solver( nx_graph=self.graph, flows=self.flows, topo_strategy=None, routing_strategy=config.GRAPH_CONFIG['routing_strategy'], scheduling_strategy=config.GRAPH_CONFIG['scheduling_strategy'], allocating_strategy=config.GRAPH_CONFIG['allocating_strategy']) self.solution = solver.generate_init_solution() solver.draw_gantt_chart(self.solution) # draw gantt chart solution_name: str = solver.generate_solution_name( solution=self.solution) import os filename: str = os.path.join(config.res_dir, solution_name) solver.analyze(solution=self.solution, target_filename=filename) # analyze solution solver.save_solution(solution=self.solution) # save solution tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename=solution_name, enhancement_enable=config. XML_CONFIG['enhancement-tsn-switch-enable']) self.tsn_network = tsn_network self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info
def test_reliability_strategy(self): solver: Solver = Solver( nx_graph=self.graph, flows=self.flows, topo_strategy=None, routing_strategy=config.GRAPH_CONFIG['routing_strategy'], scheduling_strategy=config.GRAPH_CONFIG['scheduling_strategy'], allocating_strategy=config.GRAPH_CONFIG['allocating_strategy'], reliability_strategy=config.GRAPH_CONFIG['reliability-strategy']) self.solution = solver.generate_init_solution() solver.draw_gantt_chart(self.solution) # draw gantt chart target_filename: str = os.path.join( config.flow_routes_repetition_degree_dir, self.solution.solution_name) Analyzer.analyze_flow_routes_repetition_degree( self.solution, target_filename=target_filename)
def setUp(self): topo_generator: TopoGenerator = TopoGenerator() topo_strategy_entity: Dict = { 'strategy': TOPO_STRATEGY.BA_STRATEGY, 'n': 5, 'm': 2, } config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = 2 config.FLOW_CONFIG['dest-num-set'] = [1, 2] config.FLOW_CONFIG['flow-num'] = 3 topo_generator.topo_strategy = TopoStrategyFactory.get_instance( **topo_strategy_entity) graph: nx.Graph = topo_generator.generate_core_topo() attached_edge_nodes_num: int = 3 attached_edge_nodes: List[NodeId] = topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) topo_generator.draw(graph) config.TESTING['generate-flow'] = False if config.TESTING['generate-flow']: flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_edge_nodes, graph=graph) FlowGenerator.save_flows(flows) else: flows: List[Flow] = FlowGenerator.load_flows() solver: Solver = Solver( nx_graph=graph, flows=flows, topo_strategy=topo_strategy_entity['strategy'], routing_strategy=ROUTING_STRATEGY. BACKTRACKING_REDUNDANT_ROUTING_STRATEGY, scheduling_strategy=SCHEDULING_STRATEGY. LRF_REDUNDANT_SCHEDULING_STRATEGY, allocating_strategy=ALLOCATING_STRATEGY.AEAP_ALLOCATING_STRATEGY) solver.visual = True self.solution = solver.generate_init_solution() self.solution.solution_name = 'solution' solver.save_solution(solution=self.solution) tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename='solution', enhancement_enable=config. XML_CONFIG['enhancement-tsn-switch-enable']) self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info logger.info(str(tsn_network.__class__) + ': ' + str(tsn_network)) self.tsn_network = tsn_network
def run_test(self, combinations: List = None): for combination in combinations: # create flows if combination['enable_flow_gen']: attached_nodes: List[NodeId] = [1, 2, 3, 4] self.flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_nodes, graph=self.graph) FlowGenerator.save_flows(self.flows) else: self.flows: List[Flow] = FlowGenerator.load_flows() # origin method solver: Solver = Solver( nx_graph=self.graph, flows=self.flows[:], topo_strategy=None, routing_strategy=combination['routing_strategy'], scheduling_strategy=combination['scheduling_strategy'], allocating_strategy=combination['allocating_strategy'], reliability_strategy=combination['reliability_strategy']) self.solution = solver.generate_init_solution() solver.draw_gantt_chart(self.solution) # draw gantt chart solution_name: str = self.solution.generate_solution_name( prefix='b_n7_f10_') if combination['enable_op']: # optimized method self.solution = solver.optimize() # optimize solver.draw_gantt_chart(self.solution) # draw gantt chart solution_name: str = self.solution.generate_solution_name( prefix='o_n7_f10_') solver.save_solution(solution=self.solution) # save solution # create network tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename=solution_name, enhancement_enable=config. XML_CONFIG['enhancement-tsn-switch-enable']) self.tsn_network = tsn_network self.node_edge_mac_info = tsn_network_factory.node_edge_mac_info # create test scenario ConfigFileGenerator.create_test_scenario( tsn_network=self.tsn_network, solution=self.solution, node_edge_mac_info=self.node_edge_mac_info)
def run_test(self, combinations: List = None): for combination in combinations: # origin method solver: Solver = Solver(nx_graph=self.graph, flows=self.flows[:], topo_strategy=None, routing_strategy=combination['routing_strategy'], scheduling_strategy=combination['scheduling_strategy'], allocating_strategy=combination['allocating_strategy'], reliability_strategy=combination['reliability_strategy']) solution = solver.generate_init_solution() solution.generate_solution_name(prefix='b_fixed_f{}_n{}_'.format(10, 10)) Analyzer.analyze_per_flow( solution, target_filename=os.path.join(config.solutions_res_dir, solution.solution_name)) if config.TESTING['draw-gantt-chart'] is True: solver.draw_gantt_chart(solution) logger.info('Native Objective: ' + str(solver.objective_function(solution))) # optimization method if config.OPTIMIZATION['enable'] is False or \ combination['allocating_strategy'] == ALLOCATING_STRATEGY.AEAPBF_ALLOCATING_STRATEGY or \ combination['allocating_strategy'] == ALLOCATING_STRATEGY.AEAPWF_ALLOCATING_STRATEGY or \ combination['routing_strategy'] == ROUTING_STRATEGY.DIJKSTRA_SINGLE_ROUTING_STRATEGY: continue solution = solver.optimize() # optimize solution.generate_solution_name(prefix='o_fixed_f{}_n{}_'.format(10, 10)) Analyzer.analyze_per_flow( solution, target_filename=os.path.join(config.solutions_res_dir, solution.solution_name)) if config.TESTING['draw-gantt-chart'] is True: solver.draw_gantt_chart(solution) logger.info('Optimal Objective: ' + str(solver.objective_function(solution))) # create network solver.save_solution(solution=solution) # save solution tsn_network_factory: TSNNetworkFactory = TSNNetworkFactory() tsn_network: TSNNetwork = tsn_network_factory.product( solution_filename=solution.solution_name, enhancement_enable=config.XML_CONFIG['enhancement-tsn-switch-enable']) tsn_network = tsn_network node_edge_mac_info = tsn_network_factory.node_edge_mac_info # create test scenario ConfigFileGenerator.create_test_scenario(tsn_network=tsn_network, solution=solution, node_edge_mac_info=node_edge_mac_info)
def test(self): # generate topology topo_generator: TopoGenerator = TopoGenerator() topo_generator.topo_strategy = ErdosRenyiStrategy(n=10, m=10) graph: nx.Graph = topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG['edge-node-num'] attached_edge_nodes: List[NodeId] = topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) topo_generator.draw(graph) # generate flows flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_edge_nodes, graph=graph) # get solution solver: Solver = Solver( nx_graph=graph, flows=flows, topo_strategy=TOPO_STRATEGY.ER_STRATEGY, routing_strategy=config.GRAPH_CONFIG['routing-strategy'], scheduling_strategy=config.GRAPH_CONFIG['scheduling-strategy'], allocating_strategy=config.GRAPH_CONFIG['allocating-strategy']) solver.visual = True solver.generate_init_solution()
def test_simulation(self): for test_round in range(config.TESTING['round'][0], config.TESTING['round'][1] + 1): for topo_strategy_entity in config.GRAPH_CONFIG['topo-strategy']: topo_strategy: TopoStrategy = TopoStrategyFactory.get_instance( **topo_strategy_entity) self.topo_generator.topo_strategy = topo_strategy graph: nx.Graph = self.topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG[ 'edge-node-num'] attached_edge_nodes: List[ NodeId] = self.topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) self.topo_generator.draw(graph) # generate flows flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_edge_nodes, graph=graph, flow_num=config.TESTING['flow-size'][1]) for i in range(config.TESTING['flow-size'][0], config.TESTING['flow-size'][1] + 1, config.TESTING['x-axis-gap']): # create solver solver: Solver = Solver( nx_graph=graph, flows=None, topo_strategy=topo_strategy_entity['strategy'], routing_strategy=config. GRAPH_CONFIG['routing-strategy'], scheduling_strategy=config. GRAPH_CONFIG['scheduling-strategy'], allocating_strategy=config. GRAPH_CONFIG['allocating-strategy']) solver.add_flows(copy.deepcopy(flows[:i])) # origin method self.solution = solver.generate_init_solution( ) # get initial solution solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='b_fz_t{}_n{}_'.format( test_round, len(self.solution.graph.nodes))) filename: str = os.path.join(config.flow_size_res_dir, self.solution.solution_name) solver.analyze( solution=self.solution, target_filename=filename) # analyze solution self.solution.solution_name = self.generate_solution_filename( anchor='n{}_'.format(len(self.solution.graph.nodes)), addition='f{}_'.format(i)) solver.save_solution(filename=self.solution.solution_name) self.generate_test_scenario() # generate test scenario # optimized method if config.OPTIMIZATION['enable'] is True: self.solution = solver.optimize() # optimize solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='o_fz_t{}_n{}_'.format( test_round, len(self.solution.graph.nodes))) filename: str = os.path.join( config.flow_size_res_dir, self.solution.solution_name) solver.analyze(solution=self.solution, target_filename=filename) self.solution.solution_name = self.generate_solution_filename( anchor='n{}_'.format(len( self.solution.graph.nodes)), addition='f{}_'.format(i)) solver.save_solution( filename=self.solution.solution_name) self.generate_test_scenario() # generate test scenario
def test_graph_size(self): topo_generator: TopoGenerator = TopoGenerator() flow_properties: List[Dict] = FlowGenerator.generate_flow_properties( config.FLOW_CONFIG['flow-num']) for test_round in range(config.TESTING['round'][0], config.TESTING['round'][1] + 1): for graph_size in range(config.TESTING['graph-core-size'][0], config.TESTING['graph-core-size'][1] + 1, config.TESTING['x-axis-gap']): for topo_strategy_entity in config.GRAPH_CONFIG[ 'topo-strategy']: topo_strategy_entity['n'] = graph_size topo_strategy: TopoStrategy = TopoStrategyFactory.get_instance( **topo_strategy_entity) topo_generator.topo_strategy = topo_strategy config.GRAPH_CONFIG['core-node-num'] = graph_size # config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = \ # int(graph_size * 0.6) if int(graph_size * 0.6) < config.GRAPH_CONFIG['edge-node-num'] \ # else config.GRAPH_CONFIG['edge-node-num'] config.GRAPH_CONFIG['edge-nodes-distribution-degree'] = 6 # generate topology graph: nx.Graph = topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG[ 'edge-node-num'] attached_edge_nodes: List[ NodeId] = topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) topo_generator.draw(graph) flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_edge_nodes, graph=graph, flow_properties=flow_properties) solver: Solver = Solver( nx_graph=graph, flows=flows, topo_strategy=topo_strategy_entity['strategy'], routing_strategy=config. GRAPH_CONFIG['routing-strategy'], scheduling_strategy=config. GRAPH_CONFIG['scheduling-strategy'], allocating_strategy=config. GRAPH_CONFIG['allocating-strategy']) try: import time import os # origin method self.solution = solver.generate_init_solution( ) # get initial solution solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='gz_t{}_f{}_'.format( test_round, len(flows))) filename: str = os.path.join(config.graph_size_res_dir, solution_name) solver.analyze( solution=self.solution, target_filename=filename) # analyze solution if config.OPTIMIZATION['enable'] is True: # optimized method self.solution = solver.optimize() # optimize solution_name: str = solver.generate_solution_name( solution=self.solution, prefix='o_gz_t{}_f{}_'.format( test_round, len(flows))) filename: str = os.path.join( config.graph_size_res_dir, solution_name) solver.analyze(solution=self.solution, target_filename=filename) except: # save flows if error happen FlowGenerator.save_flows(flows)
def test_flow_size(self): topo_generator: TopoGenerator = TopoGenerator() for topo_strategy_entity in config.GRAPH_CONFIG['topo-strategy']: topo_strategy: TopoStrategy = TopoStrategyFactory.get_instance( **topo_strategy_entity) topo_generator.topo_strategy = topo_strategy for test_round in range(config.TESTING['round'][0], config.TESTING['round'][1] + 1): self.round = test_round # generate topology graph: nx.Graph = topo_generator.generate_core_topo() attached_edge_nodes_num: int = config.GRAPH_CONFIG[ 'edge-node-num'] attached_edge_nodes: List[ NodeId] = topo_generator.attach_edge_nodes( graph, attached_edge_nodes_num) topo_generator.draw(graph) # generate flows flows: List[Flow] = FlowGenerator.generate_flows( edge_nodes=attached_edge_nodes, graph=graph, flow_num=config.TESTING['flow-size'][1]) for i in range(config.TESTING['flow-size'][0], config.TESTING['flow-size'][1] + 1, config.TESTING['x-axis-gap']): solver: Solver = Solver( nx_graph=graph, flows=flows[:i], topo_strategy=topo_strategy_entity['strategy'], routing_strategy=config. GRAPH_CONFIG['routing-strategy'], scheduling_strategy=config. GRAPH_CONFIG['scheduling-strategy'], allocating_strategy=config. GRAPH_CONFIG['allocating-strategy'], reliability_strategy=config. GRAPH_CONFIG['reliability-strategy']) try: import time import os # origin method self.solution = solver.generate_init_solution( ) # get initial solution self.solution.generate_solution_name( prefix='b_fz_t{}_n{}_'.format( test_round, len(self.solution.graph.nodes))) Analyzer.analyze_flow_size( self.solution, target_filename=os.path.join( config.flow_size_res_dir, self.solution.solution_name)) self.solution.generate_solution_name( prefix='b_fz_t{}_n{}_f{}_'.format( test_round, len(self.solution.graph.nodes), i)) Analyzer.analyze_flow_routes_repetition_degree( self.solution, target_filename=os.path.join( config.flow_routes_repetition_degree_dir, self.solution.solution_name)) if config.OPTIMIZATION['enable'] is True: # optimized method self.solution = solver.optimize() # optimize self.solution.generate_solution_name( prefix='o_fz_t{}_n{}_'.format( test_round, len( self.solution.graph.nodes))) Analyzer.analyze_flow_size( self.solution, target_filename=os.path.join( config.flow_size_res_dir, self.solution.solution_name)) self.solution.generate_solution_name( prefix='o_fz_t{}_n{}_f{}_'.format( test_round, len(self.solution.graph.nodes), i)) Analyzer.analyze_flow_routes_repetition_degree( self.solution, target_filename=os.path.join( config.flow_routes_repetition_degree_dir, self.solution.solution_name)) except: # save flows if error happen FlowGenerator.save_flows(flows)