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 ChooseOptimizer to
select an integer programming solver (defaults to HiGHS).
New in version 0.6: The functions
use_Gurobianduse_Cbchave been removed. The default solver is nowHiGHS. To change solvers, use theset_solverfunction fromChooseOptimizer.
-
max_indep_set(G)returns a maximum size independent set of anUndirectedGraph. -
max_clique(G)returns a maximum size clique of anUndirectedGraph. -
max_matching(G)returns a maximum size matching of anUndirectedGraph. -
fractional_matching(G)returns a (maximum) fractional matching of the graphG. This is presented a dictionary mapping edges ofGto 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 ofGis incident with exactlykedges of the set. An error is thrown if no such set exists. (Whenk==1this returns a perfect matching.)
-
min_dom_set(G)returns a smallest dominating set of anUndirectedGraph. That is, a smallest setSwith the property that every vertex ofGeither is inSor is adjacent to a vertex ofS. -
min_vertex_cover(G)returns a smallest vertex cover ofG. This is a set of verticesSsuch that every edge ofGhas at least one end point inS. -
min_edge_cover(G)returns a smallest edge cover ofG. This is a set of edgesFsuch that every vertex ofGis the end point of at least one edge inF. Note: IfGhas an isolated vertex, then no edge cover is possible and error is generated.
-
iso(G,H)finds an isomorphism between graphsGandH. Specifically, it finds aDictmapping the vertices ofGto the vertices ofHthat gives the isomorphism. If the graphs are not isomorphic, an error is raised. -
iso2(G,H)has the same functionality asisobut 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 dictionarydis an isomorphism fromGtoH. -
iso_matrix(G,H)finds an isomorphism between graphsGandH. Specifically, it finds a permutation matrixPsuch thatA*P==P*BwhereAandBare the adjacency matrices of the graphsGandH, respectively. If the graphs are not isomorphic, an error is raised. -
frac_iso(G,H)finds a fractional isomorphism between the graphs. Specifically, ifAandBare the adjacency matrices of the two graphs, then produce a doubly stochastic matrixSsuch thatA*S == S*B, or throw an error if no such matrix exists. -
is_frac_iso(G,H)returnstrueif the graphs are fractionally isomorphic andfalseif not. -
hom(G,H)finds a graph homomorphism fromGtoH. This is a mappingf(dictionary) with the property that if{u,v}is an edge ofGthen{f[u],f[v]}is an edge ofH. If no homomorphism exists an error is raised. -
hom_check(G,H,d)determines ifdis a homomorphism fromGtoH. -
info_map(G)creates a mapping from the vertices ofGto 128-bit 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 graphGwith the property that isomorphic graphs have the same hash value.
-
vertex_color(G,k)returns ak-coloring ofG(or throws an error if no such coloring exists). Ifkis 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 ofGtob-element subsets of{1,2,...,a}such that adjacent vertices are assigned disjoint sets. -
chromatic_number(G)returns the leastksuch thatGisk-colorable. -
chromatic_poly(G)computes the chromatic polynomial ofG. (See thehelpmessage for more information.) -
edge_color(G,k)returns ak-edge-coloring ofG. -
edge_chromatic_number(G)returns the edge chromatic number ofG.
-
min_cut(G)returns a minimum size (vertex) cut set.min_cut(G,s,t)return a smallest set of vertices that separatesandt. -
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 verticessandt. -
edge_connectivity(G)oredge_connectivity(G,s,t)returns the size of such an edge cut set.
-
ad(G)returns the average degree ofG. -
mad(G)returns the maximum average degree ofG. -
mad_core(G)returns a subgraphHofGfor whichad(H)==mad(G).
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,2-Kneser 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
SimpleGraphAlgorithms is built to work with UndirectedGraph objects as defined in SimpleGraphs.
To apply these functions to graphs from Julia's Graphs module, you can use SimpleGraphConverter like this:
julia> using Graphs, SimpleGraphAlgorithms, SimpleGraphs, SimpleGraphConverter
julia> g = circular_ladder_graph(9)
{18, 27} undirected simple Int64 graph
julia> chromatic_number(UG(g))
3