Skip to content

Commit 49fb9da

Browse files
authored
Refactor problem size interface (#91)
* update * tests pass * fix deps
1 parent 055ac3a commit 49fb9da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+57
-75
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1111
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
1212
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1313
UnitDiskMapping = "1b61a8d9-79ed-4491-8266-ef37f39e1727"
14-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
15-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1614

1715
[compat]
1816
BitBasis = "0.9"

docs/src/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ A problem reduction rule is a function that reduces a problem to another problem
88
- [`extract_solution`](@ref): Extract the solution of the target problem to the original problem.
99

1010
Optional functions include:
11-
- [`reduction_complexity`](@ref): The computational complexity of the reduction rule.
11+
- [`reduce_size`](@ref): Infer the size of the target problem from the source problem size.

src/ProblemReductions.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ using DocStringExtensions
55
using PrettyTables
66
using BitBasis
77
using MLStyle
8-
using Random
98

109
export @bit_str
1110
export TruthTable
@@ -32,7 +31,7 @@ export MaximalIS
3231
export PaintShop
3332

3433
# rules
35-
export target_problem, AbstractProblem, AbstractReductionResult, reduceto, extract_solution, extract_multiple_solutions, reduction_complexity
34+
export target_problem, AbstractProblem, AbstractReductionResult, reduceto, extract_solution, extract_multiple_solutions, reduce_size
3635
export LogicGadget, truth_table
3736
export ReductionSATTo3SAT
3837
export ReductionCircuitToSpinGlass, ReductionMaxCutToSpinGlass, ReductionSpinGlassToMaxCut, ReductionVertexCoveringToSetCovering, ReductionSatToColoring,

src/models/Circuit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ Base.show(io::IO, ::MIME"text/plain", x::CircuitSAT) = show(io, x)
218218
# variables interface
219219
variables(c::CircuitSAT) = collect(1:length(c.symbols))
220220
flavors(::Type{<:CircuitSAT}) = [0, 1]
221+
problem_size(c::CircuitSAT) = (; num_exprs=length(c.circuit.exprs), num_variables=length(c.symbols))
221222

222223
# parameters interface
223224
parameters(sat::CircuitSAT) = Int[]

src/models/Coloring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Coloring{K, WT<:AbstractVector} <:AbstractProblem
1818
end
1919
end
2020
Base.:(==)(a::Coloring, b::Coloring) = a.graph == b.graph && a.weights == b.weights
21-
problem_size(c::Coloring) = nv(c.graph)^2
21+
problem_size(c::Coloring) = (; num_vertices=nv(c.graph), num_edges=ne(c.graph))
2222

2323
# variables interface
2424
variables(gp::Coloring{K}) where K = collect(1:nv(gp.graph))

src/models/DominatingSet.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Base.:(==)(a::DominatingSet, b::DominatingSet) = ( a.graph == b.graph )
2121
# Variables Interface
2222
variables(gp::DominatingSet) = [1:nv(gp.graph)...]
2323
flavors(::Type{<:DominatingSet}) = [0, 1]
24+
problem_size(c::DominatingSet) = (; num_vertices=nv(c.graph), num_edges=ne(c.graph))
2425

2526
"""
2627
evaluate(c::DominatingSet, config)

src/models/Factoring.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ end
1717
# variables interface
1818
variables(f::Factoring) = collect(1:f.m+f.n)
1919
flavors(::Type{Factoring}) = [0, 1]
20+
problem_size(f::Factoring) = (; num_bits_first=f.m, num_bits_second=f.n)
2021

2122
# utilities
2223
function evaluate(f::Factoring, config)

src/models/IndependentSet.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Base.:(==)(a::IndependentSet, b::IndependentSet) = ( a.graph == b.graph )
2222
# Variables Interface
2323
variables(gp::IndependentSet) = [1:nv(gp.graph)...]
2424
flavors(::Type{<:IndependentSet}) = [0, 1]
25+
problem_size(c::IndependentSet) = (; num_vertices=nv(c.graph), num_edges=ne(c.graph))
2526

2627
"""
2728
evaluate(c::IndependentSet, config)

src/models/Matching.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Base.:(==)(a::Matching, b::Matching) = a.graph == b.graph && a.weights == b.weig
2121
flavors(::Type{<:Matching}) = [0, 1]
2222
variables(gp::Matching) = collect(1:ne(gp.graph))
2323
num_variables(gp::Matching) = ne(gp.graph)
24+
problem_size(c::Matching) = (; num_vertices=nv(c.graph), num_edges=ne(c.graph))
2425

2526
# weights interface
2627
parameters(c::Matching) = c.weights

src/models/MaxCut.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Base.:(==)(a::MaxCut, b::MaxCut) = a.graph == b.graph && a.weights == b.weights
2424
variables(gp::MaxCut) = [1:nv(gp.graph)...]
2525
num_variables(gp::MaxCut) = nv(gp.graph)
2626
flavors(::Type{<:MaxCut}) = [0, 1] #choose it or not
27+
problem_size(c::MaxCut) = (; num_vertices=nv(c.graph), num_edges=ne(c.graph))
2728

2829
# weights interface
2930
parameters(c::MaxCut) = [[c.weights[i] for i=1:ne(c.graph)]...]

0 commit comments

Comments
 (0)