Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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 src/ProblemReductions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export ReductionIndependentSetToSetPacking, ReductionSetPackingToIndependentSet
export ReductionSATToCircuit
export ReductionIndependentSetToVertexCovering
export ReductionMatchingToSetPacking
export ReductionBMFToBicliqueCover

# reduction path
export ReductionGraph, reduction_graph, reduction_paths, ConcatenatedReduction
Expand Down
2 changes: 1 addition & 1 deletion src/models/BMF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The Boolean Matrix Factorization (BMF) problem is defined on a binary matrix A i
struct BinaryMatrixFactorization<: AbstractProblem
A::BitMatrix
k::Int
function BinaryMatrixFactorization(A::BitMatrix, k::Int) where K
function BinaryMatrixFactorization(A::BitMatrix, k::Int)
new(A, k)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/models/BicliqueCover.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# Variables Interface
# each vertex is assigned to a biclique, with k bicliques, variables(c::BicliqueCover) = fill(1,c.k * nv(c.graph))
num_variables(c::BicliqueCover) = nv(c.graph) * c.k
num_flavors(c::BicliqueCover) = 2
num_flavors(::Type{BicliqueCover{Int64}}) = 2

Check warning on line 38 in src/models/BicliqueCover.jl

View check run for this annotation

Codecov / codecov/patch

src/models/BicliqueCover.jl#L38

Added line #L38 was not covered by tests

# constraints interface
function constraints(c::BicliqueCover)
Expand Down
46 changes: 46 additions & 0 deletions src/rules/BMF_BicliqueCover.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
$TYPEDEF
The reduction result from BinaryMatrixFactorization to BicliqueCover.
### Fields
- `bicliquecover`: The BicliqueCover problem.
- `k`: The number of bicliques.
"""
struct ReductionBMFToBicliqueCover{Int64} <: AbstractReductionResult
bicliquecover::BicliqueCover{Int64}
k::Int64
end
Base.:(==)(a::ReductionBMFToBicliqueCover, b::ReductionBMFToBicliqueCover) = a.bicliquecover == b.bicliquecover && a.k == b.k
target_problem(res::ReductionBMFToBicliqueCover) = res.bicliquecover

function reduceto(::Type{BicliqueCover}, bmf::BinaryMatrixFactorization)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function reduceto(::Type{BicliqueCover}, bmf::BinaryMatrixFactorization)
function reduceto(::Type{<:BicliqueCover}, bmf::BinaryMatrixFactorization)

k = bmf.k
A = Int.(bmf.A)
return ReductionBMFToBicliqueCover(ProblemReductions.biclique_cover_from_matrix(A, k), k)
end

function extract_solution(res::ReductionBMFToBicliqueCover{Int64}, solution::Vector{Vector{Int64}})
len_part1 = length(res.bicliquecover.part1)
len_part2 = nv(res.bicliquecover.graph) - len_part1
B = falses((len_part1,res.k))
C = falses((res.k,len_part1))
# each iteration, we update the a-th column of B and the a-th row of C
for a in range(1,res.k)
for i in range(1,len_part1)
if solution[a][i] == 1
B[i,a] = true
end
end
for j in range(1,len_part2)
if solution[a][j+len_part1] == 1
C[a,j] = true
end
end
end
return (B,C)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return a vector, and convert it back with read_solution. e.g.

function read_solution(factoring::Factoring,solution::AbstractVector) #return a tuple of 2 numbers result

end

function extract_multiple_solutions(res::ReductionBMFToBicliqueCover{Int64}, solution_set::Vector{Vector{Vector{Int64}}})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need this?

return unique(extract_solution.(Ref(res), solution_set))
end
3 changes: 2 additions & 1 deletion src/rules/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ include("sat_dominatingset.jl")
include("independentset_setpacking.jl")
include("circuit_sat.jl")
include("vertexcovering_independentset.jl")
include("matching_setpacking.jl")
include("matching_setpacking.jl")
include("BMF_BicliqueCover.jl")
1 change: 1 addition & 0 deletions test/models/BicliqueCover.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using Test, ProblemReductions, Graphs
# variable and weight interfaces
@test num_variables(bc) == 12
@test num_flavors(bc) == 2
@test num_flavors(BicliqueCover{Int64}) == 2
@test problem_size(bc) == (num_vertices=6, num_edges=5, k=2)
bc_matrix = ProblemReductions.biclique_cover_from_matrix([1 1 0;1 1 0;0 0 1],2)
@test bc_matrix == bc
Expand Down
17 changes: 17 additions & 0 deletions test/rules/BMF_BicliqueCover.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Test, ProblemReductions, Graphs

@testset "BMF_BicliqueCover" begin
A = [1 0 ; 1 1]
A = BitMatrix(A)
bmf1 = BinaryMatrixFactorization(A, 2)
bc1 = ProblemReductions.biclique_cover_from_matrix(Int.(A), 2)
res = reduceto(BicliqueCover, bmf1)
res1 = ReductionBMFToBicliqueCover(bc1,2)
@test res == res1
@test res.k == 2
@test res.bicliquecover == bc1
@test res.bicliquecover.part1 == [i for i in 1:size(A,1)]
@test target_problem(res) == bc1
@test extract_solution(res,[[1,1,1,0],[0,1,0,1]]) == ([true false ; true true], [true false ; false true])
@test extract_multiple_solutions(res,[[[1,1,1,0],[0,1,0,1]]]) == [([true false ; true true], [true false ; false true])]
end
4 changes: 4 additions & 0 deletions test/rules/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ end
include("matching_setpacking.jl")
end

@testset "BMF_BicliqueCover" begin
include("BMF_BicliqueCover.jl")
end

@testset "rules" begin
circuit = CircuitSAT(@circuit begin
x = a ∨ ¬b
Expand Down
Loading