Skip to content

Commit 75bba4d

Browse files
committed
add new gadget
1 parent 6c67065 commit 75bba4d

File tree

6 files changed

+121
-58
lines changed

6 files changed

+121
-58
lines changed

Diff for: project/createmap.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnitDiskMapping, GraphTensorNetworks
1+
using UnitDiskMapping, GraphTensorNetworks, Graphs
22

33
function mapped_entry_to_compact(s::Pattern)
44
locs, g, pins = mapped_graph(s)
@@ -40,8 +40,8 @@ function compute_mis_overhead(s)
4040
locs2, g2, pins2 = mapped_graph(s)
4141
m1 = mis_compactify!(solve(Independence(g1, openvertices=pins1), "size max"))
4242
m2 = mis_compactify!(solve(Independence(g2, openvertices=pins2), "size max"))
43-
@test nv(g1) == length(locs1) && nv(g2) == length(locs2)
44-
sig, diff = UnitDiskMapping.is_diff_by_const(content.(m1), content.(m2))
43+
@assert nv(g1) == length(locs1) && nv(g2) == length(locs2)
44+
sig, diff = UnitDiskMapping.is_diff_by_const(GraphTensorNetworks.content.(m1), GraphTensorNetworks.content.(m2))
4545
@assert sig
4646
return diff
4747
end
@@ -74,4 +74,5 @@ end
7474
dump_mapping_to_julia(joinpath(@__DIR__, "..", "src", "extracting_results.jl"),
7575
(Cross{false}(), Cross{true}(),
7676
Turn(), WTurn(), Branch(), BranchFix(), TrivialTurn(), TCon(), BranchFixB(),
77-
UnitDiskMapping.simplifier_ruleset...))
77+
EndTurn(),
78+
UnitDiskMapping.simplifier_ruleset...))

Diff for: src/UnitDiskMapping.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Graphs
66

77
export UGrid, apply_crossing_gadgets!, apply_simplifier_gadgets!, apply_gadget!, embed_graph
88
export unapply_gadgets!, unmatch
9-
export Pattern, Corner, Turn, Cross, source_graph, mapped_graph, TruncatedTurn
9+
export Pattern, Corner, Turn, Cross, source_graph, mapped_graph, TruncatedTurn, EndTurn
1010
export mapped_entry_to_compact, source_entry_to_configs, map_config_back, mis_overhead
1111
export UNode, contract_graph, compress_graph
1212

Diff for: src/extracting_results.jl

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function mapped_entry_to_compact(::Cross{false})
55
end
66

77
function source_entry_to_configs(::Cross{false})
8-
return Dict(Pair{Int64, Vector{BitVector}}[5 => [[1, 0, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 0, 1, 0, 1]], 12 => [[0, 1, 0, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0, 1]], 8 => [[0, 1, 0, 0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0]], 1 => [[1, 0, 0, 1, 0, 0, 0, 1, 0], [1, 0, 1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 1, 0, 0], [1, 0, 1, 0, 0, 0, 1, 0, 0]], 0 => [[0, 1, 0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 0, 1, 0, 0]], 6 => [[0, 1, 0, 1, 0, 1, 0, 0, 1]], 11 => [[1, 0, 1, 0, 1, 1, 0, 1, 0]], 9 => [[1, 0, 1, 0, 1, 0, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1, 0, 0]], 14 => [[0, 1, 0, 0, 1, 1, 0, 0, 1], [0, 0, 1, 0, 1, 1, 0, 0, 1]], 3 => [[1, 0, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 1, 0]], 7 => [[1, 0, 0, 1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 0, 1, 0, 0, 1]], 4 => [[0, 1, 0, 1, 0, 0, 1, 0, 1]], 13 => [[1, 0, 1, 0, 1, 0, 1, 0, 1]], 15 => [[1, 0, 1, 0, 1, 1, 0, 0, 1]], 2 => [[0, 1, 0, 1, 0, 1, 0, 1, 0]], 10 => [[0, 1, 0, 0, 1, 1, 0, 1, 0], [0, 0, 1, 0, 1, 1, 0, 1, 0]]])
8+
return Dict(Pair{Int64, Vector{BitVector}}[5 => [[1, 0, 1, 0, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 0, 1, 0, 1]], 12 => [[0, 1, 0, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 1, 0, 1]], 8 => [[0, 1, 0, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0, 1, 0, 0], [0, 1, 0, 0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0, 0, 1, 0]], 1 => [[1, 0, 1, 0, 0, 0, 1, 0, 0], [1, 0, 0, 1, 0, 0, 1, 0, 0], [1, 0, 1, 0, 0, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 0, 1, 0]], 0 => [[0, 1, 0, 1, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 0, 0, 1, 0]], 6 => [[0, 1, 0, 1, 0, 1, 0, 0, 1]], 11 => [[1, 0, 1, 0, 1, 1, 0, 1, 0]], 9 => [[1, 0, 1, 0, 1, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0, 0, 1, 0]], 14 => [[0, 1, 0, 0, 1, 1, 0, 0, 1], [0, 0, 1, 0, 1, 1, 0, 0, 1]], 3 => [[1, 0, 1, 0, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1, 0, 1, 0]], 7 => [[1, 0, 1, 0, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1, 0, 0, 1]], 4 => [[0, 1, 0, 1, 0, 0, 1, 0, 1]], 13 => [[1, 0, 1, 0, 1, 0, 1, 0, 1]], 15 => [[1, 0, 1, 0, 1, 1, 0, 0, 1]], 2 => [[0, 1, 0, 1, 0, 1, 0, 1, 0]], 10 => [[0, 1, 0, 0, 1, 1, 0, 1, 0], [0, 0, 1, 0, 1, 1, 0, 1, 0]]])
99
end
1010

