%!TEX root =  ../main.tex
\subsection{Growth}

\objective{Model and predict year-over-year percentile growth}

In linear equations, everything is relative to the number 0.  Have a derivative or slope
of 0 constitutes a flat line.  Numbers greater than 0 are called positive slope, while
numbers less than it are called negative slope.  If the initial value is not 0, then it is
added to the equation, unlike the slope, which is multiplied against the independent
variable.

Everything about exponential equations is moved to the next level of operators.  We saw
back in §1.4 that the standard form of an exponential equation is $y=a\cdot{}b^x$.
All such equations begin at the point $(0,a)$, because plugging in 0 yields $b^0$
and regardless of what $b$ is, anything to the zero power is 1.  Multiplying by $a$
therefore changes our initial value.  And because powers are simply repeated multiplication,
have $b$ as a base means the equation multiplies by $b$ every unit step of $x$.

What if $b=1$?  No matter what exponent we put on 1, it will remain 1.  If $b>1$,
then every increment of $x$ will grow the output.  If $b<1$, then every increment
of $x$ will reduce the output.  Because exponential equations are build off of
multiplication --- not addition --- everything is relative to 1, not 0.

Hopefully, you are very familiar with percentages, and how even the word comes
from the Latin \textit{``out of one hundred''}.  This give us the clue to convert
percentages to decimals: divide by 100.  So if a mathematical model verbally says a
system is growing at 5\%, means that any given year, the value is 105\% of the
value from the year before.  This means $b$ in our equation is $1.05$.  Were we
to use a $b$ of $0.05$, that would be a 95\% loss year-over-year!

\subsubsection{TI-8*}
The TI-8* is a very useful tool for modeling exponential growth.  In many
real-life situations, everything takes place in QI, but the $y$-scale often
varies greatly from problem to problem.  For example, what is a good
window for the following problem?  A house was purchases for \$500,000
and appreciates 3.2\% per year.  What is its future value in 5, 10, and 30
years?  When will it exceed 2 million dollars?

Because this is a strictly increasing function, the value at the beginning will be
the lowest.  This means our Xmin and Ymin should be 0 and 500000 respectively.
We know we need to see at least to the year 30, so our Xmax must be at least that,
and our Ymax must be at least 2000000.  These turn out to be overly conservative
estimates, but they help us see how to guess.  The TABLE is also very useful in
setting up windows.

\subsection{Compound Interest}
In most banking institutions, money moves hands and changes more often than once
a year, so interest is compounds (or calculated) more often.  If you are making
five percent per annum, but the bank compounds monthly, that does not mean you
make 5\% twelve times a year!   Instead, they give you a twelfth of 5\% twelve times
per year.  This makes our equation more complicated:

$$
A = P\left(1+\frac{r}{n}\right)^{n\cdot{}t}
$$

$A$ is the amount at the end of the term, $P$ is the principle which the investment began
at (the initial amout of money), $r$ is the interest rate, $n$ is the number of times per year
it is compounded, and $t$ is the number of years the investment is left in.  If banks think
in terms of periods (be they month, quarters, years, etc.) then the exponent is the number
of periods the money is left in.

\subsection{Doubling Time}
How can we build an equation when we don't know the rate of growth, except as a time?
For example, suppose your grandfather noticed that movie theater prices have doubled
every eight years.  When he was a kid, it was a quarter!  One way would be to generate
numerical data and run a regression on them.  Let $x$ be years since your grandfather
was a kid.  You know $a$ is 0.25, a quarter dollar.  So far, we have $y=\frac{1}{4}b^x$.
We know every eight years, the price has doubled, so that makes points (8,0.5) ; (16,1)
; (24,2), etc.  The TI-8*'s EXPREG yields $y=0.25(1.090507733)^x$.

Another way might be to recognize that we want to be multiplying by 2 every time (since
we are talking about doubling) but that only every 8 years should it happen.
$y=\frac{1}{4}2^x$ would double every day, so dilate the function to be 8 times wider:
$y=\frac{1}{4}2^\frac{x}{12}$.  This shows us that the same exponential function
can have multiple (in fact, infinite number of) representations.

