# Repair Method and Mueganos Structure Applied to the Nesting Problem in Finite Materials
## 2 Methodology
### Mueganos Detection and Structure  
In Mexico, the _muegano_ is a candy that physically looks like several pieces of pastry stuck together with honey or caramel. Once it hardens, it is very difficult to separate them. The name _muegano_ is also used with a social connotation to name a conglomerate of two or more people united by a strong bond. The concept of _mueganos_ can be applied in the repair process so that the patterns can be nested as much as possible and be arranged in a structure. Each _muegano_ represents a list of items that have adjacent neighboring pixels; this means that if two items are joined by a limited number of pixels, then a _muegano_ has been formed. The Flood Fill Algorithm 2 was applied to detect the _mueganos_.The algorithm receives an image containing the repaired solutions. When it finds a contiguous pixel between items, those are labeled with a gray level. ```  Initialization; \(Im\gets Image\); \(x\leftarrow\) PositionX; \(y\leftarrow\) PositionY; \(new\_color\leftarrow\) newColor; \(old\_color\leftarrow\) oldColor; \(pix\leftarrow\) grayLevel; if(\(Im[x][y]==pix\))then \(Im[x][y]=newColor\); if(\(x+1<Im.rows()\))then  FloodFill(Im, x+1, y, newColor, oldColor, grayLevel)  end if if(\(x-1>0\))then  FloodFill(Im, x-1, y, newColor, oldColor, grayLevel)  end if if(\(y+1<Im.cols()\))then  FloodFill(Im, x, y+1, newColor, oldColor, grayLevel)  end if if(\(y-1>0\))then  FloodFill(Im, x, y-1, newColor, oldColor, grayLevel)  end if  end if Result:Im

Figure 5: Sample of the item movements during the repair process. The black area represents the material, the white area represents the items, and the gray area represents the overlaps. Once the image contains the items labeled with a gray level, the process of selecting the best _mueganos_ is performed. Two fundamental conditions are considered for the selection of the _mueganos_:

1. Two or more items have contiguous pixels. 2. There is a limit of contiguous pixels between two items. Contiguous pixels are adjacent pixels between neighboring item borders. If there are more adjacent pixels between items, there is less wastage. A data structure containing the information of each _muegano_ was implemented, in other words, the number of items contained in each _muegano_ as shown in Figure 6.

An example of _muegano_ formation is shown in Figure 7.

### Sequential Greedy Algorithm

Once the _mueganos_ are generated, a sequential greedy algorithm (SGA) is implemented to fill the area of the material that has not been used. Figure 8 shows the flow diagram of the SGA. Items and _mueganos_ are randomly selected and nested avoiding overlaps between them, until there is no more space in the material. Figure 6: _Muegano_ structure. Each _muegano_ is a list of the contained items. The number of items depends on the largest number of adjacent pixels between edges of neighboring items. Figure 7: Sample nesting results. Inside of the red ellipse: example of _muegano_ formed by two items. Each item has a different gray level. ## 3 Experimental Results

This section shows the results obtained by applying the techniques explained above. The term \(waste_{m}\) in Equation (5) was used to obtain the wastage in square meters (m\({}^{2}\)) of the resulting images. The standard deviation was calculated to measure the precision according to the value obtained for the waste in the same image by repeatedly calculating the term \(waste_{m}\). In this research, materials obtained from a leather-footwear factory were utilized, including cowhole leather material and boot-type footwear patterns. These materials were processed following the arrangement outlined in the \"Calculation of waste in metric values\" Section 2.2, to obtain their real and pixel sizes. Subsequently, the procedure described in the \"Methodology\" Section 2 was employed to generate the results presented in this section. The results were obtained using 60 _mueganos_ in the solutions.