1111
mis_overhead(::Cross{false}) = -1.0
@@ -27,7 +27,7 @@ function mapped_entry_to_compact(::Turn)
2727
end
2828

2929
function source_entry_to_configs(::Turn)
30-
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 1, 0, 1, 0]], 2 => [[0, 0, 1, 0, 1], [0, 1, 0, 0, 1]], 3 => [[1, 0, 1, 0, 1]], 1 => [[1, 0, 0, 1, 0], [1, 0, 1, 0, 0]]])
30+
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 1, 0, 1, 0]], 2 => [[0, 1, 0, 0, 1], [0, 0, 1, 0, 1]], 3 => [[1, 0, 1, 0, 1]], 1 => [[1, 0, 0, 1, 0], [1, 0, 1, 0, 0]]])
3131
end
3232

3333
mis_overhead(::Turn) = -1.0
@@ -38,7 +38,7 @@ function mapped_entry_to_compact(::WTurn)
3838
end
3939

4040
function source_entry_to_configs(::WTurn)
41-
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[1, 0, 1, 0, 0]], 2 => [[1, 0, 0, 0, 1], [0, 0, 0, 1, 1]], 3 => [[0, 1, 0, 1, 1]], 1 => [[0, 1, 1, 0, 0], [0, 1, 0, 1, 0]]])
41+
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[1, 0, 1, 0, 0]], 2 => [[0, 0, 0, 1, 1], [1, 0, 0, 0, 1]], 3 => [[0, 1, 0, 1, 1]], 1 => [[0, 1, 1, 0, 0], [0, 1, 0, 1, 0]]])
4242
end
4343

4444
mis_overhead(::WTurn) = -1.0
@@ -49,7 +49,7 @@ function mapped_entry_to_compact(::Branch)
4949
end
5050

