[MUSIC] I will now present you a simple model about a traffic intersection. It's still, I want to say a toy example, but it could be refined a bit to model a real traffic intersection. So, if you understand the toy model that we present now, you could easily enrich it to be able to model a real traffic intersection or even the district in a city. So, let's start with this simple situation here. We have a main street going from east to west with two lanes and car arrived from two lanes. Let's say that lots of car passed here and a secondary street coming from south, just one lane. And most of the car in fact that will be on main street so we want to keep the traffic light as much red as we want. As much green, sorry, as we want. But sometimes cars comes from the secondary streets and so we have to switch the traffic lights. For that there's a camera, represented here by the small camera picture, that detects a car waiting in the secondary street. And we'll schedule a switch of traffic light to allow all cars in the secondary streets to pass. This switching will be limited in time, and then the secondary street traffic light will be red again. And the main street traffic light will turn to green. We're interested here in suppose that we know the flux of incoming cars, the flows of incoming cars, in the single lane street. What would be the good parameters to minimize the wait time of the cars in the secondary streets and the red light. And to avoid blocking the main streets for a, more for a Important amount of time. The system can be represented really easily if we concentrate on the necessary ingredients here. So, the states can be for example the state of traffic light can be represented by a single variable because if one of the traffic light is red we know that the other one is green. So here we have a variable f which represent the traffic light in the secondary streets. And this variable can have two states, red or green. The other thing that we have to do is to keep the number of cars waiting in the second street. We just have to keep one natural number because for the purpose of crossing the street, all the cars are the same so we don't have to distinguish different cars. As I told you in the previous model all the events will be added to 11Q which will be sorted by the time of occurrence of the model such as the first, the next event will be the next one. And every event will be represented by both a time, when the event will occur, and an action will be able to change the state and the event queue to update it. Here the model will need several parameters. First parameters related to the traffic itself, which will be the schedule of arriving car. When car arrives in the secondary streets. This parameters of this traffic can be obtained by two different ways. First of all we could, with cross sensors, measure during a week or a month exactly when cars arrive, and then we can replay this week or this month with different setting to try to optimize them. But we could also have statistical process of car arriving [INAUDIBLE] distribution and we could measure the parameter of the distribution such as to be able to draw like in the Monte Carlo context, to draw arriving cars. [SOUND] Finally we have parameters which are related to the traffic lights themselves. And in fact those are the parameters that we would like to optimize or to tune. The first one is the latency of switching the traffic lights from green to red, or red to green. So here we are concentrated especially in the secondary street. So let's say that is the amount of time needed to turn that traffic light from red to green. And then once its turned green in the secondary street, we have to wait an amount of time that all the cars, or at least some of them, could pass. For that we have two numbers, a is the latency to switch initially the traffic light. And then it will stay green for b, times the number of cars waiting. We have a simple model that's the amount of time the traffic light will stay green is proportional to the number of waiting cars. It's quite easy to represent it with a discrete event if we take only into account when car arrives and the traffic light changes color. So for that we'll have three events, here presented in pseudo Python again. First, when the car arrives is the event CAR t, would be an exogeneous event because it of the current state of the system, but what's the extra associated? So first of all, if the traffic light is red, the car would have to stop, so we can increase by 1 the number of waiting car. If now the number of getting car is equal to 1, it means that it is the first car which arrived. That will trigger the camera which will schedule the switching of traffic lights. And for that, we insert in the queue a new event which will be red to green. The traffic light turns form red to green, and it will be scheduled on time t + a where a is the latency and t is the time of the arrival of the car. And if the traffic light was green, in fact the car can pass and we don't have to record anything because it will leave the traffic intersection. And we have two other events, which are paired, to control how the traffic light in the secondary street changes color. First, we have red to green. And then the action is simple, we change the state of the traffic light to green, and we insert in the queue a new event, which is green to red. And this event will be scheduled at t, the current time, plus c, the number of waiting car time b, which was one of the two parameters I introduced before. And we can say that the number is 0 because we can assume here that all car passes. And finally, the last event is green to red and the action is simply to turn the traffic light to red. So that's super easy to implement and we can have a look at the full evolution example. So suppose here, that we have the model parameter, 30 seconds for a, so the latency is 30 seconds, and the amount of time is, say green for CAR is ten seconds. At time 0, the number of working CAR is 0. The traffic light is red and we have a queue which contain only the events because since they don't depend on the evolution of the system, we can generate them beforehand. So here we have five cars that will arrive at second stand, 25, 35, 60, and 75. So the system will peak the first event, which is a car at ten seconds. So the time jumps to ten, the event is a car arrives. And the action will do three things here. First of all, if we increase the number of waiting car to 1, because one car arrived, then it will not change the traffic light, it will stay red. But it will insert at a time which is equal to 10 + 30 seconds t + a, so 40 seconds. You would insert in the queue a new event red to green which will be inserted at it's current position. The traffic light will schedule it's switching. At 25 seconds, a new car arrives, at 35 seconds another car arrives, so c is going to three, three cars are waiting. At 40 seconds, finally, the traffic light turns to green. That will have two effects. First of all, all the waiting car will go away, c = 0, and then we'll schedule when the traffic light should be back to red. And we do it at 70 seconds, because it's 40 seconds the current time. Three cars were waiting. And we have a parameter b of 10, so it would be 40 plus 3 times 10. So at 70 seconds, the traffic lights should be read again. So a new car arrives, and since the traffic light is still green, it passes at 60 seconds. At 70 seconds, the traffic light turns red. 75 seconds, a new car arrives. And, again, that will schedule first of all the change of traffic light from red to green and then the other transition. And at 150 seconds they are no more action in the queue, so the model stops because it's finished. We could also complicate this model to take into account more realistic parameters like the limit duration for green light synchronization. The better synchronization between the two traffic lights, possibility to have a pedestrian crosswalk where on demand, pedestrian can push a button to request a green light for them for crossing. And so switching all the traffic lights to red for the cars and so on. And in fact this critical system has really great advantage to modern traffic in a city and is used in the commercial and professional context to try to model the traffic for a full city, for large city. The problem is that since only we know what happens during the events and all the rest of the evolution is real simplified. There's no way to visual correctly what was happening. And for that reason, the result generally not presented in visual fashion. And so they can have less impact when they're addressed to media or politicians that models were, you can see all the cars moving. But on the other hand, they are really fast. You can model a full city, and you can have really accurate and reliable statistic out of it. In the next module, we'll present you a real research example and we'll leave all the toy example to see what we can really do with discrete events and a geophysical example where it makes sense to use that rather than other solutions. [MUSIC]