Skip to content

Commit abe864c

Browse files
committed
Fix format
1 parent 6734a87 commit abe864c

File tree

4 files changed

+50
-16
lines changed

4 files changed

+50
-16
lines changed

src/RelativeEntropy/RelativeEntropy.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040
MOI.dimension(set::AGECone) = size(set.α, 1)
4141
Base.copy(set::AGECone) = set
4242

43-
struct AGESet{MT <: MP.AbstractMonomial} <: PolyJuMP.PolynomialSet
43+
struct AGESet{MT<:MP.AbstractMonomial} <: PolyJuMP.PolynomialSet
4444
monomial::MT
4545
end
4646
function JuMP.reshape_set(set::AGECone, shape::PolyJuMP.PolynomialShape)
@@ -56,7 +56,12 @@ function setdefaults!(data::PolyJuMP.Data)
5656
return
5757
end
5858

59-
function JuMP.build_constraint(_error::Function, p, set::Union{SAGESet,AGESet}; kws...)
59+
function JuMP.build_constraint(
60+
_error::Function,
61+
p,
62+
set::Union{SAGESet,AGESet};
63+
kws...,
64+
)
6065
coefs = PolyJuMP.non_constant_coefficients(p)
6166
monos = MP.monomials(p)
6267
cone = JuMP.moi_set(set, monos)

src/RelativeEntropy/bridges/age.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ function MOI.Bridges.Constraint.bridge_constraint(
2222
MA.add_mul!!(f, convert(T, set.α[i, var]), ν[j])
2323
end
2424
end
25-
MOI.Utilities.normalize_and_add_constraint(model, f, MOI.EqualTo(zero(T)))
25+
return MOI.Utilities.normalize_and_add_constraint(
26+
model,
27+
f,
28+
MOI.EqualTo(zero(T)),
29+
)
2630
end
2731
scalars = MOI.Utilities.eachscalar(func)
2832
f = MOI.Utilities.operate(
2933
vcat,
3034
T,
3135
scalars[set.k] + sumν,
3236
scalars[setdiff(1:m, set.k)],
33-
MOI.VectorOfVariables(ν)
37+
MOI.VectorOfVariables(ν),
3438
)
35-
relative_entropy_constraint = MOI.add_constraint(model, f, MOI.RelativeEntropyCone(2m - 1))
39+
relative_entropy_constraint =
40+
MOI.add_constraint(model, f, MOI.RelativeEntropyCone(2m - 1))
3641
return AGEBridge{T,F,G,H}(set.k, ceq, relative_entropy_constraint)
3742
end
3843

@@ -48,7 +53,9 @@ function MOI.Bridges.added_constrained_variable_types(::Type{<:AGEBridge})
4853
return Tuple{Type}[]
4954
end
5055

51-
function MOI.Bridges.added_constraint_types(::Type{<:AGEBridge{T,F,G}}) where {T,F,G}
56+
function MOI.Bridges.added_constraint_types(
57+
::Type{<:AGEBridge{T,F,G}},
58+
) where {T,F,G}
5259
return [(F, MOI.EqualTo{T}), (G, MOI.RelativeEntropyCone)]
5360
end
5461

@@ -58,7 +65,12 @@ function MOI.Bridges.Constraint.concrete_bridge_type(
5865
::Type{<:AGECone},
5966
) where {T}
6067
S = MOI.Utilities.scalar_type(H)
61-
F = MOI.Utilities.promote_operation(+, T, S, MOI.ScalarAffineFunction{Float64})
68+
F = MOI.Utilities.promote_operation(
69+
+,
70+
T,
71+
S,
72+
MOI.ScalarAffineFunction{Float64},
73+
)
6274
G = MOI.Utilities.promote_operation(vcat, T, S, F)
6375
return AGEBridge{T,F,G,H}
6476
end

src/RelativeEntropy/bridges/sage.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ function MOI.Bridges.Constraint.bridge_constraint(
1212
) where {T,F,G}
1313
m = size(set.α, 1)
1414
ν = Vector{Vector{MOI.VariableIndex}}(undef, m)
15-
age_constraints = Vector{MOI.ConstraintIndex{MOI.VectorOfVariables,AGECone}}(undef, m)
15+
age_constraints =
16+
Vector{MOI.ConstraintIndex{MOI.VectorOfVariables,AGECone}}(undef, m)
1617
for k in 1:m
17-
ν[i], age_constraints[i] = MOI.add_constrained_variables(model, AGECone(set.α, k))
18+
ν[i], age_constraints[i] =
19+
MOI.add_constrained_variables(model, AGECone(set.α, k))
1820
end
1921
scalars = MOI.Utilities.eachscalar(func)
2022
n = size(set.α, 2)
2123
equality_constraints = map(1:n) do i
22-
f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(one(T), ν[:, i]), zero(T))
23-
MOI.add_constraint(model, MA.sub!(f, scalars[i]), MOI.EqualTo(zero(T)))
24+
f = MOI.ScalarAffineFunction(
25+
MOI.ScalarAffineTerm.(one(T), ν[:, i]),
26+
zero(T),
27+
)
28+
return MOI.add_constraint(
29+
model,
30+
MA.sub!(f, scalars[i]),
31+
MOI.EqualTo(zero(T)),
32+
)
2433
end
2534
return SAGEBridge{T,F,G}(ν, age_constraints, equality_constraints)
2635
end
@@ -37,7 +46,9 @@ function MOI.Bridges.added_constrained_variable_types(::Type{<:SAGEBridge})
3746
return Tuple{Type}[AGECone]
3847
end
3948

