Let's explore how to use the QuasiStableColors library with an example.


First, install the library. One option is to run the following code:

using Pkg

After installing activate the library:

using QuasiStableColors

Let's use QSC as shorthand for the library name:

const QSC = QuasiStableColors

Coloring Graphs

Let's create a simple example graph.

using Graphs
n = 8
g = Graphs.SimpleGraphs.dorogovtsev_mendes(n, seed=0)

using GraphMakie, CairoMakie

Example network graph from above code

Now, let's generate a quasi-stable coloring C where we allow at most one edge error (i.e. $q=1$).

C = QSC.q_color(g, q=1.0)
Quasi-stable coloring(color count=4, max q-error=1.0)

We get a four-partition coloring. How are the nodes grouped?

P = QSC.partitions(C)
4-element Vector{Vector{Int64}}:
 [5, 6, 7, 8, 1]

Let's assign a unique visual color to each group:

using Colors
palette = distinguishable_colors(length(P))
color_map = Array{Colorant}(undef, nv(g))
for (i, x) in enumerate(P)
    color_map[x] .= palette[i]

and draw the graph again:

graphplot(g, node_color=color_map)

Same graph, now colored according to above partition

Summary Graphs

Let's build a summary graph using the coloring C. Each supernode represents one color:

G_super, weights = QSC.super_graph(C)

Graph of supernodes implied by coloring


This section on how to use the coloring for graph algorithms is upcoming–for now see the maximum-flow section of the API reference as an example.