Skip to content

Commit

Permalink
Fix Graph vertices logic and use Graph in MatchGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffney2010 committed Nov 13, 2024
1 parent 42ecb93 commit d110a90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
3 changes: 2 additions & 1 deletion axelrod/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down
15 changes: 3 additions & 12 deletions axelrod/match_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from axelrod.random_ import BulkRandomGenerator
from .graph import complete_graph


class MatchGenerator(object):
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit d110a90

Please sign in to comment.