是否有可能改变茱莉亚非线性约束的RHS? [英] is there any possibility to change the RHS of non-linear constraints in julia?

查看:68
本文介绍了是否有可能改变茱莉亚非线性约束的RHS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能改变非线性约束的RHS?

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);

在此代码中,约束的RHS必须更改.但是会发生此错误:

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```. 

推荐答案

您可以使用

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

这篇关于是否有可能改变茱莉亚非线性约束的RHS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