Exemple #1
0
def read_city_graph(filename):
    f = open(filename)
    g = WeightedGraph()
    global vertices
    vertices = {}
    global edges
    edges = {}

    line = f.readline()
    while line:
        fields = line.split(",")

        if fields[0] == "V":
            v = int(fields[1])
            lat = float(fields[2])
            lon = float(fields[3])
            g.add_vertex(v)
            vertices[v] = (int(lat * 100000), int(lon * 100000) )
        elif fields[0] == "E":
            e = (int(fields[1]), int(fields[2]))
            g.add_edge(int(fields[1]),int(fields[2]))
            edges[e] = {"street": fields[3]}
        line = f.readline()

    return g
def read_city_graph(filename):
    f = open(filename)
    g = WeightedGraph()
    global vertecies
    vertecies = {}
    global edges
    edges = {}

    line = f.readline()
    while line:
        fields = line.split(",")

        if fields[0] == "V":
            v = int(fields[1])
            lat = float(fields[2])
            lon = float(fields[3])
            g.add_vertex(v)
            vertecies[v] = (int(lat * 100000), int(lon * 100000))
        elif fields[0] == "E":
            e = (int(fields[1]), int(fields[2]))
            g.add_edge(int(fields[1]), int(fields[2]))
            edges[e] = {"street": fields[3]}
        line = f.readline()

    return g
def run_tournament(game: PDGame) -> None:
    """Run a tournament between all strategies.

    If <show_heatmap> is set, then display a heatmap that shows the match-ups
    between the strategies.
    """

    all_strategies = get_all_strategies()

    graph = WeightedGraph()
    for s1 in all_strategies:
        for s2 in all_strategies:
            new_game = PDGame(game.num_rounds)
            strategy1 = s1.__copy__()
            strategy2 = s2.__copy__()

            player1 = Player(strategy1, 1)
            player2 = Player(strategy2, 2)

            if isinstance(player1.strategy, LearningStrategy):
                player1 = get_trained_learner(player2, game.num_rounds)

            graph.add_vertex(player1.strategy.name)

            graph.add_vertex(player2.strategy.name)

            run_game(new_game, player1, player2)
            if strategy1.name == 'Learning Strategy' and strategy2.name == 'Learning Strategy':
                player1.curr_points, player2.curr_points = 0, 0

            graph.add_edge((player1.strategy.name, player1.curr_points),
                           (player2.strategy.name, player2.curr_points))

    display_heatmap(graph)
def read_city_graph(filename):
    #set the three variables we are gonna output
    EdGraph = WeightedGraph()
    roadNames = []
    locations = {}
    """
    Goes through each line of the file
    and creates a vertice or an edge
    """
    with open(filename,"r",) as file:
        for line in file:
            line = line.split(",")

            if line[0] == "V":
                EdGraph.add_vertex(int(line[1]))
                #appends the information we need about the vertice
                locations[int(line[1])] = [int(float(line[2])*100000),int(float(line[3])*100000)]
            elif line[0] == "E":
                EdGraph.add_edge(int(line[1]), int(line[2]), cost_distance(locations[int(line[1])],
                                                                           locations[int(line[2])]))
                roadNames.append([int(line[1]), int(line[2]), line[3].strip()])

    return EdGraph, roadNames, locations