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
show_graph(graph; locs=locations, vertex_colors=[vertex_color_map[Int(c)] for c in single_solution.c.data])
62
+
63
+
# Let us try to solve the same issue on its line graph, a graph that generated by mapping an edge to a vertex and two edges sharing a common vertex will be connected.
64
+
linegraph =line_graph(graph)
65
+
66
+
show_graph(linegraph; locs=[0.5.* (locations[e.src] .+ locations[e.dst]) for e inedges(graph)])
67
+
68
+
# Let us construct the tensor network and see if there are solutions.
Copy file name to clipboardExpand all lines: examples/MaximalIS.jl
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
# * how to compute weighted graphs and handle open vertices.
10
10
11
11
# ## Problem definition
12
-
using GraphTensorNetworks, Graphs
12
+
using GraphTensorNetworks, Graphs, Compose
13
13
14
14
# In graph theory, a [maximal independent set](https://en.wikipedia.org/wiki/Maximal_independent_set) is an independent set that is not a subset of any other independent set.
15
15
# It is different from maximum independent set because it does not require the set to have the max size.
@@ -26,6 +26,7 @@ locations = [[rot15(0.0, 1.0, i) for i=0:4]..., [rot15(0.0, 0.6, i) for i=0:4]..
26
26
show_graph(graph; locs=locations)
27
27
28
28
# ## Tensor network representation
29
+
# Type [`MaximalIS`](@ref) can be used for constructing the tensor network with optimized contraction order for solving a maximal independent set problem.
29
30
# For a vertex ``v\in V``, we define a boolean degree of freedom ``s_v\in\{0, 1\}``.
30
31
# We defined the restriction on its neighbourhood ``N[v]``:
# This result should be consistent with that given by the [Bron Kerbosch algorithm](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm) on the complement of Petersen graph.
Copy file name to clipboardExpand all lines: examples/PaintShop.jl
+89-3Lines changed: 89 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,96 @@
9
9
# * how to compute weighted graphs and handle open vertices.
10
10
11
11
# ## Problme Definition
12
-
# The [binary paint shop problem](http://m-hikari.com/ams/ams-2012/ams-93-96-2012/popovAMS93-96-2012-2.pdf).
12
+
# The [binary paint shop problem](http://m-hikari.com/ams/ams-2012/ams-93-96-2012/popovAMS93-96-2012-2.pdf) is defined as follows:
13
+
# we are given a ``2m`` length sequence containing ``m`` cars, where each car appears twice.
14
+
# Each car need to be colored red in one occurrence, and blue in the other.
15
+
# We need to choose which occurrence for each car to color with which color — the goal is to minimize the number of times we need to change the current color.
13
16
14
-
# In the following, we are going to defined a binary paint shop problem for the following string
17
+
# In the following, we use a character to represent a car,
18
+
# and defined a binary paint shop problem as a string that each character appear exactly twice.
15
19
16
20
using GraphTensorNetworks, Graphs
17
21
18
-
sequence ="abaccb"
22
+
sequence =collect("iadgbeadfcchghebif")
23
+
24
+
# We can visualize this paint shop problem as a graph
locations = [rot(0.0, 1.0, -0.25π -1.5*π*(i-0.5)/length(sequence)) for i=1:length(sequence)]
28
+
29
+
graph =path_graph(length(sequence))
30
+
for i=1:length(sequence)
31
+
j =findlast(==(sequence[i]), sequence)
32
+
i != j &&add_edge!(graph, i, j)
33
+
end
34
+
35
+
show_graph(graph; locs=locations, texts=string.(sequence), edge_colors=[sequence[e.src] == sequence[e.dst] ?"blue":"black"for e inedges(graph)])
36
+
37
+
# Vertices connected by blue edges must have different colors,
38
+
# and the goal becomes a min-cut problem defined on black edges.
39
+
40
+
# ## Tensor network representation
41
+
# Type [`PaintShop`](@ref) can be used for constructing the tensor network with optimized contraction order for solving a binary paint shop problem.
42
+
# To obtain its tensor network representation, we associating car ``c_i`` (the ``i``-th character in our example) with a degree of freedom ``s_{c_i} \in \{0, 1\}``,
43
+
# where we use ``0`` to denote the first appearance of a car is colored red and ``1`` to denote the first appearance of a car is colored blue.
44
+
# For each black edges ``(i, i+1)``, we define an edge tensor labeld by ``(s_{c_i}, s_{c_{i+1}})`` as follows:
45
+
# If both cars on this edge are their first or second appearance
0 commit comments