1 Introduction

Compound that is obtained after some products that can not be consumed as human food such as starch, flour, oil, and side products of the alcohol industry, herbal products like grains and legumes, and some of the animal products that pass through screeving, crushing, mixing processes is called as mixed feed. As per the description specified in the law on fodders, they are organic and inorganic substances or their compounds that are not harmful to animal health when they are given to animals within specific limits and under certain conditions and with the purpose of meeting the animals’ living and production needs in terms of substances and energy. In another description, mixed feed is the mixture of the organic and inorganic substances consumed through mouth which has a guaranteed structure and enables the domesticated animals to yield qualified products in large quantities [1].

The selection of a good mixed feed is the leading problem for a producer. This is because of the fact that the cost of feeds is the most important expense of the livestock farming enterprises. The basic requirement for an economical breeding is to keep this expense at a minimum level. In the feed industry, a linear programming approach has been used to determine the cheapest blend of available raw materials that meet certain nutritional requirements. During cost optimization, needs of the animals and the compounds of the feed raw materials should be recognized sufficiently and the appropriate mixtures should be prepared accordingly [2]. Therefore, the basic requirement of a good mixed feed is first to obtain the feed mixtures that will meet the needs of the animals and then to choose the one with minimum cost among these mixtures. The use of an optimization method is inevitable in order to fulfill all these objectives [3]. Linear and nonlinear programming techniques are used in the solution of many problems. These are as follows: sharing the milk resources during cheese production [4], animal diet formulation [5], assessing the life span [6], assessment of the nitrogen tax scenarios [7], optimization of performance according to energy level in the broiler diet formulation [8], and determining the cost and benefits of the separation of GM mixed feeds [9].

A superiority of a genetic algorithm to standard nonlinear programming techniques is that it can calculate global minimum instead of local minimum. Its superiority can be that it does not need derivation which, occasionally, can be obtained difficultly in mathematical functions [10]. Genetic algorithms can solve complex optimization problems quickly and can be applied in an easy and simple manner [11]. The use of standard, nonlinear programming techniques for the solution of nonlinear problems in the mixed feed cost optimization can be time-consuming and insufficient [12]. However, particle swarm optimization (PSO) has an algorithm structure that is quite simple and successful in solving many optimization problems [13]. It operates more rapidly than the other optimization methods in its category. It was designed for the solution of nonlinear problems. It does not require derivation knowledge like genetic algorithms.

In this study, an approach finding least-cost feed mixes, which satisfy the nutritional requirements for poultry and different types of animals (cattle, sheep and rabbits, etc.), is proposed by using PSO. The results obtained are compared with both linear programming model and genetic algorithm. The overall results show that the PSO yields more rapid results with fewer penalties when compared with the other optimization algorithms.

2 Material and method

Database used in this study was received from Selcuk University, Faculty of Veterinary Science, Department of Animal Nutrition and Nutritional Diseases [14]. This database was designed in line with the norms specified by American National Research Council (NRC) [15], Turkey’s Mixed Feeds Norms, and the norms certified by various firms that keep animals for breeding.

Necessary information regarding the food raw materials that will be included in the feed mixture to be prepared in order to meet the needs of the animals was entered into the database completely by forming two groups as poultries and the other animals. Poultries (chicken, goose, ostrich, etc.) and the other animals (rabbit, heifer, cattle, etc.) constitute these two animal groups. Need constraints of each animal group differ from each other. Constraints to be taken into consideration when preparing feed mix for poultries include crude protein (CP), metabolizable energy (ME), calcium (Ca), utilizable phosphor (uP), sodium (Na), methionine + cystine (met + sis), lysin (Li), threonine (Tre), tryptophane (Tri), and linoleic acid (LA). As for the other animals fed with mixed feeds, crude protein (CP), metabolizable energy (ME), calcium (Ca), phosphor (P), sodium (Na), crude cellulose (CC), and crude ash (CA) should be taken into account [16]. There is a flexibility of change in these foodstuff needs specified here.