\paragraph{e}
We will not explain its origin until next chapter, but you should know that many (if not most)
exponential equations involve the number $e$.  Like $\pi$, it is around 3, only $e$ is a little less,
not a little more.  You can find $e$ on your TI-8* as 2ND $\div$, or the more useful $e^x$
as 2ND-LN.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2003-2018 by The University of Queensland
% http://www.uq.edu.au
%
% Primary Business: Queensland, Australia
% Licensed under the Apache License, version 2.0
% http://www.apache.org/licenses/LICENSE-2.0
%
% Development until 2012 by Earth Systems Science Computational Center (ESSCC)
% Development 2012-2013 by School of Earth Sciences
% Development from 2014 by Centre for Geoscience Computing (GeoComp)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Elastic Deformation}
\label{ELASTIC CHAP}
In this section we want to examine the deformation of a linear elastic body caused by expansion through a heat distribution.
We want a displacement field $u_{i}$ which solves the momentum
equation\index{momentum equation}:
\begin{eqnarray}\label{HEATEDBLOCK general problem}
 - \sigma_{ij,j}=0
\end{eqnarray}
where the stress $\sigma$ is given by
\begin{eqnarray}\label{HEATEDBLOCK linear elastic}
 \sigma_{ij}= \lambda u_{k,k} \delta_{ij} + \mu ( u_{i,j} + u_{j,i})
 - (\lambda+\frac{2}{3} \mu)  \; \alpha  \;  (T-T_{ref})\delta_{ij} \;.
\end{eqnarray}
In this formula $\lambda$ and $\mu$ are the Lam\'e coefficients, $\alpha$ is the
temperature expansion coefficient, $T$ is the temperature distribution and $T_{ref}$ a reference temperature.
Note that \eqn{HEATEDBLOCK general problem} is similar to \eqn{WAVE general problem}
introduced in \Sec{WAVE CHAP} but the inertia term $\rho u_{i,tt}$
has been dropped as we assume a static scenario here.
Moreover, in comparison to the \eqn{WAVE stress} definition of stress $\sigma$
in \eqn{HEATEDBLOCK linear elastic} an extra term is introduced to bring in
stress due to volume changes through temperature dependent expansion.

Our domain is the unit cube
\begin{eqnarray} \label{HEATEDBLOCK natural location}
\Omega=\{(x_{i}) | 0 \le x_{i} \le 1 \}
\end{eqnarray}
On the boundary the normal stress component is set to zero
\begin{eqnarray} \label{HEATEDBLOCK natural}
\sigma_{ij}n_{j}=0
\end{eqnarray}
and on the face with $x_{i}=0$ we set the $i$-th component of the displacement to $0$:
\begin{eqnarray} \label{HEATEDBLOCK constraint}
u_{i}(x)=0 & \mbox{ where } & x_{i}=0 \;
\end{eqnarray}
For the temperature distribution we use
\begin{eqnarray} \label{HEATEDBLOCK temperature}
T(x)= T_{0} e^{-\beta \|x-x^{c}\|}
\end{eqnarray}
with a given positive constant $\beta$ and location $x^{c}$ in the domain.

