You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, the `problem` is a `Independence` instance, it contains the tensor network contraction tree for the target graph.
59
+
Here, the `problem` is a `IndependentSet` instance, it contains the tensor network contraction tree for the target graph.
60
60
Here, we choose the `TreeSA` optimizer to optimize the tensor network contraciton tree, it is a local search based algorithm, check [arXiv: 2108.05665](https://arxiv.org/abs/2108.05665). You will see some warnings, do not panic, this is because we set `sc_target` (target space complex) to 1 for agressive optimization of space complexity. Type `?TreeSA` in a Julia REPL for more information about the key word arguments.
61
-
Similarly, one can select tensor network structures for solving other problems like `MaximalIndependence`, `MaxCut`, `Matching`, `Coloring{K}`, `PaintShop` and `set_packing`.
61
+
Similarly, one can select tensor network structures for solving other problems like `MaximalIS`, `MaxCut`, `Matching`, `Coloring{K}`, `PaintShop` and `set_packing`.
# This tutorial only covers the coloring problem specific features,
5
+
# It is recommended to read the [Independent set problem](@ref) tutorial too to know more about
6
+
# * how to optimize the tensor network contraction order,
7
+
# * what are the other graph properties computable,
8
+
# * how to select correct method to compute graph properties,
9
+
# * how to compute weighted graphs and handle open vertices.
10
+
11
+
# ## Problem definition
12
+
# A [vertex coloring](https://en.wikipedia.org/wiki/Graph_coloring) is an assignment of labels or colors to each vertex of a graph such that no edge connects two identically colored vertices.
13
+
# In the following, we are going to defined a 3-coloring problem for the Petersen graph.
14
+
15
+
using GraphTensorNetworks, Graphs
16
+
17
+
graph = Graphs.smallgraph(:petersen)
18
+
19
+
# We can visualize this graph using the following function
Copy file name to clipboardExpand all lines: examples/IndependentSet.jl
+38-13Lines changed: 38 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,11 @@
1
1
# # Independent set problem
2
2
3
-
# ## Introduction
4
-
using GraphTensorNetworks, Graphs
5
-
6
-
# Please check the docstring of [`Independence`](@ref) for the definition of independence problem.
7
-
@doc Independence
8
-
3
+
# ## Problem definition
4
+
# In graph theory, an [independent set](https://en.wikipedia.org/wiki/Independent_set_(graph_theory)) is a set of vertices in a graph, no two of which are adjacent.
9
5
# In the following, we are going to defined an independent set problem for the Petersen graph.
10
6
7
+
using GraphTensorNetworks, Graphs
8
+
11
9
graph = Graphs.smallgraph(:petersen)
12
10
13
11
# We can visualize this graph using the following function
@@ -17,17 +15,38 @@ locations = [[rot15(0.0, 1.0, i) for i=0:4]..., [rot15(0.0, 0.6, i) for i=0:4]..
17
15
18
16
show_graph(graph; locs=locations)
19
17
18
+
# ## Tensor network representation
19
+
# Type [`IndependentSet`](@ref) can be used for constructing the tensor network with optimized contraction order for solving an independent set problem.
20
+
# we map a vertex ``i\in V`` to a label ``s_i \in \{0, 1\}`` of dimension 2,
21
+
# where we use 0 (1) to denote a vertex is absent (present) in the set.
22
+
# For each label ``s_i``, we defined a parametrized rank-one vertex tensor ``W(x_i)`` as
23
+
# ```math
24
+
# W(x_i)_{s_i} = \left(\begin{matrix}
25
+
# 1 \\
26
+
# x_i
27
+
# \end{matrix}\right)_{s_i}
28
+
# ```
29
+
# We use subscripts to index tensor elements, e.g.``W(x_i)_0=1`` is the first element associated
30
+
# with ``s_i=0`` and ``W(x_i)_1=x_i`` is the second element associated with ``s_i=1``.
31
+
# Similarly, on each edge ``(u, v)``, we define a matrix ``B`` indexed by ``s_u`` and ``s_v`` as
32
+
# ```math
33
+
# B_{s_i s_j} = \left(\begin{matrix}
34
+
# 1 & 1\\
35
+
# 1 & 0
36
+
# \end{matrix}\right)_{s_is_j}
37
+
# ```
20
38
# Let us contruct the problem instance with optimized tensor network contraction order as bellow.
21
-
problem =Independence(graph; optimizer=TreeSA(sc_weight=1.0, ntrials=10,
39
+
problem =IndependentSet(graph; optimizer=TreeSA(sc_weight=1.0, ntrials=10,
22
40
βs=0.01:0.1:15.0, niters=20, rw_weight=0.2),
23
41
simplifier=MergeGreedy());
24
42
25
-
#The `optimizer` is for optimizing the contraction orders.
43
+
#In the input arguments of [`IndependentSet`](@ref), the `optimizer` is for optimizing the contraction orders.
26
44
# Here we use the local search based optimizer in [arXiv:2108.05665](https://arxiv.org/abs/2108.05665).
27
45
# If no optimizer is specified, the default fast (in terms of the speed of searching contraction order)
28
46
# but worst (in term of contraction complexity) [`GreedyMethod`](@ref) will be used.
29
47
# `simplifier` is a preprocessing routine to speed up the `optimizer`.
30
-
# Please check section [Tensor Network](@ref) for more details.
48
+
# The returned instance `problem` contains a field `code` that specifies the tensor network contraction order.
49
+
# Its contraction time space complexity is ``2^{{\rm tw}(G)}``, where ``{\rm tw(G)}`` is the [tree-width](https://en.wikipedia.org/wiki/Treewidth) of ``G``.
31
50
# One can check the time, space and read-write complexity with the following function.
# For the definition of independence polynomial, please check the docstring of [`Independence`](@ref) or this [wiki page](https://mathworld.wolfram.com/IndependencePolynomial.html).
70
+
# The graph polynomial defined for the independence problem is known as the independence polynomial.
71
+
# ```math
72
+
# I(G, x) = \sum_{k=0}^{\alpha(G)} a_k x^k,
73
+
# ```
74
+
# where ``\alpha(G)`` is the maximum independent set size,
75
+
# ``a_k`` is the number of independent sets of size ``k`` in graph ``G=(V,E)``.
76
+
# The total number of independent sets is thus equal to ``I(G, 1)``.
52
77
# There are 3 methods to compute a graph polynomial, `:finitefield`, `:fft` and `:polynomial`.
53
78
# These methods are introduced in the docstring of [`GraphPolynomial`](@ref).
0 commit comments