diff --git a/axelrod/graph.py b/axelrod/graph.py index 54aaee6e9..36f82f7b7 100644 --- a/axelrod/graph.py +++ b/axelrod/graph.py @@ -46,6 +46,7 @@ def __init__(self, edges=None, directed=False): self._edges = [] if edges: self._add_edges(edges) + self._vertices = list(self.in_mapping.keys() | self.out_mapping.keys()) def _add_edge(self, source, target, weight=None): if (source, target) not in self._edges: @@ -77,7 +78,7 @@ def edges(self): @property def vertices(self): - return list(self.out_mapping.keys()) + return self._vertices def out_dict(self, source): """Returns a dictionary of the outgoing edges of source with weights.""" diff --git a/axelrod/match_generator.py b/axelrod/match_generator.py index 37038e7b5..e1e17f13f 100644 --- a/axelrod/match_generator.py +++ b/axelrod/match_generator.py @@ -1,4 +1,5 @@ from axelrod.random_ import BulkRandomGenerator +from .graph import complete_graph class MatchGenerator(object): @@ -72,10 +73,9 @@ def build_match_chunks(self): tuples ((player1 index, player2 index), match object) """ + edges = self.edges if self.edges is None: - edges = complete_graph(self.players) - else: - edges = self.edges + edges = complete_graph(len(self.players), loops=True, directed=True).edges for index_pair in edges: match_params = self.build_single_match_params() @@ -95,15 +95,6 @@ def build_single_match_params(self): } -def complete_graph(players): - """ - Return generator of edges of a complete graph on a set of players - """ - for player1_index, _ in enumerate(players): - for player2_index in range(player1_index, len(players)): - yield (player1_index, player2_index) - - def graph_is_connected(edges, players): """ Test if the set of edges defines a graph in which each player is connected