Pārlūkot izejas kodu

Project: First version of the code and report stub

tags/v4.0
Christos Choutouridis pirms 2 nedēļām
vecāks
revīzija
50c87f9d6a
4 mainītis faili ar 174 papildinājumiem un 0 dzēšanām
  1. Binārs
      Project/Project 2024.pdf
  2. Binārs
      Project/report/report.pdf
  3. +90
    -0
      Project/report/report.tex
  4. +84
    -0
      Project/scripts/main.m

Binārs
Project/Project 2024.pdf Parādīt failu


Binārs
Project/report/report.pdf Parādīt failu


+ 90
- 0
Project/report/report.tex Parādīt failu

@@ -0,0 +1,90 @@
% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode
% !TEX spellcheck = el-GR
%
% Optimization techniques project report
%
% Requires compilation with pdfLaTeX or XeLaTeX
%
% authors:
% Χρήστος Χουτουρίδης ΑΕΜ 8997
% cchoutou@ece.auth.gr

%
% Options:
%
% 1) mainlang=<language>
% Default: english
% Set the default language of the document which affects hyphenations,
% localization (section, dates, etc...)
%
% example: \documentclass[mainlang=greek]{AUThReport}
%
% 2) <language>
% Add hyphenation and typesetting support for other languages
% Currently supports: english, greek, german, frenc
%
% example: \documentclass[english, greek]{AUThReport}
%
% 3) short: Requests a shorter title for the document
% Default: no short
%
% example: \documentclass[short]{AUThReport}
%
\documentclass[a4paper, 11pt, mainlang=greek, english]{AUThReport}

\CurrentDate{\today}

% Document setup
%---------------------------------

% \WorkGroup{Ομάδα Χ}

\AuthorName{Χρήστος Χουτουρίδης}
\AuthorMail{cchoutou@ece.auth.gr}
\AuthorAEM{8997}

%\CoAuthorName{Όνομα Επίθετο}
%\CoAuthorAEM{AEM}
%\CoAuthorMail{xxx@ece.auth.gr}

\DocTitle{Project: Γενετικοί αλγόριθμοι}
\DocSubTitle{Ελαχιστοποίηση συνάρτησης πολλών μεταβλητών}

\Department{Τμήμα ΗΜΜΥ. Τομέας Ηλεκτρονικής}
\ClassName{Τεχνικές Βελτιστοποίησης}
%
\InstructorName{Γ. Ροβιθάκης}
\InstructorMail{rovithak@auth.gr}

\CoInstructorName{Θ. Αφορόζη}
\CoInstructorMail{taforozi@ece.auth.gr}


% Local package requirements
%---------------------------------

\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{array}
\usepackage{multirow}
\usepackage{float}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{amsmath}
\usepackage{footnote}
\usepackage{footmisc}


\begin{document}

\InsertTitle

%\tableofcontents


\section{Εισαγωγή}

Η παρούσα εργασία αφορά ...

\end{document}

+ 84
- 0
Project/scripts/main.m Parādīt failu

@@ -0,0 +1,84 @@
% Genetic Algorithm for Minimizing Network Traversal Time

clc;
clear;
close all;

% Problem Parameters
N = 17; % Number of roads
t = 1.5 * ones(1, N); % Fixed time for each road
a = [1.25 * ones(1, 5), 1.5 * ones(1, 5), ones(1, 7)]; % Weighting factor
c = [
54.13, 21.56, 34.08, 49.19, 33.03, 21.84, 29.96, 24.87, 47.24, 33.97, ...
26.89, 32.76, 39.98, 37.12, 53.83, 61.65, 59.73]; % Road capacities
V = 100; % Incoming vehicle rate

% Travel Time Function
travelTime = @(xi, ti, ai, ci) ti + ai * xi / (1 - xi / ci);
% Normalization Function (Infinite norm normalized to S)
normalizeSum = @(x, S) (x ./ sum(x)) * S; % Ensure sum of single row x equals S
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
maxGen = 2000; % Maximum number of generations
mutationRate = 0.05; % 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

% 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
% Crossover
newPop(1:popSize/2, :) = pop(1:popSize/2, :); % Retain top half
for i = 1:popSize/2
parent1 = newPop(randi(popSize/2), :);
parent2 = newPop(randi(popSize/2), :);
crossPoint = randi(N);
child = [parent1(1:crossPoint), parent2(crossPoint+1:end)];
child = normalizeSum(child, V);
newPop(popSize/2 + i, :) = child;
end
% Mutation
for i = 1:popSize
if rand < mutationRate
mutationIdx = randi(N);
newPop(i, mutationIdx) = rand * c(mutationIdx);
newPop(i, :) = normalizeSum(newPop(i, :), V);
end
end
% Replacement
pop = newPop;
end

% Final Solution
bestSolution = pop(1, :);
bestFitness = fitnessFunction(bestSolution, t, a, c, V, travelTime);

% Results
disp('Best Solution [veh/min]:');
disp(bestSolution);
disp(['Best Objective Value: ', num2str(bestFitness), ' [min]']);

% Fitness Function
function T_total = fitnessFunction(x, t, a, c, V, travelTime)
if abs(sum(x) - V) > 1e-6 || any(x < 0) || any(x > c)
T_total = inf; % Infeasible solutions
return;
end
T = arrayfun(@(xi, ti, ai, ci) travelTime(xi, ti, ai, ci), x, t, a, c); % Apply function to all elements
T_total = sum(T .* x); % Total traversal time
end

Notiek ielāde…
Atcelt
Saglabāt