Commit 0aba26fe authored by whzecomjm's avatar whzecomjm
Browse files

init

parents
Loading
Loading
Loading
Loading
+29 −0
Changes for CF-Projects/project 1/Target1&2/SA.m: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
m% this is SA approach in

x0_1 = rand(1,4) %% innitial guess
x0_2 = rand(1,2)
%options = optimoptions(@fmincon,'Algorithm','sqp','PlotFcns');
options = optimoptions(@fmincon,'Algorithm','sqp','PlotFcns',{@optimplotfval,@optimplotfunccount,@optimplotstepsize});
options1 =options;
option1 = saoptimset('simulannealbnd');
option = saoptimset(option1,'PlotFcns',{@saplotbestf,@saplotf,@saplottemperature,@saplotstopping});
%option = saoptimset('simulannealbnd');
tic;

[x1,f1val] = simulannealbnd(@fcnT1SA,x0_1',[],[],option) %SA
disp(['SA for 1st task need ',num2str(toc)]);  
tic;

[x1,f1val] = ... 
fmincon(@fcnT1,x0_1,[],[],[],[],[],[],@conT1,options)
disp(['fminbnd for 1st task need ',num2str(toc)]);

tic;

[x2,f2val] = simulannealbnd(@fcnT2SA,x0_2',[],[],option)
disp(['SA for 2nd task need ',num2str(toc)]);
tic;

[x2,f2val] = ... 
fmincon(@fcnT2,x0_2,[],[],[],[],[],[],@conT2,options1)
disp(['fminbnd for 2nd task need ',num2str(toc)]);
+10 −0
Changes for CF-Projects/project 1/Target1&2/conT1.m: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
function [ c,ceq ] = conT1( x )
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
     c = [x(1)^2+x(2)^2+x(3)^2+x(4)^2+x(1)-x(2)+x(3)-x(4)-8;
         x(1)^2+2*x(2)^2+x(3)^2+2*x(4)^2-x(1)-x(4)-10;
         2*x(1)^2+x(2)^2+x(3)^2+2*x(1)-x(2)-x(4)-5];
     ceq = [];

end
%% reference: http://www.mathworks.com/help/optim/ug/nonlinear-inequality-constraints.html
+13 −0
Changes for CF-Projects/project 1/Target1&2/conT2.m: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line

function [ c,ceq ] = conT2( x )
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
     ceq = [];
     c = [-x(1)*x(2)-10;
            x(1)*x(2)-x(1)-x(2)+1.5];

end
%% reference: http://www.mathworks.com/help/optim/ug/nonlinear-inequality-constraints.html


+6 −0
Changes for CF-Projects/project 1/Target1&2/fcnT1.m: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
function [ f ] = fcnT1( x )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
  f = x(1)^2+x(2)^2+2*x(3)^2+x(4)^2-5*x(1)-5*x(2)-21*x(3)+7*x(4);
end
+12 −0
Changes for CF-Projects/project 1/Target1&2/fcnT1SA.m: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
function [ f ] = fcnT1SA( x )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
    c = [x(1)^2+x(2)^2+x(3)^2+x(4)^2+x(1)-x(2)+x(3)-x(4)-8;
         x(1)^2+2*x(2)^2+x(3)^2+2*x(4)^2-x(1)-x(4)-10;
         2*x(1)^2+x(2)^2+x(3)^2+2*x(1)-x(2)-x(4)-5];
     if prod(c<=zeros(3,1))
        f = x(1)^2+x(2)^2+2*x(3)^2+x(4)^2-5*x(1)-5*x(2)-21*x(3)+7*x(4);
     else 
         f =Inf;
     end
end
Loading