## 5 Computational Experiments
### Genetic Algorithm (Ga)
#### 5.4.3 Individual Coding and Decoding  
* First phase--individual coding: The coding of each individual begins with the definition of the value of each gene, where its locus represents the product and its value represents the day on which the product meets the demand in the \(DC\) (\(G^{\prime}_{d,p,DC}\)). The value of each gene is randomly selected in the interval between \(d_{1}\) and \(d_{30}\), which corresponds to the planning horizon. From the definition of the value of the genes, we start to calculate the day of production of each product. The productions are triggered according to the demand of each product (\(DM_{p}\)), and its production time is taken into account. The initial stocks of each product in the factories (\(I_{f,p,d}\)) and \(DC\) are also considered, along with the production capacity of the factories (\(CF_{f,p}\)), production time, quarantine time (\(TQ_{p}\)), and time required for transport. The transport time considers the transport capacity (\(CT_{p}\)) and transportation cost between the origin factory \(f\) and destination factory \(f^{\prime}\). With this information, we can find out how many days we should return to meet all products' demands. When the products are dependent \(\mathcal{P}_{p}\), the calculation should consider both the demand of the dependent product and its source. If the production exceeds the transport capacity \(CT_{t,p}\), the transport time will be adjusted to double the standard value \(TT_{p,f,r}\); otherwise, we use the standard value. The solution should be repaired if the production start date is less than \(d_{1}\). Repair is performed by randomly choosing a new date between the current value of the gene and \(d_{30}\). The coding process establishes the necessary parameters for the execution of the production and transport function in the genetic algorithm model, preparing the individual to be evaluated in the following phases of the algorithm. Example: If the gene corresponding to \(p_{1}\) receives the value 26 and considering 2 days of production, 20 days of quarantine, and 4 days of transport, the beginning of production of \(p_{1}\) is computed as follows:\[G_{d,\text{I},\text{DC}}=\mathbf{26}-2-20-4+1=1 \tag{22}\]  
Thus, the production of \(p_{1}\) will start on \(d_{1}\). With the determination of the dates of the beginning and end of production, the dates of beginning and end of quarantine, as well as the beginning and end of transport are defined in sequence, observing the criteria of precedence between products, the stocks available in the factories and the total transport capacity. Notice that these phases are the time windows in which each process begins and ends; however, a detailed description of the solution is not presented at this stage.  
In the next step, the generated individuals undergo crossing and mutation operations, generating their offspring. Then, for each gene, it is verified if the beginning of the resulting production is negative, which would indicate the unfeasibility of the delivery date. If this occurs, a repair procedure is applied in which a new number is generated randomly in the range from 1 to 30. If, even after the repair, some gene remains unviable, the solution receives a penalty of 60.  
* Second phase--individual decoding:  
Knowing the start of production and transportation dates for each product, the production of each product begins in its respective factories. Then, the product is quarantined, at the end of which the production plan can use it to produce a dependent product or send it to the DC.  
The transport respects the constraints on the use of vehicles and their capacities. Then, we adjust the delivery dates of each product in DC. The incumbent solution is updated, and a new cycle begins until the stop criterion is satisfied.