Raw materials that can be found easily and can provide animals with the sufficient nutrient and are appropriate to their digestion systems are chosen in order to be included in the compound of mixed feeds. Amounts of the nutrient available in the content of these raw materials had been detected beforehand through chemical analyses and presented to the user as tables [17]. Estimated price and minimum and maximum amounts to be included in the mixed feed were also added to the raw material tables. These are not fixed; they can vary by the age and physiological state of the animal, raw material stock, and the current prices. Moreover, the amounts of the nutrient in the raw materials can be different in different animal groups. In this study, two different animal groups were used. These are the animal group of poultries and the group of other animals. Nutrient ingredients of some of the basic raw materials used in the group of other animals are indicated in the Table 1.

Table 1 The nutrients contents

Amounts that should be included in the mixture to be prepared are calculated in percentages by taking into account the animals’ daily nutrient needs determined with respect to their growth period, productivity status and their daily feed consumptions [18]. In the calculation of the nutrient needs of the animals, formulas including factors such as live weight of the animals, their productivity status (gaining weight, producing egg), feed consumptions, and the ambient temperature are used. Values obtained at the end of these calculations constitute our constraints. The first constraint to be paid ultimate attention during the preparation of the mixture is to achieve these constraints precisely or to keep them at acceptable levels. Values of the rabbit growth feed to be prepared for the rabbit that is included in the group of other animals are presented in the Table 2.

Table 2 The nutritional requirements in rabbit (constraints)

In this study, PSO method was used in the cost optimization of the mixed feeds. In today’s world, many methods designed by being inspired by biological systems are used in solving the optimization problems. For instance, artificial neural networks are simplified models of human brain, and the genetic algorithm was created by being inspired by human evolution. Social systems that are other forms of biological systems particularly examine the interaction of individuals with their social environment and their collective (common) behaviors. These behaviors are named as “swarm intelligence” [19].

PSO was designed in order to solve nonlinear problems. They are used in order to find solution to multiparameter and multivariate optimization problems. PSO shows many similarities with evolutive calculation techniques like genetic algorithms. System is launched by a population including random solutions, and it searches the most optimum solution by updating the population with each circle. Probable solutions called as particle in PSO wander around the problem space by following the Global Best and the Local Best that it obtained through its own experiences. The most important difference of PSO than the classical optimization techniques is that it does not need any information other than objective function. Applying PSO to different optimization problems is considerably simple thanks to the limited number of parameters to be adjusted. PSO can be applied successfully in many fields such as function optimization, blurry system control, artificial neural network training, and estimation problems [2024].

Pseudo code of the algorithm is shortly as follows:

figure a

3 Application of PSO algorithms to feed mixes

In this study, PSO method is modeled like below and it is applied to the problem of the mixed feed preparation (Fig. 1). Firstly, animal and feed data are entered to the system. The content of the entered animal and feed data and the number of the data can be changed. Therefore, entered data should be modeled according to PSO each time. The detailed information about the used algorithm is given at the titles below.

Fig. 1
figure 1

Flow chart for cost optimization of the feed mixes

3.1 Initial values of particles

Dimensions of particles show difference depending on the number of the food raw material that is chosen. Each dimension in the particle takes a random value that must remain between minimum and maximum amount limits of the relevant food raw material (Table 1). x = (x 1,x 2,…,x n ) is the food raw materials that will compose the feed mixture and n shows the number of food raw materials and accordingly the number of dimensions belonging to each particle. y = (y 1,y 2,…,y n) displays the contents of feeds to be included in the mixture.

Particles that enter the first iteration are composed through the following equation:

$$ {\text{Particle}}_{i,j} = y_{10j} + {\text{rand}}() \, \times \left( {y_{11j} - y_{10j} } \right) $$
(1)

