Skip to content
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

Type-generic S matrix in LDL factorization #76

Merged
merged 3 commits into from
Dec 26, 2020
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
50 changes: 50 additions & 0 deletions examples/optimal_other_type.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Tulip
import MathOptInterface
const MOI = MathOptInterface
using Test

const T = Float32

lp = Tulip.Optimizer{T}()

# Create variables
x = MOI.add_variable(lp)
y = MOI.add_variable(lp)

# Set variable bounds
MOI.add_constraint(lp, MOI.SingleVariable(x), MOI.GreaterThan(T(0))) # x >= 0
MOI.add_constraint(lp, MOI.SingleVariable(y), MOI.GreaterThan(T(0))) # y >= 0

# Add constraints
row1 = MOI.add_constraint(lp,
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[1.0, -1.0], [x, y]), T(0)),
MOI.GreaterThan(T(-2))
)
row2 = MOI.add_constraint(lp,
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[2.0, -1.0], [x, y]), T(0)),
MOI.LessThan(T(4))
)
row3 = MOI.add_constraint(lp,
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[1.0, 2.0], [x, y]), T(0)),
MOI.LessThan(T(7))
)

# Set the objective
MOI.set(lp,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float32}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[-2.0, -1.0], [x, y]), T(0))
)
MOI.set(lp, MOI.ObjectiveSense(), MOI.MIN_SENSE)

MOI.optimize!(lp)

objval = MOI.get(lp, MOI.ObjectiveValue())
x_ = MOI.get(lp, MOI.VariablePrimal(), x)
y_ = MOI.get(lp, MOI.VariablePrimal(), y)

@test objval ≈ -8
@test x_ ≈ 3
@test y_ ≈ 2
@test objval isa Float32
@test x_ isa Float32
@test y_ isa Float32
2 changes: 1 addition & 1 deletion src/KKT/ldlfact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mutable struct LDLFactSQD{T<:Real} <: AbstractKKTSolver{T}

S = [
spdiagm(0 => -θ) A';
spzeros(T, m, n) spdiagm(0 => ones(m))
spzeros(T, m, n) spdiagm(0 => ones(T, m))
]

# TODO: PSD-ness checks
Expand Down
4 changes: 4 additions & 0 deletions test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ end
@testset "$T" begin ex_unbounded(T, OutputLevel=0) end
end
end

@testset "Optimal Float32" begin
include(joinpath(examples_dir, "optimal_other_type.jl"))
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TLP = Tulip

import Convex

const TvTYPES = [Float64, BigFloat]
const TvTYPES = [Float32, Float64, BigFloat]

# write your own tests here
const testdir = dirname(@__FILE__)
Expand Down