Hi,
I wonder how I can get the value of the gradient of a constraint at some fixed point using JuMP. For example, in the following optimization problem, how can I get the gradient of the constraint with name Temp with respect to variable u[1] at the starting point (provided via the start values)?
I would really appreciate it if you could help me with this problem.
using JuMP, Ipopt
model = Model(Ipopt)
@variable(model, Tc_out[1:2])
@variable(model, T)
@variable(model, Th_out[1:2])
@variable(model, 0<= u[1:2] <= 1, start = 0.5)
@NLparameter(model, Tc_in == 41.0)
@NLparameter(model, wc == 97.0)
@NLparameter(model, Th_in[1:2] == 105.0)
set_value(Th_in[2], 206.0)
@NLparameter(model, wh[1:2] == 118.0)
set_value(wh[2], 94.0)
@NLparameter(model, UA[1:2] == 240.0)
set_value(UA[2], 502.0)
@NLobjective(model, Max, 1)
@NLconstraint(model, Tc_outL[i = 1:2], Tc_out[i] >= Tc_in)
@NLconstraint(model, Tc_outH[i = 1:2], Tc_out[i] <= Th_in[i])
@NLconstraint(model, Th_outL[i = 1:2], Th_out[i] >= Tc_in)
@NLconstraint(model, Th_outH[i = 1:2], Th_out[i] <= Th_in[i])
@NLconstraint(model, HTrans[i = 1:2], -1*Tc_out[i] + Tc_in + UA[i]*((Th_in[i]-Tc_out[i])*(Th_out[i]-Tc_in)*0.5*(Th_in[i]-Tc_out[i]+Th_out[i]-Tc_in))^(1/3)/(u[i]*wc*4.2) == 0)
@NLconstraint(model, ECon_cold, -1*T + Tc_out[1]*u[1] + Tc_out[2]*u[2] == 0)
@NLconstraint(model, ECon_HX[i = 1:2], (-1*Th_out[i] + Th_in[i])*wh[i] - (Tc_out[i] - Tc_in)*wc*u[i] == 0)
@NLconstraint(model, MCon, u[1]+u[2] -1 == 0)
@NLconstraint(model, Temp, ((Tc_out[2] - Tc_in)^2)/(Th_in[2] - Tc_in) - ((Tc_out[1] - Tc_in)^2)/(Th_in[1] - Tc_in) == 0)
set_start_value(model[:Tc_out][1], (41 + 105)*0.5)
set_start_value(model[:Tc_out][2], (41 + 206)*0.5)
set_start_value(model[:T], (2*41 + 105 + 206)*0.25)
set_start_value(model[:Th_out][1], (41 + 105)*0.5)
set_start_value(model[:Th_out][2], (41 + 206)*0.5)