Water cycle algorithm: A detailed standard code

Inspired by the observation of the water cycle process and movements of rivers and streams toward the sea, a population-based metaheuristic algorithm, the water cycle algorithm (WCA) has recently been proposed. Lately, an increasing number of WCA applications have appeared and the WCA has been utilized in different optimization fields. This paper provides detailed open source code for the WCA, of which the performance and efficiency has been demonstrated for solving optimization problems. The WCA has an interesting and simple concept and this paper aims to use its source code to provide a step-by-step explanation of the process it follows. c ⃝


Introduction
The water cycle process, also known as the hydrological or the H 2 O cycle, explains the unceasing movement of water on, above, and below the surface of the earth.It consists of several phases such as evaporation, precipitation, and surface run-off [1].As we observe in nature, streams flow into rivers and rivers flow into the sea.Finally, all the rivers and/or streams end up in the sea, the most downhill (low-altitude) place in the world [2].
Therefore, similar to a metaheuristic swarm optimization algorithm, this phenomenon lends itself to finding a global optimal solution or a near-optimal solution via effective exploration and exploitation.Inspired by this observation, the water cycle algorithm (WCA) has been developed as a new metaheuristic algorithm [3].
One of the advantages of the WCA is the lower number of insensitive user parameters it requires, which means that the WCA can address a wide range of optimization problems using the fixed user defined parameters.
Over the last few years, the WCA has been successfully applied to several varieties of optimization problems such as water resources, civil engineering, and mathematics [4,5].
This paper aims to extend the application of WCA to additional optimization problems by making the source code of the algorithm available.This would assist users to improve or modify the current version of the WCA code.A unified code for the WCA is also offered.
The remainder of this paper is organized as follows.Section 2 presents the motivations and the significance of distributing the unified code of the WCA.The standard WCA along with its detailed processes is given in Section 3. The main source code of the WCA, written in MATLAB, is provided in Section 4.An illustrative example and its link to the WCA are presented in Section 5 to provide a comparison with other optimizers.The impact of the source code of the form in which the WCA is used on research activities is given in Section 6.Finally, a summary of this paper appears in Section 7.

Motivation and significance
The source code, which is available online, is capable of addressing various optimization problems arising in many different fields of study.This availability is expected to assist readers to save time in accessing the source code and to provide them with a fair comparison with other optimizers.Some examples of WCA contributions are finding more optimal values in terms of cost (i.e., cheaper structures) [4,6] and weight (i.e., lighter products) [7].
Detailed explanations regarding the source code appear in Section 4. Lately, the WCA has gained more attention and by making its source code publicly available, the chance of other researchers using this optimizer in their applications is increased.Regarding its realistic application, the open source code of WCA can be implemented in robot path planning problems, because it can act as optimization software for finding the least distance to a destination point by a robot, and it can also be considered as one of the alternatives for the optimization toolbox used in MATLAB.

