diff options
| author | HactarCE <6060305+HactarCE@users.noreply.github.com> | 2023-11-26 22:01:00 -0500 |
|---|---|---|
| committer | HactarCE <6060305+HactarCE@users.noreply.github.com> | 2023-11-26 22:01:00 -0500 |
| commit | 427f50d3c93432ff85caac923fac10191d519d49 (patch) | |
| tree | 811d268aaf6fd528653efcd820b2ea0a55d5e4a5 /graphviz.py | |
| parent | 3ff20698d8d303ed3f9010d77e052874de12aad8 (diff) | |
| download | graph-coloring-427f50d3c93432ff85caac923fac10191d519d49.tar.gz graph-coloring-427f50d3c93432ff85caac923fac10191d519d49.zip | |
Add graph visualization
Diffstat (limited to 'graphviz.py')
| -rw-r--r-- | graphviz.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/graphviz.py b/graphviz.py new file mode 100644 index 0000000..24ee41b --- /dev/null +++ b/graphviz.py @@ -0,0 +1,23 @@ +# Paste output into https://dreampuf.github.io/GraphvizOnline/ +# +# 'circo' or 'dot' tend to look best + +COLORS = ['#1E88E5', '#D81B60', '#FFC107', '#004D40'] +USE_EDGE_COLORS = False + +graph = [(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(2,3),(2,4),(3,4)] +coloring = '0011011011' + +node_count = len(coloring) // 2 +node_colors = [COLORS[int(coloring[i*2:i*2+2], 2)] for i in range(node_count)] + +print('graph G {') +print(' node [style="filled" label="" color="white" shape="circle"]') +for i in range(len(coloring) // 2): + print(f' {i} [fillcolor="{node_colors[i]}"];') +for a, b in graph: + if USE_EDGE_COLORS: + print(f' {a} -- {b} [color="{node_colors[a]};0.5:{node_colors[b]}"];') + else: + print(f' {a} -- {b};') +print('}') |