5151
function source_entry_to_configs(::Branch)
52-
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 1, 0, 1, 0, 0, 1, 0]], 4 => [[0, 1, 0, 0, 0, 1, 0, 1], [0, 0, 1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 0, 0, 1]], 5 => [[1, 0, 1, 0, 0, 1, 0, 1]], 6 => [[0, 1, 0, 0, 1, 1, 0, 1], [0, 0, 1, 0, 1, 1, 0, 1]], 2 => [[0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 0, 1, 1, 0, 0]], 7 => [[1, 0, 1, 0, 1, 1, 0, 1]], 3 => [[1, 0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 1, 0, 0]], 1 => [[1, 0, 1, 0, 0, 0, 1, 0], [1, 0, 1, 0, 0, 1, 0, 0], [1, 0, 0, 1, 0, 0, 1, 0]]])
52+
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 1, 0, 1, 0, 0, 1, 0]], 4 => [[0, 1, 0, 0, 0, 1, 0, 1], [0, 0, 1, 0, 0, 1, 0, 1], [0, 1, 0, 1, 0, 0, 0, 1]], 5 => [[1, 0, 1, 0, 0, 1, 0, 1]], 6 => [[0, 1, 0, 0, 1, 1, 0, 1], [0, 0, 1, 0, 1, 1, 0, 1]], 2 => [[0, 1, 0, 0, 1, 1, 0, 0], [0, 0, 1, 0, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0]], 7 => [[1, 0, 1, 0, 1, 1, 0, 1]], 3 => [[1, 0, 1, 0, 1, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1, 0]], 1 => [[1, 0, 1, 0, 0, 1, 0, 0], [1, 0, 1, 0, 0, 0, 1, 0], [1, 0, 0, 1, 0, 0, 1, 0]]])
5353
end
5454

5555
mis_overhead(::Branch) = -1.0
@@ -60,7 +60,7 @@ function mapped_entry_to_compact(::BranchFix)
6060
end
6161

6262
function source_entry_to_configs(::BranchFix)
63-
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0]], 2 => [[0, 1, 0, 1, 0, 1]], 3 => [[1, 0, 1, 0, 0, 1], [1, 0, 0, 1, 0, 1]], 1 => [[1, 0, 1, 0, 1, 0]]])
63+
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 1, 0]], 2 => [[0, 1, 0, 1, 0, 1]], 3 => [[1, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1]], 1 => [[1, 0, 1, 0, 1, 0]]])
6464
end
6565

6666
mis_overhead(::BranchFix) = -1.0
@@ -99,6 +99,17 @@ end
9999
mis_overhead(::BranchFixB) = -1.0
100100

101101

102+
function mapped_entry_to_compact(::EndTurn)
103+
return Dict([0 => 0, 1 => 1])
104+
end
105+
106+
function source_entry_to_configs(::EndTurn)
107+
return Dict(Pair{Int64, Vector{BitVector}}[0 => [[0, 0, 1], [0, 1, 0]], 1 => [[1, 0, 1]]])
108+
end
109+
110+
mis_overhead(::EndTurn) = -1.0
111+
112+
102113
function mapped_entry_to_compact(::UnitDiskMapping.DanglingLeg)
103114
return Dict([0 => 0, 1 => 1])
104115
end

Diff for: src/gadgets.jl

+66-46
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,18 @@ end
108108

109109
struct Cross{CON} <: CrossPattern end
110110
iscon(::Cross{CON}) where {CON} = CON
111-
# ⋅ ● ⋅
112-
# ◆ ◉ ●
113-
# ⋅ ◆ ⋅
111+
# ⋅ ● ⋅
112+
# ◆ ◉ ●
113+
# ⋅ ◆ ⋅
114114
function source_graph(::Cross{true})
115115
locs = [(2,1), (2,2), (2,3), (1,2), (2,2), (3,2)]
116116
g = simplegraph([(1,2), (2,3), (4,5), (5,6), (1,6)])
117117
return locs, g, [1,4,6,3]
118118
end
119119

120-
# ⋅ ● ⋅
121-
# ● ● ●
122-
# ⋅ ● ⋅
120+
# ⋅ ● ⋅
121+
# ● ● ●
122+
# ⋅ ● ⋅
123123
function mapped_graph(::Cross{true})
124124
locs = [(2,1), (2,2), (2,3), (1,2), (3,2)]
125125
locs, unitdisk_graph(locs, 1.5), [1,4,5,3]
@@ -128,20 +128,20 @@ Base.size(::Cross{true}) = (3, 3)
128128
cross_location(::Cross{true}) = (2,2)
129129
connect_locations(::Cross{true}) = [(2, 1), (3,2)]
130130

