Exemplo n.º 1
0
 def generate_archipelago(self, topology_name, metric, monitor):
     from os.path import isfile
     from re import compile
     db_regex = compile(
         r'sql:(\w+)@([\w:]+),pw=([^,]+),db=([\w]+)\(name=(\w+),n_islands=(\d+),island_size=(\d+),migrant_pool_size=(\d+),generations=(\d+)\):(.*)'
     )
     if isfile(topology_name):
         import pickle
         with open(topology_name) as f:
             return pickle.load(f)['archipelago']
     elif db_regex.match(topology_name) is not None:
         m = db_regex.match(topology_name)
         from sabaody import TopologyGenerator, BiopredynTopologyGenerator
         name = m.group(5)
         if name == 'pagmo':
             generator_class = TopologyGenerator
         elif name == 'biopredyn':
             generator_class = BiopredynTopologyGenerator
         generator = generator_class(n_islands=int(m.group(6)),
                                     island_size=int(m.group(7)),
                                     migrant_pool_size=int(m.group(8)),
                                     generations=int(m.group(9)))
         topology, id = generator.find_in_database(desc=m.group(10),
                                                   user=m.group(1),
                                                   host=m.group(2),
                                                   pw=m.group(3),
                                                   db=m.group(4))
         self.topology_set_id = id
         self.topology_id = topology['id']
         self.generations = topology['generations']
         return Archipelago(
             TopologyFactory.prefixIds(topology['archipelago'].topology,
                                       prefix=self.run_id + '-'))
     else:
         # generate the topology from available presets via command line arguments
         topology_factory = TopologyFactory(
             problem=self.make_problem(),
             island_size=self.island_size,
             migrant_pool_size=self.migrant_pool_size,
             domain_qualifier=monitor.getNameQualifier(),
             mc_host=monitor.mc_host,
             mc_port=monitor.mc_port)
         if topology_name == 'ring' or topology_name == 'bidir-ring':
             return Archipelago(
                 topology_factory.createBidirRing(self.make_algorithm(),
                                                  self.n_islands), metric)
         elif topology_name == 'one-way-ring':
             return Archipelago(
                 topology_factory.createOneWayRing(self.make_algorithm(),
                                                   self.n_islands), metric)
         else:
             raise RuntimeError('Unrecognized topology')
Exemplo n.º 2
0
def test_bidir_ring_topology():
    '''
    Test the one way ring topology.
    '''
    from sabaody.topology import TopologyFactory
    domain_qual = partial(getQualifiedName,
                          'com.how2cell.sabaody.test_one_way_ring_topology')
    topology_factory = TopologyFactory(NoProblem, domain_qual, 'localhost',
                                       11211)

    t = topology_factory.createBidirRing(None, 4)
    assert len(t.island_ids) == 4
    assert len(t.islands) == 4
    for id in t.island_ids:
        assert len(t.neighbor_islands(id)) == len(t.neighbor_ids(id)) == 2
        assert len(t.outgoing_islands(id)) == len(t.outgoing_ids(id)) == 2