is there any possibility to change the RHS of non-linear constraints in julia?

邮差的信 提交于 2021-02-10 12:50:10

问题


Is there any possibility to change the RHS of non-linear constraints?

using JuMP, Ipopt, Juniper,Gurobi,CPUTime
T=0;
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, "nl_solver"=>optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0),

       "mip_solver"=>optimizer_with_attributes(Gurobi.Optimizer, "logLevel" => 0),"registered_functions" =>[Juniper.register( :f, 1, f; autodiff = true)])

       );

# variables-----------------------------------------------------------------
JuMP.register(ALT, :f, 1, f; autodiff = true);
@variable(ALT, h >= 0.1);
@variable(ALT, L >= 0.00001);
@variable(ALT, n>=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>=-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(::ConstraintRef{Model,NonlinearConstraintIndex,ScalarShape}, ::Float64)
Closest candidates are:
  set_normalized_rhs(::ConstraintRef{Model,MathOptInterface.ConstraintIndex{F,S},Shape} where Shape<:AbstractShape, ::Any) 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```. 

回答1:


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



来源:https://stackoverflow.com/questions/63537231/is-there-any-possibility-to-change-the-rhs-of-non-linear-constraints-in-julia

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!