Macro to substitute parameters used for JuMP model

As a user, you should never* write your own macro. There is always a simpler and easier way to achieve what you are trying to do.

For example, you could use a function:

using JuMP, PowerModels
function OPF(file)
    data = build_ref(parse_file(file))[:it][:pm][:nw][0]
    G = keys(data[:gen])
    Pmin(g) = data[:gen][g]["pmin"]
    Pmax(g) = data[:gen][g]["pmax"]
    model = Model(Ipopt.Optimizer)
    @variable(model, Pmin(g) <= Pgen[g in G] <= Pmax(g))
    optimize!(model)
    return
end

*with very few exceptions, which do not apply here.

1 Like