Skip to content

MIS compactify with potential (maximum possible size increase of a vertex) #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ docs/src/generated/
docs/src/assets/indigo.css
docs/src/notebooks
.vscode
.DS_Store
24 changes: 19 additions & 5 deletions src/networks/IndependentSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,38 @@ end
misv(vals) = vals

"""
mis_compactify!(tropicaltensor)
mis_compactify!(tropicaltensor; potential=nothing)

Compactify tropical tensor for maximum independent set problem. It will eliminate
some entries by setting them to zero, by the criteria that removing these entry
does not change the MIS size of its parent graph (reference to be added).

### Arguments
- `tropicaltensor::AbstractArray{T}`: the tropical tensor

### Keyword arguments
- `potential=nothing`: the maximum possible MIS contribution from each open vertex
"""
function mis_compactify!(a::AbstractArray{T}) where T <: TropicalTypes
function mis_compactify!(a::AbstractArray{T, N}; potential=nothing) where {T <: TropicalTypes, N}
@assert potential === nothing || length(potential) == N "got unexpected potential length: $(length(potential)), expected $N"
for (ind_a, val_a) in enumerate(a)
for (ind_b, val_b) in enumerate(a)
bs_a = ind_a - 1
bs_b = ind_b - 1
@inbounds if bs_a != bs_b && val_a <= val_b && (bs_b & bs_a) == bs_b
a[ind_a] = zero(T)
end
if worse_than(bs_a, bs_b, val_a.n, val_b.n, potential)
@inbounds a[ind_a] = zero(T)
end
end
end
return a
end
function worse_than(bs_a::Integer, bs_b::Integer, val_a::T, val_b::T, potential::AbstractVector) where T
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
end
function worse_than(bs_a::Integer, bs_b::Integer, val_a::T, val_b::T, ::Nothing) where T
bs_a != bs_b && val_a <= val_b && (bs_b & bs_a) == bs_b
end
readbit(bs::Integer, k::Integer) = (bs >> (k-1)) & 1

"""
is_independent_set(g::SimpleGraph, config)
Expand Down
7 changes: 5 additions & 2 deletions test/networks/IndependentSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ using GenericTensorNetworks, Test, Graphs
m = solve(g, SizeMax())
@test m isa Array{Tropical{Float64}, 4}
@test count(!iszero, m) == 12
mis_compactify!(m)
@test count(!iszero, m) == 3
m1 = mis_compactify!(copy(m))
@test count(!iszero, m1) == 3
potential = zeros(Float64, 4)
m2 = mis_compactify!(copy(m); potential)
@test count(!iszero, m2) == 1
@test get_weights(g) == UnitWeight()
@test get_weights(chweights(g, fill(3, 6))) == fill(3, 6)
end
Expand Down
Loading