%Later in \Sec{MODELFRAME} we will use
% $T$ from a time-dependent temperature diffusion problem as discussed in \Sec{DIFFUSION CHAP}.
When we insert \eqn{HEATEDBLOCK linear elastic} we get a second order system
of linear PDEs for the displacements $u$ which is called the Lam\'e equation\index{Lam\'e equation}.
We want to solve this using the \LinearPDE class.
For a system of PDEs and a solution with several components the \LinearPDE class takes PDEs of the form
\begin{equation}\label{LINEARPDE.SYSTEM.1 TUTORIAL}
-(A_{ijkl} u_{k,l})_{,j}=-X_{ij,j} \; .
\end{equation}
$A$ is a \RankFour and $X$ is a \RankTwo.
We show here the coefficients relevant for the problem we are trying to solve.
The full form is given in \eqn{LINEARPDE.SYSTEM.1}.
The natural boundary conditions\index{boundary condition!natural} take the form
\begin{equation}\label{LINEARPDE.SYSTEM.2 TUTORIAL}
n_{j} A_{ijkl} u_{k,l}=n_{j}X_{ij}
\end{equation}
while constraints\index{constraint} take the form
\begin{equation}\label{LINEARPDE.SYSTEM.3 TUTORIAL}
u_{i}=r_{i} \mbox{ where } q_{i}>0
\end{equation}
$r$ and $q$ are each a \RankOne.
We can easily identify the coefficients in \eqn{LINEARPDE.SYSTEM.1 TUTORIAL}:
\begin{eqnarray}\label{LINEARPDE ELASTIC COEFFICIENTS}
A_{ijkl}=\lambda \delta_{ij} \delta_{kl} + \mu (
\delta_{ik} \delta_{jl}
+ \delta_{il} \delta_{jk}) \\
X_{ij}=(\lambda+\frac{2}{3} \mu) \;  \alpha \; (T-T_{ref})\delta_{ij} \\
\end{eqnarray}
The characteristic function $q$ defining the locations and components where constraints are set is given by:
\begin{equation}\label{HEATEDBLOCK MASK}
q_{i}(x)=\left\{
\begin{array}{cl}
1 & x_{i}=0\\
0 & \mbox{otherwise.}\\
\end{array}
\right.
\end{equation}
Under the assumption that $\lambda$, $\mu$, $\beta$ and $T_{ref}$
are constant we may use $Y_{i}=(\lambda+\frac{2}{3} \mu) \; \alpha \; T_{i}$.
However, this choice would lead to a different natural boundary condition
which does not set the normal stress component as defined in \eqn{HEATEDBLOCK linear elastic} to zero.

Analogous to the concept of symmetry for a single PDE, we call the PDE
defined by \eqn{LINEARPDE.SYSTEM.1 TUTORIAL} symmetric\index{symmetric PDE} if
\begin{eqnarray}\label{LINEARPDE.SYSTEM.SYMMETRY TUTORIAL}
A_{ijkl} =A_{klij} \\
\end{eqnarray}
This Lam\'e equation is in fact symmetric, given the difference in $D$ and $d$ as compared to the scalar case.
The \LinearPDE class is notified of this fact by calling its \method{setSymmetryOn} method.

After we have solved the Lam\'e equation we want to analyse the actual stress distribution.
Typically the \emph{von-Mises} stress\index{von-Mises stress} defined by
\begin{equation}
\sigma_{mises} = \sqrt{
\frac{1}{2} ((\sigma_{00}-\sigma_{11})^2
            + (\sigma_{11}-\sigma_{22})^2
            + (\sigma_{22}-\sigma_{00})^2)
+ 3( \sigma_{01}^2+\sigma_{12}^2+\sigma_{20}^2) }
\end{equation}
is used to detect material damage.
Here we want to calculate the von-Mises stress and write it to a file for visualization.

The following script, which is available in \file{heatedblock.py} in the
\ExampleDirectory, solves the Lam\'e equation and writes the displacements and
the von-Mises stress\index{von-Mises stress} into a file \file{deform.vtu} in
the \VTK file format\index{scripts!\file{diffusion.py}}:
\begin{python}
  from esys.escript import *
  from esys.escript.linearPDEs import LinearPDE
  from esys.finley import Brick
  from esys.weipa import saveVTK
  #... set some parameters ...
  lam=1.
  mu=0.1
  alpha=1.e-6
  xc=[0.3, 0.3, 1.]
  beta=8.
  T_ref=0.
  T_0=1.
  #... generate domain ...
  mydomain = Brick(l0=1., l1=1., l2=1., n0=10, n1=10, n2=10)
  x=mydomain.getX()
  #... set temperature ...
  T=T_0*exp(-beta*length(x-xc))
  #... open symmetric PDE ...
  mypde=LinearPDE(mydomain)
  mypde.setSymmetryOn()
  #... set coefficients ...
  C=Tensor4(0., Function(mydomain))
  for i in range(mydomain.getDim()):
    for j in range(mydomain.getDim()):
       C[i,i,j,j]+=lam
       C[i,j,i,j]+=mu
       C[i,j,j,i]+=mu
  msk=whereZero(x[0])*[1.,0.,0.] \
     +whereZero(x[1])*[0.,1.,0.] \
     +whereZero(x[2])*[0.,0.,1.]
  sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)
  mypde.setValue(A=C, X=sigma0, q=msk)
  #... solve pde ...
  u=mypde.getSolution()
  #... calculate von-Mises stress
  g=grad(u)
  sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0
  sigma_mises=sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \
                    (sigma[2,2]-sigma[0,0])**2)/2. \
                   +3*(sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2))
  #... output ...
  saveVTK("deform.vtu", disp=u, stress=sigma_mises)
