Splatting keyword arguments to @variable macro in JuMP

No, splatting keyword arguments doesn’t work with the JuMP macros. Do this instead:

function apply_model_type(v, m::Model)
    if m.ext[:model_type] == "binary"
        set_binary.(v)
    elseif m.ext[:model_type] == "integer"
        set_integer.(v)
        set_lower_bound.(v, 0)
    elseif m.ext[:model_type] == "relaxed"
        set_lower_bound.(v, 0)
    end
end

function make_z_variable(m::Model)
    z = @variable(m, [1:10], base_name="z")
    apply_model_type(z, m)
    return z
end
2 Likes