131-
# ⋅ ⋅ ● ⋅ ⋅
132-
# ● ● ◉ ● ●
133-
# ⋅ ⋅ ● ⋅ ⋅
134-
# ⋅ ⋅ ● ⋅ ⋅
131+
# ⋅ ⋅ ● ⋅ ⋅
132+
# ● ● ◉ ● ●
133+
# ⋅ ⋅ ● ⋅ ⋅
134+
# ⋅ ⋅ ● ⋅ ⋅
135135
function source_graph(::Cross{false})
136136
locs = [(2,1), (2,2), (2,3), (2,4), (2,5), (1,3), (2,3), (3,3), (4,3)]
137137
g = simplegraph([(1,2), (2,3), (3,4), (4,5), (6,7), (7,8), (8,9)])
138138
return locs, g, [1,6,9,5]
139139
end
140140

141-
# ⋅ ⋅ ● ⋅ ⋅
142-
# ● ● ● ● ●
143-
# ⋅ ● ● ● ⋅
144-
# ⋅ ⋅ ● ⋅ ⋅
141+
# ⋅ ⋅ ● ⋅ ⋅
142+
# ● ● ● ● ●
143+
# ⋅ ● ● ● ⋅
144+
# ⋅ ⋅ ● ⋅ ⋅
145145
function mapped_graph(::Cross{false})
146146
locs = [(2,1), (2,2), (2,3), (2,4), (2,5), (1,3), (3,3), (4,3), (3, 2), (3,4)]
147147
locs, unitdisk_graph(locs, 1.5), [1,6,8,5]
@@ -151,19 +151,19 @@ cross_location(::Cross{false}) = (2,3)
151151

152152
struct Turn <: CrossPattern end
153153
iscon(::Turn) = false
154-
# ⋅ ● ⋅ ⋅
155-
# ⋅ ● ⋅ ⋅
156-
# ⋅ ● ● ●
154+
# ⋅ ● ⋅ ⋅
155+
# ⋅ ● ⋅ ⋅
156+
# ⋅ ● ● ●
157157
# ⋅ ⋅ ⋅ ⋅
158158
function source_graph(::Turn)
159159
locs = [(1,2), (2,2), (3,2), (3,3), (3,4)]
160160
g = simplegraph([(1,2), (2,3), (3,4), (4,5)])
161161
return locs, g, [1,5]
162162
end
163163

164-
# ⋅ ● ⋅ ⋅
165-
# ⋅ ⋅ ● ⋅
166-
# ⋅ ⋅ ⋅ ●
164+
# ⋅ ● ⋅ ⋅
165+
# ⋅ ⋅ ● ⋅
166+
# ⋅ ⋅ ⋅ ●
167167
# ⋅ ⋅ ⋅ ⋅
168168
function mapped_graph(::Turn)
169169
locs = [(1,2), (2,3), (3,4)]
@@ -175,20 +175,20 @@ cross_location(::Turn) = (3,2)
175175

176176
export Branch, TrivialTurn, BranchFix, WTurn, TCon, BranchFixB
177177
struct Branch <: CrossPattern end
178-
# ⋅ ● ⋅ ⋅
179-
# ⋅ ● ⋅ ⋅
180-
# ⋅ ● ● ●
181-
# ⋅ ● ● ⋅
178+
# ⋅ ● ⋅ ⋅
179+
# ⋅ ● ⋅ ⋅
180+
# ⋅ ● ● ●
181+
# ⋅ ● ● ⋅
182182
# ⋅ ● ⋅ ⋅
183183
function source_graph(::Branch)
184184
locs = [(1,2), (2,2), (3,2),(3,3),(3,4),(4,3),(4,2),(5,2)]
185185
g = simplegraph([(1,2), (2,3), (3, 4), (4,5), (4,6), (6,7), (7,8)])
186186
return locs, g, [1, 5, 8]
187187
end
188-
# ⋅ ● ⋅ ⋅
189-
# ⋅ ⋅ ● ⋅
190-
# ⋅ ● ⋅ ●
191-
# ⋅ ⋅ ● ⋅
188+
# ⋅ ● ⋅ ⋅
189+
# ⋅ ⋅ ● ⋅
190+
# ⋅ ● ⋅ ●
191+
# ⋅ ⋅ ● ⋅
192192
# ⋅ ● ⋅ ⋅
193193
function mapped_graph(::Branch)
194194
locs = [(1,2), (2,3), (3,2),(3,4),(4,3),(5,2)]
@@ -199,19 +199,19 @@ cross_location(::Branch) = (3,2)
199199
iscon(::Branch) = false
200200

