|
43 | 43 | target_problem(sg::SpinGlass) = sg.target |
44 | 44 |
|
45 | 45 | # the energy should be shifted by sum(J)/2 - sum(h) |
46 | | -for ET in [:Tropical, :ExtendedTropical, :TruncatedPoly, :CountingTropical] |
47 | | - @eval function extract_result(sg::SpinGlass, res::T) where T <: $(ET) |
48 | | - sumJ = sum(i->sg.J[i], 1:ne(sg.target.graph)) |
49 | | - sumh = sum(i->sg.h[i], 1:nv(sg.target.graph)) |
| 46 | +function extract_result(sg::SpinGlass) |
| 47 | + sumJ = sum(i->sg.J[i], 1:ne(sg.target.graph)) |
| 48 | + sumh = sum(i->sg.h[i], 1:nv(sg.target.graph)) |
| 49 | + function extractor(res::T) where T <: Union{Tropical, ExtendedTropical, TruncatedPoly, CountingTropical} |
50 | 50 | # the cut size is always even if the input J is integer |
51 | 51 | return res * _x(T; invert=false) ^ (-sumJ + sumh) |
52 | 52 | end |
53 | | -end |
54 | | -function extract_result(sg::SpinGlass, res::Union{Polynomial{BS,X}, LaurentPolynomial{BS,X}}) where {BS,X} |
55 | | - sumJ = sum(i->sg.J[i], 1:ne(sg.target.graph)) |
56 | | - sumh = sum(i->sg.h[i], 1:nv(sg.target.graph)) |
57 | | - # the cut size is always even if the input J is integer |
58 | | - lres = LaurentPolynomial{BS,X}(res) |
59 | | - return lres * LaurentPolynomial{BS,X}([one(eltype(res.coeffs))], -sumJ + sumh) |
60 | | -end |
61 | | - |
62 | | -# the configurations are not changed, vectors are treated as configurations |
63 | | -for ET in [:SumProductTree, :ConfigSampler, :ConfigEnumerator, :Real, :AbstractVector] |
64 | | - @eval extract_result(sg::SpinGlass, res::T) where T <: $(ET) = res |
| 53 | + function extractor(res::T) where {BS, X, T <: Union{Polynomial{BS,X}, LaurentPolynomial{BS,X}}} |
| 54 | + lres = LaurentPolynomial{BS,X}(res) |
| 55 | + return lres * LaurentPolynomial{BS,X}([one(eltype(res.coeffs))], -sumJ + sumh) |
| 56 | + end |
| 57 | + function extractor(res::T) where T<:Union{SumProductTree, ConfigSampler, ConfigEnumerator, Real, AbstractVector} |
| 58 | + return res |
| 59 | + end |
| 60 | + return extractor |
65 | 61 | end |
66 | 62 |
|
67 | 63 | """ |
|
0 commit comments