Skip to content

Commit

Permalink
Merge pull request #878 from ericphanson/fix-float64
Browse files Browse the repository at this point in the history
Remove some Float64 assumptions
  • Loading branch information
blegat authored Sep 15, 2019
2 parents 345c03b + 4e6275f commit 10bbddb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Bridges/Constraint/rsoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function rotate_function(f::MOI.AbstractVectorFunction, T::Type)
t = f_scalars[1]
u = f_scalars[2]
x = f_scalars[3:d]
s2 = 2
s2 = T(2)
ts = MOIU.operate!(/, T, t, s2)
us = MOIU.operate!(/, T, u, s2)
# Cannot use `operate!` here since `ts` and `us` are needed for the next
Expand Down Expand Up @@ -94,7 +94,8 @@ function rotate_result(model,
attr::Union{MOI.ConstraintPrimal, MOI.ConstraintDual},
ci::MOI.ConstraintIndex)
x = MOI.get(model, attr, ci)
s2 = 2
T = eltype(x)
s2 = T(2)
return [x[1]/s2 + x[2]/s2; x[1]/s2 - x[2]/s2; x[3:end]]
end
# Need to define both `get` methods and redirect to `rotate_result` to avoid
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function bridge_constraint(::Type{ScalarSlackBridge{T, F, S}}, model,
f::MOI.AbstractScalarFunction, s::S) where {T, F, S}
slack, slack_in_set = MOI.add_constrained_variable(model, s)
new_f = MOIU.operate(-, T, f, MOI.SingleVariable(slack))
equality = MOI.add_constraint(model, new_f, MOI.EqualTo(0.0))
equality = MOI.add_constraint(model, new_f, MOI.EqualTo(zero(T)))
return ScalarSlackBridge{T, F, S}(slack, slack_in_set, equality)
end

Expand Down
9 changes: 5 additions & 4 deletions src/Bridges/Variable/soc_to_rsoc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ function rotate_result(
model, attr::Union{MOI.ConstraintPrimal, MOI.ConstraintDual},
ci::MOI.ConstraintIndex)
x = MOI.get(model, attr, ci)
s2 = 2
T = eltype(x)
s2 = T(2)
return [x[1]/s2 + x[2]/s2; x[1]/s2 - x[2]/s2; x[3:end]]
end

Expand Down Expand Up @@ -75,7 +76,7 @@ function MOI.get(model::MOI.ModelLike, attr::MOI.VariablePrimal,
bridge::SOCtoRSOCBridge{T}, i::IndexInVector) where T
if i.value == 1 || i.value == 2
t, u = MOI.get(model, attr, bridge.variables[1:2])
s2 = convert(T, 2)
s2 = T(2)
if i.value == 1
return t/s2 + u/s2
else
Expand All @@ -87,7 +88,7 @@ function MOI.get(model::MOI.ModelLike, attr::MOI.VariablePrimal,
end

function MOIB.bridged_function(bridge::SOCtoRSOCBridge{T}, i::IndexInVector) where T
s2 = convert(T, 2)
s2 = T(2)
if i.value == 1 || i.value == 2
t = MOIU.operate(/, T, MOI.SingleVariable(bridge.variables[1]), s2)
u = MOIU.operate(/, T, MOI.SingleVariable(bridge.variables[2]), s2)
Expand All @@ -102,7 +103,7 @@ function MOIB.bridged_function(bridge::SOCtoRSOCBridge{T}, i::IndexInVector) whe
end
function unbridged_map(bridge::SOCtoRSOCBridge{T}, vis::Vector{MOI.VariableIndex}) where T
umap = Pair{MOI.VariableIndex, MOI.ScalarAffineFunction{T}}[]
s2 = convert(T, 2)
s2 = T(2)
t = MOIU.operate(/, T, MOI.SingleVariable(vis[1]), s2)
u = MOIU.operate(/, T, MOI.SingleVariable(vis[2]), s2)
push!(umap, bridge.variables[1] => MOIU.operate(+, T, t, u))
Expand Down

0 comments on commit 10bbddb

Please sign in to comment.