Skip to content

Commit

Permalink
Conditionally define NL opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbowly committed Oct 29, 2024
1 parent 490ce31 commit 48d518c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ repo = "https://github.com/jump-dev/Gurobi.jl"
version = "1.3.1"

[deps]
Gurobi_jll = "c018c7e6-a5b0-4aea-8f80-9c1ef9991411"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[compat]
Gurobi_jll = "~9.5, ~10.0, ~11.0"
Libdl = "<0.0.1, 1.6"
MathOptInterface = "1.21"
Random = "<0.0.1, 1.6"
Expand Down
42 changes: 23 additions & 19 deletions src/MOI_wrapper/MOI_nonlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

const _OPCODE_MAP = Dict(
:+ => GRB_OPCODE_PLUS,
:- => GRB_OPCODE_MINUS,
:* => GRB_OPCODE_MULTIPLY,
:/ => GRB_OPCODE_DIVIDE,
# GRB_OPCODE_UMINUS 6
# GRB_OPCODE_SQUARE 7
:sqrt => GRB_OPCODE_SQRT,
:sin => GRB_OPCODE_SIN,
:cos => GRB_OPCODE_COS,
:tan => GRB_OPCODE_TAN,
:^ => GRB_OPCODE_POW,
:exp => GRB_OPCODE_EXP,
:log => GRB_OPCODE_LOG,
:log2 => GRB_OPCODE_LOG2,
:log10 => GRB_OPCODE_LOG10,
:logistic => GRB_OPCODE_LOGISTIC,
)

_supports_nonlinear() = _GUROBI_VERSION >= v"12.0.0"

if _supports_nonlinear()
const _OPCODE_MAP = Dict(
:+ => GRB_OPCODE_PLUS,
:- => GRB_OPCODE_MINUS,
:* => GRB_OPCODE_MULTIPLY,
:/ => GRB_OPCODE_DIVIDE,
# GRB_OPCODE_UMINUS 6
# GRB_OPCODE_SQUARE 7
:sqrt => GRB_OPCODE_SQRT,
:sin => GRB_OPCODE_SIN,
:cos => GRB_OPCODE_COS,
:tan => GRB_OPCODE_TAN,
:^ => GRB_OPCODE_POW,
:exp => GRB_OPCODE_EXP,
:log => GRB_OPCODE_LOG,
:log2 => GRB_OPCODE_LOG2,
:log10 => GRB_OPCODE_LOG10,
:logistic => GRB_OPCODE_LOGISTIC,
)
else
const _OPCODE_MAP = Dict()
end

function MOI.supports_constraint(
::Optimizer,
::Type{MOI.ScalarNonlinearFunction},
Expand Down

0 comments on commit 48d518c

Please sign in to comment.