Optimal synthesis of four-bar linkages for path generation using the individual repairing method

Constraints are one of the main factors that hinder the optimal synthesis of linkages to obtain the global optimum. At present, the most commonly used constraint handling method is called the penalty function (PF) method, but this technique has proven to be inefficient and unreliable in path synthesis. In this paper, a novel and effective constraint handling method called the individual repairing (IR) method is developed for the optimization model of four-bar mechanisms for path synthesis. The function of the IR method is to check the conformity of each individual to the Grashof condition, the sequence condition, and the variable range condition after population initialization and each iteration as well as to repair all unreasonable individuals according to the corresponding repairing technique to make them all satisfy the constraint conditions. In other words, the new constraint handling method establishes a transformation method so that each infeasible point in the search space uniquely corresponds to a feasible point. Based on the IR method, the optimization of path synthesis can be effectively carried out. Finally, the validity and reliability of the new constraint handling method are verified using three examples.


Introduction
A linkage mechanism is a kind of commonly used mechanism that is employed to realize the motion transformation and power transmission . Among various linkage mechanisms, the fourbar mechanism is essential and widely used due to its simple structure, stable output, and the fact that it is easy to control and maintain (Buśkiewicz, 2019;Kadarno et al., 2021;Lee et al., 2021;Yildiz, 2021;Zhao et al., 2014).
A class of design tasks for linkage mechanisms is called path synthesis. The purpose of path synthesis is to find the optimal dimensional parameters of a mechanism so that a point on the coupler link can move along a desired curve (Fox and Willmert, 1967;Han, 1966;Li et al., 2020;Khan et al., 2015). In general, the desired curve of path synthesis usually refers to a sequence of precision points. Because of the high nonlinearity of the problem, the path synthesis task is usually treated as an optimization problem (Marín and González, 2003). In order to ensure the rationality of the final linkage solution, three constraints are usually introduced into the op-timization model of path synthesis of four-bar mechanisms, including the Grashof condition, the sequence condition, and the variable range condition. However, the introduction of constraints leads to a highly discontinuous search space. In general, constraints are considered to be one of the main factors hindering the optimal synthesis of linkages to obtain the global optimum (Angeles et al., 1988;Acharyya and Mandal, 2009;Lin, 2010;Peñuñuri et al., 2011;Ebrahimi and Payvandy, 2015;Sleesongsom and Bureerat, 2018;Bureerat and Sleesongsom, 2021).
At present, the penalty function (PF) method is the most commonly used method to deal with the constraint conditions in path synthesis. The principle of the PF method is to add a very large value to the objective function of individuals who do not meet the constraint conditions so that these individuals will be eliminated in the optimization. However, this causes the vast majority or even all of the individuals of the initial population to be eliminated by the penalty function, especially when dealing with the sequence condition (Acharyya and Mandal, 2009;Peñuñuri et al., 2011). As a re-sult, the PF method usually requires a very large population, otherwise the optimization will be inefficient or will even fail (Sleesongsom and Bureerat, 2018;Bureerat and Sleesongsom, 2021). However, a large population is accompanied by a sharp increase in the computational cost. In this context, researchers have made some useful explorations. Acharyya and Mandal (2009) first proposed a method to rearrange the randomly generated input angles in the initial population to reduce the probability of individuals being rejected in the next iteration. Additionally, they proposed a refinement scheme to ensure that all individuals in the initial population satisfy the Grashof condition by reassigning link lengths to individuals that do not satisfy the abovementioned condition. Lin (2010) further introduced the method of rearranging input angles during both population initialization and each iteration, so that the sequence condition of input angles could be ignored until the end of the optimization. Ebrahimi and Payvandy (2015) developed an innovative technique to generate the initial population that satisfies the Grashof condition. Sleesongsom and Bureerat (2018) and Bureerat and Sleesongsom (2021) designed two new individual generation techniques for the Grashof condition and the sequence condition, respectively, which can ensure the generation of individuals that satisfy the constraints. However, the individual generation techniques that they designed did not take the parameters of the original individual into account and, instead, generated a completely new individual.
In this paper, a novel and effective constraint handling method called the individual repairing (IR) method is introduced. The principle of the IR method is to develop the corresponding repairing technique for each constraint condition of the optimization model, so as to ensure that all of the individuals in the optimization always meet the constraints. The design of these repairing techniques follows the same criterion, which is to transform the original unreasonable individual into a unique corresponding reasonable individual. In other words, the IR method transforms every infeasible point in the search space into a unique corresponding feasible point. This is the difference between this study and other relevant studies and is also the main innovation described in this work. Based on the new constraint handling method, the optimization of path synthesis can be effectively carried out.
In Sect. 2, the kinematics analysis and the classic optimization model of four-bar mechanisms for path synthesis are described. Section 3 then introduces three repairing techniques corresponding to the three constraint conditions of the classic optimization model of four-bar mechanisms for path synthesis. Following this, Sect. 4 shows the optimization results using the new IR method through three classical path synthesis tasks. Finally, the conclusions of the paper and the plan for future work are presented in Sect. 5.