\end{python}

\begin{figure}
\centerline{\includegraphics[width=\figwidth]{HeatedBlock}}
\caption{von-Mises Stress and Displacement Vectors}
\label{HEATEDBLOCK FIG 2}
\end{figure}

\noindent Finally, the results can be visualized by calling
\begin{verbatim}
mayavi2 -d deform.vtu -f CellToPointData -m Vectors -m Surface
\end{verbatim}
Note that the filter \text{CellToPointData} is applied to create a smoother
representation of the von-Mises stress.
\fig{HEATEDBLOCK FIG 2} shows the results where the colour of the vertical
planes represent the von-Mises stress and a horizontal plane of arrows shows
the displacements vectors.


\section*{Exercise 26.2-7}
Proof of Lemma 26.2.
\\
\\
We first prove, that $f_p$ is a flow in $G_f$, by proving the capacity constraint and flow conservation property holds in $G_f$.
\\
\\
Capacity constraint:
\\
It is given, that $f_p(u,v)=c_f(p)$, if $(u,v)$ is on the path $p$. We also know that the residual capacity $c_f(p)$ is the minimum capacity of any edge on $p$, which gives us the upper bound on the flow through all edges on the path
\\
$f_p(u,v)\leq c_f(u,v)$
\\
Furthermore, it is also given, that $f_p(u,v)=0$, if $(u,v)$ is not on $p$, which gives the lower bound on the flow
\\
$0 \leq f_p(u,v)$.
\\
\\
Flow conservation property:
\\
As noted earlier, the flow on $p$ will be determined by the residual capacity $c_f(p)$ of $p$, meaning the same flow will be pushed through all edges on $p$. Hence, the flow conservation property holds.
\\
\\
Proof that $|f_p| = c_f(p)>0$:
\\
We know from the definition of the value of a flow, that
\begin{align}
|f| = \sum_{v\in V}f(s,v) - \sum_{v\in V}f(v,s)
\end{align}

On a path from $s$ to $t$, the number of edges with a positive flow leaving $s$ will be exactly one more than the number of edges with a positive flow that are entering $s$. If this was not the case, then $p$ would not be a path from $s$ to $t$. Hence as all flow on $p$ is the same, the net flow out of $s$ corresponds to what a single edge in the flow can carry in the path $p$ which is $c_f(p)$. So
\begin{align}
|f| = \sum_{v\in V}f(s,v) - \sum_{v\in V}f(v,s) = c_f(p)
\end{align}
To show that $c_f(p)>0$, we note that $c_f(p)$ is the minimum residual capacity on $p$, and since only edges with a positive residual capacity are included in the residual network, the value must be positive.


\subsubsection{int -- a numeric type}
Booleans are a subtype of integers.
Integers have unlimited precision.

Bitwise operations make sense for integers: \mintinline{python}{x | y} (bitwise or), \mintinline{python}{x ^ y} (bitwise xor), \mintinline{python}{x & y} (bitwise and), \mintinline{python}{x << n} (left shift), \mintinline{python}{x >> n} (right shift).
% Todo: underscores in integers (requires Python 3.6+).


