can you test this gamuiobj on zdt1 test function
%% GAMULTIOBJ test on Smart Building Data
% Script to run GAMULTIOBJ on optimizing user comfort and energy consumption
clc;
clear;
close all;
% Data from UTHM
dataSH=[
1.0000 60.0000 15.5600 711.0000 610.0000
2.0000 65.0000 18.3300 717.0000 670.0000
3.0000 67.0000 19.4400 718.0000 650.0000
4.0000 66.0000 18.8900 717.0000 640.0000
5.0000 67.0000 19.4400 700.0000 600.0000
6.0000 63.0000 17.2200 713.0000 620.0000
7.0000 62.0000 16.6700 724.0000 670.0000
8.0000 81.0000 27.2200 710.0000 920.0000
9.0000 80.0000 26.6700 914.0000 920.0000
10.0000 81.0000 27.2200 900.0000 960.0000
11.0000 83.0000 28.3300 897.0000 900.0000
12.0000 80.0000 26.6700 895.0000 930.0000
13.0000 79.0000 26.1100 904.0000 950.0000
14.0000 82.0000 27.7800 903.0000 960.0000
15.0000 81.0000 27.2200 906.0000 970.0000
16.0000 80.0000 26.6700 898.0000 925.0000
17.0000 66.0000 18.8900 728.0000 610.0000
18.0000 63.0000 17.2200 703.0000 670.0000
19.0000 66.0000 18.8900 714.0000 630.0000
20.0000 66.0000 18.8900 721.0000 645.0000
21.0000 66.0000 18.8900 722.0000 650.0000
22.0000 67.0000 19.4400 703.0000 600.0000
23.0000 66.0000 18.8900 701.0000 670.0000
24.0000 81.0000 27.2200 728.0000 980.0000
25.0000 81.0000 27.2200 891.0000 930.0000
26.0000 82.0000 27.7800 906.0000 948.0000
27.0000 80.0000 26.6700 901.0000 965.0000
28.0000 81.0000 27.2200 901.0000 916.0000
29.0000 79.0000 26.1100 915.0000 900.0000
30.0000 83.0000 28.3300 914.0000 960.0000
31.0000 79.0000 26.1100 890.0000 970.0000
32.0000 81.0000 27.2200 912.0000 930.0000
33.0000 65.0000 18.3300 717.0000 610.0000
34.0000 67.0000 19.4400 714.0000 620.0000
35.0000 65.0000 18.3300 724.0000 670.0000
36.0000 67.0000 19.4400 726.0000 680.0000
37.0000 66.0000 18.8900 723.0000 650.0000
38.0000 64.0000 17.7800 726.0000 660.0000
39.0000 65.0000 18.3300 708.0000 640.0000
40.0000 80.0000 26.6700 712.0000 900.0000
41.0000 83.0000 28.3300 917.0000 910.0000
42.0000 79.0000 26.1100 905.0000 920.0000
43.0000 82.0000 27.7800 893.0000 980.0000
44.0000 80.0000 26.6700 920.0000 940.0000
45.0000 81.0000 27.2200 913.0000 950.0000
46.0000 81.0000 27.2200 905.0000 940.0000
47.0000 82.0000 27.7800 896.0000 970.0000
48.0000 80.0000 26.6700 898.0000 980.0000];
% Problem parameters
NPop = 300; % Population size
T = 300; % Number of iterations
dim = 48 * 3; % 3 decision variables (Temp, Lux, IAQ) for each of the 48 time instances
% Define the lower and upper bounds
lb = [20 720 700]; % Lower bounds for Temp(C), Lux, IAQ
ub = [25.56 880 880]; % Upper bounds for Temp(C), Lux, IAQ
% Expand the bounds for all time instances (48 rows of data)
lb = repmat(lb, 1, 48); % Repeat the bounds for each time instance
ub = repmat(ub, 1, 48);
% Objective function for GAMULTIOBJ
objectiveFunction = @(X) cost_function(dataSH, X, lb, ub);
% Options for GAMULTIOBJ
options = optimoptions('gamultiobj', 'PopulationSize', NPop, 'MaxGenerations', T, ...
'Display', 'iter', 'PlotFcn', {@gaplotpareto, @gaplotscorediversity});
% Run GAMULTIOBJ
[x, fval] = gamultiobj(objectiveFunction, dim, [], [], [], [], lb, ub, options);
% Extract the best solution
Best_Optim = reshape(x(1,:), 3, 48)'; % Reshape to get Temp, Lux, IAQ for each time instance
% Plot the results
figure();
set(gcf, 'Color', 'w');
plot(fval(:, 1), '-b', 'LineWidth', 2);
xlabel('Iteration');
ylabel('Fitness');
% Fitness Over Iterations:
figure();
set(gcf, 'Color', 'w');
plot(fval(:, 1), '-b', 'LineWidth', 2);
xlabel('Iteration');
ylabel('Fitness');
title('Fitness Value Over Iterations');
% Temperature plot
figure();
set(gcf, 'Color', 'w');
Tc = dataSH(:, 3); % Current temperature
To = Best_Optim(:, 1); % Optimized temperature
Ts = ones(1, 48) .* 22.78; % User set temperature
plot(Ts, 'g', 'LineWidth', 2); hold on;
plot(Tc, '-b', 'LineWidth', 2); hold on;
plot(To, '-r', 'LineWidth', 2);
xlabel('Time (Hour)');
ylabel('Temperature (ºC)');
legend({'User Set', 'Environment', 'Optimized by GAMULTIOBJ'});
grid on;
% Illumination plot
figure();
set(gcf, 'Color', 'w');
Lc = dataSH(:, 4); % Current illumination
Lo = Best_Optim(:, 2); % Optimized illumination
Ls = ones(1, 48) .* 800; % User set illumination
plot(Ls, 'g', 'LineWidth', 2); hold on;
plot(Lc, '-b', 'LineWidth', 2); hold on;
plot(Lo, '-r', 'LineWidth', 2);
xlabel('Time (Hour)');
ylabel('Illumination (lux)');
legend({'User Set', 'Environment', 'Optimized by GAMULTIOBJ'});
title('Illumination parameter');
grid on;
% Air Quality plot
figure();
set(gcf, 'Color', 'w');
Ac = dataSH(:, 5); % Current air quality
Ao = Best_Optim(:, 3); % Optimized air quality
As = ones(1, 48) .* 800; % User set air quality
plot(As, 'g', 'LineWidth', 2); hold on;
plot(Ac, '-b', 'LineWidth', 2); hold on;
plot(Ao, '-r', 'LineWidth', 2);
xlabel('Time (Hour)');
ylabel('Air Quality (iAQ)');
legend({'User Set', 'Environment', 'Optimized by GAMULTIOBJ'});
title('Air Quality parameter');
grid on;
% Plot Pareto front after optimization
figure();
set(gcf, 'Color', 'w'); % Set white background for the plot
plot(fval(:, 1), fval(:, 2), 'ro', 'LineWidth', 2); % Plot the Pareto front
xlabel('Objective 1 (Comfort)'); % Label for first objective
ylabel('Objective 2 (Energy Consumption)'); % Label for second objective
title('Pareto Front - Comfort vs Energy Consumption'); % Plot title
grid on; % Add grid to the plot
legend('Non-dominated solutions'); % Add legend to indicate the Pareto front solutions
% Sort Pareto front by the first column (Objective 1)
fval = sortrows(fval, 1);
% Plot Pareto front after optimization
figure();
set(gcf, 'Color', 'w'); % Set white background for the plot
plot(fval(:, 1), fval(:, 2), 'r-o', 'LineWidth', 2); % Plot the Pareto front with line and markers
xlabel('Objective 1 (Comfort)'); % Label for first objective
ylabel('Objective 2 (Energy Consumption)'); % Label for second objective
title('Pareto Front - Comfort vs Energy Consumption (lined)'); % Plot title
grid on; % Add grid to the plot
legend('Non-dominated solutions'); % Add legend to indicate the Pareto front solutions
% Cost Function for MOEMA
function obj = cost_function(dataSH, X, lb, ub)
% Constants for comfort
ideal_temp = 22; % Ideal temperature in Celsius
ideal_lux = 500; % Ideal illumination level
ideal_iaq = 500; % Ideal IAQ level
% Weights for comfort
w_temp = 0.5;
w_lux = 0.3;
w_iaq = 0.2;
% Extract temperature, lux, and IAQ values from X
Temp = X(1:3:end); % Temperature values
Lux = X(2:3:end); % Lux values
IAQ = X(3:3:end); % IAQ values
% Calculate comfort index
temp_comfort = sum(exp(-(Temp - ideal_temp).^2 / 10));
lux_comfort = sum(exp(-(Lux - ideal_lux).^2 / 10000));
iaq_comfort = sum(exp(-(IAQ - ideal_iaq).^2 / 10000));
comfort_index = w_temp * temp_comfort + w_lux * lux_comfort + w_iaq * iaq_comfort;
% Energy consumption calculation (simplified models)
hvac_energy = sum(abs(Temp - dataSH(:, 3)').^1.5);
lighting_energy = sum(Lux) / 1000;
iaq_energy = sum(IAQ) / 100;
% Total energy consumption
energy_consumption = hvac_energy + lighting_energy + iaq_energy;
% Normalize objectives
max_comfort = 48 * (w_temp + w_lux + w_iaq); % Maximum possible comfort
max_energy = sum(abs(ub(1:3:end) - dataSH(:, 3)').^1.5) + sum(ub(2:3:end)) / 1000 + sum(ub(3:3:end)) / 100; % Maximum possible energy consumption
comfortIndex = 1 - (comfort_index / max_comfort); % Higher values are better for comfort
energyConsumption = energy_consumption / max_energy; % Lower values are better for energy consumption
% Return objectives as [Comfort Index, Energy Consumption]
obj = [comfortIndex, energyConsumption];
end