コード例 #1
0
 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))
コード例 #2
0
 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)))
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
0
 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)