def battle(max_size, programs):
    permutations = itertools.permutations(programs)
    pairs = set([])
    triples = set([])
    cumulative = {}
    for p in programs:
        cumulative[p] = 0
    for p in permutations:
        pairs.add(tuple(sorted(p[:2])))
        if len(programs) > 2:
            triples.add(tuple(sorted(p[:3])))
    for mapfile in glob.glob('maps/*.json'):
        with open(mapfile) as f:
            themap = rwjson.readJson(f)
        if len(themap['rivers']) > max_size:
            print mapfile,'is too long with size', len(themap['rivers'])
            continue
        print '\ntesting map', mapfile, 'with size', len(themap['rivers'])
        for pair in pairs:
            scores = arena.arena(mapfile, pair)
            ranks = rank_scores(scores)
            print 'ranks are', ranks, 'and scores are', scores
            for p in ranks:
                cumulative[p] += ranks[p]
        for pair in triples:
            scores = arena.arena(mapfile, pair)
            ranks = rank_scores(scores)
            for p,v in ranks:
                cumulative[p] += v
        print 'cumulative so far:', cumulative
    print 'cumulative score:', cumulative
示例#2
0
def get_simulation_details():
    """Get simulation specifications from the user."""

    data = {}
    mode = input(">>>Select Mode<<<\n[1] Evolution\n[2] Learning\n")
    mode = 'evolution' if mode == 1 else 'learning'
    data['mode'] = mode

    arena_no = input(">>>Select Arena<<<\n[1] Arena 1 (687x371)\n[2] Arena 2 \
(500x270)\n[3] Arena 3 (800x432)\n")
    data['arena'] = arena_no

    ar = arena.arena(arena_no)

    model = input(">>>Select Neuronal Model<<<\n[1] Multi-timescale Adaptive \
Threshold (MAT)\n[2] Leaky Intergate and Fire (LIF)\n")
    model = 'mat' if model == 1 else 'iaf'
    data['model'] = model

    init = input(">>>Select Input Pose<<<\n[1] Random\n[2] Fixed\n")
    init = 'random' if init == 1 else 'fixed'
    data['init'] = init

    if init == 'fixed':
        x = input(">>> Enter initial X-Position (max %d)<<<\n"""\
        % ar.maximum_length())
        y = input(">>>Enter initial Y-Position (max %d)<<<\n"""\
        % ar.maximum_width())
        theta = input(">>>Enter initial orientation angle<<<\n")
        data['x_init'] = x
        data['y_init'] = y
        data['theta_init'] = theta

    if mode == 'evolution':
        # Evolution
        pop_id = input(">>>Select Population id<<<\n[1] Population 1\n[2] \
Population 2\n[3] Population 3\n")
        data['population'] = pop_id
        
        generations = input(">>>Number of Generations<<<\n")
        data['generations'] = generations
    else:
        #Learning
        runs = input(">>>Number of Runs<<<\n")
        data['runs'] = runs

    time = input(">>>Duration of Simulation in Seconds<<<\n")
    data['time'] = time*1000

    interval = input(">>>Duration of Interval in Milliseconds<<<\n")
    data['interval'] = interval

    return data
示例#3
0
def battle(max_size, programs, vis):
    permutations = itertools.permutations(programs)
    pairs = {}
    for i in range(len(programs) + 1):
        pairs[i] = set([])
    cumulative = {}
    games = {}
    for p in programs:
        cumulative[p] = 0
        games[p] = 0
    for p in permutations:
        for l in range(2, len(programs) + 1):
            pairs[l].add(tuple(p[:l]))
    groups = []
    for l in range(2, len(programs) + 1):
        pairs[l] = list(pairs[l])
        random.shuffle(pairs[l])
        groups += pairs[l][:len(pairs[2])]

    jobs = []
    for mapfile in glob.glob('maps/*.json'):
        with open(mapfile) as f:
            themap = rwjson.readJson(f)
        if len(themap['rivers']) > max_size:
            print mapfile, 'is too long with size', len(themap['rivers'])
            continue
        for pair in groups:
            jobs.append((mapfile, pair))
    random.shuffle(jobs)
    for mapfile, pair in jobs:
        print '  {} {}'.format(mapfile, pair)
        with open(mapfile) as f:
            themap = rwjson.readJson(f)
            scores = arena.arena(mapfile, pair, vis=vis)
            ranks = rank_scores(scores)
            for p in ranks:
                cumulative[p] += ranks[p]
                games[p] += 1
            for (s, p) in scores:
                print '    {} [{:.2f}]: {} ({})'.format(
                    ranks[p], cumulative[p] / games[p], p, s)
    for p in programs:
        print '{}: {}'.format(cumulative[p], p)
示例#4
0
    def do_arena(self, line):
        _arena = arena(self.line_bot_api, self.event)

        return _arena.process(line.parsed.args)
示例#5
0
        runs = input(">>>Number of Runs<<<\n")
        data['runs'] = runs

    time = input(">>>Duration of Simulation in Seconds<<<\n")
    data['time'] = time*1000

    interval = input(">>>Duration of Interval in Milliseconds<<<\n")
    data['interval'] = interval

    return data


if __name__ == '__main__':

    data = get_simulation_details()
    arena = arena.arena(data['arena'])
    if data['mode'] == 'evolution':
        # Evolution
        population, num_individuals = ev.load_population(data['population'])
        average_fitness, average_connectivity, best_of_generation = [], [], []
        elite = [0, 0]
        results.set_results_path(data['init'], data['model'], data['arena'],
                                 data['population'])
        print results.path
        for gen in range(data['generations']):
            # Create a separate folder for each generation results
            results.create_generation_folder(gen)
            print 'generation: %d' % (gen + 1)
            generation_log = []
            for i in range(num_individuals):
                print i