\begin{flushleft}
    \subsection{Data Clustering}
        Data clustering is a common practice that is often used in
        Exploratory Data Analysis (EDA) and Data Mining (DM) for the
        benefit of gaining insight on your data. In a society where there
        is a vast amount of data to draw insight from, it is quite necessary
        for the knowledge extraction process to happen efficiently. Due to this
        many data scientists use Machine Learning (ML) algorithms, specifically
        unsupervised ML algorithms, because often times the data they wish to cluster
        does not have predefined labels.
        \\
        Granted that the focus of this assignment is on the application of MOPSO, rather
        than data clustering, I have chosen the KMeans algorithm which is a relatively simple
        yet effective unsupervised ML algorithm that will, for the sake of this assignment,
        demonstrate how MOPSO can be applied to traditional static data clustering. The reader
        should be aware that other unsupervised ML algorithms such as ...  that are commonly used
        could perhaps provide a more efficient solution than the one proposed in this report. However,
        that investigation is ommitted in this report and left for the reader to persue.

    \subsection{KMeans Clustering Algorithm}
        The standard KMeans clustering algorithm operates by doing the following: \\
        let S be the dataset, where each data sample is of I-dimensions \\
        Randomly initialize K cluster centroids c[k] each of I-dimensions, where 1 <= k <= K \\
        Repeat \\
            let s be a data sample not yet presented \\
            let c be the centroid closest to s \\
            for every cluster c[k] \\
                move that cluster to the average(mean) of points assigned to that cluster \\
        Until stopping_condition \\

        Note that for my implementation, I added slight variations to the standard KMeans algorithm to remove
        any possible biases in the order of presentation or in the initial value for the centroids.
        For this, I simply randomly shuffled the data samples after every epoch and initialized each centroid to
        uniformly distributed values within the ranges of each attribute of the data set.

    \subsection{Multi Objective Particle Swarm Optimization}
        MOPSO is a class of Computation Intelligence, namely Swarm Intelligence, and often describes optimization
        problems with more than one, but less than four objectives to optimize.

        For this assignment there were two objectives:
        \begin{itemize}
            \item minimize the intra-cluster distances, and
            \item maximize the inter-cluster distances.
        \end{itemize}

        In my approach, I viewed the task at hand as a traditional clustering task that required finding a set of cluster centroids,
        such that the intra-cluster distances are minimized and the inter-cluster distances are maximize. As a result my approach
        involves using two sub-swarms, each swarm aiming to solve the objective function that finds the centroids who's summated
        intra-cluster distance is minimal and who's summated inter-cluster distance is maximal over all. However, with this approach,
        rises a need for communication between particles of each swarm such that the global best solutions of each swarm
        can be utilized in satisfying the given objectives. To achieve this I chose to represent a particle in the following way: \\
        \begin{itemize}
            \item A particle has a set of centroids, i.e. the set of centroids that satisfy the objectives.
            \item A particle's position is a vector that contains the intra-cluster distances and the inter-cluster distances for the
            centroids belonging to that particle.
            \item A particle's personal best and velocity vectors are of the same dimensions as the particle's position vector.
        \end{itemize}
        The swarms of the MOPSO algorithm are also then represented in the following way: Each swarm contains a set of particles,
        a global best position vector and a global best centroids set, which will be the set of centroids that make up the global
        best position vector's elements.

        For the case of dynamically determining the optimal number of clusters, I applied the above approach through several cluster sizes,
        and with each, measuring the silhouette score and finally determining the optimal number of clusters by taking the difference between
        adjacent cluster's silhouette scores and selecting the one with the highest difference, i.e. selecting the cluster with the steepest slope.
\end{flushleft}


\section{Heuristic optimization}

A heuristic is a problem-solving strategy that is based on rules
of thumb or common sense, possibly also using expert
knowledge. Heuristics are often used when no efficient (exact) algorithms
are known, or when applying such algorithms would take too
long.

\subsection{Hill Climbing}
Search for improvements in neighborhood and improve current solution successively.

\begin{enumerate}
    \item Initialization: Start with random solution. \\
    Evaluate initial solution.
    \item Iteratively: \\
    Explore neighborhood and evaluate new solution candidates. Continue with best solution found, if this improves the target function. (Otherwise we’re in a local optimum.)
    \item Return solution
\end{enumerate}

\begin{tcolorbox}[colback=red!5!white,colframe=red!75!black]
Variant: Always take best solution from neighborhood, even if this decreases target function. Pros and cons?
\begin{itemize}
    \item Might escape from local optima.
    \item Not monotone increasing.
    \item Might go back and forth, i.e. run into a cycle.
