Esempio n. 1
0
def show_path_lengths(node, task, ants):
    ant_path_lengths = [ant.get_path_length() for ant in ants]
    print 'r%d,path_length,%s,%s,%s' % (i, node.get_name(), task,
        ','.join(str(length) for length in ant_path_lengths))
    print 'r%d,path_average,%s,%s,%f' % (i, node.get_name(), task,
        average(ant_path_lengths))

if __name__ == '__main__':
    number_of_ants = 10
    number_of_nodes = 10
    evaporation_rate = 0.1
    base_pheromones = 1000
    best_path_prob = 0.05
    max_connections = 7

    nodes = create_nodes(number_of_nodes, max_connections, evaporation_rate,
            base_pheromones, best_path_prob)

    random.SystemRandom()
    for x in range(len(nodes)):
        for y in range(max_connections):
            other = random.randint(0, len(nodes) - 1)
            print "link %d,%d" % (x, other)
            try:
                link(nodes[x], nodes[other])
            except TooManyConnections:
                continue

    taskfactory = TaskFactory()
    nodes[5].add_task(taskfactory.get_task(TaskFactory.tasks.TASKA))
    nodes[3].add_task(taskfactory.get_task(TaskFactory.tasks.TASKA))
    nodes[8].add_task(taskfactory.get_task(TaskFactory.tasks.TASKB))