1
- struct IndependentSetKSGResult {NT, VT} <: ProblemReductions.AbstractReductionResult
1
+ struct IndependentSetToKSG {NT, VT} <: ProblemReductions.AbstractReductionResult
2
2
mapres:: MappingResult{NT}
3
3
weights:: VT
4
4
end
5
+ function _to_gridgraph (g:: UnitDiskMapping.GridGraph )
6
+ return ProblemReductions. GridGraph (g. size, getfield .(g. nodes, :loc ), g. radius)
7
+ end
8
+ function _extract_weights (g:: UnitDiskMapping.GridGraph{<:WeightedNode} )
9
+ getfield .(g. nodes, :weight )
10
+ end
5
11
6
- # unweighted reduction
12
+ # ##### unweighted reduction
7
13
function ProblemReductions. reduceto (:: Type{ProblemReductions.IndependentSet{ProblemReductions.GridGraph, Int, ProblemReductions.UnitWeight}} , problem:: ProblemReductions.IndependentSet{GT, Int, ProblemReductions.UnitWeight} where GT<: SimpleGraph )
8
- return IndependentSetKSGResult (map_graph (UnWeighted (), problem. graph), problem. weights)
14
+ return IndependentSetToKSG (map_graph (UnWeighted (), problem. graph), problem. weights)
9
15
end
10
16
11
- function ProblemReductions. reduceto (:: Type{ProblemReductions.IndependentSet{ProblemReductions.GridGraph, T, Vector{T}}} where T, problem:: ProblemReductions.IndependentSet{GT} where GT<: SimpleGraph )
12
- return IndependentSetKSGResult (map_graph (Weighted (), problem. graph), problem. weights)
17
+ function ProblemReductions. target_problem (res:: IndependentSetToKSG{<:UnWeightedNode} )
18
+ return ProblemReductions. IndependentSet (_to_gridgraph (res. mapres. grid_graph))
19
+ end
20
+ function ProblemReductions. extract_solution (res:: IndependentSetToKSG , sol)
21
+ return map_config_back (res. mapres, sol)
13
22
end
14
23
15
- function ProblemReductions. target_problem (res:: IndependentSetKSGResult{<:UnWeightedNode} )
16
- return ProblemReductions. IndependentSet (SimpleGraph (res. mapres. grid_graph))
24
+ # ##### Weighted reduction
25
+ # TODO : rescale the weights to avoid errors
26
+ function ProblemReductions. reduceto (:: Type{ProblemReductions.IndependentSet{ProblemReductions.GridGraph, T, Vector{T}}} where T, problem:: ProblemReductions.IndependentSet{GT} where GT<: SimpleGraph )
27
+ return IndependentSetToKSG (map_graph (Weighted (), problem. graph), problem. weights)
17
28
end
18
- function ProblemReductions. target_problem (res:: IndependentSetKSGResult {<:WeightedNode} )
19
- graph, _ = graph_and_weights (res. mapres. grid_graph)
29
+ function ProblemReductions. target_problem (res:: IndependentSetToKSG {<:WeightedNode} )
30
+ graph = _to_gridgraph (res. mapres. grid_graph)
20
31
weights = UnitDiskMapping. map_weights (res. mapres, res. weights)
21
32
return ProblemReductions. IndependentSet (graph, weights)
22
33
end
23
34
24
- function ProblemReductions. extract_solution (res:: IndependentSetKSGResult , sol)
25
- return map_config_back (res. mapres, sol)
35
+ # ##### Factoring ######
36
+ struct FactoringToIndependentSet{NT} <: ProblemReductions.AbstractReductionResult
37
+ mapres:: FactoringResult{NT}
38
+ raw_graph:: ProblemReductions.GridGraph
39
+ raw_weight:: Vector{Int}
40
+ vmap:: Vector{Int}
41
+ problem:: ProblemReductions.IndependentSet{ProblemReductions.GridGraph, Int, Vector{Int}}
42
+ end
43
+ function ProblemReductions. reduceto (:: Type{ProblemReductions.IndependentSet{ProblemReductions.GridGraph, T, Vector{T}}} where T, problem:: ProblemReductions.Factoring )
44
+ mres = map_factoring (problem. m, problem. n)
45
+ g = _to_gridgraph (mres. grid_graph)
46
+ ws = getfield .(mres. grid_graph. nodes, :weight )
47
+ mg, vmap = set_target (g, [mres. pins_zeros... , mres. pins_output... ], problem. input << length (mres. pins_zeros))
48
+ return FactoringToIndependentSet (mres, g, ws, vmap, ProblemReductions. IndependentSet (mg, ws[vmap]))
49
+ end
50
+
51
+ function ProblemReductions. target_problem (res:: FactoringToIndependentSet )
52
+ return res. problem
53
+ end
54
+
55
+ function ProblemReductions. extract_solution (res:: FactoringToIndependentSet , sol)
56
+ cfg = zeros (Int, nv (res. raw_graph))
57
+ cfg[res. vmap] .= sol
58
+ i1, i2 = map_config_back (res. mapres, cfg)
59
+ return vcat ([i1>> (k- 1 ) & 1 for k= 1 : length (res. mapres. pins_input1)], [i2>> (k- 1 ) & 1 for k= 1 : length (res. mapres. pins_input2)])
26
60
end
0 commit comments