Skip to content

Commit

Permalink
Fix bounded coefficient gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Oct 30, 2023
1 parent 0fced95 commit fc22ab3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/encoding/abstract.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function encodes(f::PBO.AbstractPBF{V,T}, S::Tuple{T,T}, tol::T) where {V,T}
return encodes(f, S, tol)

Check warning on line 2 in src/encoding/abstract.jl

View check run for this annotation

Codecov / codecov/patch

src/encoding/abstract.jl#L1-L2

Added lines #L1 - L2 were not covered by tests
end
2 changes: 1 addition & 1 deletion src/encoding/encoding.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Encoding

import MathOptInterface as MOI
import QUBOTools: PBO
import PseudoBooleanOptimization as PBO

const VI = MOI.VariableIndex

Expand Down
5 changes: 5 additions & 0 deletions src/encoding/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ function encode end
"""
function encode! end

@doc raw"""
encodes(f::AbstractPBF, S::Tuple{T,T}, tol::T) where {T}
"""
function encodes end

@doc raw"""
encoding_bits(e::VariableEncodingMethod, S::Tuple{T,T}, tol::T) where {T}
"""
Expand Down
4 changes: 2 additions & 2 deletions src/encoding/variables/interval/bounded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function encode(
a, b = S

= abs(b - a)
r = ceil(Int, ℓ / e.μ - 1)
r = floor(Int, ℓ / e.μ - 1)
δ =- r * e.μ

Δ::Tuple{T,T} = (0, δ)
Expand Down Expand Up @@ -108,7 +108,7 @@ function encoding_bits(
a, b = S

= abs(b - a)
r = ceil(Int, ℓ / e.μ - 1)
r = floor(Int, ℓ / e.μ - 1)
δ =- r * e.μ

Δ::Tuple{T,T} = (0, δ)
Expand Down
16 changes: 8 additions & 8 deletions test/unit/encoding/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,23 @@ function test_variable_encoding_methods()
let μ = 1.0
= ToQUBO.Encoding.Bounded(e, μ)
φ = PBO.vargen(VI)
S = (-2.0, 2.0)
S = (-1.0, 2.5)
n = 8

y, ξ, χ = ToQUBO.Encoding.encode(φ, ê, S, n)

@test length(y) == n
@test y == VI.(1:n)
@test ξ == PBO.PBF{VI,Float64}(
y[1] => 1 / 31,
y[2] => 2 / 31,
y[3] => 4 / 31,
y[4] => 8 / 31,
y[5] => 16 / 31,
y[6] => 1.0,
y[1] => 1.5 / 63,
y[2] => 3 / 63,
y[3] => 6 / 63,
y[4] => 12 / 63,
y[5] => 24 / 63,
y[6] => 48 / 63,
y[7] => 1.0,
y[8] => 1.0,
-2.0,
-1.0,
)
@test isnothing(χ)
end
Expand Down

0 comments on commit fc22ab3

Please sign in to comment.