Kinematics analysis
The schematic diagram of a planar four-bar mechanism is shown in Fig. 1. The mechanism is represented by nine independent design variables: Here, l 1 is the length of the fixed link AD, l 2 is the length of input link AB, and l 3 and l 4 represent the lengths of coupler link BC and output link CD, respectively. The coupler point P is a point on the coupler link BC which generates a continuous curve, and r and α determine the position of P relative to the coupler link BC. x 0 , y 0 and θ determine the offset and rotation angle of the fixed link AD relative to the coordinate system xoy, respectively. Based on the variable definition shown in Fig. 1, the position of the coupler point P can be formulated as follows: where the variable β represents the angle between the coupler link BC and the fixed link AD. Actually, the variable β is a dependent variable, and Freudenstein (1954) provides the relation equation of the variable β, the input angle φ, and the dimensional parameters of the mechanism. where The following simplified equation can then be derived: where The two solutions of Eq. (5) represent two respective branches of the four-bar mechanism. In summary, the Eq. (2) can be simplified as follows:

Classic optimization model
The path synthesis problem is usually considered to be an optimization problem, and an objective function is specified to minimize the difference between the desired curve and an actual generated curve. The tracking error is the most commonly used objective function to quantify this difference, and it is defined as the sum of the squares of the Euclidian distances between the target points and the same number of comparison points on the generated curve. In order to obtain these comparison points, the classical model introduces N input angles as optimization variables in addition to the nine design variables of the four-bar mechanism, where N is equal to the number of target points. In addition, the Grashof condition, the sequence condition, and the variable range condition are used as constraint functions in the classic optimization model of four-bar mechanisms for path synthesis. Therefore, the optimization variables of the classic model usually include the following: As a result, the classic model can be defined as follows: min subject to where (G x i , G y i ) is the position of the actual generated precision points for comparison, (D x i , D y i ) is the prescribed position of the target point, φ j = min{φ 1 , φ 2 , . . ., φ N }, mod(m, n) is the remainder of the quotient of m/n(set mod(m, m) = m), x i is the ith parameter in X 0 , and L i and U i are the lower and upper limits of the variable x i , respectively.
Constraint conditions (a)-(c) in Eq. (9) represent the Grashof condition, the sequence condition, and the variable range condition, respectively. It should be noted that this paper uses the crank-rocker mechanism as the research object, so the link AB is directly defined as the shortest link in constraint (a). In addition, it should be mentioned that the purpose of the sequence condition is to restrict the rotation direction of the crank so that it cannot be rotated backwards. Currently, some literature forces input angles to be arranged in increasing order, which overdefines the sequence condition and may lead to a reduced potential for the optimization to obtain the optimal solution. As far as we know, a reasonable expression for the sequence condition was first proposed by Cabrera et al. (2002), but they miswrote the comparison symbol in the formula. The correct definition of the sequence condition is represented in constraint (b). Finally, constraint (c) ensures that all optimization variables are within their respective predetermined reasonable ranges.

Individual repairing (IR) method
Although it is the most common constraint handling method in path synthesis, the PF method has been proven to be inefficient and to have poor repeatability (Sleesongsom and Bureerat, 2018;Bureerat and Sleesongsom, 2021;Acharyya and Mandal, 2009;Lin, 2010;Peñuñuri et al., 2011;Ebrahimi and Payvandy, 2015). Actually, using PF methods to deal with constraint functions will result in most or all of the individuals in the initial population being eliminated by penalty functions, especially when dealing with the sequence condition.
The probability that a uniform random sequence is already sorted is 1/n! (Peñuñuri et al., 2011). Therefore, the probability of randomly generated individuals meeting the sequence condition is 1/(n − 1)!. A simple example is illustrated here. For the path synthesis task with six target points, 3 000 000 individuals were randomly generated by a uniform distribution to form the initial population. Among them, the proportion of individuals conforming to the Grashof condition is 12.4944 %, the proportion of individuals conforming to the sequence condition is 0.8356 %, and the proportion of individuals conforming to both constraints is 0.1039 %. This means that the vast majority of randomly generated individuals do not satisfy the constraint conditions. In this case, the PF method will lead to the majority or even all of the individuals in the initial population being eliminated, resulting in the inefficiency or even failure of the optimization. In addition, it is easy to understand that even if the optimization is successful, the optimization completed by a few initial individuals conforming to the constraints will not have satisfactory repeatability. This is especially problematic when there are more target points.
Therefore, a new constraint handling method called the IR method is developed in this section. The principle of the IR method is to develop different individual repairing techniques corresponding to each constraint condition, so as to repair the individuals that do not meet the constraint condition after the initial population generation and each iter-  ation. The repairing techniques corresponding to the constraint conditions of the optimization model for path synthesis of four-bar mechanisms are described below.