Particle i,j refers to the value of jth dimension belonging to ith particle. y 10j and y 11j show the lower and upper limit values belonging to jth feed. As for rand() statement, it is a random number produced in the closed interval of [0, 1]. Random initial values are introduced within the requested limit intervals without any overflow by using the (1).

3.2 Constraints

The primary objective to be paid attention during the preparation of feed mixtures is to meet nutrient needs. These needs constitute our constraints. Constraint values of each particle should be calculated in order to enable the control of constraint values.

Constraint values are calculated through the following equation:

$$ \begin{array}{*{20}c} {z_{1} = \sum\limits_{i = 0}^{n} {(x_{i} *y_{1} )/100} } \hfill \\ {z_{2} = \sum\limits_{i = 0}^{n} {(x_{i} *y_{2} )/100} } \hfill \\ \vdots \hfill \\ {z_{n} = \sum\limits_{i = 1}^{j} {(x_{i} *y_{n} )/100} } \hfill \\ \end{array} $$
(2)

In this equation, z = 1, 2,…,n shows the value of n item constraint(s) belonging to one particle. x = 1, 2,…,j indicates the raw material amount in j item dimension(s) in one particle. y = 1, 2,…,n refers to the total value of n item constraint(s) of each food raw material. Constraint values are available for each value (Table 2), and the feed mixture that will be formed at the end of feed mix should not exceed these value limits. Constraint intervals are as follows (3).

$$ \begin{array}{*{20}c} {z_{1\min } \le z_{1} \le z_{1\max } } \hfill \\ {z_{2\min } \le z_{2} \le z_{2\max } } \hfill \\ \vdots \hfill \\ {z_{n\,\min } \le z_{n} \le z_{n\,\max } } \hfill \\ \end{array} $$
(3)

3.3 Penalty values

In this study, total penalty value is calculated for each particle by punishing the overflows of minimum and maximum values of constraints. If there is not any overflow in the constraint, value of that constraint is taken as 0. Total penalties that are calculated constitute our conformity values.

Penalty values are calculated for each particle as follows:

$$ \begin{array}{*{20}c} {{\text{If}}\,z_{1} \,{\text{value}}\,{\text{exceeds}}\,z_{1\max } \,{\text{constraint}},\,G\left( 1 \right) = \left( {{{\left( {z_{1} - z_{1\max } } \right)*100} \mathord{\left/ {\vphantom {{\left( {z_{1} - z_{1\max } } \right)*100} {z_{1\max } }}} \right. \kern-\nulldelimiterspace} {z_{1\max } }}} \right)} \hfill \\ {{\text{If}}\,z_{1} \,{\text{value}}\,{\text{exceeds}}\,z_{1\min } \,{\text{constraint}},\,G\left( 2 \right) = \left( {{{\left( {z_{1\min } - \, z_{1} } \right)*100} \mathord{\left/ {\vphantom {{\left( {z_{1\min } - \, z_{1} } \right)*100} {z_{1\min } }}} \right. \kern-\nulldelimiterspace} {z_{1\min } }}} \right)} \hfill \\ {{\text{If}}\,z_{2} \,{\text{value}}\,{\text{exceeds}}\,z_{2\max } \, {\text{constraint}},\,G\left( 3 \right) = \left( {{{\left( {z_{2} - \, z_{2\max } } \right)*100} \mathord{\left/ {\vphantom {{\left( {z_{2} - \, z_{2\max } } \right)*100} {z_{2\max } }}} \right. \kern-\nulldelimiterspace} {z_{2\max } }}} \right)} \hfill \\ {{\text{If}}\,z_{2} \,{\text{value}}\,{\text{exceeds}}\,z_{2\min } \, {\text{constraint}},\,G\left( 4 \right) = \left( {{{\left( {z_{2\min } - \, z_{2} } \right)*100} \mathord{\left/ {\vphantom {{\left( {z_{2\min } - \, z_{2} } \right)*100} {z_{2\min } }}} \right. \kern-\nulldelimiterspace} {z_{2\min } }}} \right)} \hfill \\ \vdots \hfill \\ {{\text{If}}\,z_{n} \,{\text{value}}\,{\text{exceeds}}\,z_{n\,\max } {\text{constraint}},\,G\left( {2n - 1} \right) = \left( {{{\left( {z_{n} - \, z_{n\,\max } } \right)*100} \mathord{\left/ {\vphantom {{\left( {z_{n} - \, z_{n\,\max } } \right)*100} {z_{n\,\max } }}} \right. \kern-\nulldelimiterspace} {z_{n\,\max } }}} \right)} \hfill \\ {{\text{If}}\,z_{n} \,{\text{value}}\,{\text{exceeds}}\,z_{n\,\min } \,{\text{constraint}},\,G\left( {2n} \right) = \left( {{{\left( {z_{n\,\min } - \, z_{n} } \right)*100} \mathord{\left/ {\vphantom {{\left( {z_{n\,\min } - \, z_{n} } \right)*100} {z_{n\,\min } }}} \right. \kern-\nulldelimiterspace} {z_{n\,\min } }}} \right)} \hfill \\ \end{array} $$
(4)

