How to examine properties of a candidate solution vector to an optimization problem in JuMP?

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(

function obj(x)
    return x^2

# Ex-post IC
function test_constraint(x)
    return x^3

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
status = @sprintf("%s", JuMP.termination_status(model));
if (status=="LOCALLY_SOLVED")
    @show value(x);

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.


You might be able to make use of primal_feasibility_report, explained in the documentation here: Checking feasibility of solutions

To compute the value of the objective at a point, see: Evaluate the objective function at a point