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

Add option to consider edge colours to node strategy #38

Merged
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
13 changes: 9 additions & 4 deletions listcolouring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ def first_permissible_or_none(G, u, v):
choice = None
return(choice)

def first_permissible_or_none_node(G, u):
def first_permissible_or_none_node(G, u, edges = False):
""" Returns the first element of A = P - X if A is non-empty otherwise returns None.
X is the list of colours on neighbours of u.
P is the list of permissible colours for node u.
X is the list of colours on neighbours of u if edges = False and the union of
the list of colours on neighbours of u and the list of colours on edges incident
with u if edges = True.
P is the list of permissible colours for node u.
"""
X = colours_on_neighbours(G, u)
if edges:
X = colours_on_neighbours(G, u).union(colours_incident_with(G, u))
else:
X = colours_on_neighbours(G, u)
P = set(G.nodes[u]["permissible"])
choices = P - X
if(len(choices) > 0):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_first-permissible-or-none-node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ def test_first_permissible_or_none_node():
assert first_permissible_or_none_node(G, 0) == 0
assert first_permissible_or_none_node(G, 1) == 1
assert first_permissible_or_none_node(G, 2) == 2
nx.set_edge_attributes(G, 2, "colour")
assert first_permissible_or_none_node(G, 0, edges = True) == 0
assert first_permissible_or_none_node(G, 1, edges = True) == 1
assert first_permissible_or_none_node(G, 2, edges = True) == 3
Loading