40-
function MOI.Bridges.added_constraint_types(::Type{<:SAGEBridge{T,F}}) where {T,F}
49+
function MOI.Bridges.added_constraint_types(
50+
::Type{<:SAGEBridge{T,F}},
51+
) where {T,F}
4152
return Tuple{Type,Type}[(F, MOI.EqualTo{T})]
4253
end
4354

@@ -47,6 +58,11 @@ function MOI.Bridges.Constraint.concrete_bridge_type(
4758
::Type{<:SAGECone},
4859
) where {T}
4960
S = MOI.Utilities.scalar_type(G)
50-
F = MOI.Utilities.promote_operation(-, T, MOI.ScalarAffineFunction{Float64}, S)
61+
F = MOI.Utilities.promote_operation(
62+
-,
63+
T,
64+
MOI.ScalarAffineFunction{Float64},
65+
S,
66+
)
5167
return AGEBridge{T,F,G}
5268
end

test/relative_entropy.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ using PolyJuMP
1414
function test_motzkin(x, y, T, solver)
1515
model = Model(solver)
1616
PolyJuMP.setpolymodule!(model, PolyJuMP.RelativeEntropy)
17-
motzkin = x^4*y^2 + x^2*y^4 + one(T) - 3x^2*y^2
18-
@constraint(model, motzkin in PolyJuMP.RelativeEntropy.AGESet(x^2*y^2))
17+
motzkin = x^4 * y^2 + x^2 * y^4 + one(T) - 3x^2 * y^2
18+
@constraint(model, motzkin in PolyJuMP.RelativeEntropy.AGESet(x^2 * y^2))
1919
optimize!(model)
2020
@test termination_status(model) == MOI.OPTIMAL
2121
@test primal_status(model) == MOI.FEASIBLE_POINT
2222
end
2323

2424
import ECOS
25-
const SOLVERS = [optimizer_with_attributes(ECOS.Optimizer, MOI.Silent() => true)]
25+
const SOLVERS =
26+
[optimizer_with_attributes(ECOS.Optimizer, MOI.Silent() => true)]
2627

2728
function runtests(x, y, T)
2829
for name in names(@__MODULE__; all = true)

0 commit comments

Comments
 (0)