Grashof condition repairing technique
The Grashof condition is a constraint on the link lengths of a four-bar mechanism. Its purpose is to ensure the existence of a crank in the four-bar mechanism. In this work, a linkage repairing technique is proposed to transform all of the non-Grashof linkage solutions into reasonable solutions in the optimization process. The flow of the linkage repairing technique is shown in Fig. 2.
As shown in Fig. 2, the linkage repairing technique is mainly divided into two steps, making the link lengths meet the two respective inequality constraints of the Grashof condition as shown in Eq. (9). The function of the first step is to ensure that link AB becomes the shortest link, which is easy to understand. The function of the second step is to ensure that the sum of the shortest link and longest link is less than the sum of the other two links, which may be difficult to intuitively understand. The principle of the second step is presented in Fig. 3.
Assuming that the link length values are arranged on a positive line as shown in Fig. 3, the second inequality constraint of the Grashof condition can be transformed into a more graphical representation: the thick dashed line representing the average length M 1 of the longest and shortest links must be to the left of the thin dashed line representing the average length M 2 of the remaining two links. For linkages that do not satisfy this inequality constraint, Fig. 3 shows an ingenious repairing technique that takes x = M 1 as the axis of symmetry and then redefines the values of l m and l n .  In contrast to the work of Ebrahimi and Payvandy (2015), Sleesongsom and Bureerat (2018), and Bureerat and Sleesongsom (2021), the linkage repairing technique developed in this study is based on the parameters of the irrational linkage solution itself, rather than regenerating another completely unrelated linkage solution. Based on this new technique, the repaired linkage solution is more likely to remain competitive in the next iteration.

Sequence condition repairing technique
Similar to the studies of Acharyya andMandal (2009), Lin (2010), and Ebrahimi and Payvandy (2015), this study also adopted the method of rearranging input angles in increasing order to ensure that all individuals meet the sequence condition in the optimization process. However, in contrast to the method of Acharyya and Mandal (2009) and Ebrahimi and Payvandy (2015), who randomly selected an input angle as the first angle, and the method of Lin (2010), who selected the smallest input angle as the first angle, this study keeps the original first input angle unchanged. Figure 4 shows the schematic of the angle repairing technique used in this study.
Assuming that a randomly generated set of input angles is arranged on a positive line, the angles' arrangement is likely to be chaotic, as shown in Fig. 4. The function of the angles repairing technique is to give this set of angles a new order so that the angles are neatly arranged on the positive line according to the sequence condition.

Variable range condition repairing technique
In the iterative process of population, some parameters of some individuals are likely to break through the predetermined range. At present, the commonly used optimization technique is to set the parameter value of the breakthrough range as the boundary value, but there is no relevant research on path synthesis to describe this handling technique of the variable range condition. Figure 5 illustrates the principle of this variable range repairing technique in detail.
Similarly, suppose that a parameter value and its corresponding boundary value of an individual in the population are arranged on a positive line as shown in Fig. 5. The principle of variables repairing technique is to set parameters beyond the upper boundary as the upper boundary and parameters beyond the lower boundary as the lower boundary.

Application of the IR method in optimization
Based on the three individual repairing techniques shown above, the elitism of population was guaranteed during the whole optimization procedure. Finally, the application method of these repairing techniques in the path synthesis of four-bar mechanism is shown in Fig. 6.
In Fig. 6, the variable N p represents the population number and I max represents the maximum iteration number.

Numerical examples
In order to verify the validity and reliability of the new constraint handling method, three classic path synthesis tasks are discussed in this section, including one path synthesis task without prescribed timing and two path synthesis tasks with prescribed timing. Additionally, three classical optimization algorithms are selected to search for the optimal solution. The parameters of these optimization algorithm are set as follows: 1. for the genetic algorithm (GA), C p = 0.8 and M p = 0.2; 2. for the particle swarm optimization (PSO), w = 0.7, c 1 = 1.49, and c 2 = 1.49; 3. for the differential evolution (DE), F = 0.5 and C p = 0.9.
Here, the parameters C p , M p , w, c 1 , c 2 , and F represent the crossover probability, the mutation probability, the inertia factor, the global learning weight, the local learning weight, and the scaling factor, respectively. Additionally, the population number N p is set to 100, and the maximum iteration number I max is set to 1000. Finally, results from other studies using the same optimization algorithms were compared with the results of this study.

Example 1: six target points and 15 optimization variables
This example is a path synthesis task without prescribed timing for a straight-line path with six target points. The range of the design variables in this example is defined as follows: The optimization variables are X 0 = l 1 , l 2 , l 3 , l 4 , r, α, θ, x 0 , y 0 , φ 1 , φ 2 , φ 3 , φ 4 , φ 5 , φ 6 . Table 1 shows the optimization results of the new method proposed in this study using the three optimization algorithms for Example 1. In addition, the results from Acharyya and Mandal (2009) using the same optimization algorithms are also shown in Table 1. It is worth noting that the original literature does not show the tracking error; instead, it shows the square root of the tracking error. As can be seen from Table 1, the results obtained by adopting the IR method are better than those obtained using other constraint handling methods in previous work under the same optimization algorithm. Figure 7 shows the coupler curve of the linkage solutions obtained in this study for Example 1.

Example 2: six target points and nine optimization variables
This example is a path synthesis task with prescribed timing for a semicircular arc path with six target points. The range of the design variables in this example is defined as follows: l 1 , l 2 , l 3 , l 4 ∈ [5, 50]; r ∈ [0, 70]; x 0 , y 0 ∈ [−50, 50]; α, θ ∈ [0, 2π ]; and The target points are     The optimization variables are X 0 = [l 1 , l 2 , l 3 , l 4 , r, α, θ, x 0 , y 0 ]. Table 2 shows the optimization results of the new method proposed in this study using the three optimization algorithms for Example 2. Similarly, it can be seen from Table 2 that the error of the linkage solutions obtained by the IR method is smaller than the error of the linkage solutions obtained by previous work (Acharyya and Mandal, 2009) using the same three optimization algorithms. Figure 8 shows the coupler curve of the linkage solutions obtained in this study for Example 2.

Example 3: 18 target points and 10 optimization variables
This example is a path synthesis task with prescribed timing for a path with 18 target points. The range of the design variables in this example is defined as follows: l 1 , l 2 , l 3 , l 4 ∈ [5, 50]; r ∈ [0, 70]; x 0 , y 0 ∈ [−50, 50]; α, θ ∈ [0, 2π ]; and The target points are The optimization variables are X 0 = [l 1 , l 2 , l 3 , l 4 , r, α, θ, x 0 , y 0 , φ 1 ]. Table 3 shows the optimization results of the new method proposed in this study using the three optimization algorithms for Example 3. Additionally, this example has also been studied by Cabrera et al. (2002) and Peñuñuri et al. (2011) using the GA and DE algorithms, respectively. As can be seen from Table 3, the results obtained by adopting the IR method are better using the same optimization algorithms. Figure 9 shows the coupler curve of the linkage solutions obtained in this study for Example 3.

Conclusions
In this paper, different constraint handling methods are discussed in detail, and a new constraint handling method based on the idea of individual repairing is proposed for the path synthesis of four-bar mechanisms. The function of the new method is to transform individuals that do not meet the constraints into the individuals that meet the constraints in time, so as to ensure the success and effectiveness of the optimization. More precisely, the principle of the new constraint processing method is to build a converter based on the constraints of the optimization model, so as to transform any infeasible point in the search space into a unique corresponding feasible point. Experimental results show that, compared with other constraint handling methods, the proposed method can obtain better linkage solutions using the same optimization algorithm for the same path synthesis task. The core innovation of this research is the constraint handling method based on the idea of individual repairing, which is universal in theory and can be matched with different optimization algorithms, so as to be applied to other constrained engineering optimization problems. In the future, it is planned to extend the constraint handling method based on the idea of individual repairing to the kinematics synthesis of six-bar mechanisms, eight-bar mechanisms, and other mechanisms in the field of mechanical design, including not only path synthesis but also motion synthesis and function synthesis.
Code and data availability. The code and data used in this paper can be obtained upon request from the corresponding author.
Author contributions. XY provided the ideas and wrote the first draft of the paper, XW designed the comparative experiment, WS and JK completed the code, and ZL helped modify the paper.
Competing interests. The contact author has declared that neither they nor their co-authors have any competing interests.
Disclaimer. Publisher's note: Copernicus Publications remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. Review statement. This paper was edited by Daniel Condurache and reviewed by three anonymous referees.