Water cycle algorithm: Idea, motivation, and design
The WCA mimics the flow of rivers and streams toward the sea and was derived by observing the water cycle process.Let us assume that there are some rain or precipitation phenomena.An initial population of design variables (i.e., population of streams) is randomly generated after the raining process.The best individual (i.e., the best stream), classified in terms of having the minimum cost function (for minimization problems), is chosen as the sea [3].
Then, a number of good streams (i.e., cost function values close to the current best record) are chosen as rivers, whereas the remaining streams flow into the rivers and the sea.
Starting the optimization algorithm requires the generation of an initial population representing a matrix of streams of size N pop × D, where D is the dimension.Hence, this matrix, which is generated randomly, is given as (the rows and column represent the population size (N pop ) and the number of design variables, D, respectively): In the first step, N pop streams are created.Then, a number of best individuals N sr (minimum values) are selected as the sea and rivers.The stream which has the minimum value (objective function) among the others is considered as the sea.In fact, N sr is the summation of the number of rivers (which is defined by the user) and a single sea.The rest of the population (N stream ) are considered as streams flowing into the rivers or may alternatively flow directly into the sea.Depending on the magnitude of the flow, each river absorbs water from streams.Hence, the amount of water entering a river and/or the sea varies from stream to stream.In addition, rivers flow to the sea, which is the most downhill location.The designated streams for each river and the sea are calculated using the following Eq.[8]: where N S n is the number of streams which flow into the specific rivers and the sea.Fig. 1a shows a schematic view of a stream flowing towards a specific river along their connecting line.
For the exploitation phase of the WCA, new positions for streams and rivers have been suggested as follows [3]: where t is an iteration index, 1 < C < 2, and the best value for C may be chosen as 2, and rand is a uniformly distributed random number between zero and one.Eqs. ( 3) and ( 4) are for streams which flow into the sea and their corresponding rivers, respectively.If the solution given by a stream is more optimal than that of its connecting river, the positions of the river and stream are exchanged (i.e., the stream becomes a river and the river becomes a stream).A similar exchange can be performed for a river and the sea.
The evaporation process operator is also introduced to avoid premature (immature) convergence to local optima (exploitation phase) [3].Basically, evaporation causes sea water to evaporate as rivers/streams flow into the sea.This leads to new precipitation.Therefore, we have to check whether the river/stream is sufficiently close to the sea to enable the evaporation process to occur.For that purpose, the following criterion is utilized for the evaporation condition between a river and the sea: Perform raining process by uniform random search, end where d max is a small number close to zero.After evaporation, the raining process is applied and new streams are formed in different locations (similar to mutation in the GAs).Indeed, the evaporation operator is responsible for the exploration phase in the WCA.Uniform random search is used to specify the new locations of the newly formed streams: A large value for d max prevents additional searches and small values encourage the search intensity near the sea.Therefore, d max controls the search intensity near the sea (i.e., best obtained solution).The value of d max adaptively decreases as follows [8]: The development of the WCA optimization process is illustrated in Fig. 1b where the circles, stars, and the diamond correspond to streams, rivers, and the sea, respectively.The white (empty) shapes denote the new positions occupied by streams and rivers.

