示例#1
0
 def test_add_vertex(self):
     """A WeightedGraph object is a composition (has-a relationship) 
     of one or multiple WeightedVertex objects.
     
     """
     # example id of a vertex
     vertex_id = 'A'
     # test instantiation of weighted directed graph
     d_graph = WeightedGraph()
     self.assertEqual(len(list(d_graph.vertex_dict.items())), 0)
     self.assertTrue(d_graph.is_directed)
     # test adding a vertex
     d_graph.add_vertex(vertex_id)
     self.assertEqual(len(list(d_graph.vertex_dict.items())), 1)
     vertex_added = d_graph.vertex_dict[vertex_id]
     self.assertTrue(isinstance(vertex_added, WeightedVertex))
     self.assertEqual(vertex_added.id, vertex_id)
示例#2
0
def graph():
    g = WeightedGraph(4)

    g.add_edge(WeightedEdge(0, 1, 0.1))
    g.add_edge(WeightedEdge(0, 2, 0.2))
    g.add_edge(WeightedEdge(0, 3, 0.3))
    g.add_edge(WeightedEdge(1, 2, 1.2))

    return g
示例#3
0
def graph():
    g = WeightedGraph(8)

    g.add_edge(WeightedEdge(4, 5, 0.35))
    g.add_edge(WeightedEdge(4, 7, 0.37))
    g.add_edge(WeightedEdge(5, 7, 0.28))
    g.add_edge(WeightedEdge(0, 7, 0.16))
    g.add_edge(WeightedEdge(1, 5, 0.32))
    g.add_edge(WeightedEdge(0, 4, 0.38))
    g.add_edge(WeightedEdge(2, 3, 0.17))
    g.add_edge(WeightedEdge(1, 7, 0.19))
    g.add_edge(WeightedEdge(0, 2, 0.26))
    g.add_edge(WeightedEdge(1, 2, 0.36))
    g.add_edge(WeightedEdge(1, 3, 0.29))
    g.add_edge(WeightedEdge(2, 7, 0.34))
    g.add_edge(WeightedEdge(6, 2, 0.40))
    g.add_edge(WeightedEdge(3, 6, 0.52))
    g.add_edge(WeightedEdge(6, 0, 0.58))
    g.add_edge(WeightedEdge(6, 4, 0.93))

    return g
示例#4
0
    def make_large_graph(self):
        graph = WeightedGraph(is_directed=False)
        vertex_a = graph.add_vertex('A')
        vertex_b = graph.add_vertex('B')
        vertex_c = graph.add_vertex('C')
        vertex_c = graph.add_vertex('D')
        vertex_c = graph.add_vertex('E')
        vertex_c = graph.add_vertex('F')
        vertex_c = graph.add_vertex('G')
        vertex_c = graph.add_vertex('H')
        vertex_c = graph.add_vertex('J')

        graph.add_edge('A', 'B', 4)
        graph.add_edge('A', 'C', 8)
        graph.add_edge('B', 'C', 11)
        graph.add_edge('B', 'D', 8)
        graph.add_edge('C', 'F', 1)
        graph.add_edge('C', 'E', 4)
        graph.add_edge('D', 'E', 2)
        graph.add_edge('D', 'G', 7)
        graph.add_edge('D', 'H', 4)
        graph.add_edge('E', 'F', 6)
        graph.add_edge('F', 'H', 2)
        graph.add_edge('G', 'H', 14)
        graph.add_edge('G', 'J', 9)
        graph.add_edge('H', 'J', 10)

        return graph
