Can we improve JuMP.set_objective_coefficient?

For 1, do:

f = objective_function(model)
coefficient(f, x)

I don’t want to add objective_function_coefficient(model, x) because this implies that we can efficiently query an objective coefficient, which we cannot do. We have added normalized_coefficient for constraints, but I tend to think this was a mistake that I don’t want to repeat.

For 2: use broadcasting, or reshape into a vector. JuMP’s philosophy is to severely restrict the input types to provide a consistent and correct API experience. Allowing some sort of AbstractArray input makes MethodErrors much more likely, and we don’t think they are a good user experience.

For 3: no. Note that this would only be faster than two separate calls if we could actually communicate this to a solver in a single function call. That would require a much bigger change throughout the entire JuMP/MathOptInterface ecosystem which is not worth it for this single use-case, so use two separate calls, or if you really must:

JuMP.set_objective_coefficient(
    model,
    vcat(x; vec(Y)),
    vcat(rand(4), vec(rand(2, 3))),
)

As a related comment, supporting Varargs like this is a pain. At minimum, we’d want something more regular like:

JuMP.set_objective_coefficient(model, x => rand(4), Y => rand(2, 3))

but even then, the Pairs would be different types, so dispatch will be slow etc. We’d probably require:

JuMP.set_objective_coefficient(model, x => rand(4), vec(Y) => vec(rand(2, 3)))

but then you may as well use the vcat approach.