# Efficient Intersection Management Based on an Adaptive Fuzzy-Logic Traffic Signal
## 4 Proposed Adaptive Traffic Signal Controller Based on Fuzzy Logic
### Fuzzy Inference Description  
A Mamdani-type FIS [70] was designed to compute the cycle duration based on the following reasoning:  
_The higher the traffic flow, the longer the cycle length._  
Within an intersection, however, there is an inherent contention among the incoming traffic streams. For this reason, the proposed FIS computes the cycle length by relating all the possible combinations of flow rates among the involved streams.  
For a \(\chi\)-way intersection with \(n\) incoming traffic streams (\(n\leq\chi\)), there is a set of input variables \(S=\{s_{1},s_{2},\ldots,s_{n}\}\). Each \(s_{i}\in S\) has a scalar value in vehicles per hour (veh/h), which is related to the upstream traffic flow rate retrieved by on-road sensors. These inputs are fuzzified by using \(c\) triangular membership functions or fuzzy sets \(f_{Q_{1}}(x),f_{Q_{2}}(x),\ldots,f_{Q_{c}}(x)\), which are defined in the universe of discourse established by the interval \([q_{min}(s_{i}),q_{max}(s_{i})]\), which describes that the range the traffic flow may fluctuate between the minimum (\(q_{min}(s_{i})\)) and maximum (\(q_{max}(s_{i})\)) expected rates. Here, these minimum and maximum expected flow rates may be established from an in situ traffic  
Figure 2: Triangular function.  
count survey. For practicality's sake, each fuzzy set \(f_{Q_{j}}(x)\), \(j\in\{1,2,\ldots,c\}\), is identified by a linguistic term that qualifies the traffic flow with adjectives such as _very low_, _low_, _medium_, _high_, _very high_, and so on.  
For the cycle length \(cl\), there are defined \(m\) triangular membership functions \(f_{T_{1}}(x)\), \(f_{T_{2}}(x)\), \(\ldots\), \(f_{T_{m}}(x)\) in the universe of discourse established by the interval \([t_{min},t_{max}]\), whose values are expressed in seconds. Analogously to the membership functions for flow rate, the membership functions \(f_{T_{k}},h\in\{1,2,\ldots,m\}\) are related to linguistic terms as _very low_, _low_, _average_, _extended_, _very extended_, and so on.  
Based on the fuzzy sets defined for the inputs and the output, the knowledge base of the FIS is defined by a set of if-then rules \(r_{1},r_{2},\ldots,r_{k},\ldots,r_{z}\), each one of the form:  
\[r_{k}:s_{1}\text{ is }f_{Q_{j}}\wedge s_{2}\text{ is }f_{Q_{j^{\prime}}}\wedge\ldots\wedge s_{n}\text{ is }f_{Q_{j^{\prime\prime}}}\Rightarrow f_{T_{k}}.\]  
As an example, a first rule \(r_{1}\) would be interpreted as:  
_if \(s_{1}\) is very low and \(s_{2}\) is very low, \(\ldots\) and \(s_{n}\) is very low, then the cycle length is very low._  
These rules are established by considering all the expected traffic conditions at the intersection. Among the \(i\) incoming streams, not all the combinations of flow rates are possible, therefore, the total number of rules is less than \(c^{n}\).  
The inference module is specified through Algorithm 1, which uses the Mamdani fuzzy implication [71] to compute the inference rules (see lines 7 to 9). Since the fuzzy sets associated with \(cl\) are defined by triangular membership functions, the algorithm defuzzificates the system's output by the weighted average method (see line 10).  
```
1:procedureFuzzyInference(\(S=\{s_{1},s_{2},\ldots,s_{n}\}\))
2:*Fuzzification with triangular functions
3:for each input value \(s_{i}\in S\)do
4:for each fuzzy set \(f_{Q_{j}}(x),j\in\{1,2,\ldots,c\}\), do
5:\(v_{i,j}=max(min(\frac{s_{i}-L_{j}}{C_{j}-L_{j}},\frac{R_{j}-s_{i}}{R_{j}-C_{ j}}),0)\)
6:endfor
7:\(z\) inference rules (\(z<n^{c}\))
8:\(r_{1}=min(v_{1,j},v_{2,j^{\prime}},\ldots,v_{n,j})\)
9:
10:\(r_{k}=min(v_{1,j},v_{2,j^{\prime}},\ldots,v_{n,j})\)
11:\(\vdots\)
12:\(r_{z}=min(v_{1,j},v_{2,j^{\prime}},\ldots,v_{n,j})\)
13:\(\bullet\)defuzzification with the WA method
14:\(cl=\frac{\sum\limits_{k=1}^{n}\sum\limits_{k=1}^{n}r_{k}\cdot\tilde{x}_{k}}{ \sum\limits_{k=1}^{n}r_{k}}\)
15:return\(cl\)
16:endprocedure
```  
**Algorithm 1** Fuzzy inference module