-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdisplayAllTruss.m
104 lines (90 loc) · 3.98 KB
/
displayAllTruss.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function displayAllTruss(dirName)
%displayAllTruss Display All Results
%Get File List %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dirData = dir(fullfile(dirName,'*.mat'));
dirIndex = [dirData.isdir];
fileList = {dirData(~dirIndex).name};
%Initialization %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load(fullfile(dirName,fileList{1}));
[func] = feval(strcat(Solution.prob)); % Load Problem
feval(strcat(func,'encode')); % Set Upper and Lower Limit
oldIndi=0;
%Prepare Figure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all
scrsz = get(0,'ScreenSize');
figure('Name','BestFitness','Position',[1 scrsz(4)/2 scrsz(3) scrsz(4)/2]);
figure('Name','History','Position',[1 1 scrsz(3) scrsz(4)/2]);
global PRB; % From Problem
global NOF; % From Truss2Dencode
%Load Statistic from last Result %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
noFile=length(fileList);
load(fullfile(dirName,fileList{noFile}))
set(0,'CurrentFigure',2);
StatAll=Running.stat;
displayStat(noFile,StatAll,'Generations Number',PRB.info.Label)
pause(0.0001);
%Loop Display
for j=1:noFile
%Draw Structure when Result is change
load(fullfile(dirName,fileList{j}));
if ~isequal(oldIndi,Solution.indi)
%Display Detail
set(0,'CurrentFigure',1);
clf(1,'reset');
hold on;
daspect([1 1 1]);
xlim([PRB.dv.xMin PRB.dv.xMax]);
ylim([PRB.dv.yMin PRB.dv.yMax]);
til=sprintf('Best Individual\n');
title(til,'FontWeight','bold');
ylabel('y');
xlabel(sprintf('x\n\nGeneration %d, Fitness %.0f %s\n%s, Population''s size %d',j,Running.stat(j,3),PRB.info.Label,Method.name,Method.NoSolver));
%Transform RAW Data to Truss Structure
[node, member]=feval(strcat(Solution.func,'decode'),Solution.indi);
noMember=length(member(:,1));
noNode=length(node(:,1));
maxA=max(member(:,3));
minA=min(member(:,3));
% switch PRB.dv.TypeSection
% case TypeSection.Discrete
% maxA=max(PRB.dv.crossSection(:,1));
% minA=min(PRB.dv.crossSection(:,1));
% case TypeSection.Continuous
% maxA=PRB.dv.sectionMax;
% minA=PRB.dv.sectionMin;
% end
%Draw Structure
for i=1:noMember
lw=1+4*(member(i,3)-minA)/(maxA-minA);
if minA==maxA
lw=5;
end
plot(node(member(i,1:2),1),node(member(i,1:2),2),'-black','LineWidth',lw);
end
%Draw Node
plot(node(NOF.FixNode:noNode,1),node(NOF.FixNode:noNode,2),'mO','LineWidth',1,'MarkerEdgeColor','b','MarkerFaceColor','Yellow','MarkerSize',7);
%Draw Load
plot(PRB.bc.node(PRB.bc.load(:,1),1),PRB.bc.node(PRB.bc.load(:,1),2),'mV','LineWidth',1,'MarkerEdgeColor','b','MarkerFaceColor','red','MarkerSize',7);
%Draw Support
plot(PRB.bc.node(PRB.bc.fix(:,1),1),PRB.bc.node(PRB.bc.fix(:,1),2),'ms','LineWidth',1,'MarkerEdgeColor','b','MarkerFaceColor','b','MarkerSize',7);
%Draw Maker
set(0,'CurrentFigure',2);
clf;
displayStat(noFile,StatAll,'Generations Number','Weight (kg)')
plot(j,StatAll(j,3),'-h','MarkerEdgeColor','y','MarkerFaceColor','y','MarkerSize',15,'Color','black');
pause(0.1);
oldIndi=Solution.indi;
end
end
end
function displayStat(gen,StatAll,xLabel,yLabel)
cF=[47/255 51/255 59/255]; cP=[255/255 54/255 0/255];
hold on;
plot(1:gen,StatAll(1:gen,1),'-o','LineWidth',1,'MarkerEdgeColor','black','MarkerFaceColor','black','MarkerSize',2,'Color','black');
plot(1:gen,StatAll(1:gen,2),'-v','LineWidth',1,'MarkerEdgeColor',cP,'MarkerFaceColor',cP,'MarkerSize',3,'Color',cP);
plot(1:gen,StatAll(1:gen,3),':x','LineWidth',1,'MarkerEdgeColor',cF,'MarkerFaceColor',cF,'MarkerSize',3,'Color',cF);
legend('Medain','Mode','Min');
xlabel(xLabel);
ylabel(yLabel);
title('Statistic of Population','FontWeight','bold')
end