Title: is there any possibility to change the RHS of non-linear constraints in julia?
Tags: julia;julia-jump
Question: Is there any possibility to change the RHS of non-linear constraints?
using JuMP, Ipopt, Juniper,Gurobi,CPUTime
ZT=zeros(2,1);
ZB=zeros(2,1);
#-----Model parameters--------------------------------------------------------
sig=0.86;
landa=50;
E=T0=T1=.0833;
T2=0.75;
gam2=1; gam1=0;
a1=5; a2=4.22; a3=977.4; ap=977.4;
C1=949.2; c0=114.24;
f(x) = cdf(Normal(0, 1), x);
#---------------------------------------------------------------------------
ALT= Model(optimizer_with_attributes(Juniper.Optimizer, &quot;nl_solver&quot;=&gt;optimizer_with_attributes(Ipopt.Optimizer, &quot;print_level&quot; =&gt; 0),
&quot;mip_solver&quot;=&gt;optimizer_with_attributes(Gurobi.Optimizer, &quot;logLevel&quot; =&gt; 0),&quot;registered_functions&quot; =&gt;[Juniper.register( :f, 1, f; autodiff = true)])
);
# variables-----------------------------------------------------------------
JuMP.register(ALT, :f, 1, f; autodiff = true);
@variable(ALT, h &gt;= 0.1);
@variable(ALT, L &gt;= 0.00001);
@variable(ALT, n&gt;=2, Int);
#---------------------------------------------------------------------------
@NLexpression(ALT,k7,1-f(L-sig*sqrt(n))+f(-L-sig*sqrt(n)));
#constraints--------------------------------------------------------
@NLconstraint(ALT, f(-L) <= 1/400);
#objective function---------------------------------------------------------
@NLexpression(ALT,f2,1/k7);
#------------------------------------------------------------------------
@NLconstraint(ALT,rf2,f2<=10000);
@NLconstraint(ALT,lf2,f2&gt;=-10000);
@NLobjective(ALT,Min,f2);
optimize!(ALT);
minf2=getvalue(f2)
set_normalized_rhs(rf2,minf2);
ZB[2]=getvalue(f2);
@NLobjective(ALT,Min,f1);
optimize!(ALT);
ZB[1]=getvalue(f1);
In this code the RHS of constraints must change. But this error happens:
ERROR: MethodError: no method matching set_normalized_rhs(75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0onstraintRef{Model,NonlinearConstraintIndex,ScalarShape}, 75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0loat64)
Closest candidates are:
set_normalized_rhs(75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0onstraintRef{Model,MathOptInterface.ConstraintIndex{F,S},Shape} where Shape<:AbstractShape, 75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0ny) where {T, S<:Union{MathOptInterface.EqualTo{T}, MathOptInterface.GreaterThan{T}, MathOptInterface.LessThan{T}}, F<:Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}}} at C:\Users\admin\.julia\packages\JuMP\YXK4e\src\constraints.jl:478
Stacktrace:
[1] top-level scope at none:1```.

Here is the accepted answer: You can use a nonlinear parameter in place of the right-hand side and update its value after a solve.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:08/22/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<julia><julia-jump>', 'Title': 'is there any possibility to change the RHS of non-linear constraints in julia?', 'ViewCount': 91, 'id': 63537231, 'user_AboutMe': '', 'user_AccountId': 10936260.0, 'user_DisplayName': 'Soma', 'user_Reputation': 723.0, 'user_Views': 84.0, 'user_id': 8417332.0}}