SimpleGraphAlgorithms
This module provides additional functions for the SimpleGraphs
module that rely on integer programming. In addition to requiring the
SimpleGraphs
module, it also requires JuMP
and MathProgBase
which, in turn, requires that some solvers be loaded. I've used Cbc
.
Functions
Cliques and independent sets

max_indep_set(G)
returns a maximum size independent set of aSimpleGraph
. 
max_clique(G)
returns a maximum size clique of aSimpleGraph
. 
max_matching(G)
returns a maximum size matching of aSimpleGraph
. 
fractional_matching(G)
returns a (maximum) fractional matching of the graphG
. This is presented a dictionary mapping edges ofG
to rational values in{0, 1/2, 1}
. 
kfactor(G,k)
returns ak
factor ofG
. This is a set of edges with the property that every vertex ofG
is incident with exactlyk
edges of the set. An error is thrown if no such set exists. (Whenk==1
this returns a perfect matching.)
Covering and domination

min_dom_set(G)
returns a smallest dominating set of aSimpleGraph
. That is, a smallest setS
with the property that every vertex ofG
either is inS
or is adjacent to a vertex ofS
. 
min_vertex_cover(G)
returns a smallest vertex cover ofG
. This is a set of verticesS
such that every edge ofG
has at least one end point inS
. 
min_edge_cover(G)
returns a smallest edge cover ofG
. This is a set of edgesF
such that every vertex ofG
is the end point of at least one edge inF
. Note: IfG
has an isolated vertex, then no edge cover is possible and error is generated.
Isomorphism

iso(G,H)
finds an isomorphism between graphsG
andH
. Specifically, it finds aDict
mapping the vertices ofG
to the vertices ofH
that gives the isomorphism. If the graphs are not isomorphic, an error is raised. 
iso2(G,H)
has the same functionality asiso
but omits various preliminary checks. This may be faster for highly symmetric graphs (e.g., for vertex transitive graphs). 
is_iso(G,H)
checks if the two graphs are isomorphic. 
is_iso(G,H,d)
checks if the dictionaryd
is an isomorphism fromG
toH
. 
iso_matrix(G,H)
finds an isomorphism between graphsG
andH
. Specifically, it finds a permutation matrixP
such thatA*P==P*B
whereA
andB
are the adjacency matrices of the graphsG
andH
, respectively. If the graphs are not isomorphic, an error is raised. 
hom(G,H)
finds a graph homomorphism fromG
toH
. This is a mappingf
(dictionary) with the property that if{u,v}
is an edge ofG
then{f[u],f[v]}
is an edge ofH
. If no homomorphism exists an error is raised. 
hom_check(G,H,d)
determines ifd
is a homomorphism fromG
toH
. 
info_map(G)
creates a mapping from the vertices ofG
to 128bit integers. If there is an automorphism between a pair of vertices, then they will map to the same value, and the converse is likely to be true. 
uhash(G)
creates a hash value for the graphG
with the property that isomorphic graphs have the same hash value.
Coloring

vertex_color(G,k)
returns ak
coloring ofG
(or throws an error if no such coloring exists). Ifk
is omitted, the number of colors isχ(G)
(chromatic number). 
vertex_color(G,a,b)
returns ana:b
coloring ofG
(or throws an error if no such coloring exists). Ana:b
coloring is a mapping from the vertices ofG
tob
element subsets of{1,2,...,a}
such that adjacent vertices are assigned disjoint sets. 
chromatic_number(G)
returns the leastk
such thatG
isk
colorable. 
chromatic_poly(G)
computes the chromatic polynomial ofG
. (See thehelp
message for more information.) 
edge_color(G,k)
returns ak
edgecoloring ofG
. 
edge_chromatic_number(G)
returns the edge chromatic number ofG
.
Connectivity

min_cut(G)
returns a minimum size (vertex) cut set.min_cut(G,s,t)
return a smallest set of vertices that separates
andt
. 
connectivity(G)
orconnectivity(G,s,t)
returns the size of such a cut set. 
min_edge_cut(G)
returns a minimum size edge cut set.min_edge_cut(G,s,t)
returns a minimum set of edges that separate verticess
andt
. 
edge_connectivity(G)
oredge_connectivity(G,s,t)
returns the size of such an edge cut set.
Maximum average degree

ad(G)
returns the average degree ofG
. 
mad(G)
returns the maximum average degree ofG
. 
mad_core(G)
returns a subgraphH
ofG
for whichad(H)==mad(G)
.
Examples
julia> using SimpleGraphs; using SimpleGraphAlgorithms; using ChooseOptimizer; using ShowSet
julia> set_solver_verbose(false)
[ Info: Setting verbose option for Cbc to false
julia> G = Paley(17)
Paley (n=17, m=68)
julia> max_indep_set(G)
{1,4,7}
julia> max_clique(G)
{3,4,5}
julia> min_dom_set(G)
{3,6,9}
julia> max_matching(G)
{(1, 16),(2, 4),(3, 12),(5, 9),(6, 15),(7, 8),(10, 11),(13, 14)}
julia> vertex_color(G,6)
Dict{Int64,Int64} with 17 entries:
2 => 3
16 => 1
11 => 4
0 => 4
7 => 6
9 => 2
10 => 1
8 => 3
6 => 4
4 => 6
3 => 5
5 => 3
13 => 1
14 => 5
15 => 2
12 => 2
1 => 6
Petersen's graph can be described as either the 5,2Kneser graph or as the complement of the line graph of K(5).
julia> G = Kneser(5,2);
julia> H = complement(line_graph(Complete(5)));
julia> iso(G,H)
Dict{Set{Int64},Tuple{Int64,Int64}} with 10 entries:
{1,4} => (1, 5)
{2,4} => (1, 4)
{2,5} => (3, 4)
{1,3} => (2, 5)
{3,4} => (1, 2)
{1,2} => (4, 5)
{3,5} => (2, 3)
{4,5} => (1, 3)
{2,3} => (2, 4)
{1,5} => (3, 5)
julia> iso_matrix(G,H)
10×10 Array{Int64,2}:
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 1 0 0 0 0 0 0 0
Setting Solver and its Options
By default, the Cbc
solver is used for integer programming
and the optimizer does no output.
The function use_Cbc()
sets the solver to be the Cbc
solver.
Called as use_Cbc(true)
causes the solver to be verbose in
its working.
The Gurobi
solver may used instead. Since this module is not
dependent on Gurobi
, do this:
julia> using Gurobi
julia> use_Gurobi()
Alternatively, use_Gurobi(true)
for extensive output as the
solver does its work.
To switch back to the Cbc
solver, do use_Cbc()
.
These functions rely on my ChooseOptimizer
module.