## 2 Materials and Methods
### Heuristic Refinement  
The initial solution obtained from the skeletonized and processed output needs further refinement. This refinement is performed using an evolutionary algorithm that iteratively improves the solution. Unlike the biomimetic structural optimization, the iterative algorithm is based on a theoretical mathematical model proved to be valid, and the proposed solution is heuristic and created experimentally. The algorithm is designed to be fast, and the trade-off is reduced accuracy. The evolutionary algorithm requires the definition of the Fitness Function to calculate a score for each candidate and select the best one. The Fitness Function must be quick to compute and at the same time accurate to enable visiting many candidates in a short time. The optimal solution of a feature recognition algorithm is a set of features that completely fill the volume of input data and do not exceed it. Scoring based on volume requires the time-consuming operation of intersecting the input mesh with the scored solution to find differences. The optimization of this approach uses a mesh discretized using a slice-based approach and comparing discrete sets of points. This approach has \(O(n^{3})\) complexity, so a more efficient but less precise approach was used. As the algorithm operates on the surface, the not-volumetric, mesh, surface-based approach was also used for the Fitness Function. Two sets of points are calculated: control points and guide points. Control points are points on a mesh surface that are used to determine how close a solution's surface is to the input surface. A set of guide points is obtained by the morphology dilation of the input mesh. The size of the dilation is an input parameter of the algorithm. Details of the mesh surrounded by the guide points are shown in Figure 7.  
Figure 6: (**a**) Optimized cantilever beam. Mesh was created out of a 2D image by extruding it. Skeleton generated for the shown mesh is drawn over. (**b**) Initial solution generated from processed skeleton. Two skeleton edges were below the minimum length threshold and collapsed. Bottom-right node of the solution graph was generated by splitting an edge of the skeleton graph. The Fitness Function is calculated for a solution consisting of the set of elements, \(E\), the given set of control mesh points, \(P\), and guide points, \(G\). \(Surface\_distance(p,e)\) is a function that returns the Euclidean distance between element \(e\)'s surface and point \(p\). \(is\_inside(p,e)\) is 1 if the point \(p\) is inside geometry \(g\), and is otherwise 0. \[S_{positive}=\sum_{p\in P}\min_{v\in e\in E}surface\_distance(p,e)^{2} \tag{1}\]  
\[S_{negative}=\sum_{g\in G}\min_{\forall v\in E}-(surface\_distance(g,e)* is\_inside(g,e))^{2} \tag{2}\]  
\[Fitness=\alpha S_{positive}+\beta S_{negative} \tag{3}\]  
The solution is scored positively for the matching input surface and is penalized for enveloping guide points and taking more volume than required. Both positive and negative scores are aggregated using weights, \(\alpha\) and \(\beta\), used to equalize imbalances in the size of two sets. For tests, \(\alpha=1\) and \(\beta=50\) were used. To increase performance, for each evolutionary algorithm iteration, a subset of both sets was generated. A total of 20% of mesh points and 4% of guide points were randomly selected. The size of the guide set is five times smaller than the size of the control points so, effectively, the weight of the negative score was ten times higher than the positive. It is important to note that this approach works well because the input mesh, obtained from the mesh generator, which is part of the structural optimization algorithm, is built from regularly spaced elements. Without this feature, an extra algorithm step would be required to ensure that the mesh vertices are equally spaced and uniformly cover the mesh surface. The evolutionary algorithm works iteratively, creating a set of candidates using random sampling of a solution neighborhood space using two available operations.