Skip to content
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -30,6 +31,7 @@ JSONSchema = "1"
MutableArithmetics = "1"
NaNMath = "0.3, 1"
OrderedCollections = "1"
SnoopPrecompile = "1"
SpecialFunctions = "0.8, 1, 2"
julia = "1.6"

Expand Down
32 changes: 32 additions & 0 deletions src/MathOptInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,36 @@ we provide this `MOI.IndexMap` as an alias.
"""
const IndexMap = Utilities.IndexMap

import SnoopPrecompile

SnoopPrecompile.@precompile_setup begin
SnoopPrecompile.@precompile_all_calls begin
let
optimizer =
() -> Utilities.MockOptimizer(
Utilities.UniversalFallback(Utilities.Model{Float64}()),
)
model = Utilities.CachingOptimizer(
Utilities.UniversalFallback(Utilities.Model{Float64}()),
instantiate(optimizer; with_bridge_type = Float64),
)
set(model, Silent(), true)
x = add_variables(model, 3)
add_constraint(model, x[1], ZeroOne())
add_constraint(model, x[2], Integer())
add_constraint(model, x[1], GreaterThan(0.0))
add_constraint(model, x[2], LessThan(0.0))
add_constraint(model, x[3], EqualTo(0.0))
f = 1.0 * x[1] + x[2] + x[3]
add_constraint(model, f, GreaterThan(0.0))
add_constraint(model, f, LessThan(0.0))
add_constraint(model, f, EqualTo(0.0))
y, _ = add_constrained_variables(model, Nonnegatives(2))
set(model, ObjectiveSense(), MAX_SENSE)
set(model, ObjectiveFunction{typeof(f)}(), f)
optimize!(model)
end
end
end

end
4 changes: 2 additions & 2 deletions src/instantiate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const _INSTANTIATE_NOT_CALLABLE_MESSAGE =
Create an instance of optimizer by calling `optimizer_constructor`.
Then check that the type returned is an empty [`ModelLike`](@ref).
"""
function _instantiate_and_check(optimizer_constructor)
function _instantiate_and_check((@nospecialize optimizer_constructor))
if !applicable(optimizer_constructor)
error(_INSTANTIATE_NOT_CALLABLE_MESSAGE)
end
Expand Down Expand Up @@ -143,7 +143,7 @@ problem incrementally (see [`supports_incremental_interface`](@ref)), then a
model.
"""
function instantiate(
optimizer_constructor;
(@nospecialize optimizer_constructor);
with_bridge_type::Union{Nothing,Type} = nothing,
)
optimizer = _instantiate_and_check(optimizer_constructor)
Expand Down