-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathMTKInfiniteOptExt.jl
26 lines (23 loc) · 1.02 KB
/
MTKInfiniteOptExt.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module MTKInfiniteOptExt
import ModelingToolkit
import SymbolicUtils
import NaNMath
import InfiniteOpt
import InfiniteOpt: JuMP, GeneralVariableRef
# This file contains method definitions to make it possible to trace through functions generated by MTK using JuMP variables
for ff in [acos, log1p, acosh, log2, asin, tan, atanh, cos, log, sin, log10, sqrt]
f = nameof(ff)
# These need to be defined so that JuMP can trace through functions built by Symbolics
@eval NaNMath.$f(x::GeneralVariableRef) = Base.$f(x)
end
# JuMP variables and Symbolics variables never compare equal. When tracing through dynamics, a function argument can be either a JuMP variable or A Symbolics variable, it can never be both.
function Base.isequal(::SymbolicUtils.Symbolic,
::Union{JuMP.GenericAffExpr, JuMP.GenericQuadExpr, InfiniteOpt.AbstractInfOptExpr})
false
end
function Base.isequal(
::Union{JuMP.GenericAffExpr, JuMP.GenericQuadExpr, InfiniteOpt.AbstractInfOptExpr},
::SymbolicUtils.Symbolic)
false
end
end