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 example of edge list-colouring #5

Merged
merged 5 commits into from
Nov 27, 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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
png: png/petersen-node.png
png: png/petersen-edge.png png/petersen-node.png

png/petersen-edge.png: src/petersen-edge.py
poetry run python $<

png/petersen-node.png: src/petersen-node.py
poetry run python $<
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ Constraint-based list-colouring in Python with vizing.

![](png/petersen-node.png)

## Edge list-colouring

![](png/petersen-edge.png)

Binary file added png/petersen-edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = "Constraint-based list-colouring in Python with vizing."
authors = ["Matthew Henderson <[email protected]>"]
license = "MIT"
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
Expand Down
31 changes: 31 additions & 0 deletions src/petersen-edge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import listcolouring as lc
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import networkx as nx
import vizing as vz

G = nx.petersen_graph()

G = lc.list_init(G, range(0, 10), 3, 0)

G = vz.edge_list_colouring_solution(G)

G_layout = nx.shell_layout(G, nlist = [range(5, 10), range(5)], rotate = 0.)
edge_colours = nx.get_edge_attributes(G,'colour').values()

nx.draw(G,
pos = G_layout,
edge_color = edge_colours,
with_labels = False,
edge_cmap = plt.cm.tab10,
width = 5,
node_size = 150,
node_color = 'black')

edge_labels = dict([((n1, n2), str(d['colour']) + ': ' + str(sorted(d['permissible']))) for n1, n2, d in G.edges(data = True)])
X = nx.draw_networkx_edge_labels(G, pos = G_layout, edge_labels = edge_labels, font_size = 6)

patches = [mpatches.Patch(color = plt.cm.tab10(i), label = f'{i}') for i in edge_colours]
plt.legend(handles = patches, title = "Colours", bbox_to_anchor = (1, 1))

plt.savefig("png/petersen-edge.png", format = "PNG")
12 changes: 4 additions & 8 deletions src/petersen-node.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import listcolouring as lc
import networkx as nx
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

import listcolouring
from listcolouring import list_init_node

import vizing
from vizing import list_colouring_solution
import vizing as vz

G = nx.petersen_graph()
G = list_init_node(G, range(1, 10), 3, 0)
G = list_colouring_solution(G)
G = lc.list_init_node(G, range(1, 10), 3, 0)
G = vz.node_list_colouring_solution(G)

G_layout = nx.shell_layout(G, nlist = [range(5, 10), range(5)], rotate = 0.)

Expand Down