# Digital Twin-Based Clamping Sequence Analysis and Optimization for Improved Geometric Quality
## 2 Method
### Sequence Optimization  
The clamping sequence optimization is a combinatorial problem. From a black-box perspective, the permutations of the sequences are the input to the assembly system, and the geometric outcome from the simulation is the output. The objective of clamping sequence optimization is to reduce the relative displacements in the weld points. Previously, it has been shown that capturing the weld relative displacement can be utilized for weld sequence simulation [15]. Therefore, to ensure that the outcome of clamping sequence optimization results in higher geometrical quality after joining and releasing the assembly from the fixture, the objective of the clamping sequence optimization is formulated to minimize the relative displacements in the welding points as follows:  
\[\begin{split}\underset{d_{c_{i}}}{\text{minimize}}& \sqrt{d_{c_{i}}^{1}+d_{c_{i}}^{2}+...+d_{c_{i}}^{n}}\\ \text{subject to}&\mathbf{c}:\{1,\dots,z\}\rightarrow\{z, \dots,1\},\;z\in\mathbb{N}.\end{split} \tag{10}\]In the objective of the minimization problem, the root sum square of the weld relative displacements \(d_{ci_{i}}^{1-n}\), from weld pair 1 to \(n\), are calculated. The subscript \(c_{i}\) is the decision variable and corresponds to the clamping sequence chosen from the set \(c\). The subscript \(i\) indicates each member of the set \(c\), which is a permutation of the clamping sequences from clamp 1 to \(z\).  
To solve the optimization problem (10), a stepwise algorithm introduced in [38] for welding sequence optimization is adapted to the clamping sequence problem. The algorithm is based on a greedy search with the backward propagation of the sequence element while spanning the state-space tree at each decision step. Initially, all the combinations possible for the first sequence elements are generated, and the objective is evaluated. The sub-optimal solution with respect to the evaluated elements is chosen, and this process is continued until the optimal solution is achieved, Algorithm 1. After identifying the optimal clamping sequence, which minimizes the weld relative displacements, with a similar formulation, the welding sequence optimization is performed. For weld sequence optimization, to have a generic metric for analyzing the overall geometric quality of the assembly, the root mean square of the displacements of all the nodes after releasing the assembly and springback is considered. In the next section, the details of the reference assemblies on which the proposed method is evaluated are introduced.  
```
Input: \(N\) Number of the clamps \(s\) Initialization step number Output: \(C_{s}^{*}\) Optimal clamp sequence \(D^{*}\) Weld relative displacements Initialization
1: Define \(N\) Define \(s\) \(C_{s}\leftarrow[1:N]\), define the sequence \(C_{s}\) \(l\gets 0\), the number of the sequences to be evaluated
2:for\(i=1\) to \(N-s\)do
3:\(l\gets l+1\)
4:endfor
5:\(l\leftarrow\binom{N}{s}s!+l\), calculated number of sequences to be evaluated
6:\([P_{all}]\leftarrow[0]\;l\times N+1\), predefine the matrix of all steps Step 1
7:\([P_{1}]_{u\times v}\gets\mathit{perms}\;(C_{s},1,s)\), Generate permutations of Step 1
8:\([P_{all}]_{(1:u)\times(1:N+1)}\leftarrow\mathit{Evaluate}(P_{1})\), evaluate each clamping sequence in the first step and save \(D\)
9:\(idx\gets Min(P_{all}((1:u),(N+1))\), find the row of the sequence with minimum \(D\)
10:\(C_{s}\gets P_{all}(idx,(1:N+1))\), set the sequence with the minimum \(D\)
```  
**Main loop**
14:for\(k=s+1\) to \(N-1\)do
15:\([P_{k}]_{u\times v}\gets\mathit{perms}(C_{s},k,1)\), create the step sequence
16:\([P_{all}]_{(1:u)\times(1:N+1)}\leftarrow\mathit{Evaluate}(P_{k})\), evaluate clamping sequence in the step \(k\)
17:\(idx\leftarrow Min(P_{all}((1:u),(N+1))\), find the minimum row
18:\(C_{s}\gets P_{all}(idx,(1:N+1))\), assign the sequence
19:endfor
20:\(C_{s}^{*}\leftarrow C_{s}\), set the last evaluated sequence as the optimum
21:\(D^{*}\gets P_{all}(l,N+1)\), set the last evaluated weld relative displacement ```  
**Algorithm 1** Stepwise clamp sequence optimization.