Project: Report added

This commit is contained in:
2025-02-07 23:15:29 +02:00
parent 50c87f9d6a
commit 79fd37b1c3
17 changed files with 335 additions and 98 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

@@ -20,25 +20,29 @@ normalizeSum = @(x, S) (x ./ sum(x)) * S; % Ensure sum of single row x equa
normalizeSum2 = @(x, S) (x ./ sum(x, 2)) * S; % Ensure sum of each row of 2D matrix x equals S
% Genetic Algorithm Parameters
popSize = 100; % Population size
popSize = 36; % Population size
maxGen = 2000; % Maximum number of generations
mutationRate = 0.05; % Mutation probability
mutationRate = 0.1; % Mutation probability
% Initialize Population
pop = rand(popSize, N) .* c; % Random initial solutions (0 <= x <= c)
pop = normalizeSum2(pop, V); % Ensure sum of each solution equals V
newPop = zeros(popSize, N); % Pre-allocate new population buffer
bestFitness = zeros(maxGen, 1); % Result array
% Genetic Algorithm Execution
for gen = 1:maxGen
% Fitness Calculation
fitness = arrayfun(@(i) fitnessFunction(pop(i, :), t, a, c, V, travelTime), 1:popSize);
% Selection
[~, idx] = sort(fitness); % Sort based on fitness (ascending order)
pop = pop(idx, :); % Retain the best solutions
% Keep the best chromosome
bestFitness(gen) = fitnessFunction(pop(1, :), t, a, c, V, travelTime);
% Crossover
newPop(1:popSize/2, :) = pop(1:popSize/2, :); % Retain top half
for i = 1:popSize/2
@@ -63,14 +67,24 @@ for gen = 1:maxGen
pop = newPop;
end
% Final Solution
bestSolution = pop(1, :);
bestFitness = fitnessFunction(bestSolution, t, a, c, V, travelTime);
% Results
bestSolution = pop(1, :);
disp('Best Solution [veh/min]:');
disp(bestSolution);
disp(['Best Objective Value: ', num2str(bestFitness), ' [min]']);
disp(['Best Objective Value: ', num2str(bestFitness(end)), ' [min]']);
figure('Name', 'Time over generations', 'NumberTitle', 'off');
set(gcf, 'Position', [100, 100, 960, 640]); % Set the figure size
plot(1:maxGen, bestFitness, '-b', 'LineWidth', 1);
% Customize the plot
title(['Population = ', num2str(popSize), ' - Mutation = ', num2str(mutationRate)], 'Interpreter', 'latex', 'FontSize', 16); % Title of the plot
xlabel('Generations') ;
ylabel('T_{total}');
% save the figure
print(gcf, ['figures/constV_pop_', num2str(popSize), 'mut_', num2str(mutationRate), '.png'], '-dpng', '-r300');
% Fitness Function
function T_total = fitnessFunction(x, t, a, c, V, travelTime)