201201
struct BranchFix <: CrossPattern end
202-
# ⋅ ● ⋅ ⋅
202+
# ⋅ ● ⋅ ⋅
203+
# ⋅ ● ● ⋅
203204
# ⋅ ● ● ⋅
204-
# ⋅ ● ● ⋅
205205
# ⋅ ● ⋅ ⋅
206206
function source_graph(::BranchFix)
207207
locs = [(1,2), (2,2), (2,3),(3,3),(3,2),(4,2)]
208208
g = simplegraph([(1,2), (2,3), (3,4),(4,5), (5,6)])
209209
return locs, g, [1, 6]
210210
end
211-
# ⋅ ● ⋅ ⋅
212-
# ⋅ ● ⋅ ⋅
213211
# ⋅ ● ⋅ ⋅
214-
# ⋅ ● ⋅ ⋅
212+
# ⋅ ● ⋅ ⋅
213+
# ⋅ ● ⋅ ⋅
214+
# ⋅ ● ⋅ ⋅
215215
function mapped_graph(::BranchFix)
216216
locs = [(1,2),(2,2),(3,2),(4,2)]
217217
return locs, unitdisk_graph(locs, 1.5), [1, 4]
@@ -221,18 +221,18 @@ cross_location(::BranchFix) = (2,2)
221221
iscon(::BranchFix) = false
222222

223223
struct WTurn <: CrossPattern end
224-
# ⋅ ⋅ ⋅ ⋅
225-
# ⋅ ⋅ ● ●
226-
# ⋅ ● ● ⋅
224+
# ⋅ ⋅ ⋅ ⋅
225+
# ⋅ ⋅ ● ●
226+
# ⋅ ● ● ⋅
227227
# ⋅ ● ⋅ ⋅
228228
function source_graph(::WTurn)
229229
locs = [(2,3), (2,4), (3,2),(3,3),(4,2)]
230230
g = simplegraph([(1,2), (1,4), (3,4),(3,5)])
231231
return locs, g, [2, 5]
232232
end
233-
# ⋅ ⋅ ⋅ ⋅
234-
# ⋅ ⋅ ⋅ ●
235-
# ⋅ ⋅ ● ⋅
233+
# ⋅ ⋅ ⋅ ⋅
234+
# ⋅ ⋅ ⋅ ●
235+
# ⋅ ⋅ ● ⋅
236236
# ⋅ ● ⋅ ⋅
237237
function mapped_graph(::WTurn)
238238
locs = [(2,4),(3,3),(4,2)]
@@ -243,19 +243,19 @@ cross_location(::WTurn) = (2,2)
243243
iscon(::WTurn) = false
244244

245245
struct BranchFixB <: CrossPattern end
246-
# ⋅ ⋅ ⋅ ⋅
246+
# ⋅ ⋅ ⋅ ⋅
247247
# ⋅ ⋅ ● ⋅
248-
# ⋅ ● ● ⋅
248+
# ⋅ ● ● ⋅
249249
# ⋅ ● ⋅ ⋅
250250
function source_graph(::BranchFixB)
251251
locs = [(2,3),(3,3),(3,2),(4,2)]
252252
g = simplegraph([(1,3), (2,3), (2,4)])
253253
return locs, g, [1, 4]
254254
end
255-
# ⋅ ⋅ ⋅ ⋅
256-
# ⋅ ⋅ ⋅ ⋅
255+
# ⋅ ⋅ ⋅ ⋅
256+
# ⋅ ⋅ ⋅ ⋅
257+
# ⋅ ● ⋅ ⋅
257258
# ⋅ ● ⋅ ⋅
258-
# ⋅ ● ⋅ ⋅
259259
function mapped_graph(::BranchFixB)
260260
locs = [(3,2),(4,2)]
261261
return locs, unitdisk_graph(locs, 1.5), [1, 2]
@@ -267,7 +267,7 @@ iscon(::BranchFixB) = false
267267