Amount limit value is also added to the total penalty apart from the constraints. At the end of this formulation, total feed mixture is demanded to be 100 kg. If there is a difference resulting from this value, this is also added to the total penalty.

$$ Ap_{j} = \left( {100 - \sum\limits_{i = 1}^{n} {(x_{j,i} )} } \right)^{2} $$
(5)

In the (5), difference of all dimensions total of jth particle out of 100 is squared.

Conformity (total penalty) value of the target particle is calculated by determining the total of penalties to be detected as in the (6).

$$ \psi_{j} (x) = \sum\limits_{i = 1}^{k} {\left[ {g_{i}^{j} (x)} \right]^{2} } + Ap_{j} $$
(6)

In the (6), j value refers to the jth particle. k value shows the number of the detected penalties.

3.4 Costs

In this study, the particle with the lowest cost was chosen out of the particles whose penalty values are zero or acceptable values. Cost of a particle is calculated as follows:

$$ f(x) = \sum\limits_{i = 1}^{n} {{{(x_{i} *c_{i} )} \mathord{\left/ {\vphantom {{(x_{i} *c_{i} )} {100}}} \right. \kern-\nulldelimiterspace} {100}}} $$
(7)

Cost is calculated by multiplying the amount value of food raw material kept in dimensions of each particle with the price value of that feed and then dividing it with 100.

3.5 Local and global bests

Penalty and cost values calculated for each particle are kept in different areas where local and global best values are available. Local best values are the optimum solutions belonging to that relevant particle beginning from the iteration. As for global best, it is the optimum solution that all particles reach to until the existing iteration.

Values determined in the primary iteration are taken both as local and global best values. In the following iterations, if neither of the particles is within the conformity interval, the one with the lower penalty score is chosen; if one of these chromosomes is within the conformity interval, that particle is chosen; if both chromosomes are within the conformity interval, the one with the lower cost is chosen. In accordance with this selection method, local and global best values are readjusted at every iteration.

3.6 Velocity and position updates

In PSO, data available in the dimensions of each particle are called as position information. Position information is reupdated at all iterations depending on the local and global best values. During this update process, firstly, the velocity value is calculated. Velocity values are calculated separately for all dimensions of a particle. This calculation is made as follows:

$$ v_{i}^{k + 1} = v_{i}^{k} + c_{1} .{\text{rand}}_{1}^{k} \left( {{\text{pbest}}_{i}^{k} - x_{i}^{k} } \right) + c_{2} .{\text{rand}}_{2}^{k} \left( {{\text{gbest}}^{k} - x_{i}^{k} } \right) $$
(8)

c 1 and c 2 are learning factors in the (8). Taking learning factors as 2 usually enable the users to obtain better results. Rand is a random number produced in the [0, 1] closed interval. \( {\text{pbest}}_{i}^{k} \) is the local best value of ith particle in the kth iteration. \( {\text{gbest}}_{i}^{k} \) is the global best value found up to the kth iteration. \( v_{i}^{k} \) is the velocity value in the previous iteration.

