@@ -11,85 +11,70 @@ function config_type(::Type{T}, n, num_flavors; all::Bool, tree_storage::Bool) w
1111end
1212
1313"""
14- largest_solutions(problem ; all=false, usecuda=false, invert=false, tree_storage::Bool=false)
14+ largest_solutions(net::GenericTensorNetwork ; all=false, usecuda=false, invert=false, tree_storage::Bool=false, T=Float64 )
1515
16- Find optimal solutions with bounding.
17-
18- * When `all` is true, the program will use set for enumerate all possible solutions, otherwise, it will return one solution for each size.
19- * `usecuda` can not be true if you want to use set to enumerate all possible solutions.
20- * If `invert` is true, find the minimum.
21- * If `tree_storage` is true, use [`SumProductTree`](@ref) as the storage of solutions.
16+ Find optimal solutions, with bounding. Please check [`solutions`](@ref) for argument descriptions.
2217"""
23- function largest_solutions (gp :: GenericTensorNetwork ; all= false , usecuda= false , invert= false , tree_storage:: Bool = false , T= Float64)
18+ function largest_solutions (net :: GenericTensorNetwork ; all= false , usecuda= false , invert= false , tree_storage:: Bool = false , T= Float64)
2419 if all && usecuda
2520 throw (ArgumentError (" ConfigEnumerator can not be computed on GPU!" ))
2621 end
27- xst = generate_tensors (_x (Tropical{T}; invert), gp )
28- ymask = trues (fill (num_flavors (gp ), length (getiyv (gp . code)))... )
22+ xst = generate_tensors (_x (Tropical{T}; invert), net )
23+ ymask = trues (fill (num_flavors (net ), length (getiyv (net . code)))... )
2924 if usecuda
3025 xst = togpu .(xst)
3126 ymask = togpu (ymask)
3227 end
3328 if all
3429 # we use `Float64` as default because we want to support weighted graphs.
35- T = config_type (CountingTropical{T,T}, length (labels (gp )), num_flavors (gp ); all, tree_storage)
36- xs = generate_tensors (_x (T; invert), gp )
37- ret = bounding_contract (AllConfigs {1} (), gp . code, xst, ymask, xs)
30+ T = config_type (CountingTropical{T,T}, length (variables (net )), num_flavors (net ); all, tree_storage)
31+ xs = generate_tensors (_x (T; invert), net )
32+ ret = bounding_contract (AllConfigs {1} (), net . code, xst, ymask, xs)
3833 return invert ? asarray (post_invert_exponent .(ret), ret) : ret
3934 else
4035 @assert ndims (ymask) == 0
41- t, res = solution_ad (gp . code, xst, ymask)
36+ t, res = solution_ad (net . code, xst, ymask)
4237 ret = fill (CountingTropical (asscalar (t). n, ConfigSampler (StaticBitVector (map (l-> res[l], 1 : length (res))))))
4338 return invert ? asarray (post_invert_exponent .(ret), ret) : ret
4439 end
4540end
4641
4742"""
48- solutions(problem, basetype ; all, usecuda=false, invert=false, tree_storage::Bool=false)
43+ solutions(net::GenericTensorNetwork, ::Type{BT} ; all::Bool , usecuda::Bool =false, invert::Bool =false, tree_storage::Bool=false) where BT
4944
50- General routine to find solutions without bounding,
45+ Find all solutions, solutions with largest sizes or solutions with smallest sizes. Bounding is not supported.
5146
52- * `basetype` can be a type with counting field,
47+ ### Arguments
48+ - `net` is a [`GenericTensorNetwork`](@ref) instance.
49+ - `BT` is the data types used for computing, which can be
5350 * `CountingTropical{Float64,Float64}` for finding optimal solutions,
5451 * `Polynomial{Float64, :x}` for enumerating all solutions,
5552 * `Max2Poly{Float64,Float64}` for optimal and suboptimal solutions.
56- * When `all` is true, the program will use set for enumerate all possible solutions, otherwise, it will return one solution for each size.
57- * `usecuda` can not be true if you want to use set to enumerate all possible solutions.
58- * If `tree_storage` is true, use [`SumProductTree`](@ref) as the storage of solutions.
53+
54+ ### Keyword arguments
55+ - `all` is an indicator whether to find all solutions or just one of them.
56+ - `usecuda` is an indicator of using CUDA or not, which must be false if `all` is true.
57+ - `invert` is an indicator of whether flip the size or not. If true, instead of finding the maximum, it find the minimum.
58+ - `tree_storage` is an indicator of whether using more compact [`SumProductTree`](@ref) as the storage or not.
5959"""
60- function solutions (gp :: GenericTensorNetwork , :: Type{BT} ; all:: Bool , usecuda:: Bool = false , invert:: Bool = false , tree_storage:: Bool = false ) where BT
60+ function solutions (net :: GenericTensorNetwork , :: Type{BT} ; all:: Bool , usecuda:: Bool = false , invert:: Bool = false , tree_storage:: Bool = false ) where BT
6161 if all && usecuda
6262 throw (ArgumentError (" ConfigEnumerator can not be computed on GPU!" ))
6363 end
64- T = config_type (BT, length (labels (gp )), num_flavors (gp ); all, tree_storage)
65- ret = contractx (gp , _x (T; invert); usecuda= usecuda)
64+ T = config_type (BT, length (variables (net )), num_flavors (net ); all, tree_storage)
65+ ret = contractx (net , _x (T; invert); usecuda= usecuda)
6666 return invert ? asarray (post_invert_exponent .(ret), ret) : ret
6767end
6868
69- """
70- largest2_solutions(problem; all=true, usecuda=false, invert=false, tree_storage::Bool=false)
71-
72- Finding optimal and suboptimal solutions.
73- """
74- largest2_solutions (gp:: GenericTensorNetwork ; all= true , usecuda= false , invert:: Bool = false , T= Float64) = solutions (gp, Max2Poly{T,T}; all, usecuda, invert)
75-
76- function largestk_solutions (gp:: GenericTensorNetwork , k:: Int ; invert:: Bool = false , tree_storage:: Bool = false , T= Float64)
77- xst = generate_tensors (_x (Tropical{T}; invert), gp)
78- ymask = trues (fill (2 , length (getiyv (gp. code)))... )
79- T = config_type (TruncatedPoly{k,T,T}, length (labels (gp)), num_flavors (gp); all= true , tree_storage)
80- xs = generate_tensors (_x (T; invert), gp)
81- ret = bounding_contract (AllConfigs {k} (), gp. code, xst, ymask, xs)
69+ function largestk_solutions (net:: GenericTensorNetwork , k:: Int ; invert:: Bool = false , tree_storage:: Bool = false , T= Float64)
70+ xst = generate_tensors (_x (Tropical{T}; invert), net)
71+ ymask = trues (fill (2 , length (getiyv (net. code)))... )
72+ T = config_type (TruncatedPoly{k,T,T}, length (variables (net)), num_flavors (net); all= true , tree_storage)
73+ xs = generate_tensors (_x (T; invert), net)
74+ ret = bounding_contract (AllConfigs {k} (), net. code, xst, ymask, xs)
8275 return invert ? asarray (post_invert_exponent .(ret), ret) : ret
8376end
8477
85- """
86- all_solutions(problem)
87-
88- Finding all solutions grouped by size.
89- e.g. when the problem is [`MaximalIS`](@ref), it computes all maximal independent sets, or the maximal cliques of it complement.
90- """
91- all_solutions (gp:: GenericTensorNetwork ; T= Float64) = solutions (gp, Polynomial{T,:x }, all= true , usecuda= false , tree_storage= false )
92-
9378# NOTE: do we have more efficient way to compute it?
9479# NOTE: doing pair-wise Hamming distance might be biased?
9580"""
0 commit comments