\end{itemize}
\end{tcolorbox}

\subsubsection{Stochastic hill climbing}

\begin{enumerate}
    \item Initialization: Start with random solution. \\
    Evaluate initial solution.
    \item Iteratively: \\
    Choose random solution in neighborhood (i.e. perform a
random modification). Evaluate new solution candidate,
and accept it, if it is better. Continue until termination
criterion is reached.
    \item Return solution
\end{enumerate}

\clearpage
\subsubsection{Continuous hill climbing}

\begin{enumerate}
    \item Initialization: $i = 0$:
    Initial solution $x_0$.
    \item Iteration $i \rightarrow i + 1$: \\
        $x_{i+1} =
        \begin{cases}
        y_i       & \quad \text{if } f(y_i) \leq f(x_i)\\
        x_i       & \quad \text{if } f(y_i) > f(x_i)
        \end{cases}$
        \item Return solution
\end{enumerate}

\subsection{Tabu search}
Similar to hill climbing, but with some memory. Try to avoid steps that go back to previously visited solutions, or
that undo the effect of previous steps. (These steps are „tabu“.). The goal is to promote diversity of the solutions explored, in
particular to reduce cyclic behaviour and to escape from local
optima.

\begin{enumerate}
    \item Start with random solution. \\
        Evaluate initial solution.
    \item Iteratively: \\
    Explore neighborhood and evaluate new solution
candidates. Only consider steps that are not tabu.
Proceed with step 2 with the best solution found and
update tabu list until termination criterion is reached.
    \item Return solution
\end{enumerate}

\subsubsection{Tabu List}
\begin{itemize}
    \item Simplest variant: Only store last solution as a tabu (to
avoid going back and forth).
\item Probably better: Keep e.g. a tabu list corresponding to last
k moves.
\item How restrictive should the tabus be? (Forbid specific
configurations, whole classes of moves, certain values for
certain variables, ...?)
\item Duration of tabus (short- vs. mid- vs. longterm)?
Size and organization of tabu list(s)?
\item Are the tabus enforced strictly or do we allow exceptions
(„aspiration“)? When and why?
\end{itemize}

\subsubsection{Randomized tabu search}
\textbf{Stochastic version.}

\begin{enumerate}
    \item Start with random solution. \\
        Evaluate initial solution.
    \item Iteratively: \\
Choose a random solution from the neighborhood.
Evaluate the new solution candidate, if its not tabu.
If a better solution is found, continue with this solution,
update tabu list and proceed with step 2. Continue until
termination criterion is reached.
    \item Return solution
\end{enumerate}

\subsection{Simulated annealing}
Similar to hill climbing, but also allow non-improving
moves to escape from local optima.

\begin{enumerate}
    \item Start with random solution. \\
        Evaluate initial solution.
    \item Iteratively: \\
Choose random solution in neighborhood and evaluate it. If
it is better, accept it. If it is worse, accept it only with some
probability.
Continue until termination criterion is reached.
    \item Return solution
\end{enumerate}

With other words

\begin{enumerate}
    \item Initialization: \\
    Start with $x_0$
    \item Iteratively: $x_i \rightarrow x_{i+1}$ \\
    Sample a random solution $y_i$ in the neighborhood and accept it to be $x_{i+1}$ with probability $min\{ 1, e^{\frac{f(x_i)-f(y_i)}{T_i}}\}$
\end{enumerate}

\subsection{Population based methods}
An evolving population of (partial) solutions, whose
members evolve and adapt individually to the problem and are
searching for the optimum. Problem-specific information can be
exchanged between the members of the population, and can
also be passed on to descendants.

\clearpage
\subsection{Genetic Algorithms}

\begin{figure}[H]
\centering
\includegraphics[width=0.6\textwidth]{figures/encodingGenotype.png}
\caption{Genotype encoding}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[width=0.9\textwidth]{figures/knapsackGenotype.png}
\caption{Genotype encoding - Knapsack Example}
\end{figure}