268268
struct TCon <: CrossPattern end
269269
# ⋅ ◆ ⋅ ⋅
270-
# ◆ ● ⋅ ⋅
270+
# ◆ ● ⋅ ⋅
271271
# ⋅ ● ⋅ ⋅
272272
function source_graph(::TCon)
273273
locs = [(1,2), (2,1), (2,2),(3,2)]
@@ -306,6 +306,26 @@ cross_location(::TrivialTurn) = (2,2)
306306
iscon(::TrivialTurn) = true
307307
connect_locations(::TrivialTurn) = [(1,2), (2,1)]
308308

309+
struct EndTurn <: CrossPattern end
310+
# ⋅ ● ⋅ ⋅
311+
# ⋅ ● ● ⋅
312+
# ⋅ ⋅ ⋅ ⋅
313+
function source_graph(::EndTurn)
314+
locs = [(1,2), (2,2), (2,3)]
315+
g = simplegraph([(1,2), (2,3)])
316+
return locs, g, [1]
317+
end
318+
# ⋅ ● ⋅ ⋅
319+
# ⋅ ⋅ ⋅ ⋅
320+
# ⋅ ⋅ ⋅ ⋅
321+
function mapped_graph(::EndTurn)
322+
locs = [(1,2)]
323+
return locs, unitdisk_graph(locs, 1.5), [1]
324+
end
325+
Base.size(::EndTurn) = (3,4)
326+
cross_location(::EndTurn) = (2,2)
327+
iscon(::EndTurn) = false
328+
309329
############## Rotation and Flip ###############
310330
export RotatedGadget, ReflectedGadget
311331
struct RotatedGadget{GT} <: Pattern
@@ -402,4 +422,4 @@ function _boundary_config(pins, config)
402422
res += Int(config[p]) << (i-1)
403423
end
404424
return res
405-
end
425+
end

Diff for: src/mapping.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ end
7272
const crossing_ruleset = (Cross{false}(),
7373
Turn(), WTurn(), Branch(), BranchFix(), TCon(), TrivialTurn(),
7474
RotatedGadget(TCon(), 1), ReflectedGadget(Cross{true}(), "y"),
75-
ReflectedGadget(TrivialTurn(), "y"), BranchFixB(),
75+
ReflectedGadget(TrivialTurn(), "y"), BranchFixB(), EndTurn(),
7676
ReflectedGadget(RotatedGadget(TCon(), 1), "y"))
7777
function apply_crossing_gadgets!(ug::UGrid, ruleset=crossing_ruleset)
7878
tape = Tuple{Pattern,Int,Int}[]

Diff for: test/mapping.jl

+32-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,37 @@ end
6060
end
6161
end
6262

63+
64+
@testset "interface_K23" begin
65+
g = SimpleGraph(5)
66+
67+
add_edge!(g, 1, 5)
68+
add_edge!(g, 4, 5)
69+
add_edge!(g, 4, 3)
70+
add_edge!(g, 3, 2)
71+
add_edge!(g, 5, 2)
72+
add_edge!(g, 1, 3)
73+
74+
res = map_graph(g)
75+
76+
# checking size
77+
gp = Independence(SimpleGraph(res.grid_graph); optimizer=TreeSA(ntrials=1, niters=10), simplifier=MergeGreedy())
78+
missize_map = solve(gp, "size max")[].n
79+
missize = solve(Independence(g), "size max")[].n
80+
@test res.mis_overhead + missize == missize_map
81+
82+
# checking mapping back
83+
misconfig = solve(gp, "config max")[].c
84+
c = zeros(Int, size(res.grid_graph.content))
85+
for (i, loc) in enumerate(findall(!iszero, res.grid_graph.content))
86+
c[loc] = misconfig.data[i]
87+
end
88+
original_configs = map_configs_back(res, [c])
89+
@test count(isone, original_configs[1]) == missize
90+
@test is_independent_set(g, original_configs[1])
91+
end
92+
93+
6394
@testset "interface" begin
6495
g = smallgraph(:petersen)
6596
res = map_graph(g)
@@ -79,4 +110,4 @@ end
79110
original_configs = map_configs_back(res, [c])
80111
@test count(isone, original_configs[1]) == missize
81112
@test is_independent_set(g, original_configs[1])
82-
end
113+
end

0 commit comments

Comments
 (0)