예제 #1
0
    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))
    nodes[6].add_task(taskfactory.get_task(TaskFactory.tasks.TASKB))

    print ""
    print_nodes(nodes)
    print ""

    # initialise pheromones
    for task in TaskFactory.get_task_names():
        task = taskfactory.get_task(task)
        for node in nodes:
            node.initialise_pheromones(task)