예제 #1
0
def pruning_test():
    # Setup Team Object
    team_edm = Team()
    lines = list()
    lines.append(Line(0, 1.701))
    lines.append(Line(1, 0.658))
    lines.append(Line(2, 0.299))
    lines.append(Line(3, 0.433))
    team_edm.set_team("EDM", lines=lines,
                      start_line_index=0)  # Edmonton Oilers

    path = Path()
    path.team = team_edm

    values_best = []
    for i in range(30):
        temp_path = path.copy()
        optimal_path, num_visited = process(team_edm[team_edm.curr_line_index],
                                            temp_path, 1, i)
        values_best.append(num_visited)

    path.team[path.team.curr_line_index].toi = 0
    values_worst = []
    for i in range(30):
        temp_path = path.copy()
        optimal_path, num_visited = process(team_edm[team_edm.curr_line_index],
                                            temp_path, 1, i)
        values_worst.append(num_visited)

    theoretical_values = [theoretical_nodes(i) for i in range(30)]
    print(theoretical_values)
    print(values_best)
    print(values_worst)
예제 #2
0
def main():
    """
    Sets up and processes team, EXAMPLE;
    :return: NONE
    """
    # Setup Team Object
    team_edm = Team()
    lines = list()
    lines.append(Line(0, 1.701))
    lines.append(Line(1, 0.658))
    lines.append(Line(2, 0.299))
    lines.append(Line(3, 0.433))
    team_edm.set_team("EDM", lines=lines,
                      start_line_index=0)  # Edmonton Oilers

    print(team_edm)

    # Setup Path Object
    path = Path()
    path.team = team_edm

    schedule = []
    num_intervals = PERIOD_LENGTH // INTERVAL
    start = time.time()
    for i in range(num_intervals - 1):

        max_depth = MAX_DEPTH
        if num_intervals - i < MAX_DEPTH:
            max_depth = num_intervals - i

        # start = time.time()
        # find optimal path from curr_line for the next (MAX_DEPTH * INTERVAL) seconds
        temp_path = path.copy()
        optimal_path, num_visited = process(team_edm[team_edm.curr_line_index],
                                            temp_path, 1, max_depth)

        # print("\n\n", path.team, "\n\n")
        path.team.update(optimal_path[1], INTERVAL)
        schedule.append(optimal_path[1].line_num)
        elapsed_time = time.time() - start

        t_nodes = theoretical_nodes(max_depth)

        # print("Optimal       ", optimal_path)
        #
        print("Progress:     {p:3.0f}% @ t: {e:5.2f}".format(
            p=i / (num_intervals - 1) * 100, e=elapsed_time))
        # print("Look Ahead:   ", LOOK_AHEAD)
        # print("Depth:        ", max_depth)
        # print("Visited:      ", num_visited)
        # print("Theoretical:  ", t_nodes)
        # print("Removal Rate: ", "{0:0.5f}".format((t_nodes - num_visited)/t_nodes))
        # print("Speed Up:     ", "{0:4.2f}".format(t_nodes/num_visited))
        #
        # print("\nTime:       ", elapsed_time)

    print(schedule)
예제 #3
0
    path = collection.pop()

    # get its last node
    node = path.last

    # get its neighbors
    raw_neighbors = create_pages(node.links)

    # get its unvisited neighbors
    neighbors = list(
        filter(lambda x: not (x in collection.visited), raw_neighbors))

    # for each neighbor
    for n in neighbors:
        # copy the base path so we can create a new path for each neighbor
        new_path = path.copy()

        # create a path for the neighbor
        new_path.add(n)

        # let the collection decide whether to add it or not
        collection.add(new_path)

    # find the next min path
    collection.set_min()

end = time.time()

paths_out()
sitemap_out()
dead_out()