The greedy randomized adaptive search procedure algorithm (GRASP) is a metaheuristic proposed by Feo et al. [
26,
27]. The GRASP algorithm is a multistart process that has two phases. The first phase corresponds to a heuristic construction, which provides a highquality solution, and the second phase improves the solution through a local search. However, given the nature of the solution, a slight change in the placement of the rectangular objects for an alreadycompleted solution would produce a huge problem for repairing highlypossible overlaps or would increase wastes. Therefore, we avoid the use of local search, limiting the algorithm to the heuristic construction phase.
Algorithm 1 shows the general procedure of our proposed optimization method; it generates the solutions with a defined number of iterations. The process starts with the
LoadInstance function that loads the instance. The
InitializeParameters function initializes the main parameters to use in GRASP construction. The
ReorderObjects function consists of ordering the objects from the smallest area to the largest area. The
SPPGRASP function constructs the GRASP solutions; we validate the solutions to obtain the best solution. This code is available at
https://github.com/csalas07/GraspSpp (accessed on 4 February 2022).
Algorithm 1 GRASP General Procedure 
 1:
$Sol=\u2300$, $best=\varnothing $  2:
LoadInstance()  3:
InitializeParameters()  4:
ReorderObjects()  5:
for $i=1\to MaxIter$ do  6:
$Sol=SPPGRASP\left(\right)$  7:
if $f\left(Sol\right)<best$ then  8:
$best=f\left(Sol\right)$  9:
end if  10:
end for

Output: best 
3.1. GRASP Construction
One of the main contributions of this paper is the use of flags, and at the beginning of the algorithm, we set a single flag at the lowest left corner of the strip to mark the first place for setting an object.
Algorithm 2 describes the initial construction that consists of three parts. The first is to select an available flag index with the
FindFlagIndex function (see line 4), which iterates a list of available flags and selects the index of the flag that has the lowest height, and if there were several flags with the same height, it chooses the one furthest to the left. The second part consist of the use of waste functions (see Equations (
5)–(
7)) to analyze the objects’ waste. Finally, the last part is constructing the candidate list (
CL) and the restricted candidate list (
RCL).
Algorithm 2 GRASP Construction Part 1 
Input:k 1:
$miss=\leftO\right$  2:
while$miss>0$ do  3:
$CL=\u2300$  4:
$j=FindFlagIndex\left(Flags\right)$  5:
for $i=0\to \leftO\right$ do  6:
if ${s}_{i}=0$ && $o{w}_{i}\le tf{w}_{j}$ then  7:
$CL=CL\cup \left\{{o}_{i}\right\}$  8:
$w{k}_{ij}=CalculateWaste\left(k\right)$  9:
$W=W\cup \left\{{w}_{ij}\right\}$  10:
end if  11:
end for  12:
if $CL\ne \varnothing $ then  13:
$kElems=max\left(\rightCL\times 0.10,5)$  14:
$RCL=\u2300$  15:
$RW=\u2300$  16:
for $i=1\to kElem$ do  17:
$imin={arg\; min}_{i}w{k}_{ij}\forall w{k}_{ij}\in W$  18:
$RCL=RCL\cup \left\{{o}_{imin}\right\}$  19:
$RW=RW\cup \left\{w{k}_{imin}\right\}$  20:
$W=W\setminus \left\{w{k}_{imin}\right\}$  21:
end for  22:
$Limit=max\left(W\right)+(\beta \times (max\left(W\right)min\left(W\right)\left)\right)$  23:
for $i=1\to \leftRCL\right$ do  24:
if $w{k}_{ij}\in RW>Limit$ then  25:
$RW=RW\setminus \left\{w{k}_{ij}\right\}$  26:
$RCL=RCL\setminus \left\{{o}_{i}\right\}$  27:
end if  28:
end for  29:
${O}_{r}=Roulette(RCL,RW)$

The algorithm checks that the set value
${s}_{i}$ is equal to zero, where
$S=\{{s}_{1},{s}_{2},\dots ,{s}_{n}\}$ is a set that represents the availability of the objects (see Equation (
4)).
The
$CalculateWaste\left(k\right)$ function calculates the waste area of an object
$w{k}_{ij}$ (see line 8). We use three waste functions (see Equations (
5)–(
7)) to analyze the objects’ waste. Each function validates different components among the rectangular objects and a specific flag.
where
$O=\{{o}_{1},{o}_{2},\dots ,{o}_{n}\}$ is the set of objects and
$w{k}_{ij}$ is the waste of the object
i on the flag
j. Hence, in the algorithm, we calculate the waste for all the available objects
${o}_{i}$ for the selected flag
${f}_{j}$.
Figure 1 shows the characteristics of the flags and the objects, i.e.,
$df{w}_{j}$ and
$tf{w}_{j}$ are the flag’s desirable and total width, respectively;
$lf{h}_{j}$ and
$rf{h}_{j}$ are the height to the left and to the right of the flag. Finally,
$SP$ is the starting point and
$o{w}_{i}$ and
$o{h}_{i}$ are the current object width and height, respectively.
The selection of the first object is the one with the largest area. We select the rest of the elements according to the waste area function which is similar in some sense to the feature selection used in [
28]; the
$WA$ value stores all waste area values for each object for a specific flag. Additionally, we validate that
$CL\ne \varnothing $ in line 12. Therefore, if no object fits in the space of the flag, then we try to raise the flag (see line 35 of Algorithm 3).
Algorithm 3 GRASP Construction Part 2 
 30:
if $NoObjectOverlapping\left(\right)$ then  31:
$FixFlagOverlapping\left(\right)$  32:
$Set({O}_{r},j)$  33:
end if  34:
else  35:
$RiseFlag\left(\right)$  36:
end if  37:
end while

Later, Equation (
8) calculates a limit value, which will be compared with the waste areas of the candidate objects to create the restricted candidate list (
$RCL$).
where
$\beta $ is a real number between 0 and 1; we made several tests to identify the best value, but we could not find it; hence, we chose to use random values between 0.4 and 0.5, which were the values with the best performance.. Additionally, the objects have a wide variety of sizes and, therefore, wastes, meaning that there might be lower or higher differences among the wastes. Hence, we could end up without candidates or with a lot of them, nullifying the purpose of the restricted candidate list.
Therefore, the candidate list selects $kElems$, which are either five elements or 10% of the objects in $CL$ until exhaust $CL$ (see line 13). As a result, the algorithm initializes the restricted candidate list with the elements in $CL$ with the lowest waste.
Line 17 obtains the index of the object for which the waste $w{k}_{ij}$ is minimal. Then, we update the restricted candidate list ($RCL$) and the restricted waste list ($RW$), respectively (see lines 18, and 19). Finally, the procedure removes $w{k}_{imin}$ from W (see line 20).
The algorithm calculates the $Limit$ value to further restrict the $RCL$ to those wastes that have a lower or equal value than $Limit$ (see line 22). Therefore, the algorithm updates $RW$ and $RCL$ in lines 25 and 26, respectively.
The procedure selects an object
${O}_{r}$ in
$RCL$ randomly with a roulette technique [
29] (see line 29); for further explanation see
Section 3.2.