@@ -11,16 +11,16 @@ function best_solutions(gp::GraphProblem; all=false, usecuda=false)
1111 throw (ArgumentError (" ConfigEnumerator can not be computed on GPU!" ))
1212 end
1313 syms = symbols (gp)
14- T = (all ? set_type : sampler_type)(CountingTropical{Int64}, length (syms), bondsize (gp))
14+ T = (all ? set_type : sampler_type)(CountingTropical{Int64}, length (syms), nflavor (gp))
1515 vertex_index = Dict ([s=> i for (i, s) in enumerate (syms)])
16- xst = generate_tensors (l-> TropicalF64 ( get_weight (gp, vertex_index[l] )), gp)
16+ xst = generate_tensors (l-> TropicalF64 .( get_weights (gp, l )), gp)
1717 ymask = trues (fill (2 , length (getiyv (gp. code)))... )
1818 if usecuda
1919 xst = CuArray .(xst)
2020 ymask = CuArray (ymask)
2121 end
2222 if all
23- xs = generate_tensors (l-> _onehotv (T , vertex_index[l], 1 , get_weight (gp, vertex_index[l] )), gp)
23+ xs = generate_tensors (l-> _onehotv .( Ref (T) , vertex_index[l], flavors (gp), get_weights (gp, l )), gp)
2424 return bounding_contract (AllConfigs {1} (), gp. code, xst, ymask, xs)
2525 else
2626 @assert ndims (ymask) == 0
@@ -59,57 +59,39 @@ best2_solutions(gp::GraphProblem; all=true, usecuda=false) = solutions(gp, Max2P
5959function bestk_solutions (gp:: GraphProblem , k:: Int )
6060 syms = symbols (gp)
6161 vertex_index = Dict ([s=> i for (i, s) in enumerate (syms)])
62- xst = generate_tensors (l-> TropicalF64 ( get_weight (gp, vertex_index[l] )), gp)
62+ xst = generate_tensors (l-> TropicalF64 .( get_weights (gp, l )), gp)
6363 ymask = trues (fill (2 , length (getiyv (gp. code)))... )
64- T = set_type (TruncatedPoly{k,Float64,Float64}, length (syms), bondsize (gp))
65- xs = generate_tensors (l-> _onehotv (T , vertex_index[l], 1 , get_weight (gp, vertex_index[l] )), gp)
64+ T = set_type (TruncatedPoly{k,Float64,Float64}, length (syms), nflavor (gp))
65+ xs = generate_tensors (l-> _onehotv .( Ref (T) , vertex_index[l], flavors (gp), get_weights (gp, l )), gp)
6666 return bounding_contract (AllConfigs {k} (), gp. code, xst, ymask, xs)
6767end
6868
6969"""
7070 all_solutions(problem)
7171
72- Finding all solutions.
72+ Finding all solutions grouped by size .
7373e.g. when the problem is `MaximalIndependence`, it computes all maximal independent sets, or the maximal cliques of it complement.
7474"""
7575all_solutions (gp:: GraphProblem ) = solutions (gp, Polynomial{Float64,:x }, all= true , usecuda= false )
7676
77- # return a mapping from label to variable `x`
78- for GP in [:Independence , :Matching , :MaximalIndependence , :MaxCut , :PaintShop ]
79- @eval function fx_solutions (gp:: $GP , :: Type{BT} , all:: Bool ) where BT
80- syms = symbols (gp)
81- T = (all ? set_type : sampler_type)(BT, length (syms), bondsize (gp))
82- vertex_index = Dict ([s=> i for (i, s) in enumerate (syms)])
83- return l-> _onehotv (T, vertex_index[l], 1 , get_weight (gp, vertex_index[l]))
84- end
85- end
86- function fx_solutions (gp:: Coloring{K} , :: Type{BT} , all:: Bool ) where {K,BT}
77+ # return a mapping from label to onehot bitstrings (degree of freedoms).
78+ function fx_solutions (gp:: GraphProblem , :: Type{BT} , all:: Bool ) where {K,BT}
8779 syms = symbols (gp)
88- T = (all ? set_type : sampler_type)(BT, length (syms), bondsize (gp))
80+ T = (all ? set_type : sampler_type)(BT, length (syms), nflavor (gp))
8981 vertex_index = Dict ([s=> i for (i, s) in enumerate (syms)])
9082 return function (l)
91- map (1 : K) do k
92- _onehotv (T, vertex_index[l], k, get_weight (gp, vertex_index[l]))
93- end
83+ _onehotv .(Ref (T), vertex_index[l], flavors (gp), get_weights (gp, l))
9484 end
9585end
9686function _onehotv (:: Type{Polynomial{BS,X}} , x, v, w) where {BS,X}
97- @assert isone (w)
98- Polynomial {BS,X} ([zero (BS), onehotv (BS, x, v)])
87+ Polynomial {BS,X} ([zero (BS), onehotv (BS, x, v)])^ w
9988end
10089function _onehotv (:: Type{TruncatedPoly{K,BS,OS}} , x, v, w) where {K,BS,OS}
101- @assert isone (w)
102- TruncatedPoly {K,BS,OS} (ntuple (i-> i< K ? zero (BS) : onehotv (BS, x, v), K),one (OS))
90+ TruncatedPoly {K,BS,OS} (ntuple (i-> i< K ? zero (BS) : onehotv (BS, x, v), K),one (OS))^ w
10391end
10492function _onehotv (:: Type{CountingTropical{TV,BS}} , x, v, w) where {TV,BS}
10593 CountingTropical {TV,BS} (TV (w), onehotv (BS, x, v))
10694end
10795function _onehotv (:: Type{BS} , x, v, w) where {BS<: ConfigEnumerator }
10896 onehotv (BS, x, v)
109- end
110-
111- for GP in [:Independence , :Matching , :MaximalIndependence , :Coloring ]
112- @eval symbols (gp:: $GP ) = labels (gp. code)
113- end
114- symbols (gp:: MaxCut ) = getixsv (gp. code)
115- symbols (gp:: PaintShop ) = getixsv (gp. code)
97+ end
0 commit comments