A small change in genotype should corresponds to a small
change in phenotype.

Important points in the evolutionary process, i.e. when creating a new generation:
\begin{itemize}
    \item Population development
    \item Natural selection: Selection of individuals for reproduction
    \item Recombination
    \item Mutation
\end{itemize}

\clearpage
\subsubsection{Terminology}

An \textbf{individual} is often represented as a vector with $n$ (binary, integer or
real) entries. The individual entries in (e.g.) the vector representation of an
individual are its \textbf{genes}. They describe the genetic information and the properties of the
individuals. E.g., the individual (0, 0, 1, 0, 1) (binary encoding) consists of
five genes.

The concrete values of a gene can take in an individual are
called \textbf{alleles}. In binary-encoded individuals, the only possible alleles are 0
and 1.

The \textbf{population}is the set of all individuals in an optimization
problem at a given time. A \textbf{generation} is the population at a specific point in time.

The \textbf{genotype} is the encoded form of an individual. The \textbf{phenotype} is the decoded form of an individual. It does
not depend on our choice of encoding. The \textbf{fitness function} is our measure for the quality of a
solution candidate in the optimization problem.

\subsubsection{Algorithm}

\begin{enumerate}
    \item \textbf{Initialization:} Random starting population
    \item \textbf{Iteratively:} Create next generation according to
evoluationary principles:
\begin{itemize}
    \item Assign fitness to individuals
    \item Natural selection and choosing parents for reproduction
    \item Recombination process
    \item Mutation process
\end{itemize}
Repeat 2 until termination criterion is satisfied
\item Return best individual
\end{enumerate}

\subsubsection{Selection Pressure}
Better individuals should have a higher
chance of reproduction.
\begin{itemize}
    \item \textbf{Better exploration} of search space when selection pressure is \textbf{low}.
    \item \textbf{Better exploitation} of good individuals when selection pressure is \textbf{high}. \\
    Be careful with dominant solution candidates $\rightarrow$ crowding
\end{itemize}

\textbf{Strategy:}Low selection pressure early on, increasing selection
pressure in later generations. (Compare with simulated
annealing.)

\clearpage
\subsubsection{Recombinations}

\textbf{One-Point Crossover}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/onepointcrossover.png}
\caption{One-Point Crossover}
\end{figure}

\textbf{Two-Point Crossover}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/twopointcrossover.png}
\caption{Two-Point Crossover}
\end{figure}

\textbf{Repair Mechanism for Two-Point Crossover}
\begin{figure}[H]
\centering
\includegraphics[width=0.4\textwidth]{figures/repairtwopointcrossover.png}
\caption{Repair Mechanism for Two-Point Crossover}
\end{figure}

\textbf{Uniform Crossover}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/uniformcrossover.png}
\caption{Uniform Crossover}
\end{figure}

\textbf{Adjacency method}
\begin{figure}[H]
\centering
\includegraphics[width=0.5\textwidth]{figures/adjacencyMethod.png}
\caption{Adjacency Method}
\end{figure}

\clearpage
\subsubsection{Mutations}
Important to obtain new solution candidates (diversification) for exploration of search space.

\begin{figure}[H]
\centering
\includegraphics[width=0.6\textwidth]{figures/mutations.png}
\caption{Mutations}
\end{figure}

\subsubsection{Combination}

\begin{figure}[H]
\centering
\includegraphics[width=0.9\textwidth]{figures/combination.png}
\caption{Combination}
\end{figure}

\subsection{Ant Colony}
\begin{itemize}
    \item No central instance that coordinates ants. The colony is self-organized. Ants are indpendent from each other.
    \item An individual ant lays down pheromone trails when looking for food.
    \item The higher the pheromone concentration on a path, the higher the probability an ant chooses it. If an ant lays down pheromone at a constant rate, shorter paths receive more pheromone per time. $\rightarrow$ Frequently used good paths are reinforced and attract even more ants.
    \item Unused paths become unattractive because of evaporation.
\end{itemize}

\begin{figure}[H]
\centering
\includegraphics[width=0.9\textwidth]{figures/ants.png}
\caption{Ant Colony}
\end{figure}

\clearpage