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

Use nx functions to apply node and edge colourings. #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 3 additions & 6 deletions src/vizing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import constraint as ct
import networkx as nx

def node_list_colouring_problem(G):
"""
Expand All @@ -22,9 +23,7 @@ def node_list_colouring_solution(G):
:return A properly list-coloured graph.
"""
P = node_list_colouring_problem(G)
S = P.getSolution()
for node in S:
G.nodes[node]['colour'] = S[node]
nx.set_node_attributes(G, P.getSolution(), name = 'colour')
return(G)

def edge_list_colouring_problem(G, directed = False):
Expand Down Expand Up @@ -56,9 +55,7 @@ def edge_list_colouring_solution(G, directed = False):
:return A properly edge list-coloured graph.
"""
P = edge_list_colouring_problem(G, directed)
S = P.getSolution()
for edge in G.edges():
G.edges()[edge]['colour'] = S[edge]
nx.set_edge_attributes(G, P.getSolution(), 'colour')
return(G)

def total_list_colouring_problem(G):
Expand Down
Loading