# Coverage Fulfillment Automation in Hardware Functional Verification Using Genetic Algorithms
## 3 Materials and Methods
### Description of Developed Programming Ecosystem Based on Genetic Algorithms  
Development of all functions entitled to implement the genetic algorithm focuses on creating a programming ecosystem that can deliver good results as quickly as possible. In the first instance, the coverage targets are stated using different parameters. The most important parameters used in the current work are the number of intervals in a signal value range that should be hit, the number of generated transfers, the width of signals to be covered, the number of generations (or iterations), the number of parents in each generation, and the number (percentage) of individuals that converge to the desired outcome. The steps in the application of genetic algorithms in the current work are depicted in Algorithm 1. Figure 6: Mutation operator representation. ```
1 Initialize population with random values in accepted range Initialize algorithms parameters: \(n\_iter\) number of iterations number of operations which are executed before coverage is collected r_mututation probability width width width of operators n_bits no_of_operations* width pop population existing into a generation n_pop number of individuals in a population crossover rate (20% of best genes are directly copied as future parents no_of_coverage_intervals) number of coverage intervals for result value \(best\_eval\) score for the best evaluated individual, initially 0 Initialize pop with random generated individuals repeat n_iter times Evaluate each individual using OBJECTIVE \(\rightarrow\) array named scores is obtained for i in [1.. \(n\_pop\) if scores[i]> = best_eval best_eval best_eval = scores[i] insert individual in sorted array named best select best n_pop/2 performing individuals from scores \(\rightarrow\) array named selected sort selected array in descending order based on the evaluation score for i in [1.. \(len\)(selected)] \(p1\), \(p2\) = selected[i], selected[1 + 1] if (i<1-r_cross)g*n_pop children_append(p1) apply crossover operator between \(p1\), \(p2\) \(\rightarrow\)the children \(c1\), \(c2\) are obtained if (random < r_mut) apply mutation on \(c1\) or \(c2\) children.append(c1,c2) pop = children
3 return best
```  
**Algorithm 1** Genetic Algorithm  
The general description of the objective function, which represents the fitness function in the current approach, is found in Algorithm 2:  
```
1 Input: 2 \(x\) Individual representation as an array the width (measured in bits) for each gene in individual Path to folder where the simulator is located Number of desired coverage intervals in which the values of data of interest is split Using \(x\) data, generate a stimuli file in which the values of interest (i.e., luminosity values) are prepared to be used in the next step: simulation Using input parameters, call a subprocess that simulates the DUT behavior in ModelSim Extract coverage values from calling the simulation report return coverage value
```  
**Algorithm 2** Objective  
For better understanding, the steps for applying the genetic algorithms seen in Algorithm 1 are further explained here. First, the initial population is randomly generated,containing a fixed number of elements (the population size). Each population contains a sequence of data items representing the stimuli for each performed transaction during a simulation, as represented in (3). The elements can be represented either as binary or as decimal numbers (the researchers used both options during the current work). Because inside each generation there will be the same number of parents, each of them having the same structure, the next part of the program is common for all generations (represented by consecutive program iterations). \[X=\{x\in\mathbb{N}:min\leq x\leq max\},\ |X|=NOOPS \tag{3}\]  
where \(min\) and \(max\) represent boundaries of legal values range for each individual (i.e., 0-900 is the legal range of luminosity values employed in case of Ambiental controller), and \(NOOPS\) is the abbreviation for \"Number of Operations Per Simulation\" and represents the population size.