From bb003f9cb9ae315690c453c758a16fcfe138da25 Mon Sep 17 00:00:00 2001 From: Americo Cunha <36556019+americocunhajr@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:08:38 -0300 Subject: [PATCH] Add files via upload --- ..._Truss10_MassMin_FrequencyBounds_BoxPlot.m | 50 ++++++---- ...Main_Truss10_MassMin_YieldStress_BoxPlot.m | 51 ++++++---- ..._Truss37_MassMin_FrequencyBounds_BoxPlot.m | 50 ++++++---- CROSS-OPT-1.0/PlotBoxComparison.m | 99 +++++++++++++++++++ 4 files changed, 199 insertions(+), 51 deletions(-) create mode 100644 CROSS-OPT-1.0/PlotBoxComparison.m diff --git a/CROSS-OPT-1.0/Main_Truss10_MassMin_FrequencyBounds_BoxPlot.m b/CROSS-OPT-1.0/Main_Truss10_MassMin_FrequencyBounds_BoxPlot.m index 7416f9a..b465459 100644 --- a/CROSS-OPT-1.0/Main_Truss10_MassMin_FrequencyBounds_BoxPlot.m +++ b/CROSS-OPT-1.0/Main_Truss10_MassMin_FrequencyBounds_BoxPlot.m @@ -222,21 +222,37 @@ disp(' ------------------- ') disp(' ') -figure -x = [Fopt_SQP Fopt_GA Fopt_CE]; -boxplot(x,'Notch','off','Labels',{'SQP','GA','CE'}); -ylabel('Truss Mass (kg)','FontSize',20,'FontName', 'Helvetica') -title("Number samples: " + Nbp, 'FontSize',20,'FontName', 'Helvetica') -set(gca, 'FontName', 'Helvetica'); -set(gca, 'FontSize', 18); -box on - -figure -x = [Fcount_SQP Fcount_GA Fcount_CE]; -boxplot(x,'Notch','off','Labels',{'SQP','GA','CE'}); -ylabel('Function Evaluations','FontSize',20,'FontName', 'Helvetica') -title("Number samples: " + Nbp, 'FontSize',20,'FontName', 'Helvetica') -set(gca, 'FontName', 'Helvetica'); -set(gca, 'FontSize', 18); -box on +% .......................................................... +graphobj1.gname = 'Truss10_MassMin_FrequencyBounds_BoxPlot_Fopt'; +graphobj1.gtitle = 'Objetive Function'; +graphobj1.xmin = 'auto'; +graphobj1.xmax = 'auto'; +graphobj1.ymin = 'auto'; +graphobj1.ymax = 'auto'; +graphobj1.xlab = []; +graphobj1.ylab = 'Truss Mass (kg)'; +graphobj1.leg1 = 'CE'; +graphobj1.leg2 = 'GA'; +graphobj1.leg3 = 'SQP'; +graphobj1.print = 'yes'; +graphobj1.close = 'no'; +Fig1 = PlotBoxComparison(Fopt_CE,Fopt_GA,Fopt_SQP,graphobj1); +% .......................................................... + +% .......................................................... +graphobj2.gname = 'Truss10_MassMin_FrequencyBounds_BoxPlot_Fcount'; +graphobj2.gtitle = 'Computational Cost'; +graphobj2.xmin = 'auto'; +graphobj2.xmax = 'auto'; +graphobj2.ymin = 'auto'; +graphobj2.ymax = 'auto'; +graphobj2.xlab = []; +graphobj2.ylab = 'Function Evaluations'; +graphobj2.leg1 = 'CE'; +graphobj2.leg2 = 'GA'; +graphobj2.leg3 = 'SQP'; +graphobj2.print = 'yes'; +graphobj2.close = 'no'; +Fig2 = PlotBoxComparison(Fcount_CE,Fcount_GA,Fcount_SQP,graphobj2); +% .......................................................... % ------------------------------------------------------------------ diff --git a/CROSS-OPT-1.0/Main_Truss10_MassMin_YieldStress_BoxPlot.m b/CROSS-OPT-1.0/Main_Truss10_MassMin_YieldStress_BoxPlot.m index a4cd855..161b0d8 100644 --- a/CROSS-OPT-1.0/Main_Truss10_MassMin_YieldStress_BoxPlot.m +++ b/CROSS-OPT-1.0/Main_Truss10_MassMin_YieldStress_BoxPlot.m @@ -230,21 +230,38 @@ disp(' ------------------- ') disp(' ') -figure -x = [Fopt_SQP Fopt_GA Fopt_CE]; -boxplot(x,'Notch','off','Labels',{'SQP','GA','CE'}); -ylabel('Truss Mass (kg)','FontSize',20,'FontName', 'Helvetica') -title("Number samples: " + Nbp, 'FontSize',20,'FontName', 'Helvetica') -set(gca, 'FontName', 'Helvetica'); -set(gca, 'FontSize', 18); -box on - -figure -x = [Fcount_SQP Fcount_GA Fcount_CE]; -boxplot(x,'Notch','off','Labels',{'SQP','GA','CE'}); -ylabel('Function Evaluations','FontSize',20,'FontName', 'Helvetica') -title("Number samples: " + Nbp, 'FontSize',20,'FontName', 'Helvetica') -set(gca, 'FontName', 'Helvetica'); -set(gca, 'FontSize', 18); -box on +% .......................................................... +graphobj1.gname = 'Truss10_MassMin_YieldStress_BoxPlot_Fopt'; +graphobj1.gtitle = 'Objetive Function'; +graphobj1.xmin = 'auto'; +graphobj1.xmax = 'auto'; +graphobj1.ymin = 'auto'; +graphobj1.ymax = 'auto'; +graphobj1.xlab = []; +graphobj1.ylab = 'Truss Mass (kg)'; +graphobj1.leg1 = 'CE'; +graphobj1.leg2 = 'GA'; +graphobj1.leg3 = 'SQP'; +graphobj1.print = 'yes'; +graphobj1.close = 'no'; +Fig1 = PlotBoxComparison(Fopt_CE,Fopt_GA,Fopt_SQP,graphobj1); +% .......................................................... + +% .......................................................... +graphobj2.gname = 'Truss10_MassMin_YieldStress_BoxPlot_Fcount'; +graphobj2.gtitle = 'Computational Cost'; +graphobj2.xmin = 'auto'; +graphobj2.xmax = 'auto'; +graphobj2.ymin = 'auto'; +graphobj2.ymax = 'auto'; +graphobj2.xlab = []; +graphobj2.ylab = 'Function Evaluations'; +graphobj2.leg1 = 'CE'; +graphobj2.leg2 = 'GA'; +graphobj2.leg3 = 'SQP'; +graphobj2.print = 'yes'; +graphobj2.close = 'no'; +Fig2 = PlotBoxComparison(Fcount_CE,Fcount_GA,Fcount_SQP,graphobj2); +% .......................................................... + % ------------------------------------------------------------------ diff --git a/CROSS-OPT-1.0/Main_Truss37_MassMin_FrequencyBounds_BoxPlot.m b/CROSS-OPT-1.0/Main_Truss37_MassMin_FrequencyBounds_BoxPlot.m index 53b2b91..0b6e76c 100644 --- a/CROSS-OPT-1.0/Main_Truss37_MassMin_FrequencyBounds_BoxPlot.m +++ b/CROSS-OPT-1.0/Main_Truss37_MassMin_FrequencyBounds_BoxPlot.m @@ -281,21 +281,37 @@ disp(' ------------------- ') disp(' ') -figure -x = [Fopt_SQP Fopt_GA Fopt_CE]; -boxplot(x,'Notch','off','Labels',{'SQP','GA','CE'}); -ylabel('Truss Mass (kg)','FontSize',20,'FontName', 'Helvetica') -title("Number samples: " + Nbp, 'FontSize',20,'FontName', 'Helvetica') -set(gca, 'FontName', 'Helvetica'); -set(gca, 'FontSize', 18); -box on - -figure -x = [Fcount_SQP Fcount_GA Fcount_CE]; -boxplot(x,'Notch','off','Labels',{'SQP','GA','CE'}); -ylabel('Function Evaluations','FontSize',20,'FontName', 'Helvetica') -title("Number samples: " + Nbp, 'FontSize',20,'FontName', 'Helvetica') -set(gca, 'FontName', 'Helvetica'); -set(gca, 'FontSize', 18); -box on +% .......................................................... +graphobj1.gname = 'Truss37_MassMin_FrequencyBounds_BoxPlot_Fopt'; +graphobj1.gtitle = 'Objetive Function'; +graphobj1.xmin = 'auto'; +graphobj1.xmax = 'auto'; +graphobj1.ymin = 'auto'; +graphobj1.ymax = 'auto'; +graphobj1.xlab = []; +graphobj1.ylab = 'Truss Mass (kg)'; +graphobj1.leg1 = 'CE'; +graphobj1.leg2 = 'GA'; +graphobj1.leg3 = 'SQP'; +graphobj1.print = 'yes'; +graphobj1.close = 'no'; +Fig1 = PlotBoxComparison(Fopt_CE,Fopt_GA,Fopt_SQP,graphobj1); +% .......................................................... + +% .......................................................... +graphobj2.gname = 'Truss37_MassMin_FrequencyBounds_BoxPlot_Fcount'; +graphobj2.gtitle = 'Computational Cost'; +graphobj2.xmin = 'auto'; +graphobj2.xmax = 'auto'; +graphobj2.ymin = 'auto'; +graphobj2.ymax = 'auto'; +graphobj2.xlab = []; +graphobj2.ylab = 'Function Evaluations'; +graphobj2.leg1 = 'CE'; +graphobj2.leg2 = 'GA'; +graphobj2.leg3 = 'SQP'; +graphobj2.print = 'yes'; +graphobj2.close = 'no'; +Fig2 = PlotBoxComparison(Fcount_CE,Fcount_GA,Fcount_SQP,graphobj2); +% .......................................................... % ------------------------------------------------------------------ diff --git a/CROSS-OPT-1.0/PlotBoxComparison.m b/CROSS-OPT-1.0/PlotBoxComparison.m new file mode 100644 index 0000000..683d69c --- /dev/null +++ b/CROSS-OPT-1.0/PlotBoxComparison.m @@ -0,0 +1,99 @@ +% ----------------------------------------------------------------- +% PlotBoxComparison.m +% ----------------------------------------------------------------- +% programmers: Marcos Vinicius Issa +% Anderson Pereira +% Americo Cunha Jr +% +% Originally programmed in: Sep 18, 2024 +% Last updated in: Sep 18, 2024 +% ----------------------------------------------------------------- +% This function plots a boxplot comparison of truss mass results +% from different optimization methods. +% +% Input: +% x1 - results series 1 +% x2 - results series 2 +% x3 - results series 3 +% graphobj - struct containing graph configuration parameters +% +% Output: +% fig - handle to the created figure +% ----------------------------------------------------------------- + +function fig = PlotBoxComparison(x1,x2,x3,graphobj) + + % Check number of arguments + if nargin < 4 + error('Too few inputs.'); + elseif nargin > 4 + error('Too many inputs.'); + end + + % Ensure all input vectors are row vectors + if ~iscolumn(x1) + x1 = x1'; + end + if ~iscolumn(x2) + x2 = x2'; + end + if ~iscolumn(x3) + x3 = x3'; + end + + % Prepare the data for the boxplot + x = [x1 x2 x3]; + + % Create figure + fig = figure('Name', graphobj.gname, 'NumberTitle', 'off'); + + % Create the boxplot + boxplot(x,'Notch','off',... + 'Labels',{graphobj.leg1,graphobj.leg2,graphobj.leg3}); + + % Set font and box + set(gcf,'color','white'); + set(gca,'position',[0.2 0.2 0.7 0.7]); + set(gca,'Box','on'); + set(gca,'TickDir','out','TickLength',[.02 .02]); + set(gca,'XMinorTick','off','YMinorTick','off'); + set(gca,'XGrid','off','YGrid','off'); + set(gca,'XColor',[.3 .3 .3],'YColor',[.3 .3 .3]); + set(gca,'FontName','Helvetica'); + set(gca,'FontSize',18); + box on; + %grid on; + + % Set axis limits + if ( strcmp(graphobj.xmin,'auto') || strcmp(graphobj.xmax,'auto') ) + xlim('auto'); + else + xlim([graphobj.xmin graphobj.xmax]); + end + + if ( strcmp(graphobj.ymin,'auto') || strcmp(graphobj.ymax,'auto') ) + ylim('auto'); + else + ylim([graphobj.ymin graphobj.ymax]); + end + + % Set labels + xlabel(graphobj.xlab, 'FontSize', 20, 'FontName', 'Helvetica'); + ylabel(graphobj.ylab, 'FontSize', 20, 'FontName', 'Helvetica'); + + % Set the title + title(graphobj.gtitle, 'FontSize', 24, 'FontName', 'Helvetica'); + + % Save the plot if required + if strcmp(graphobj.print, 'yes') + print('-depsc2', [graphobj.gname, '.eps']); + print('-dpng', [graphobj.gname, '.png']); + end + + % Close the figure if requested + if strcmp(graphobj.close, 'yes') + close(fig); + end + +end +% ----------------------------------------------------------------- \ No newline at end of file