Software description
The source code given in this section is written in MATLAB.The main parts of the WCA source code such as the movements of streams, rivers, and the sea, and the evaporation condition have been included in this section.The WCA creates a uniform random initial population.Based on the objective function value (e.g., cost/fitness), the generated population is sorted and individuals are named as the sea, rivers, and streams accordingly.Afterwards, as mentioned in Section 3, the sea and rivers depend on their intensity of flow (objective function value) can absorb streams as can be seen in Eq. ( 2).The notations F best, obj river, and obj stream correspond to the best objective function obtained so far (i.e., sea), and the objective functions for the rivers and streams, respectively.
The main loop of WCA is as follows.First, we assume streams flow into the sea, and if they find more optimal positions compared with the sea, their positions will be exchanged.These processes have been coded and provided in Lines 1-10.
where LB and UB are the lower and upper bounds of a given problem, respectively.Afterward, streams that have been assigned to specific rivers flow to their corresponding rivers (Lines 11-31).In case of improvement in terms of the objective function value (i.e., cost/fitness), the position of a stream and its corresponding river switches (see .In addition, we should ensure that our solution is updated as the best obtained solution so far (sea).Therefore, Lines 24-28 compare the goodness of the new river with the sea as follows: In the last movement phase, rivers flow to the sea as shown in Lines 32-41.If a newly generated river is found to be more optimal than the sea, their roles will be switched (see Lines 37-40): Lines 42-53 are considered as the evaporation operator for both rivers (see Lines 42-48) and streams (see Line 49-53).
At Line 53, one iteration of WCA finishes and this process continues until the maximum number of iterations is reached.

An illustrative example
An engineering optimization problem, the so-called welded beam design problem, which is often used as a benchmark problem, is considered in this paper [9].In this problem, a welded beam is designed with the aim of minimizing its cost, subject to constraints on shear stress (τ ), bending stress (σ ) in the beam, buckling load on the bar (P b ), end deflection of the beam (δ), and side constraints.This requires four design variables as shown in Fig. 2: h(x 1 ), l(x 2 ), t (x 3 ), and b(x 4 ).
In order to apply the reported problem on WCA, first, objective function which is minimization and all constraints should be defined and coded in separate m file in MATLAB.Therefore, lines 54-56 correspond to the cost function of the welded beam design problem as follows: Accordingly, for the constraints, Lines 57-66 belong to subjected constraints as given in the following: For constraint handling approach, one can use any type of strategy for satisfying the subjected constraints such as penalty function technique.However, for this problem authors used the direct method (i.e., 4 simple rules) in this paper [4].Talking about the connection among objective and constraints functions, Line 67 shows a general command for lunching the WCA source code.Therefore, for the considered problem, as can be seen in Line 68, WCA along with its initial parameters is prepared for optimizing our problem of interest (NFEs stand for the maximum of functional evaluations).
where X and Cost (considered as the outputs) are optimum values for design variables and the optimized cost obtained after optimization using the WCA, respectively.The optimization methods previously applied to this problem include genetic algorithms (GAs) [10], a cultural algorithm with evolutionary process (CAEP) [11], hybrid Nelder-Mead simplex search and particle swarm optimization (NM-PSO) [12], modified GA (MGAs) [13], society and civilization (SC) [14], differential evolution (DE) [15], and PSO-DE [16].The WCA, based on the mentioned source code in Section 4, was applied to solve this design problem for 30 independent runs.The results of the comparison of the statistical optimization are listed in Table 1.
Among the previously reported results, the best solution was obtained using the WCA with an objective function value of f (x) = 1.7235 with fewer NFEs (i.e., 30,000).The statistical optimization results obtained by the WCA were superior to the results obtained by the other considered algorithms when considering that the WCA required a smaller number of NFEs as shown in Table 1.

Impact
The ability to produce better optimal solutions and the advantages of the WCA (simple in terms of coding and implementation) make it an attractive optimization method for researchers who work in optimization related areas.Recently, Haddad et al. [17] utilized the WCA to optimize the operation of reservoir systems.The optimization results they obtained demonstrated the high efficiency and reliability of the WCA in solving reservoir operation problems.Lenin et al. [18] used the WCA for detecting optimum reactive power dispatch problems.They claimed to have applied the WCA to standard IEEE 30 bus test systems and their simulation results clearly show the superior performance of the WCA in decreasing real power loss.
Jabbar and Zainudin [19] applied the WCA to attribute reduction problems in rough set theory.Based on their findings, it has been shown that the WCA performed equally well or even better than other methods for detecting optimal attribute selection.
Guney and Basbug [20] proposed an improved version of the WCA, named the quantized WCA (QWCA) and applied it to solve antenna array pattern synthesis.Yet another improved version of the WCA was recently developed by Sadollah et al. [8], who proposed a modification for WCA using different evaporation rates for rivers.Evaporation rate-based WCA (ER-WCA) was applied to a number of unconstrained and constrained optimization problems and compared with the standard WCA [8].Moreover, the WCA has been applied to the sizing optimization of sandwich panels with prismatic cores with the goal of designing ultra-light weight sandwich panels [7].The WCA was also applied to optimize the cost design of water distribution systems [21].
Ramzanpour and Abdi [22,23] applied the WCA for solving economic load dispatch problems among power plants considering different concepts.Lately, Ashouri and Hosseini [24] have utilized the WCA for dynamic economic load dispatch problems in the operation of power systems.Baghipour et al. [25] used the WCA to find the optimal number, location, and size of multiple types of distributed generation units in a distribution system.The attained optimization results demonstrate successful application of the WCA for distributed generation units.
In mathematics, approximate solutions of ordinary differential equations (ODEs) were obtained by using the WCA to efficiently solve nonlinear ODEs along with other optimization methods [5].The approximate solutions that were obtained using the WCA were superior to the results of other optimization methods [5].
In civil engineering, the WCA has been implemented to reduce the cost of truss structures.Comparative studies showed the superiority of the WCA over other considered methods [4,6].More recently, Sadollah et al. proposed a multi-objective version of WCA (MOWCA) for solving unconstrained and constrained multi-objective optimization problems [26,27].Various performance metrics were used for evaluating the efficiency of MOWCA against other optimizers.The optimization results obtained indicated that MOWCA outperformed the other state-of-the-art metaheuristic methods.

Conclusions
This paper provides and considers the open source code of the water cycle algorithm (WCA) in detail.The original principle of WCA was inspired by nature and the water cycle process.In addition, this paper also presents explanations of the standard WCA and its applications.The provided source code is easy to implement, is based on a simple concept, and is efficient for solving a wide range of optimization problems.

Fig. 1 .
Fig. 1.Schematic illustration of (a) streams flowing into a specific river; (b) the WCA optimization process.

Table 1
Comparison of the statistical optimization results obtained from different optimizers for the welded beam design problem.
a Standard deviation.b Not available.