示例#5
0
    # print('Finding shortest path from vertex A to vertex E...')
    # shortest_path = graph.find_shortest_path('A', 'E')
    # print(shortest_path)

    # # Find all vertices N distance away
    # print('Finding all vertices distance 2 away...')
    # vertices_2_away = graph.find_vertices_n_away('A', 2)
    # print(vertices_2_away)
    vertex_a = WeightedVertex('a')
    vertex_b = WeightedVertex('b')
    vertex_c = WeightedVertex('c')
    vertex_d = WeightedVertex('d')
    vertex_e = WeightedVertex('e')
    vertex_f = WeightedVertex('f')

    graph = WeightedGraph(False)

    graph.add_vertex(vertex_a.get_id())
    graph.add_vertex(vertex_b.get_id())
    graph.add_vertex(vertex_c.get_id())
    graph.add_vertex(vertex_d.get_id())
    graph.add_vertex(vertex_e.get_id())
    graph.add_vertex(vertex_f.get_id())

    graph.add_edge(vertex_a.get_id(), vertex_b.id, 5)
    graph.add_edge(vertex_b.get_id(), vertex_c.id, 1)
    graph.add_edge(vertex_c.get_id(), vertex_d.id, 2)
    graph.add_edge(vertex_d.get_id(), vertex_a.id, 4)
    graph.add_edge(vertex_e.get_id(), vertex_a.id, 10)
    graph.add_edge(vertex_f.get_id(), vertex_e.id, 5)
    graph.add_edge(vertex_f.get_id(), vertex_a.id, 3)
    def make_large_graph(self):
        graph = WeightedGraph(is_directed=False)
        vertex_a = graph.add_vertex('A')  # 0
        vertex_b = graph.add_vertex('B')  # 1
        vertex_c = graph.add_vertex('C')  # 2
        vertex_c = graph.add_vertex('D')  # 3
        vertex_c = graph.add_vertex('E')  # 4
        vertex_c = graph.add_vertex('F')  # 5
        vertex_c = graph.add_vertex('G')  # 6
        vertex_c = graph.add_vertex('H')  # 7
        vertex_c = graph.add_vertex('J')  # 8

        graph.add_edge('A', 'B', 4)  # 0-1
        graph.add_edge('A', 'C', 8)  # 0-2
        graph.add_edge('B', 'C', 11)  # 1-2
        graph.add_edge('B', 'D', 8)  # 1-3
        graph.add_edge('C', 'F', 1)  # 2-5
        graph.add_edge('C', 'E', 4)  # 2-4
        graph.add_edge('D', 'E', 2)  # 3-4
        graph.add_edge('D', 'G', 7)  # 3-6
        graph.add_edge('D', 'H', 4)  # 3-7
        graph.add_edge('E', 'F', 6)  # 4-5
        graph.add_edge('F', 'H', 2)  # 5-7
        graph.add_edge('G', 'H', 14)  # 6-7
        graph.add_edge('G', 'J', 9)  # 6-8
        graph.add_edge('H', 'J', 10)  # 7-8

        return graph
from graphs.weighted_graph import WeightedGraph
from util.file_reader import read_graph_from_file
# from graphs.weighted_graph import WeightedGraph

# Driver code
if __name__ == '__main__':

    # Create the graph

    graph = WeightedGraph(is_directed=False)
    vertex_a = graph.add_vertex('A')
    vertex_b = graph.add_vertex('B')
    vertex_c = graph.add_vertex('C')
    vertex_c = graph.add_vertex('D')
    vertex_c = graph.add_vertex('E')
    vertex_c = graph.add_vertex('F')
    vertex_c = graph.add_vertex('G')
    vertex_c = graph.add_vertex('H')
    vertex_c = graph.add_vertex('J')

    graph.add_edge('A', 'B', 4)
    graph.add_edge('A', 'C', 8)
    graph.add_edge('B', 'C', 11)
    graph.add_edge('B', 'D', 8)
    graph.add_edge('C', 'F', 1)
    graph.add_edge('C', 'E', 4)
    graph.add_edge('D', 'E', 2)
    graph.add_edge('D', 'G', 7)
    graph.add_edge('D', 'H', 4)
    graph.add_edge('E', 'F', 6)
    graph.add_edge('F', 'H', 2)
                    default=15,
                    help='the number of matches to use for generating a build')
parser.add_argument('--verbose',
                    action="store_true",
                    help='print debug messages while generating the build')
build_sources = parser.add_mutually_exclusive_group(required=True)
build_sources.add_argument(
    '--player',
    help='the player whose builds should be used to create a build')
build_sources.add_argument('--role',
                           help='the role for which a build should be created')

args = parser.parse_args()
ptable = PlayerTable(Player)

item_graph = WeightedGraph()
relic_graph = WeightedGraph()
item_tracker = BuildTracker(item_graph, ItemTracker,
                            default_maps.default_item_maps)
relic_tracker = BuildTracker(relic_graph, ItemTracker,
                             default_maps.default_relic_maps)
item_creator = ItemBuildCreator(default_filters.default_item_filters)
relic_creator = RelicBuildCreator(default_filters.default_relic_filters)

# Player-based search
if args.player:
    player = ptable.get_player_by_name(args.player)
    if player:
        scraper = SmiteGuruScraper(Item,
                                   Build,
                                   player,