$$ x_{i}^{k + 1} = x_{i}^{k} + v_{i}^{k + 1} $$
(9)

New position value is found by adding the calculated velocity value to the previous position value (9).

3.7 Convergence test

New penalty and cost values are calculated following the calculation of velocity information and the update of the position information. Local and global best values are updated by taking these new values into account and iteration process is kept going. Termination process is conducted only when a determined penalty value or the desired number of iteration(s) is reached to.

4 Experimental results

In the study, cost optimization process was conducted on the test animals selected out of two animal groups. Coşkun et al. [17] had analyzed the low-cost feed mixtures for these animal groups by using Ms Excel Solver that includes linear programming techniques in its structure. However, there are some shortcomings as regard to Office programs on the grounds that they need to be developed constantly, the user can have various versions and some macros available in older versions have to be readjusted for the new versions. Furthermore, MS Excel Solver add-in can not conduct convergence in the event that it can not produce exact results and leaves unsettled.

In our previous study, real-coded genetic algorithms were used in the cost optimization due to the fact that linear programming does not achieve enough success in the solution of nonlinear problems. It was indicated in the studies which were carried out that real-coded genetic algorithm was not as successful as linear programming in the solution of linear problems, and it yielded more effective results in the solution of nonlinear or unsolvable problems in which linear programming remained incapable to solve them [12].

In the study where cost optimization of feed mixtures was conducted through real-coded genetic algorithm, the fact that the study was carried out more slowly than the linear programming and it yielded different results in each study shows that it can not operate in a steady manner. Thus, different methods were sought for so as to ensure steadiness. At the end of the researches, it was found out that PSO yielded effective and steady results in the solution of low parameter, nonlinear problems and yielded these results rapidly thanks to its simple algorithmic structure.

In this study, PSO was used as a method with which we thought we could cover the deficiencies of real-coded genetic algorithm.

In the study, real-coded genetic algorithm and PSO were coded in matlab program in order to test them under the same conditions. Tests were conducted in the same computer environment, and the aim was to reach to correct results. Algorithms were operated ten times for the same animal species, and certain conclusions were drawn from the recorded results.

The most outstanding finding of the study was that PSO behaved rather steadily in the solution of nonlinear problems. It was determined that genetic coded algorithm could not behave in a sufficiently steady way, and it stuck to local minimums (Table 3).

Table 3 Results (stability test)

All methods were operated ten times in the study and the average of the results was found. When the results were examined, it was observed that low-cost feed mixes having fewer penalties were available in linear programming in the solution of linear feed mix problems. However, it is observed that RCGA and PSO produce better results in the solution of nonlinear feed mix problems. While PSO yields more rapid results with fewer penalties in the solution of nonlinear problems when compared with RCGA, its cost generally becomes too high (Table 4). Primary objective to be taken into consideration during the preparation of feed mixes is low penalty rate. PSO was accepted to produce better results than RCGA as cost was a secondary factor to observe.

Table 4 Results (linear prg, RCGA, PSO)

5 Conclusions

RCGA and PSO that produce better results than linear programming in the solution of nonlinear feed mix problems which is one of the problems encountered in the optimization of feed mixtures were modeled in compliance with the problem and used. PSO is applied for the cost optimization of the feed mixtures and a software is developed by using Matlab environment, which provides flexible, extensible, and user-friendly framework for tuning the heuristic relevant parameters and improving the solution quality. According to results, PSO produces more rapid and steady results having low penalty rates but its cost is slightly higher than RCGA. It is thought that in the future studies, both steady and low-cost results will be able to be achieved through the use of different optimization methods and hybrid methods. It has already been accepted that new generation optimization techniques have a great deal of future prospects as it has direct practical utility in the field of animal nutrition.