## 3 Design
Subsequently, a new population should be generated by transferring the best individuals of the population obtained after the convergence to the new one. The remaining individuals are randomly generated. This MAIS was specifically developed for the optimization of the traffic light program cycles (traffic lights). In Algorithm 1, _ExtGen_ is the current generation and _Max Generations_ is the stop criterion for the MAIS external loop. _Generation_ is the current generation and _NominalConv_ is the stop criterion for the MAIS inner loop. \(F\) is the initial population, \(S\) is the selected population, and \(C\) is the cloned population. In addition, \(M\) denotes the cloned mutated population, \(R\) is the ranked population, and \(E\) is for the self regulated population. ```
1:functionMAIS(\(F(x)\))
2:F \(\leftarrow\) Start a population of five antibodies()
3:forExtGen \(\leftarrow\) 1 to ExtGen < MaxGenerations do
4:forGeneration \(\leftarrow\) 1 to Generation < NominalConv do
5:S \(\leftarrow\) Select the n best antibodies based on ranking (F)
6:C \(\leftarrow\) Clone all the antibodies (S)
7:M \(\leftarrow\) Cloning mutation(C)
8:R \(\leftarrow\) Selection based on ranking (M)
9:E \(\leftarrow\) Replace d antibodies by novel ones (R)
10:F \(\leftarrow\) SelfRegulation by eliminating remaining clones(E)
11:endfor
12:E \(\leftarrow\) Algorithm reset(F)
13:if Generation < NominalConv then
14:f \(\leftarrow\) Create 3 new random antibodies to maintain diversity(E)
15:endif
16:endfor
17:endfunction
```  
**Algorithm 1** MAIS--Micro Artificial Immune System  
The MAIS algorithm works as follows:  
1. _A population of five antibodies (individuals) is generated randomly_ (Algorithm 1, **line 2**). The first generation of the population will contain these five antibodies. It is established that ten generations will be sufficient to achieve nominal convergence. The stop criterion (**MaxGenerations** for the MAIS external loop) is given as an input parameter when the algorithm is used. 2. _A selection based on ranking with respect to affinity is used_ (Algorithm 1, **line 5**), where each of the antibodies is evaluated using the objective function. In the MAIS terminology, it is called an antigen (Ag). 3. _Subsequently, the cloning of all antibodies is performed_ (Algorithm 1, **line 6**), using the following equation:  
\[N_{c}=\sum_{i=1}^{n}(n-(i-1)), \tag{4}\]  
where \(N_{c}\) indicates the number of clones that will be generated for each of the antibodies, \(n\) is the total number of antibodies in the population, and \(i\) is the current antibody, starting with the one with the highest affinity (_BestAb_). If a population of five antibodies is considered, a population of fifteen clones will be generated: the best antibody will generate five antibodies, the second best antibody will be cloned four times, and so on, until only one clone is generated for the worst antibody. 4. _Cloning mutation_ (Algorithm 1, **line 7**). The probability of mutation is set at the beginning of the nominal convergence for each group of clones obtained from the same antibody. This probability is proportional to the affinity of the antibody that generated the clones and will decrease in each of the generations. In this way, the clone group of the best antibody will be less likely to mutate than the other clone groups that were generated from the rest of the antibodies. The clone obtained from the _worst_ antibody will have the greatest chance of _mutating_. \[\text{ProbMutation}(i)=\frac{Aff(i)}{\sum_{i=1}^{n}Aff(i)}\] (5) Here, \(i\) is the antibody that will establish the probability of mutation for the group of clones that were generated from it and \(n\) is the total number of antibodies of the population. The following equation is used to uniformly decrease the probability of mutation in each of the generations. \[\text{if prob}\leq\frac{\text{ProbMutation}(i)}{\text{Generation}},\] (6) where, _prob_ is randomly chosen \(\in[0,1]\) and _Generation_ is the current generation within the nominal convergence.