コード例 #1
0
ファイル: experiment2b.py プロジェクト: yarox/alos
            info.append({'generation': i,
                         'agent': 0,
                         'fitness': explorer.fitness,
                         'solution': explorer.solution})

            # Update pheromones
            for a, b in graph.edges():
                weight = graph[a][b]['weight']

                if (a, b) in explorer or (b, a) in explorer:
                    increase = explorer.fitness
                else:
                    increase = 0

                graph[a][b]['weight'] = ant_system_update(learning_rate, weight, increase)

            # Construct solutions
            for j, agent in enumerate(population, start=1):
                agent.search(graph, max_steps)
                agent.evaluate()

                info.append({'generation': i,
                             'agent': j,
                             'fitness': agent.fitness,
                             'solution': agent.solution})

            # Log generation info
            collection_agents.insert(info)
            print('# generation {0}'.format(i))
コード例 #2
0
ファイル: experiment3.py プロジェクト: yarox/alos
            for i in range(generations):
                population = [ProportionalAnt(start, end) for x in range(agents)]
                info = []

                # Construct solutions
                for j, agent in enumerate(population):
                    agent.search(graph, max_steps)
                    agent.evaluate()

                    info.append({'generation': i,
                                 'agent': j,
                                 'fitness': agent.fitness,
                                 'solution': agent.solution})

                # Log generation info
                collection_agents.insert(info)
                print('# generation {0}'.format(i))

                # Update pheromones
                for a, b in graph.edges():
                    weight = graph[a][b]['weight']
                    increase = sum([agent.fitness for agent in population
                                    if (a, b) in agent or (b, a) in agent])

                    graph[a][b]['weight'] = ant_system_update(rho, weight, increase)

                # Log pheromone info
                collection_pheromones.insert({'generation': i,
                                              'pheromones': graph.edges(data=True)})