In each iteration, a parent selection process is applied to the current population to determine which solutions of this population will compose the mating pool, and therefore will be utilized to generate new encoded solutions. In this respect, the well-known tournament selection process [
6] is applied with a tournament size
k, to promote the selection of diverse high-fitness solutions regarding the sequences of actions indicated for the
m smartphones. Then, the solutions in the mating pool are paired, and a crossover process is applied on each pair of solutions with a probability
Pc to generate a pool of new solutions. In this sense, we designed a crossover process feasible for the used encoding of solutions, which generates new solutions by interchanging the sequences of actions indicated for the
m smartphones in the parent solutions. Then, a mutation process is applied on each new solution with a probability
Pm to incorporate diversity in the pool of new solutions. In this respect, we designed a mutation process feasible for the used encoding of solutions, which generates changes in the sequences of actions indicated for the
m smartphones. After that, each new solution is evaluated by the fitness evaluation process. Then, a survival selection process is applied on the current population and the pool of new solutions to decide which solutions will compose the new population for the next iteration. In this respect, the well-known steady-state selection process is applied [
6], with a replacement percentage
r, in order to preserve the best solutions obtained by the algorithm so far.
Once the algorithm reaches the stop condition (i.e., after a given number of iterations, the algorithm outputs the best solution in the last population as result). This solution is used by the component to automatically prepare the whole set of m smartphones.
3.2.1. Encoding of Solutions
Each solution in the population of the algorithm is represented as an
m-tuple <
s1,
s2, …,
sm>, where
m is the number of smartphones considered, i.e., attached to the platform at the time the synchronized test starts. Then, the term
si (
i = 1,…,
m) represents a feasible sequence of charge/discharge actions (
ai1,
ai2, …,
ain(i)) for smartphone
i, which allows to reach
sbl(
i) (the start battery level corresponding to
i) from
cbl(
i) (the current battery level of
i). When
cbl(
i) is lower than
sbl(
i),
cbl(
i) must be increased; thus, sequence
si only includes battery charge actions. Otherwise, when
cbl(
i) is higher than
sbl(
i),
cbl(
i) must be decreased; thus, sequence
si only includes discharge actions. In both cases, the number,
n(i), of actions of the sequence
si is calculated as detailed in Equations (1) and (2).
Each action
aij (
j = 1,…,
n(i)) is represented as a tuple with five elements: <
k_action,
initial_level,
finish_level,
CPU_load,
screen_state>, where
k_action refers to the kind of battery-related action (i.e., charge/discharge),
initial_level indicates the initial battery level for the action, and
finish_level indicates the end battery level for the action. The element
CPU_load refers to the CPU load under which the action increases/decreases from/to
initial_level. As mentioned in
Section 3.1, CPU load belongs to the set {0, 30, 50, 75, 100}%. Finally, the element
screen_state refers to the screen state (i.e., on/off) under which the action increases/decreases from/to
initial_level.
Thus, the length of an encoded solution <
s1,
s2, …,
sm> is calculated as detailed in Equation (3).
Figure 5 shows a sample encoded solution where two smartphones are considered, and a test plan requiring these smartphones to start with 23% and 71% of battery, respectively. In relation to smartphone 1, it has a current battery level of 20%. Thus, the solution proposes a sequence of three charge actions for this smartphone. In this sequence, the first action increases the battery level from 20% to 21% under a CPU load of 30% with the screen on. Then, the second action increases the battery level from 21% to 22% under a CPU load of 75% with the screen off. Finally, the third action increases the battery level from 22% to 23% under a CPU load of 100% with the screen on. Thus, this sequence starts from the battery level 20% and reaches the required battery level of 23%. Regarding smartphone 2, it has a current battery level of 75%. Here, the solution proposes a sequence of four discharge actions for this smartphone. This sequence starts from the battery level 75% and reaches the required battery level of 71%.
3.2.2. Fitness Evaluation Process
This process is applied to evaluate each encoded solution of the population according to the objective considered. Recall that the objective is to reach the pre-defined start battery levels for the m smartphones in the minimum amount of time for the set of smartphones. Considering that, as detailed below, the minimal possible time to prepare the set of m smartphones can be estimated as per the existence of (dis)charge profiles, then the mentioned objective means minimizing the difference (i.e., the error) between the time required by each smartphone to achieve the corresponding start battery level and the minimal possible time to prepare the set of m smartphones. In order to evaluate each encoded solution regarding this objective, the process follows the steps described below.
Given an encoded solution <s1, s2, …, sm>, where si represents a feasible sequence of charge/discharge actions to prepare the smartphone i, the process calculates the average difference (i.e., average error) between the time of each sequence si and the minimum amount of time to prepare the m smartphones. This average difference is determined by a well-known metric named mean absolute percentage error (MAPE). This metric is calculated as detailed in Equation (4), where t(si) refers to the time (milliseconds) of si and T is the minimal possible time (milliseconds) to prepare the m smartphones. The term t(si) is calculated by Equation (5), where t(aij) represents the time (milliseconds) required to develop the action aij. In this respect, the times of actions aij are provided by the charge/discharge profiles of smartphone i.
The term T is calculated by Equation (6), where min(i) refers to the minimum amount of time in milliseconds (i.e., optimal time) for preparing smartphone i. Then, the maximum of these minimum preparation times defines the minimal possible time to prepare the whole set of m smartphones so they all reach the next battery level as specified in the test plan being exercised. Regarding min(i), this time is provided by the existing charge/discharge profiles of i. Specifically, when the current battery level of i must be charged to reach the start battery level pre-defined for i, the minimal possible time is achieved by charging the battery under a CPU load of 0% with the screen off. Thus, the minimal possible time to prepare i is provided by the charge profile inherent to a CPU load of 0% with the screen off. This is the case when the current test specifies a higher battery level than the current battery level of smartphone i; thus, a CPU load of 0% with the screen off means charging at a high rate. On the other hand, when the current battery level of i must be discharged to reach the start battery level pre-defined for i, the minimal possible time is achieved by discharging the battery under a CPU load of 100% with the screen on. Therefore, the minimal possible time to prepare i is provided by the discharge profile inherent to a CPU load of 100% with the screen on. This is the case when the current test specifies a lower battery level than the current battery level of smartphone i; thus, a CPU load of 100% with the screen on means discharging at a high rate.
By applying Equation (4), an MAPE value higher than or equal to 0% is assigned as the fitness value of each encoded solution. Better MAPE values (i.e., lower MAPE values) are assigned to those solutions in which the times, t(si), of the sequences si detailed for preparing the m smartphones are closest to T. In these solutions, the times, t(si), of the sequences si are also closer to each other. Therefore, these solutions minimize the discharge of the m smartphones once these are prepared according to the sequences si (i.e., once the start battery levels, sbl(i), are reached).
Figure 6 shows the MAPE values and the times
t(
si) of the sequences
si of two feasible solutions A and B for an example case where a set of four smartphones have to be prepared. These solutions differ considerably regarding their MAPE value. In this sense, the MAPE value of solution A (0.01%) is much better (i.e., much lower) than that of solution B (52.37%). This is because the times,
t(
si), of solution A (i.e.,
t(
s1) = 16,575,027,
t(
s2) = 16,575,096,
t(
s3) = 16,584,583, and
t(
s4) = 16,575,097) are closer to
T than those of solution B (i.e.,
t(
s1) = 5,819,963,
t(
s2) = 16,575,096,
t(
s3) = 1,623,840, and
t(
s4) = 7,560,004). As a result, the times,
t(
si), of solution A are closer to each other. Specifically, the times,
t(
si), of solution A have very low differences among them (i.e., differences are in the range of [1,9556] ms), whereas the times,
t(
si), of solution B have very significant differences among them (i.e., the differences are in the range of [9,015,092, 14,951,256] ms).
This means than these solutions differ with respect to the discharge of the smartphones once the start battery levels,
sbl(
i), are reached. In this sense, in solution A, the time
t(
s3) is the maximum of the times
t(
si). Therefore, smartphone 1 will reach
sbl(1) at
t(
s1), and so it will be prepared before smartphone 3 reaches
sbl(3). Then, given that the time between
t(
s1) and
t(
s3) (i.e., 9556 ms) is not enough to decrease
sbl(1), smartphone 1 will maintain
sbl(1) until smartphone 3 reaches
sbl(3). In a similar way, smartphone 2 will maintain
sbl(2) and smartphone 4 will maintain
sbl(4) until smartphone 3 reaches
sbl(3). Thus, solution A prevents the discharge of the start battery levels
sbl(
i) reached by the smartphones. Unlike solution A, in solution B, the time
t(
s2) is the maximum of the times
t(
si). Thus, smartphone 4 will reach
sbl(4) at
t(
s4), and it will be prepared before smartphone 2 reaches
sbl(2). Then, since the time between
t(
s4) and
t(
s2) (i.e., 9,015,092 ms) is long enough to decrease
sbl(4), smartphone 4 will not be able to maintain
sbl(4) until smartphone 2 reaches
sbl(2). Likewise, smartphone 1 will not be able to maintain
sbl(1) and smartphone 3 will not be able to maintain
sbl(3) until smartphone 2 reaches
sbl(2). Note that the decrease in the levels of
sbl(4)/
sbl(1)/
sbl(3) (in battery units) depends on the time between
t(
s4)/
t(
s1)/
t(
s3) and
t(
s2). The longer the time between
t(
s4)/
t(
s1)/
t(
s3) and
t(
s2), the higher the decrease in
sbl(4)/
sbl(1)/
sbl(3). Therefore, solution B enables the discharge of the start battery levels
sbl(
i) reached by the smartphones. All in all, solution A outperforms solution B in terms of minimizing the discharge of the smartphones once the start battery levels
sbl(
i) are reached.
3.2.3. Crossover Process
A crossover process is applied to generate new encoded solutions from the solutions in the mating pool. In this respect, the evolutionary algorithm decides which solutions from the current population will compose the mating pool by applying the well-known tournament selection process [
6]. Then, the solutions in the mating pool are organized in pairs, and the crossover process is applied on each pair of solutions with a probability
Pc to generate new encoded solutions. We designed a crossover process feasible for the encoding of solutions presented in
Section 3.2.1. The details of this process is described below.
Given two encoded solutions, p1 and p2, the crossover process generates two new encoded solutions, o1 and o2, by following the next iterative behavior. For each one of the smartphones i, this process considers the sequences of actions si detailed in p1 and p2 for i, and after that analyzes one by one the actions, aij, of each sequence. For each action, aij, of the sequence si detailed in p1(p2), the process considers the five elements which compose the action and then copies the values detailed in p1(p2) for k_action, initial_level, and finish_level to the new solution o1(o2), in the same positions for these values in p1(p2). Regarding the values detailed in p1(p2) for the elements CPU_load and screen_state, each of these values is copied to the new solution, o1(o2), according to a given probability, u. Specifically, for each of the mentioned elements, the process generates a random number in the range of [0,1]. If this number is lower than u, the process copies the value detailed in p1(p2) for the element to o1(o2), in the same position for this value in p1(p2). Otherwise, if this number is higher than or equal to u, the process copies the value detailed in p1(p2) for the element to o2(o1), in the same position for this value in p1(p2). Therefore, this crossover process allows the generation of two new encoded solutions by interspersing the values detailed in p1 and p2 for the elements of the actions of each sequence.
Figure 7 shows an example of the crossover process. In this example, the process is applied on the encoded solutions
p1 and
p2 and generates the encoded solutions
o1 and
o2. Bold values in
o1 and
o2 indicate values interchanged between
p1 and
p2.
3.2.4. Mutation Process
A mutation process is applied to each solution obtained by the crossover process with a probability
Pm, so as to incorporate diversity into the pool of new encoded solutions, and thus to preserve the diversity of the population throughout the generations of the algorithm. We designed a mutation process feasible for the encoding of solutions presented in
Section 3.2.1. The behavior of this process is described below.
Considering an encoded solution p1, our mutation process generates a new encoded solution o1, by following the next iterative behavior. For each of the smartphones i, this process considers the sequence of actions, si, detailed in p1 for i, and then analyzes one by one the actions, aij, of this sequence. For each action, aij, the process considers the five elements that compose the action. Then, the process copies the values detailed in p1 for k_action, initial_level, and finish_level to the new solution o1, in the same positions for these values in p1. In relation to the values detailed in p1 for the elements CPU_load and screen_state, each one of these values is copied to the new solution o1 according to the mutation probability, Pm. In particular, for each one of the two mentioned elements, the process generates a random number in the range of [0,1]. When this number is higher than Pm, the process copies the value detailed in p1 for the element to o1 to the same position for this value in p1. On the other hand, when this number is lower than or equal to Pm, the process does not copy the value detailed in p1 for the element to o1. In this case, the process randomly chooses other possible value for the element, and then copies this value to o1 to the same position for the value detailed in p1. Thus, this mutation process allows the generation of a new encoded solution by changing the values detailed in p1 for the elements of the actions of each sequence according to Pm.
Figure 8 shows an example of the mutation process. In this example, the process is applied on the encoded solution
p1, and generates the encoded solution
o1. Bold values in
o1 indicate new values compared to those in
p1.