# Dimensional Tolerances in Mechanical Assemblies: A Cost-Based Optimization Approach
## 3 A Proposal for Tolerance Synthesis
```
0:\(m\): number of parts
0:\(p\): number of chains
0:\(\{t_{k}\}\): set of all tolerances \(1\leq k\leq m\)
0:\(\{\min(t_{k})\}\): set of all minimum tolerances, considering the specific process \(1\leq k\leq m\)
0:\(c_{i}=\{t_{i,j}\}\): set of all tolerances \(j\) for chains \(i\), it is known that \(t_{i,j}\in\{t_{k}\}\)
0:\(\{R^{i}_{j}\}\): functional constraints for all chains \(1\leq i\leq p\)
0:\(\{t^{0}_{k}\}\): set of all optimized tolerances
1:\(\{t^{0}_{k}\}\leftarrow\{t_{k}\}\): Copy the set of tolerances
2:\(<\): Calculate the chains \(\text{tolerance}\{t(c_{i})\}>\)
3:\(\delta\leftarrow\emptyset\): Initiates the set of optimized tolerances with empty set
4:for i = 1:\(p\)do: Process all chains
5: flag \(\leftarrow\) false: This flag indicates if all tolerances reached the minimum
6:while\(t(c_{i})>R^{i}_{j}\) and **not** flag **do**: The chain tolerance is not optimized
7: flag \(\leftarrow\) true
8:\(\gamma\leftarrow\emptyset\): Initiates the set of cost differences
9:for\(j=\text{\rm{num}}(\{t_{ij}\})\)do: Process all tolerances in chain \(i\)
10:\(\gamma\), flag \(\leftarrow\)\(<\)ProcessChainTolerances\(>\)(\(i\), \(j\), \(\{\min(t_{k})\}\), \(t^{0}_{i,j}\), \(\delta\), flag, \(\gamma\))
11:endfor
12:if not flag then: The set \(\gamma\) is not empty
13:\(\delta\), \(\{t^{0}_{i,j}\}\leftarrow\)\(<\) DetermineOptimizedTolerancesCosts \(>\)(\(m\), \(i\), \(\gamma\), \(\delta\), \(\{t^{0}_{i,j}\}\))
14:else
15:for j = 1:\(\text{\rm{num}}(\{t_{i,j}\})\)do: Process all tolerances in chain \(i\)
16:\(\gamma\), flag \(\leftarrow\)\(<\)ProcessAllChainTolerances\(>\)(\(i\), \(j\), \(\{\min(t_{k})\}\), \(t^{0}_{i,j}\), flag, \(\gamma\))
17:endfor
18:if not flag then: The set \(\gamma\) is not empty
19:\(\delta\), \(\{t^{0}_{i,j}\}\leftarrow\)\(<\) DetermineOptimizedTolerancesCosts \(>\)(\(m\), \(i\), \(\gamma\), \(\delta\), \(\{t^{0}_{i,j}\}\))
20:else
21: The chain cannot be optimized
22:endif
23:endif
24:endwhile
25:endfor
```  
**Algorithm 1** Optimization Algorithm  
```
0:\(m\): number of parts
0:\(i\): current chain
0:\(j\): current tolerance
0:\(\{\text{\rm{min}}(t_{k})\}\): set of all minimum tolerances, considering the specific process \(1\leq k\leq m\)
0:\(t_{i,j}\): tolerances \(j\) for chains \(i\), it is known that \(t_{i,j}\in\{t_{k}\}\)
0:\(\delta\): set of optimized tolerances
0:\(\gamma\): set of cost differences
0:Output
0:\(\gamma\): set of cost differences
0: flag: indicates if the tolerance was optimized
1:ProcessChainTolerances(\(m\), \(i\), \(j\), \(\{\min(t_{k})\}\), \(t_{i,j}\), \(\delta\), \(\gamma\))
2:if\(t^{0}_{i,j}-t_{d}>\min(t^{0}_{i,j})\) and \(t^{0}_{i,j}\
otin\delta\)then: The minimum has not been reached
3: flag \(\leftarrow\) false: At least one tolerance did not reach the minimum
4:\(t^{0}_{i,j}\leftarrow\)\(t^{0}_{i,j}-t_{d}\): Decrement the tolerance
5:\(C^{0}_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the new tolerance
6:\(C_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the actual tolerance
7:\(\Delta C_{i,j}\leftarrow\)\(C^{0}_{i,j}-C_{i,j}\): Calculate the difference between the two costs
8:\(\gamma\leftarrow\gamma\cup\Delta C_{i,j}\): Include just the calculated cost difference in the set
9:endif
```  
**Algorithm 2** Process Chain Tolerances  
```
0:\(\gamma\): set of cost differences
1:ProcessChainTolerances(\(m\), \(i\), \(j\), \(\{\min(t_{k})\}\), \(t_{i,j}\), \(\delta\), \(\gamma\))
2:if\(t^{0}_{i,j}-t_{d}>\min(t^{0}_{i,j})\) and \(t^{0}_{i,j}\
otin\delta\)then: The minimum has not been reached
3: flag \(\leftarrow\) false: At least one tolerance did not reach the minimum
4:\(t^{0}_{i,j}\leftarrow\)\(t^{0}_{i,j}-t_{d}\): Decrement the tolerance
5:\(C^{0}_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the new tolerance
6:\(C_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the actual tolerance
7:\(\Delta C_{i,j}\leftarrow\)\(C^{0}_{i,j}-C_{i,j}\): Calculate the difference between the two costs
8:\(\gamma\leftarrow\gamma\cup\Delta C_{i,j}\): Include just the calculated cost difference in the set
9:endif
```  
**Algorithm 3** Process Chain Tolerances  
```
0:\(\gamma\): set of cost differences
1:ProcessChainTolerances(\(m\), \(i\), \(j\), \(\{\min(t_{k})\}\), \(t_{i,j}\), \(\delta\), \(\gamma\))
2:if\(t^{0}_{i,j}-t_{d}>\min(t^{0}_{i,j})\) and \(t^{0}_{i,j}\
otin\delta\)then: The minimum has not been reached
3: flag \(\leftarrow\) false: At least one tolerance did not reach the minimum
4:\(t^{0}_{i,j}\leftarrow\)\(t^{0}_{i,j}-t_{d}\): Decrement the tolerance
5:\(C^{0}_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the new tolerance
6:\(C_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the actual tolerance
7:\(\Delta C_{i,j}\leftarrow\)\(C^{0}_{i,j}-C_{i,j}\): Calculate the difference between the two costs
8:\(\gamma\leftarrow\gamma\cup\Delta C_{i,j}\): Include just the calculated cost difference in the set
9:endif
```  
**Algorithm 4** Process Chain Tolerances  
```
0:\(\gamma\): set of cost differences
1:ProcessChainTolerances(\(m\), \(i\), \(j\), \(\{\min(t_{k})\}\), \(t_{i,j}\), \(\delta\), \(\gamma\))
2:if\(t^{0}_{i,j}-t_{d}>\min(t^{0}_{i,j})\) and \(t^{0}_{i,j}\
otin\delta\)then: The minimum has not been reached
3: flag \(\leftarrow\) false: At least one tolerance did not reach the minimum
4:\(t^{0}_{i,j}\leftarrow\)\(t^{0}_{i,j}-t_{d}\): Decrement the tolerance
5:\(C^{0}_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the new tolerance
6:\(C_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the actual tolerance
7:\(\Delta C_{i,j}\leftarrow\)\(C^{0}_{i,j}-C_{i,j}\): Calculate the difference between the two costs
8:\(\gamma\leftarrow\gamma\cup\Delta C_{i,j}\): Include just the calculated cost difference in the set
9:endif
```  
**Algorithm 4** Process Chain Tolerances  
```
0:\(\gamma\): set of cost differences
1:ProcessChainTolerances(\(m\), \(i\), \(j\), \(\{\min(t_{k})\}\), \(t_{i,j}\), \(\delta\), \(\gamma\))
2:if\(t^{0}_{i,j}-t_{d}>\min(t^{0}_{i,j})\) and \(t^{0}_{i,j}\
otin\delta\)then: The minimum has not been reached
2: flag \(\leftarrow\) false: At least one tolerance did not reach the minimum
3:\(t^{0}_{i,j}\leftarrow\)\(t^{0}_{i,j}-t_{d}\): Decrement the tolerance
4:\(C^{0}_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the new tolerance
5:\(C^{0}_{i,j}\leftarrow\)\(cost(t^{0}_{i,j})\): Calculate the cost for the actual tolerance
6:\(\Delta C_{i,j}\leftarrow\)\(C^{0}_{i,j}-C_{i,j}\): Calculate the difference between the two costs
7:\(\gamma\leftarrow\)\(\gamma\cup\Delta C_{i,j}\): Include just the calculated cost difference in the set
9:endif
```  
**Algorithm 5** Process Chain Tolerances  
```
0:\(\gamma\): set of cost differences
1:ProcessChainTolerances(\(m\), \(i\), \(j\), \(\{\min(t_{k})\}\), \(t_{i,j}\), \(\delta\), \(\gamma\))
2:if\(t^{0}_{i,j}-t_{d}>\min(t^{0}_{i,j})\) and \(t^{0}_{i,j}\
otin\delta\)then: The minimum has not been reached
3: flag \(\leftarrow\) false: At least one tolerance did not reach the minimum
4:\(t^{0}_{i,j}\leftarrow\)\(t^{0}
```
0:\(m\): number of parts
1: current chain
2:\(i\): set of cost differences
3: get of optimized tolerances
4:\(\{t_{i,j}^{o}\}\): set of tolerances for chains \(i\), it is known that \(t_{i,j}\in\{t_{k}\}\)
5:Output
7: set of cost differences
8:\(\{t_{i,j}^{o}\}\): set of tolerances for chains \(i\), it is known that \(t_{i,j}\in\{t_{k}\}\)
9: DetermineOptimizedTolerancesCosts(\(m\), \(i\), \(\{t_{i,j}^{o}\}\), \(\gamma\), \(\delta\))
10:\(k\leftarrow\min(\gamma)\): Determines the tolerance with minimum cost difference
11:for\(j=\mathrm{Innum}\left(\{t_{i,j}\}\right)\)do: Process all tolerances in chain \(i\)
12:if\(\Delta C_{ij}==\Delta C_{ik}\) and \(\Delta C_{ij}\in\gamma\)then: If the cost is equal to the minimum
13:\(t_{i,j}^{o}\gets t_{i,j}^{o}-t_{d}\): The tolerance with minimum cost is optimized
14:\(\delta\leftarrow\delta\cup\{t_{i,j}^{o}\}\): Indule the optimized tolerance in the set
15:endif
16:endfor
```
**Algorithm 3** Determine Optimized Tolerances Costs

If no tolerance within the current chain can be optimized, an alternative procedure is executed.