Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Graph vertices logic and use Graph in MatchGenerator #1455

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading