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

Implement neighbouring colours. #33

Merged
merged 1 commit into from
Nov 6, 2024
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
4 changes: 4 additions & 0 deletions listcolouring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def colours_incident_with(G, u):
"""The list of colours on edges incident with vertex u in graph G."""
return(set([G[u][v]["colour"] for v in nx.neighbors(G, u)]))

def colours_on_neighbours(G, n):
"""The set of all colours on neighbours of a node n in a graph G."""
return(set([nx.get_node_attributes(G, "colour")[m] for m in G.neighbors(n)]))

def first_permissible_or_none(G, u, v):
"""
Returns the first element of A if A is non-empty otherwise returns None.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_colours_on_neighbours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import networkx as nx

import listcolouring
from listcolouring import colours_on_neighbours

def test_colours_on_neighbours():
G = nx.complete_graph(3)
node_colours_dict = {0: 3, 1: 2, 2:1}
nx.set_node_attributes(G, node_colours_dict, "colour")
assert colours_on_neighbours(G, 0) == set([2, 1])
assert colours_on_neighbours(G, 1) == set([3, 1])
assert colours_on_neighbours(G, 2) == set([3, 2])

Loading