|
53 | 53 | misv(vals) = vals
|
54 | 54 |
|
55 | 55 | """
|
56 |
| - mis_compactify!(tropicaltensor) |
| 56 | + mis_compactify!(tropicaltensor; potential=nothing) |
57 | 57 |
|
58 | 58 | Compactify tropical tensor for maximum independent set problem. It will eliminate
|
59 | 59 | some entries by setting them to zero, by the criteria that removing these entry
|
60 | 60 | does not change the MIS size of its parent graph (reference to be added).
|
| 61 | +
|
| 62 | +### Arguments |
| 63 | +- `tropicaltensor::AbstractArray{T}`: the tropical tensor |
| 64 | +
|
| 65 | +### Keyword arguments |
| 66 | +- `potential=nothing`: the maximum possible MIS contribution from each open vertex |
61 | 67 | """
|
62 |
| -function mis_compactify!(a::AbstractArray{T}) where T <: TropicalTypes |
| 68 | +function mis_compactify!(a::AbstractArray{T, N}; potential=nothing) where {T <: TropicalTypes, N} |
| 69 | + @assert potential === nothing || length(potential) == N "got unexpected potential length: $(length(potential)), expected $N" |
63 | 70 | for (ind_a, val_a) in enumerate(a)
|
64 | 71 | for (ind_b, val_b) in enumerate(a)
|
65 | 72 | bs_a = ind_a - 1
|
66 | 73 | bs_b = ind_b - 1
|
67 |
| - @inbounds if bs_a != bs_b && val_a <= val_b && (bs_b & bs_a) == bs_b |
68 |
| - a[ind_a] = zero(T) |
69 |
| - end |
| 74 | + if worse_than(bs_a, bs_b, val_a.n, val_b.n, potential) |
| 75 | + @inbounds a[ind_a] = zero(T) |
| 76 | + end |
70 | 77 | end
|
71 | 78 | end
|
72 | 79 | return a
|
73 | 80 | end
|
| 81 | +function worse_than(bs_a::Integer, bs_b::Integer, val_a::T, val_b::T, potential::AbstractVector) where T |
| 82 | + bs_a != bs_b && val_a + sum(k->readbit(bs_a, k) < readbit(bs_b, k) ? potential[k] : zero(T), 1:length(potential)) <= val_b |
| 83 | +end |
| 84 | +function worse_than(bs_a::Integer, bs_b::Integer, val_a::T, val_b::T, ::Nothing) where T |
| 85 | + bs_a != bs_b && val_a <= val_b && (bs_b & bs_a) == bs_b |
| 86 | +end |
| 87 | +readbit(bs::Integer, k::Integer) = (bs >> (k-1)) & 1 |
74 | 88 |
|
75 | 89 | """
|
76 | 90 | is_independent_set(g::SimpleGraph, config)
|
|
0 commit comments