Suppose I am solving an optimization problem in JuMP (see example below), and I want to try out a candidate solution vectors to the problem and see what it’s objective value and constraint values it yields (in particular if they bind). Is there a standard way to do this in JuMP?
Obviously, I could just evaluate the objective and the constraint functions at the candidate solution separately without using JuMP. But it might be more convenient to be able to do all these evaluations with one line of code using a function of the JuMP model or something. Is this possible?
using JuMP model = Model(optimizer_with_attributes( Ipopt.Optimizer)) function obj(x) return x^2 end # Ex-post IC function test_constraint(x) return x^3 end register(model, :obj, 1, obj; autodiff = true) register(model, :test_constraint, 1, test_constraint; autodiff = true) @variable(model, x >= 0) @NLconstraint(model, test_constraint(x) <= 5) @NLobjective(model, Max, obj(x)) using Printf set_silent(model) optimize!(model); status = @sprintf("%s", JuMP.termination_status(model)); if (status=="LOCALLY_SOLVED") @show value(x); end
So for example, now I might want to try out x=3 and see what objective it gives and whether the constraint
x^3 <= 5 binds.