# Harnessing Energy Balance and Genetic Algorithms for Efficient Building Demolition
## 2 Materials and Methods
### Mathematical Model and Time Complexity Analysis  
In the previous introduction, we elaborated on our algorithm steps. Now, we will present the mathematical model and algorithm complexity:  
Building Model Representation: The architectural model can be visualized as an image, where each pixel represents an image unit. This image is represented by the matrix M, where M[i][j] represents a certain pixel. Initially, all points (M[i][j]) are set to 0. Region Division: The image is divided into N regions; each region \(\mathbf{R_{i}}\) (i = 1, 2, \(\ldots\), N) has an energy release point \(\mathbf{E_{i}}\). The function f(i,j) is used to determine the region to which each pixel belongs; f(i,j) = k (k = 1, 2, \(\ldots\), N) means that the energy release point \(\mathbf{E_{i}}\) belongs to the region \(\mathbf{R_{k}}\). Energy Release: The potential function V(\(\mathbf{E_{i}}\),\(\mathbf{R}\)) describes the energy state of each energy release point, where \(\mathbf{R}\) is the diffusion distance. In each iteration, each energy release point Ei releases energy according to V(\(\mathbf{E_{i}}\), \(\mathbf{R}\)). With each iteration, R increases by 0.25 m, corresponding to a pixel size, spreading in a ring shape affecting surrounding pixels, and setting the passed pixel M[i][j] = k, until the energy balance is reached at the adjacent region boundary. Area Calculation: After each regional boundary energy balance, calculate the area of each region. The function A(\(\mathbf{R_{k}}\)) represents the area of region \(\mathbf{R_{k}}\), A(\(\mathbf{R_{k}}\)) = sum(f(i,j) = k). Figure 10: Optimization with Enhanced Genetic Algorithm. Energy Balance Iteration Process: The function D(A\({}_{-}\) current, A\({}_{-}\) previous) represents the area difference in each iteration. If D(A\({}_{-}\)current, A\({}_{-}\)previous) satisfies Equation (3), the energy balance process concludes. Otherwise, the centroid coordinates of all the current regions are identified, all of the pixel points are set to M[i][j] = 0, they are used as new energy release points, and the energy release process is continued until the difference meets the criteria. Maximum and Minimum Area Difference: By comparing the areas of all regions, the maximum and minimum areas are identified. Amax and Amin represent the maximum and minimum areas, respectively. If their difference satisfies Equation (4), the results are output and the algorithm is exited. Otherwise, the genetic algorithm is proceeded to. Genetic Algorithm: The regions with the maximum and minimum areas are found, and the coordinates of their center points are encoded into 12-bit binary numbers, each bit representing a distance of 0.25 m. Crossing and mutating are carried out at the lower six bits (representing a distance of 16 m) to obtain new center point coordinates. Genetic Algorithm Iteration Process: The energy release and balance process is repeated until the area difference of all regions is within an acceptable range. Multiple iterations may be needed until the termination condition is met. We proceed to analyze the algorithmic complexity, where M represents the total number of pixel points in a provided image. The initial step involves dividing the image into N regions. This operation, although involving N divisions, is contingent upon traversing all M pixel points, leading to a complexity of O(M). In the subsequent energy release phase, the complexity remains O(M), as each energy release point diffuses energy throughout the image, necessitating another complete traversal of pixel points. When energy levels at the borders of adjacent regions equalize, the energy balance iteration commences. With k iterations, the complexity escalates to O(kM). The process of area calculation, involving another round of pixel point traversal to identify and record coordinates of points with identical values, retains the O(M) complexity. Comparing preceding and succeeding area differences, alongside the maximum and minimum disparities across N regions, incurs a complexity of O(N).