예제 #1
0
class AlgorithmTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        logging.basicConfig(level=logging.INFO)

    def setUp(self):
        parser = Parser('./data', 'euro16_k2.txt')
        self.scenario = parser.get_scenario(0)
        self.graph = graph_factory(self.scenario.networkTopology)
        self.logger = logging.getLogger(str(self.__class__))
        candidate_path_fetcher = CandidatePathsFetcher(self.scenario.candidatePaths,
                                                       self.scenario.networkTopology.n_nodes,
                                                       self.scenario.pathsLengths)
        self.demand_factory = DemandsFactory(candidate_path_fetcher)
        self.sa = SimulatedAnnealing()

    def test_create_first_solution(self):
        uni_demands = self.demand_factory.get_unicast_demands(self.scenario.unicastDemands)
        for demand in uni_demands:
            self.logger.info("name: %s, selected path: %s", demand.name, demand.get_selected_path_id())

        self.logger.info("--------------")
        demands = self.sa.create_first_solution(uni_demands)
        for demand in demands:
            self.logger.info("name; %s, selected path: %s", demand.name, demand.get_selected_path_id())
        self.sa.create_first_solution(uni_demands)
        self.logger.info("--------------")
        for demand in demands:
            self.logger.info("name; %s, selected path: %s", demand.name, demand.get_selected_path_id())

        uni_demands[1].select_path(1)
        for demand in demands:
            self.logger.info("name; %s, selected path: %s", demand.name, demand.get_selected_path_id())
예제 #2
0
 def setUp(self):
     parser = Parser('./data', 'euro16_k2.txt')
     self.scenario = parser.get_scenario(0)
     self.graph = graph_factory(self.scenario.networkTopology)
     self.logger = logging.getLogger(str(self.__class__))
     candidate_path_fetcher = CandidatePathsFetcher(self.scenario.candidatePaths,
                                                    self.scenario.networkTopology.n_nodes,
                                                    self.scenario.pathsLengths)
     self.demand_factory = DemandsFactory(candidate_path_fetcher)
     self.sa = SimulatedAnnealing()
예제 #3
0
        return self.temperature > self.minimal_temperature


if __name__ == "__main__":
    from parser.parser import Parser
    from graph.graph import graph_factory
    from graph.path import CandidatePathsFetcher
    from demand.demand import DemandsFactory
    logging.basicConfig(level=logging.INFO)
    test_parser = Parser('../test/test_data', 'euro16_k2.txt')
    scenario = test_parser.get_scenario(100)
    graph = graph_factory(scenario.networkTopology)
    candidate_path_fetcher = CandidatePathsFetcher(scenario.candidatePaths,
                                                   scenario.networkTopology.n_nodes,
                                                   scenario.pathsLengths)
    demand_factory = DemandsFactory(candidate_path_fetcher)
    sa = SimulatedAnnealing()
    uni_demands = demand_factory.get_unicast_demands(scenario.unicastDemands)
    any_demands = demand_factory.get_anycast_demands(scenario.anycastDemands, scenario.dataCenters)
    demands = uni_demands + any_demands
    sa.run(graph, demands)
    print sa.best_energy
    # for demand in sa.best_solution:
    #     if isinstance(demand, UnicastDemand):
    #         print demand.get_selected_path()
    #     elif isinstance(demand, AnycastDemand):
    #         print demand.get_selected_path_up()
    #         print demand.get_selected_path_down()
    print sa.final_time