📄 al_main.m
字号:
%this code just fornonlinear equality constraints augmented Langrangian algorithms
%for the inequality constraints , we could add some nonnegative slack %variables to turn them into the equality constraints
%perface
%start condition
%'this codt for nonlinear equality and inequality constraints augmented Langrangian algorithms');
%'for the inequality constraints , we could add some nonnegative slack variables
%'please write the obj function in the obj.m, the constrains function in the constrains.m ');
%'pena;%penalty parameter;c_scale;%scale parameter;e_al;%tolerance', are kebian);
%'you can change them in the AL_main.m');
%'please put in the start point x_al_start the r_al_start, and the opt_newton, where opt1==1 DFP and golden, or ==2 BFGS and wolfe );
% the N_equ is the number of equality, the N_inequ, is the number of the inequality
%'function f=AL_main( x_al_start, r_al_start, N_equ, N_inequ, opt1 )');
function [X,FVAL]=AL_main(x_al)
%==============initial the program========================
global r_al pena N_equ N_inequ;
%r_al=[1,1,1]
%N_equ=1;
%N_inequ=2;
strong=0;
pena=10;%penalty parameter;
c_scale=2;%scale parameter;
cta=0.5; %cta ( 0, 1 )
e_al=0.005;%tolerance
max_itera=25;
out_itera=1;% out iteration
% the start ponit
%x_start=(x_al, r_al);
N_x_al=max( size( x_al));
N_r_al=max( size( r_al));
%=====================start the iteration======================
while out_itera < 26
x_al0=x_al;
r_al0=r_al;
compare0=compare(x_al0);
%quasi_newton
[X,FVAL]=fminsearch(@AL_obj,[1,1,1]);
x_al=X; %get the new x
% check the stop condition
%if norm( constrains( x_al ) ) < e_al
if compare( x_al ) < e_al
disp('we get the opt point:');
break
end
%constrains think over!!!!!!!!!!!!!1
if compare( x_al ) < cta * compare0
%% pena=pena
else
pena=min(1000, c_scale*pena);%% the max pena is 1000;
disp(' pena=10*pena ');
end
%change the r_al
%% where is the equality part
N=N_equ+N_inequ;
temp_constrains=constrains( x_al );
for i=1:N
%% the equality constrains part;
if N_equ~=0 && N_equ>=i
r_al(i)=r_al(i) - pena*temp_constrains(i);
end
%% the inequality constrains part;
if N_inequ~=0 && i>N_equ
r_al(i)=max( 0, ( r_al(i)-pena*temp_constrains(i)));
end
end
if strong==1
if compare( x_al) > compare0 %%% not descend
x_al=x_al0;
r_al=r_al0;
disp('@@@@@@@ouccer constrains(x)>constrains(x0), but get the fit point!!!!!!@@@@@@');
break
end
end
% if obj( x_al ) > obj( x_al0 )
% disp('@@@@@@@ouccer obj(x)>obj(x0), but get the fit point!!!!!!@@@@@@');
% break
%end
out_itera=out_itera+1;
out_itera
[x_al,r_al]
[compare( x_al),obj(x_al)]
% disp('the value of constrains ');
% norm( constrains( x_al ) )
end
%++++++++++++the iteration end ++++++
%disp('x_al=');
%x_al
disp('!!!!!!!!!!!!!!!!!the iteration over!!!!!!!!!!!!!!!!!!!!!!');
disp('iteration of the out');
out_itera
disp('the value of the obj function');
obj( x_al )
disp('the value of constrains ');
compare( x_al )
disp('the opt point');
r_al
X=x_al;
FVAL=obj(X);
% opt_valu( x_al )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -