Next Article in Journal
A Novel Linear-Based Closed-Loop Control and Analysis of Solid-State Transformer
Previous Article in Journal
Aggregators Used in Fuzzy Control—A Review
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A Novel Ant Colony Algorithm for Optimizing 3D Printing Paths

by
Xinghan Lin
,
Zhigang Huang
*,
Wentian Shi
and
Keyou Guo
School of Computer and Artificial Intelligence, Beijing Technology and Business University, Beijing 102488, China
*
Author to whom correspondence should be addressed.
Electronics 2024, 13(16), 3252; https://doi.org/10.3390/electronics13163252
Submission received: 5 July 2024 / Revised: 31 July 2024 / Accepted: 6 August 2024 / Published: 16 August 2024
(This article belongs to the Section Systems & Control Engineering)

Abstract

:
The advancement of 3D printing technology has enabled the fabrication of intricate structures, yet the complexity of the print head’s motion path significantly hampers production efficiency. Addressing the challenges posed by the dataset of section points in 3D-printed workpieces, this study introduces an innovative ant colony optimization algorithm tailored to enhance the print head’s trajectory. By framing the optimization of the motion path as a Traveling Salesman Problem (TSP), the research employs a custom-designed K-means clustering algorithm to categorize the dataset into distinct clusters. This clustering algorithm partitions each printing point into different subsets based on density, optimizes these subsets through improved K-means clustering computations, and then aggregates the results to classify the entire dataset. Subsequently, the ant colony algorithm arranges the printing sequence of these clusters based on the cluster centers, followed by computing the shortest path within each cluster. To form a cohesive motion trajectory, the nearest nodes between adjacent clusters are linked, culminating in a globally optimal solution. Comparative experiments repeatedly demonstrate significant enhancements in the print head’s motion path, leading to marked improvements in printing efficiency.

1. Introduction

Three-dimensional printing is a computer-controlled process that constructs objects layer by layer and has found applications across various industries [1,2]. At the heart of this technology is the central control system of the 3D printer, which is crucial for coordinating tasks such as motion control, temperature regulation, limit sensing, and automatic leveling [3,4,5,6,7,8]. This central module processes G-Code instructions from the slicing software on a PC, directing the printer’s mechanisms to function in unison and complete the printing process [9,10,11,12,13]. Motion control plays a pivotal role in determining the manufacturing efficiency and the quality of the final product. Path planning, a critical aspect of motion control, orchestrates the movement of the print head to optimize the printing process, significantly impacting both quality and efficiency [14]. Currently, the commonly used Z-type and biased-wheel-contour path planning algorithms exhibit marked limitations, particularly in handling large parts. With the growing integration of artificial intelligence, the development of intelligent path planning algorithms for 3D printing is set to gain prominence [15].
After many years of development, the intelligent path optimization algorithm has developed rapidly. In the research of 3D printing path planning, Liu et al. [16] proposed a reciprocating parallel scanning method. This algorithm is simple to calculate, and the scanning path forms a return line to print inside the contour; however, this method has a single structure, and multiple starts and stops can easily cause surface deformation of the model, resulting in defects such as wire drawing and warping. Wang et al. [17] proposed an adaptive path optimization method on this basis. This method starts with the longest side to fill the internal contour, which can reduce the number of nozzle starts and stops, change the traditional parallel line filling method, and improve the quality of the molded material. Kamnik et al. [18] proposed a printing method of parallel offsetting of the outer contour, which improves the accuracy, especially for uniform wall thickness solid models. However, when the outer contour line is complex and the model has an inner contour, this situation increases the difficulty of the algorithm, requiring a large amount of calculation, thus increasing the printing time. To this end, Zhao et al. [19] proposed a variable offset printing path optimization, using a non-equidistant offset contour method. This filling method can change the traditional offset distance, and when encountering an inner contour, it will adaptively adjust the distance, thus reducing the calculations, optimizing the internal filling, and improving the printing efficiency. Yang et al. [20] proposed a method for optimizing the printing path using fractal curves. By dividing the outer contour into multiple curves for internal offset planning, this approach resembles a partitioned form where each small segment serves as a starting edge for inward movement. This technique ensures a more uniform movement curve within the internal area. However, the challenge lies in determining the optimal number of segments, as too many or too few can adversely affect the forming quality.
The motion path of the printing head for each layer in 3D printing bears a significant resemblance to the Traveling Salesman Problem (TSP), a classic optimization problem that seeks the shortest possible route for a traveler to visit a set of locations and return to the origin point. This analogy arises because the print head must traverse numerous discrete points (representing the geometry of the layer) in the most efficient manner to minimize travel time and enhance print quality. Despite its straightforward definition, the TSP is computationally challenging to solve, especially as the number of points increases, leading to combinatorial explosion.
With the advancement of evolutionary algorithms, heuristic methods have emerged to tackle the complexities of TSP. Among these, the ant colony optimization (ACO) algorithm is particularly noteworthy. Inspired by the foraging behavior of ants, ACO is robust and flexible, making it a favored approach in various optimization tasks. However, ACO’s efficacy diminishes when applied to large-scale TSP instances due to its propensity to become trapped in local optima.
To mitigate this issue, Li Zhen introduced a K-means clustering ant colony algorithm [21]. This algorithm first employs K-means clustering to group the data points, then applies ACO within each cluster. The algorithm enhances exploration by mutating data points with low pheromone concentrations and boosting the pheromone levels of promising paths. Despite its innovative approach, this method is computationally intensive and often exhibits low solving efficiency.
Expanding on this concept, Zheng Xufeng et al. proposed another K-means clustering ant colony algorithm tailored for TSP problems with inherent clustering characteristics [22]. This method uses K-means to partition the TSP into manageable subproblems, which are then solved and reassembled. Although this approach improves solving efficiency, it does not address the inherent limitations of ACO, such as its vulnerability to premature convergence [23].
In parallel, other researchers have focused on optimizing the motion paths of 3D printing nozzles. Thompson and Yoon developed a method to reduce filament waste by maintaining a constant nozzle velocity and adopting a rapid transition motion profile [24,25]. This approach minimizes speed fluctuations, significantly enhancing print quality by predicting and correcting velocity errors.
Ganganath et al. conceptualized the nozzle path optimization as a TSP, proposing several modified TSP algorithms evaluated through computer simulations [26]. These simulations, focusing on single-layer print segments, demonstrated considerable improvements over traditional greedy-based solvers. Building on this foundation, Fok et al. refined a Christofides-based solver and applied it to complex, real-life 3D models [26,27]. Their results indicated that this algorithm outperforms the widely used Cura(15.04) slicing software in terms of path optimization and print quality [28]. In path optimization at slicing time, in study [29], a novel slicing method has been developed that allows for slicing implicit surfaces and generating printing paths without the need for stereolithography (STL) files, thereby avoiding slicing errors introduced by meshing steps. By slicing each implicit surface separately, the corresponding G-code files are generated. The literature [30] proposes a five-axis path planning method based on spherical slicing. By leveraging an implicit expression equation based on cylinders, this approach effectively achieves efficient surface slicing and the generation of five-axis spherical paths.
These advancements illustrate the continuous evolution of optimization algorithms in 3D printing, highlighting the importance of addressing both computational efficiency and practical implementation challenges to achieve superior printing outcomes. However, the aforementioned methods perform poorly when faced with significant variations in print density and the simultaneous printing of multiple objects. Therefore, this paper develops a novel ant colony algorithm to address these issues.
In this paper, a novel ant colony algorithm is proposed to optimize the motion path of the printing head for the characteristics of the 3D printing workpiece section point dataset. The proposed method equates the optimization of the printing head motion path to a TSP problem, and uses the designed novel K-means clustering algorithm to segment the printing point dataset reached by the printing head. After the entire dataset is divided into multiple clusters, the printing order of the clusters is sorted by the ant colony algorithm and the cluster centers, and then, the shortest route of each cluster is calculated. Finally, the nearest nodes between adjacent clusters are connected to obtain a complete printing head motion path, i.e., the global optimal solution. The contributions of this paper are as follows:
(1)
A novel K-means clustering algorithm for 3D printing model section data;
(2)
By using the novel K-means clustering algorithm designed in this paper to segment the printing area of the 3D printing model section, the ant colony algorithm is optimized to obtain a better 3D printing head motion path.
The remainder of this paper is organized as follows. The TSP problem in 3D printing is introduced in Section 2 and the path planning framework is presented in Section 3. The experiment results are described and discussed in Section 4 and the paper is finally concluded in Section 5.

2. Related Work

Three-dimensional printing requires a good algorithmic control and trajectory optimization strategy to control the motion of stepper motors and improve the overall performance of 3D printing. In this section, the optimization of the print head trajectory is transformed into the Traveling Salesman Problem (TSP).

2.1. TSP Problem in 3D Printing

The motion actuator for controlling the motion trajectory in 3D printing is a precision stepper motor. The pulse signals for the stepper motor are generated by the host computer in the form of G-Code instructions. These signals are then transmitted to the controller, which executes the G-Code instructions to manipulate the stepper motor and initiate rotation. The rotation of the stepper motor drives the rotation of the lead screw, resulting in the movement of the print head. In computer systems, 3D models are mostly represented as spaces enveloped by triangular facets. These models are sliced into a series of two-dimensional cross-sections using slicing software. The control of how the print head moves within these two-dimensional planes is a key technological aspect in 3D printing process control research. When the motion trajectory of the print head is optimized, both printing efficiency and quality can be significantly improved. Typically, the motion trajectory in 3D printing is planned within the Cartesian coordinate system, with the trajectories mostly being straight lines. Although straight lines are convenient and efficient, they do not necessarily yield the highest operational efficiency. In this paper, we treat the motion trajectory of the print head as a TSP-like problem, aiming to optimize it by solving the TSP problem.
As a classic problem in combinatorial optimization, the TSP can be conceptually described as follows: A traveling salesman needs to visit n cities, starting from one city and then traversing all the remaining cities. Each city can only be visited once, and the salesman must return to the starting city. The core of this problem lies in how to plan the route to minimize the distance traveled by the salesman while completing the task. The significance of TSP can be more intuitively described by the concept of a Hamiltonian cycle in graph theory. A Hamiltonian cycle refers to a cycle that includes all nodes without any branches. Therefore, the TSP is also known as the minimum Hamiltonian cycle problem.

2.2. Mathematical Model of TSP Problem

The optimization of the 3D printing trajectory primarily involves optimizing the path of the print head as it passes through a large number of coordinate points. For a given weighted undirected graph G = V , W , where V is the set of vertices and W is the set of edges, we aim to find a Hamiltonian cycle C in G. The total weight of C is defined as follows:
w ( C ) = v i , v j C w v i , v j
such that the total power of C is minimized. If the paths passing between the nodes are denoted by x i j , i.e., the decision variables are as follows:
x = 0   v i , v j C 1   v i , v j C
Then, the TSP problem’s objective function is expressed as follows, requiring the minimum total distance of the print head through the path:
min Z = i V j V d i j x i j
where d i j denotes the Euclidean distance between data points i and j .
s . t .           j V x i j = 1 ,     i = 1 , , n                         i V x i j = 1 ,     j = 1 , , n
The print head of a printer can be seen as the traveling salesman in the TSP problem, with the points to be printed representing the cities. For complex-shaped printing objects, the size of the city set can be very large, reaching hundreds of thousands or even millions of coordinate points. Therefore, for such complex print jobs, the path planning of the print head is of great importance.

2.3. Summary of Previous Works

To provide a clearer understanding of previous works in the field of 3D printing technology and TSP optimization, we have summarized the key approaches and findings in Table 1.

3. Algorithm

In this section, we first discuss the ant colony algorithm and its corresponding main state formulation, secondly, we discuss the related clustering methods, and finally propose a new ant colony algorithm in this paper based on the discussed ant colony algorithm and clustering methods.

3.1. Principle of Ant Colony Algorithm

The ant colony algorithm is a type of optimization algorithm that simulates the foraging behavior of ants. Its basic principle originates from the shortest path problem encountered by ants in nature. Based on observations by entomologists, it has been found that ants in nature, despite having underdeveloped vision, can find the shortest path from a food source to their nest without any explicit cues. They can also adaptively search for new optimal paths when the environment changes, such as the presence of obstacles on the original path.
When ants search for food sources, they release a specific secretion known as pheromones along the path they have traveled. These pheromones can be detected by other ants within a certain range, influencing their future behavior. As more ants pass through certain paths, they deposit more pheromones, leading to an increase in pheromone intensity (which gradually weakens over time). Consequently, the probability of ants choosing that path also increases, further enhancing the intensity of pheromones on that path. This selection process is referred to as the self-stimulatory behavior of ants. Due to its principle of positive feedback, the ant colony algorithm can also be understood as a form of reinforcement learning system, often referred to as an enhanced learning system or “ant colony”.

3.2. Main State Calculation

For the TSP problem, without loss of generality, let us assume the total number of ants in the ant colony is m , and the number of cities is n. The distance between city i to city j is denoted as d i j for i , j = 1 , 2 , , n . The concentration of pheromones on the connection path between city i and city j at time t is denoted as τ i j t . At the initial time, ants are placed in different cities, and the concentration of pheromones on the connection paths between cities is the same, denoted as τ i j 0 = τ 0 . Then, ants will choose routes according to certain probabilities. Let P i j k t denote the random probability of ant k at time t transitioning from city i to city j . We know that the “Ant TSP” strategy is influenced by two factors: the expectation of visiting a certain city and the concentration of pheromones released by other ants. Therefore, the random probability P i j k t is defined as follows:
P i j k t = τ i j t α η i j t β μ J k i τ i j t α η i j t β ,   j J k i 0 ,     Otherwise
where J k i is the set of cities that ants have not yet traversed; τ i j t represents the concentration of pheromones on the edge i , j at time t; η i j t represents the heuristic expectation of transitioning from city i to city j , given by η i j t = 1 / d i j ; and parameter α represents the importance factor of pheromones, where a larger value increases the likelihood of ants following the path of previous ants, reducing randomness. When this value is small, although the randomness of the search is increased, the convergence speed of the algorithm may become slower. Parameter β represents the importance factor of the heuristic function. If it is too large, the randomness of the algorithm decreases, leading to a higher chance of becoming trapped in local optima. When β is small, although the randomness of the algorithm increases, the difficulty of optimization also increases.
During the process of ants traversing cities, a characteristic similar to the actual scenario is that while ants release pheromones, the strength of pheromones on the connection paths between cities gradually diminishes through evaporation and other means. To describe this feature, let ρ 0 < ρ < 1 represent the evaporation factor of pheromones. Thus, after all ants have completed a full traversal of all cities, the concentration of pheromones on the connection paths between cities can be expressed as follows:
τ i j t + n = 1 ρ τ i j t + Δ τ i j Δ τ i j = k = 1 m Δ τ i j k
where Δ τ i j represents the increment in pheromones after one iteration; the ρ directly affects the pheromone content on the path, which in turn affects the global search ability and convergence speed of the algorithm. The pheromones left on the path i , j by the k-th ant in a certain iteration is the following equation:
Δ τ i j k = Q L k ,   Ant   k   passes   through   i , j   on   this   tour 0 ,     Otherwise
where Q is the normal number; L k denotes the length of the path taken by ant k.

3.3. Clustering Algorithm

The K-means clustering algorithm is characterized by its clear semantics, simple structure, and fast computation speed. For solving large-scale TSP problems, the introduction of the K-means algorithm allows for dividing unevenly distributed city locations into a specified number of clusters [37]. Since the ant colony algorithm is more suitable for solving small-scale TSP problems, incorporating this idea can effectively address the drawbacks of slow computation speed and unstable results in the ant colony algorithm.

3.3.1. K-Means Clustering

The K-means clustering algorithm divides the original dataset into k disjointed clusters. First, k initial cluster centers are randomly selected, and the Euclidean distance between the remaining data points and the initial cluster centers is computed. According to the nearest neighbor principle, the data points with the smallest distance are assigned to the cluster corresponding to the closest cluster center. After the assignment is completed, the new cluster centers are recalculated. Finally, the new Euclidean distances between each cluster center and each data point are computed, and the process is iterated until a predetermined threshold is reached to stop the computation. When using the K-means clustering algorithm for image segmentation, clustering is performed based on the features of image pixels. Let x × y be the resolution of an image and k be the number of clusters. Given an input pixel P x , y and a cluster center C k , the computation principle is as follows:
(1)
Select a reasonable k initial clustering centers C k ( 0 ) ;
(2)
Calculate the Euclidean distance d between the image center and each pixel according to Equation (1):
d = p x , y C k
(3)
Assign all pixels to the nearest center based on the distance d ;
(4)
Recalculate new clustering centers according to Equation (2) after all pixels have been assigned:
C k = 1 k y C k x C k P x , y
(5)
Repeat the iterative calculation until the determined threshold value is satisfied and then stop the calculation.
The bulleted list of the K-means algorithm is shown below:
  • Initialization: randomly select k data points as initial centroids;
  • Assignment: assign each data point to the cluster of the nearest centroid;
  • Update: recalculate the centroid of each cluster as the mean of all data points in the cluster;
  • Convergence: repeat the assignment and update the steps until the centroids no longer change or a preset number of iterations is reached.
Although it has some advantages, such as simplicity and efficiency, the K-means clustering algorithm also has some disadvantages. Here are some of the drawbacks of the K-means clustering algorithm:
(1)
The initial selection of cluster centers has a significant impact on the results: The K-means algorithm requires the selection of initial cluster centers at the beginning, and this choice can greatly influence the final clustering results. Improper initial center selection may lead to inaccurate or unstable clustering results;
(2)
Sensitivity to initial cluster centers: The K-means algorithm is highly sensitive to the choice of initial cluster centers. Different initial center selections may result in different clustering outcomes. This means that when applying the K-means algorithm, it is necessary to try different initial centers multiple times to obtain better clustering results;
(3)
Sensitivity to cluster shapes and sizes: The K-means algorithm assumes that each cluster has a convex shape, and the size differences between clusters are not significant. This implies that if there are clusters with non-convex shapes or clusters with large differences in sizes in the dataset, the K-means algorithm may not accurately capture the structure of these clusters;
(4)
Sensitivity to noise and outliers: The K-means algorithm is highly sensitive to noise and outliers. Individual noise points or outliers can affect the entire clustering result, leading to inaccurate clustering results;
(5)
Requires pre-specification of the number of clusters: The K-means algorithm requires the pre-specification of the number of clusters, denoted as K. However, in practical applications, we often do not know the optimal number of clusters. Choosing an inappropriate number of clusters can result in inaccurate clustering results;
(6)
Not suitable for handling nonlinear data: The K-means algorithm is based on the Euclidean distance, which makes it perform well on linearly separable data; however, for nonlinearly separable data, the K-means algorithm may not produce reasonable clustering results.
Therefore, it is clear from the above-mentioned disadvantages that the method cannot be applied to various point sets of 3D-printed cut surfaces, and improvements are needed for the related disadvantages.

3.3.2. Novel K-Means Clustering

Due to the absence of “noise” points in the printing points of all the sections in 3D printing, there is no interference from “noise” points. However, the printing points in the sections of printed objects with uneven internal filling are sparse, which means that the density of the printing points varies greatly due to different filling ratios. Therefore, the classical K-means algorithm is not suitable for this type of dataset. In addition, the algorithm heavily relies on the selection of initial cluster centers and requires prior knowledge of the number of clusters, which limits the application of the K-means clustering algorithm in the segmentation of 3D printing section point sets.
To address the shortcomings of the K-means clustering algorithm mentioned above, this paper proposes a new type of K-means clustering algorithm. The idea of this algorithm is as follows: First, calculate the density of each printing point, and based on the density, divide the printing points into multiple groups of datasets where the printing points in each group have similar density values. Then, analyze the number of cluster centers based on each group of datasets, evaluate the clustering results with different numbers of cluster centers using the silhouette coefficient, and obtain a reasonable number of cluster centers. Next, use the corresponding point with the highest density as the initial point for each cluster center, and recompute the K-means clustering for the datasets. Perform the aforementioned clustering calculation for each group of datasets to obtain the classification of each group. Finally, merge all the clustering clusters together to form the final classification result. The calculation principle of this new clustering algorithm is as follows:
(1)
Calculate the density ρ i of each data point i:
ρ i = i j , j = 1 n χ d i j ε 0
where χ · is a logical judgment function, when · < 0 , χ · = 1 otherwise χ · = 0 ; ε 0 is the neighborhood truncation distance of data point i, and can be calculated as ε 0 = α N i = 1 N d i ( k ) ; α is a scaling factor typically chosen between 1 and 2; N is the total number of data points; d i ( k ) represents the distance between data point i and its k-th nearest neighbor [38];
(2)
Based on the density values calculated in the previous step, the density point set is divided. The division method first calculates the number of points within each unit range for each density value ε ρ , and then divides the dataset into λ datasets H 1 , H 2 , , H λ based on the density value where the number of points in the unit range is less than the number of points in two adjacent unit ranges. ε ρ is a unit scale of ρ in the partition Formula (10), which can be optimized through the backpropagation algorithm;
(3)
For the dataset H i in the previous step, K-means cluster analysis is performed while the cluster centers are calculated from 2 to m to obtain the classification results for the corresponding pairs, and then their contour coefficients are calculated separately; the corresponding contour coefficients are calculated as follows:
s i = b i a i max a i , b i
where a i is equal to the average of the dissimilarity of data point i to other points in the same cluster; and b i is equal to the minimum of the average dissimilarity of data point i to other clusters. The optimal number of clusters is selected by the contour coefficients, and the final result of the selected optimal number of clusters ο i is the classification result H i c 1 i , c 2 i , , c ο i i of the dataset H i ;
(4)
Finally, the classification results of all datasets H 1 , H 2 , , H λ are aggregated to obtain the final clustering results:
c 1 1 , c 2 1 , , c ο 1 1 , c 1 2 , c 2 2 , , c ο 2 2 , , c 1 i , c 2 i , , c ο i i , , c 1 λ , c 2 λ , , c ο λ λ
The flowchart of the new K-means clustering algorithm is shown in the Figure 1 below:

3.4. Novel Ant Colony Algorithm

The novel ant colony algorithm utilizes the Novel K-means clustering algorithm to partition and split large-scale TSP (Traveling Salesman Problem) instances into K small regions. Then, the TSP problem is solved once for each of these K regions to obtain the printing sequence for each region. After that, the ACA (ant colony algorithm) is applied to each region to obtain the movement trajectory of the printing heads. The computational principle of this new ant colony algorithm is as shown in Algorithm 1:
Algorithm 1 Novel ant colony algorithm
1: Select a collection of large-scale 3D printing data points;
2: Use Equation (10) to calculate the density ρ i for each data point i;
3: Based on the density values calculated in the previous step, the density point set is divided;
4: K-means clustering analysis is performed for the dataset in the previous step, while the cluster centers are calculated from 2 to m to obtain the classification results for the corresponding;
5: The contour coefficients are calculated using Equation (11), and the optimal number of clusters is selected by the contour coefficients to obtain the classification result H i c 1 i , c 2 i , , c ο i i of the dataset H i ;
6: Aggregate the classification results of all datasets to obtain the final clustering segmentation results;
7: The ant colony algorithm solves the paths for all the clustering centers and obtains the printing order between the regions;
8: Based on the printing order, the path is solved for each of the K regions of each cut separately using the ant colony algorithm;
9: Aggregate the print head motion paths for all areas.

4. Results

In this section, we carry out experimental studies based on the number of prints printed simultaneously. In order to verify the timeliness of the proposed algorithm, simulations are conducted to compare the proposed algorithm with the simple linear path planning algorithm, loopback algorithm, Archimedean spiral path planning algorithm, and the Hilbert curve path planning algorithm. The experiments are divided into two groups: the first group of experiments in which 10 prints are selected to be printed together; the second group of experiments uses 20 prints to be printed together. Each group of experiments compares the printing time after path planning for several algorithms.

4.1. Test Platform

The 3D printer system employed in this paper is a desktop-level control system comprising a general PC, MCU (Microcontroller Unit), and hardware control card. This system performs complex path planning calculations on the computer, using a decoupled approach between the computer and the printer. This allows the printer to operate independently from the computer, enhancing the performance of the entire printer control system. The printer’s logic control unit utilizes an ARM AT32F403, and the software environment is Marlin 2.0. The motherboard and printer platform are shown in Figure 2. Additionally, we used Python 3.12 to develop our algorithms and conduct experiments, generating our own slicing results.

4.2. Experiment I

In this part of the experiment, a scene with 10 different regular parts printed together is selected, as shown in Figure 3 (a 60° view from the front). The linear path planning algorithm, loopback algorithm, Archimedean spiral path planning algorithm, the Hilbert curve path planning algorithm, and the algorithm proposed in this paper are used to path plan the printed parts in this scene, and the print head motion path of its single layer is shown in Figure 4.
The linear path planning algorithm, loopback algorithm, Archimedean spiral path planning algorithm, the Hilbert curve path planning algorithm, and the single-layer print path planned by the algorithm proposed in this paper are shown in Figure 4 and Figure 5. Through observation, it is evident that the proposed algorithm in this paper results in shorter inter-region connecting lines, allowing for a direct visual comparison that demonstrates the superiority of our algorithm over several others. Furthermore, regarding the time consumption of various trajectory planning algorithms, the performance test parameters for printing one layer are presented in the Table 2 below.

4.3. Experiment II

This section of the experiment selected a scenario where 20 different rule parts are printed together, as shown in Figure 6 (a 45° view from the front). The linear path planning algorithm, the loop algorithm, the Archimedean spiral path planning algorithm, the Hilbert curve path planning algorithm, and the algorithm proposed in this paper were used to plan the paths of the printed parts in this scenario. The movement path of the print head for each layer is shown in Figure 7.
The linear path planning algorithm, loopback algorithm, Archimedean spiral path planning algorithm, the Hilbert curve path planning algorithm, and the single-layer print path planned by the algorithm proposed in this paper are shown in Figure 7 and Figure 8. Similarly, through observation, it was found that the proposed algorithm in this paper features shorter connecting lines between regional blocks, allowing for a direct visual comparison that demonstrates the superior path efficiency of our algorithm compared to others. Additionally, calculations using the ant colony algorithm indicate that the overall printing sequence between modules is superior to that of the other algorithms. The performance test parameters for printing a single layer, focusing on the time consumption of each trajectory planning algorithm, are presented in the Table 3 below.

4.4. Discussion

According to the data in the above table, the proposed method optimizes the time consumption of printing due to the path optimization, which results in a shorter path of the print head. Based on Experiment I and Experiment II, the total time consumption of the proposed algorithm is improved by 9.6 and 10.5% compared to the linear path planning method, respectively; 8.0% and 9.1% compared to the loopback path planning algorithm, respectively; 7.8% and 10.3% compared to the Archimedean spiral path planning algorithm, respectively; and 45.9% and 40.1% compared to the Hilbert curve algorithm. In addition, we test another 100 sets of models to obtain the experimental results in Figure 9. Our proposed algorithm consumes less time than several other methods. Therefore, it can be proven that the proposed algorithm in this paper has better timing performance for the case of simultaneous printing of multiple parts, and the more parts are printed, the better the timing performance is. However, it should be noted that the method proposed in this paper does not have much advantage if a simple part is printed alone.
The 3D printing process consists of three main steps: 3D modeling, slicing, and printing with a 3D printer. The algorithm we proposed is utilized during the slicing stage, which is executed on a computer. It is important to note that our proposed algorithm has a higher slicing time consumption compared to other algorithms. Specifically, in Experiment I, the slicing time for our proposed algorithm was 471 s, while the slicing times for the linear path planning algorithm, loopback algorithm, Archimedean spiral path planning algorithm, and Hilbert curve path planning algorithm were 253 s, 198 s, 292 s, and 337 s, respectively. In Experiment II, the slicing time for our proposed algorithm was 788 s, whereas the slicing times for the linear path planning algorithm, loopback algorithm, Archimedean spiral path planning algorithm, and Hilbert curve path planning algorithm were 361 s, 308 s, 411 s, and 485 s, respectively. Although our proposed algorithm increases the slicing time, it optimizes the printing path planning for large-scale industrial device production, where slicing is only performed once. This optimization can significantly reduce the overall 3D printing time during subsequent large-scale production, thereby greatly saving production time.
In addition, the proposed algorithm is primarily designed for 3D printers using thread-based materials. Meanwhile, the proposed algorithm is implemented using Python programming language and generates G-code. The basic processing workflow includes the following: reading the 3D model, slicing along the Z-axis, generating paths (with our proposed algorithm), generating the G-code, and outputting the G-code.

5. Conclusions

This paper proposes a new ant colony algorithm to optimize the motion path of the print head. The proposed method equates the optimization of the print head motion path to a TSP problem and uses a newly designed K-means clustering algorithm to divide the print point dataset reached by the print head. After the whole dataset is divided into multiple clusters, the printing order of the clusters is sorted by the ant colony algorithm and the cluster center, and then the shortest route of each cluster is calculated. Finally, the nearest nodes between adjacent clusters are connected to obtain a complete motion path of the print head, that is, the global optimal solution.
The key findings from our study are as follows:
Optimization efficiency: the ant colony algorithm significantly optimized the motion path of the print head, resulting in reduced transition times and improved overall printing efficiency;
Clustering effectiveness: the application of the K-means clustering algorithm effectively divided the print points, facilitating a more manageable and efficient path optimization process;
Comparison results: repeated comparison experiments demonstrate that the optimized motion path consistently outperformed traditional methods in terms of both path length and printing speed.
These findings provide a robust basis for further research in the field of 3D printing optimization. The methodologies and algorithms presented in this study can be adapted and expanded upon for various 3D printing scenarios, potentially leading to even greater efficiencies and advancements in the technology.
In the future, we would like to work on 3D printing optimization techniques and further explore our path optimization technique for a wider range of multiple 3D manufacturing. Additionally, the integration of machine learning techniques with the proposed algorithms could provide further improvements and new insights into the optimization of complex 3D printing processes.

6. Recommendations for Future Research

Given the promising results of our study, we recommend the following directions for future research:
  • Integration with machine learning: exploring the integration of machine learning techniques with our proposed algorithms to enhance the adaptability and efficiency of the optimization process;
  • Real-time path optimization: developing real-time path optimization algorithms that can dynamically adjust to changes during the printing process, ensuring continuous optimization;
  • Multi-material printing: investigating the application of our optimization techniques in multi-material 3D printing scenarios to address the unique challenges posed by different material properties.
  • Scalability: testing the scalability of our algorithms with larger and more complex datasets to ensure they can handle industrial-scale 3D printing tasks.
These research directions aim to build on the foundation laid by our current study and contribute to the ongoing advancement of 3D printing technologies.

Author Contributions

Conceptualization, X.L. and Z.H.; methodology, Z.H.; software, X.L. and W.S.; validation, K.G., W.S. and X.L.; formal analysis, W.S. and Z.H.; investigation, X.L.; writing—original draft preparation, X.L.; writing—review and editing, X.L. and Z.H.; funding acquisition, Z.H. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the National Key Research and Development Program of China, grant number 2022YFC2406000.

Data Availability Statement

The original contributions presented in the study are included in the article, further inquiries can be directed to the corresponding author/s.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Romeo, J. Plastics Engineering’s New Frontier: Embracing the Brave New World of 3D Printing. Plast. Eng. 2019, 75, 22–27. [Google Scholar] [CrossRef]
  2. Podsiadły, B.; Bezgan, L.; Słoma, M. 3D Printed Electronic Circuits from Fusible Alloys. Electronics 2022, 11, 3829. [Google Scholar] [CrossRef]
  3. Padole, M.; Gharde, S.; Kandasubramanian, B. Three-dimensional printing of molluscan shell inspired architectures via fused deposition modeling. Environ. Sci. Pollut. Res. 2021, 28, 46356–46366. [Google Scholar] [CrossRef]
  4. Lee, M.P.; Cooper, G.J.T.; Hinkley, T.; Gibson, G.M.; Padgett, M.J.; Cronin, L. Development of a 3D Printer Using Scanning Projection Stereolithography. Sci. Rep. 2015, 5, 9875. [Google Scholar] [CrossRef] [PubMed]
  5. Ventola, C.L. Medical Applications for 3D Printing: Current and Projected Uses. Pharm. Ther. 2014, 39, 704–711. [Google Scholar]
  6. Berman, B. 3-D Printing: The New Industrial Revolution. Bus. Horiz. 2012, 55, 155–162. [Google Scholar] [CrossRef]
  7. Yu, Y.; Liu, F.; Liu, J. Direct 3D Printing of Low Melting Point Alloy via Adhesion Mechanism. Rapid Prototyp. J. 2017, 23, 642–650. [Google Scholar] [CrossRef]
  8. Warrier, N.; Kate, K.H. Fused Filament Fabrication 3D Printing with Low-Melt Alloys. Prog. Addit. Manuf. 2018, 3, 51–63. [Google Scholar] [CrossRef]
  9. Salo, T.; Di Vito, D.; Halme, A.; Vanhala, J. Electromechanical Properties of 3D-Printed Stretchable Carbon Fiber Composites. Micromachines 2022, 13, 1732. [Google Scholar] [CrossRef]
  10. Tang, Z.; Jia, S.; Zhou, C.; Li, B. 3D printing of highly sensitive and large-measurement-range flexible pressure sensors with a positive piezoresistive effect. ACS Appl. Mater. Interfaces 2020, 12, 28669–28680. [Google Scholar] [CrossRef]
  11. Kim, E.; Khaleghian, S.; Emami, A. Behavior of 3D Printed Stretchable Structured Sensors. Electronics 2023, 12, 18. [Google Scholar] [CrossRef]
  12. Mazzanti, V.; Malagutti, L.; Mollica, F. FDM 3D printing of polymers containing natural fillers: A review of their mechanical properties. Polymers 2019, 11, 1094. [Google Scholar] [CrossRef] [PubMed]
  13. Shang, J.; Tian, X.; Luo, M.; Zhu, W.; Li, D.; Qin, Y.; Shan, Z. Controllable inter-line bonding performance and fracture patterns of continuous fiber reinforced composites by sinusoidal-path 3D printing. Compos. Sci. Technol. 2020, 192, 108096. [Google Scholar] [CrossRef]
  14. Li, N.; Link, G.; Wang, T.; Ramopoulos, V.; Neumaier, D.; Hofele, J.; Walter, M.; Jelonnek, J. Path-designed 3D printing for topological optimized continuous carbon fibre reinforced composite structures. Compos. Part B Eng. 2020, 182, 107612. [Google Scholar] [CrossRef]
  15. Liu, H.H.; Zhao, T.; Li, L.Y.; Liu, W.J.; Wang, T.Q.; Yue, J.F. A path planning and sharp corner correction strategy for wire and arc additive manufacturing of solid components with polygonal cross-sections. Int. J. Adv. Manuf. Technol. 2020, 106, 4879–4889. [Google Scholar] [CrossRef]
  16. Zhen, X.; Seng, J.C.Y.; Somani, N. Adaptive automatic robot tool path generation based on point cloud projection algorithm. In Proceedings of the 2019 24th IEEE International Conference on Emerging Technologies and Factory Automation (ETFA), Zaragoza, Spain, 10–13 September 2019; IEEE: Piscataway, NJ, USA, 2019; pp. 341–347. [Google Scholar]
  17. Kraljić, D.; Kamnik, R. Trajectory planning for additive manufacturing with a 6-dof industrial robot. In Advances in Service and Industrial Robotics: Proceedings of the 27th International Conference on Robotics in Alpe-Adria Danube Region (RAAD 2018), Bucharest, Romania, 27–29 May 2015; Springer: Cham, Germany, 2018; pp. 456–465. [Google Scholar]
  18. Zhao, G.; Ma, G.; Feng, J.; Xiao, W. Nonplanar slicing and path generation methods for robotic additive manufacturing. Int. J. Adv. Manuf. Technol. 2018, 96, 3149–3159. [Google Scholar] [CrossRef]
  19. Yang, J.; Bin, H.; Zhang, X.; Liu, Z. Fractal scanning path generation and control system for selective laser sintering (SLS). Int. J. Mach. Tools Manuf. 2003, 43, 293–300. [Google Scholar] [CrossRef]
  20. Li, J.; Chen, Z.; Harabor, D.; Stuckey, P.J.; Koenig, S. Anytime multi-agent path finding via large neighborhood search. In Proceedings of the International Joint Conference on Artificial Intelligence (IJCAI), Montreal, QC, Canada, 19–27 August 2021. [Google Scholar]
  21. Li, Z. Research on K-Means Algorithm and Its Integration with Intelligent Algorithms; Anhui University: Hefei, China, 2016. [Google Scholar]
  22. Zheng, F.; Zhou, J. K-means Clustering ant Colony Algorithm for Large-scale TSP Problems. Logist. Technol. 2018, 2, 37–40. [Google Scholar]
  23. Fok, K.Y.; Cheng, C.T.; Ganganath, N.; Iu, H.H.C.; Chi, K.T. An ACO-based Tool-Tath Optimizer for 3-D Printing Applications. IEEE Trans. Ind. Inform. 2018, 15, 2277–2287. [Google Scholar] [CrossRef]
  24. Thompson, B.; Yoon, H.S. Efficient path planning algorithm for additive manufacturing systems. IEEE Trans. Compon. Packag. Manuf. Technol. 2014, 4, 1555–1563. [Google Scholar] [CrossRef]
  25. Thompson, B.; Yoon, H.S. Velocity-regulated path planning algorithm for aerosol printing systems. J. Manuf. Sci. Eng. 2015, 137, 20–31. [Google Scholar] [CrossRef]
  26. Ganganath, N.; Cheng, C.T.; Fok, K.Y.; Tse, C.K. Trajectory planning for 3D printing: A revisit to traveling salesman problem. In Proceedings of the 2016 2nd International Conference on Control, Automation and Robotics (ICCAR), Hong Kong, China, 28–30 April 2016; pp. 287–290. [Google Scholar]
  27. Fok, K.Y.; Ganganath, N.; Cheng, C.T.; Tse, C.K. A 3D printing path optimizer based on christofides algorithm. In Proceedings of the 2016 IEEE International Conference on Consumer Electronics-Taiwan (ICCE-TW), Nantou County, Taiwan, 27–29 May 2016; pp. 1–2. [Google Scholar]
  28. Ultimaker. Cura 3D Printing Slicing Software. Available online: https://ultimaker.com/en/products/cura-software (accessed on 1 July 2016).
  29. Dong, B.; Wang, Y.; Lu, Y. A Slicing and Path Generation Method for 3D Printing of Periodic Surface Structure. J. Manuf. Process. 2024, 120, 694–702. [Google Scholar] [CrossRef]
  30. Liu, B.; Feng, J.; Lin, Z.; Wu, S.; He, Y.; Fu, J. Spherical Path Planning for Multi-Axis Support-Free Additive Manufacturing of Truss Structures. J. Manuf. Processes. 2024, 109, 198–212. [Google Scholar] [CrossRef]
  31. Lechowicz, P.; Koszalka, L.; Pozniak-Koszalka, I.; Kasprzak, A. Path Optimization in 3D Printer: Algorithms and Experimentation System. In Proceedings of the 2016 4th International Symposium on Computational and Business Intelligence (ISCBI), Olten, Switzerland, 5–7 September 2016; IEEE: Piscataway, NJ, USA, 2016; pp. 137–142. [Google Scholar]
  32. Merzah, A.; Celebi, F.V. Tool-Path Optimization in FFF 3D Printing Machine Using Lines Approach Algorithms. Doctoral Dissertation, Ankara Yıldırım Beyazıt Üniversitesi Fen Bilimleri Enstitüsü, Ankara, Türkiye, 2018. [Google Scholar]
  33. Iori, M.; Novellani, S. Optimizing the Nozzle Path in the 3D Printing Process. In Design Tools and Methods in Industrial Engineering: Proceedings of the International Conference on Design Tools and Methods in Industrial Engineering, ADM 2019, Modena, Italy, 9–10 September 2019; Springer International Publishing: Berlin/Heidelberg, Germany, 2019; pp. 912–924. [Google Scholar]
  34. Liu, H.; Liu, R.; Liu, Z.; Xu, S. Minimizing the Number of Transitions of 3D Printing Nozzles Using a Traveling-Salesman-Problem Optimization Model. Int. J. Precis. Eng. Manuf. 2021, 22, 1617–1637. [Google Scholar] [CrossRef]
  35. Pinochet, D.; Tsamis, A. Path Optimization for Multi-material 3D Printing Using Self-Organizing Maps. In Proceedings of the International Conference on Computer-Aided Architectural Design Futures, Delft, The Netherlands, 5–7 July 2021; Springer Singapore: Singapore, 2021; pp. 329–343. [Google Scholar]
  36. Riabko, A.V.; Zaika, O.V.; Kukharchuk, R.P.; Vakaliuk, T.A.; Hordiienko, I.V. Algorithm of Ant Colony Optimization (ACO) for 3D Variation Traveling Salesman Problem. In Journal of Physics: Conference Series; IOP Publishing: Bristol, UK, 2022; Volume 2288, p. 012001. [Google Scholar]
  37. Hartigan, J.A.; Wong, M.A. Algorithm AS 136: A K-Means Clustering Algorithm. J. R. Stat. Soc. Ser. C (Appl. Stat.) 1979, 28, 100–108. [Google Scholar] [CrossRef]
  38. Wang, T.; Wu, S.; Cao, L.; Du, K.; Zhao, Z.; He, Z. A Novel Possibilistic Clustering Algorithm for Measurement Data of Vehicle MMW Radar. IEEE Sens. J. 2023, 23, 17103–17116. [Google Scholar] [CrossRef]
Figure 1. Flowchart of the new K-means clustering algorithm.
Figure 1. Flowchart of the new K-means clustering algorithm.
Electronics 13 03252 g001
Figure 2. Control motherboard and test platform: (a) control motherboard; (b) test platform.
Figure 2. Control motherboard and test platform: (a) control motherboard; (b) test platform.
Electronics 13 03252 g002
Figure 3. Three-dimensional view of 10 printouts (Authors’ compilation based on Blender (4.0).
Figure 3. Three-dimensional view of 10 printouts (Authors’ compilation based on Blender (4.0).
Electronics 13 03252 g003
Figure 4. Print head path diagram after planning by several different algorithms (Authors’ compilation based on the Ultimaker Cura(15.04)): (a) straight line path planning algorithm; (b) loopback path algorithm; (c) Archimedean spiral path planning algorithm; (d) Hilbert curve path planning algorithm.
Figure 4. Print head path diagram after planning by several different algorithms (Authors’ compilation based on the Ultimaker Cura(15.04)): (a) straight line path planning algorithm; (b) loopback path algorithm; (c) Archimedean spiral path planning algorithm; (d) Hilbert curve path planning algorithm.
Electronics 13 03252 g004
Figure 5. Proposed algorithm printing the printhead path for 10 parts as shown in Figure 3.
Figure 5. Proposed algorithm printing the printhead path for 10 parts as shown in Figure 3.
Electronics 13 03252 g005
Figure 6. Three-dimensional view of 20 printouts (Authors’ compilation based on Blender).
Figure 6. Three-dimensional view of 20 printouts (Authors’ compilation based on Blender).
Electronics 13 03252 g006
Figure 7. Planned print head paths for 20 parts printed simultaneously with several different algorithms (Authors’ compilation based on the Ultimaker Cura): (a) straight line path planning algorithm; (b) loopback path algorithm; (c) Archimedean spiral path planning algorithm; (d) Hilbert curve path planning algorithm.
Figure 7. Planned print head paths for 20 parts printed simultaneously with several different algorithms (Authors’ compilation based on the Ultimaker Cura): (a) straight line path planning algorithm; (b) loopback path algorithm; (c) Archimedean spiral path planning algorithm; (d) Hilbert curve path planning algorithm.
Electronics 13 03252 g007aElectronics 13 03252 g007b
Figure 8. Proposed algorithm printing the printhead path for 20 parts as shown in Figure 6.
Figure 8. Proposed algorithm printing the printhead path for 20 parts as shown in Figure 6.
Electronics 13 03252 g008
Figure 9. Comparison of 3D printing time consumption for 100 sets of models (Authors’ compilation based on Python).
Figure 9. Comparison of 3D printing time consumption for 100 sets of models (Authors’ compilation based on Python).
Electronics 13 03252 g009
Table 1. Summary of relevant research results.
Table 1. Summary of relevant research results.
StudyFocusMethodologyKey Findings
Lechowicz et al. [31]Path optimization in 3D printingHybrid algorithms (greedy and annealing algorithms)Reduced total length of print paths, lowering print time.
Fok et al. [23]ACO-based tool-path optimizerAnt colony optimizationImproved computation time, print time, and visual quality of printed objects.
Merzah et al. [32]Tool-path optimization in FFF 3D printingLinear greedy algorithm and linear two-opt algorithmProposed a hybrid algorithm that shows promise in path optimization.
Iori et al. [33]Optimizing nozzle path in 3D printingHeuristic algorithmsAchieved significant reductions in print time and proposed future research directions.
Liu et al. [34]Minimizing transitions of print nozzlesGenetic algorithmGenerated paths with fewer transitions, improving print quality.
Pinochet et al. [35]Path optimization for multi-material 3D printingSelf-organizing mapsGenerated optimized print paths based on material behavior, improving G-code generation.
Riabko et al. [36]3D TSP optimizationAnt colony optimizationAchieved execution times similar to 2D TSP for 3D TSP problems.
Table 2. Performance comparison of each algorithm for planning print paths with 10 components.
Table 2. Performance comparison of each algorithm for planning print paths with 10 components.
Name of the AlgorithmCircumferenceExterior ProfileInternal PaddingTotal Time
(s)
Time
(s)
Percentage (%)Time
(s)
Percentage (%)Time
(s)
Percentage (%)
Linear287.04611.732081.3394
Loopback algorithm287.54311.431681.1387
Archimedean spiral266.84110.631982.6386
Hilbert curve284.6416.758988.7658
Proposed algorithm267.23610.529482.3356
Table 3. Performance comparison of each algorithm for planning print paths with 20 components.
Table 3. Performance comparison of each algorithm for planning print paths with 20 components.
Name of the AlgorithmCircumferenceExterior ProfileInternal PaddingTotal Time
(s)
Time
(s)
Percentage (%)Time
(s)
Percentage (%)Time
(s)
Percentage (%)
Linear827.315111.275881.5991
Loopback algorithm897.817312.071480.2976
Archimedean spiral807.414910.676082.0989
Hilbert curve824.81566.9124488.31482
Proposed algorithm797.412710.868181.8887
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Lin, X.; Huang, Z.; Shi, W.; Guo, K. A Novel Ant Colony Algorithm for Optimizing 3D Printing Paths. Electronics 2024, 13, 3252. https://doi.org/10.3390/electronics13163252

AMA Style

Lin X, Huang Z, Shi W, Guo K. A Novel Ant Colony Algorithm for Optimizing 3D Printing Paths. Electronics. 2024; 13(16):3252. https://doi.org/10.3390/electronics13163252

Chicago/Turabian Style

Lin, Xinghan, Zhigang Huang, Wentian Shi, and Keyou Guo. 2024. "A Novel Ant Colony Algorithm for Optimizing 3D Printing Paths" Electronics 13, no. 16: 3252. https://doi.org/10.3390/electronics13163252

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop