Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 12, 2024
1 parent 5c100eb commit 4f52bd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
27 changes: 27 additions & 0 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,30 @@ for file in readdir(joinpath(@__DIR__, "macros"))
include(joinpath(@__DIR__, "macros", file))
end
end

# These methods must come after the macros are included, because they use both
# `@variable` and `@constraint`.

function _build_subexpression(
::Function,
model::AbstractModel,
expr::AbstractJuMPScalar,
name::String,
)
y = @variable(model)
set_name(y, name)
@constraint(model, y == expr)
return y
end

function _build_subexpression(
::Function,
model::AbstractModel,
expr::Array{<:AbstractJuMPScalar},
name::String,
)
y = [@variable(model) for _ in expr]
set_name.(y, name)
@constraint(model, y .== expr)
return y
end
24 changes: 0 additions & 24 deletions src/macros/@expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,6 @@ macro expression(input_args...)
)
end

function _build_subexpression(
::Function,
model::AbstractModel,
expr::AbstractJuMPScalar,
name::String,
)
y = @variable(model)
set_name(y, name)
@constraint(model, y == expr)
return y
end

function _build_subexpression(
::Function,
model::AbstractModel,
expr::Array{<:AbstractJuMPScalar},
name::String,
)
y = [@variable(model) for _ in expr]
set_name.(y, name)
@constraint(model, y .== expr)
return y
end

function _build_subexpression(
error_fn::Function,
::AbstractModel,
Expand Down

0 comments on commit 4f52bd6

Please sign in to comment.