# Stochastic Model Predictive Control for Urban Traffic Networks
## 4 Optimization Method  
### Stochastic Simulation  
According to Label (7), the variable \(x_{i,r}(k+1)\) could be rewritten as  
\[x_{i,r}(k+1)=h\big{(}x_{i,r}(k),u_{i,p}(k),d_{i,r}(k),e_{i,r}(k)\big{)}. \tag{20}\]  
In addition, applying Label (7) to the whole network, we have Label (13). Then, by defining \(\mathbf{\Theta}(k)=[\mathbf{d}(k)^{T},\mathbf{e}(k)^{T}]^{T}\) we can rewrite Label (13) as follows:  
\[\mathbf{x}(k+1)=\varphi\big{(}\mathbf{x}(k),\mathbf{u}(k),\mathbf{\Theta}(k)\big{)}. \tag{21}\]  
Similarly, for \(k=1,2,3,...\), the vector form of chance constraints (12) can be defined as follows:  
\[\mathbf{P}\big{\{}0\leq\varphi\big{(}\mathbf{x}(k),\mathbf{u}(k),\mathbf{\Theta}( k)\big{)}\leq N\big{\}}\geq\beta. \tag{22}\]  
In order to solve the optimization problem (17), the key issue is to deal with the chance constraints (22). One traditional method to solve the aforementioned problem is transforming the chance constraints (22) to deterministic constraints. However, the results reported in [27] pointed out that the deterministic constraints include multi-integrated terms. The transformed deterministic problem is a special nonlinear problem that can hardly be solved with analytic methods. It is well known that a stochastic simulation method can trace the evolution of variables, which change stochastically (randomly) with certain probabilities. In [28], by using a stochastic simulation method, [PERSON] et al. developed a convenient method to deal with a certain class of uncertain functions.  
Based on the above discussion, both the expected value of the objective function defined in Label (17) and the left term in Label (22) can be seen as uncertain functions. Therefore, to calculate the probability value \(\mathbf{P}\big{\{}0\leq g\big{(}\cdot\big{)}\leq N\big{\}}\) defined in Label (22) and the expected value \(E\big{[}f(\mathbf{x},\mathbf{u})\big{]}\) defined in Label (17), for any \(k=1,2,3,...\) and given variable \(\mathbf{x}(k)\) and \(\mathbf{u}(k)\), we propose a stochastic simulation algorithm (Algorithm 1) to generate input-output data for the uncertain function  
\[F:(\mathbf{x},\mathbf{u})\rightarrow\big{(}F_{1}(\mathbf{x},\mathbf{u},\mathbf{ \Theta}),F_{2}(\mathbf{x},\mathbf{u},\mathbf{\Theta})\big{)}, \tag{23}\]  
\[F_{1}(\mathbf{x},\mathbf{u},\mathbf{\Theta})= \mathbf{P}\big{\{}0\leq\varphi\big{(}\mathbf{x},\mathbf{u},\mathbf{ \Theta}\big{)}\leq\mathbf{N}\big{\}}, \tag{24}\]  
\[F_{2}(\mathbf{x},\mathbf{u},\mathbf{\Theta})=E\big{[}f(\mathbf{x},\mathbf{u}) \big{]}, \tag{25}\]  
where \(\mathbf{\Theta}=[\mathbf{d}^{T},\mathbf{e}^{T}]^{T}\) denotes the uncertainty vector corresponding to the whole network. Furthermore, we define \((\Omega_{1},A_{1},Pr_{1})\) and \((\Omega_{2},A_{2},Pr_{2})\) as the probability spaces of \(\mathbf{d}\) and \(\mathbf{e}\), respectively.  
```
Step 1 : (Initialize) Set \(K=0\), \(J=0\). Step 2 : (Sample) Generate \(\omega_{1}\) and \(\omega_{2}\) from the probability space \((\Omega_{1},A_{1},Pr_{1})\) and \((\Omega_{2},A_{2},Pr_{2})\),  respectively. Produce \(\xi_{1}(\omega_{1})\) and \(\xi_{2}(\omega_{2})\). Then generate two random vector \(\xi_{1}\) and \(\xi_{2}\) from  their probability distribution. As a result, we have \(\mathbf{\Theta}=[\xi_{1}^{T},\xi_{2}^{T}]\). Step 3 : (Check) If the constraint \(\mathbf{P}\big{\{}0\leq\varphi\big{(}\mathbf{x},\mathbf{u},\mathbf{\Theta}\big{)} \leq\mathbf{N}\big{\}}\) is satisfied, then we let \(K=K+1\). Step 4 : (Update) Let \(J=J+f(\mathbf{x},\mathbf{u})\). Herein \(f(\mathbf{x},\mathbf{u})\) is the objective function defined in Equation (17). Step 5 : (Repeat) Repeat Step 2 to Step 4 \(n\) times. Step 6 : (Terminate) Return \(F_{1}(\mathbf{x},\mathbf{u},\mathbf{\Theta})=K/n\) and \(F_{2}(\mathbf{x},\mathbf{u},\mathbf{\Theta})=J/n\).
```  
**Algorithm 1** Stochastic Simulation for Uncertain Functions.