The environmental damage caused by air pollution has recently become the focus of city council policies. The concept of the green city has emerged as an urban solution by which to confront environmental challenges worldwide and is founded on air pollution levels that have increased meaningfully as a result of traffic in urban areas. Local governments are attempting to meet environmental challenges by developing public traffic policies such as air pollution protocols. However, several problems must still be solved, such as the need to link smart cars to these pollution protocols in order to find more optimal routes. We have, therefore, attempted to address this problem by conducting a study of local policies in the city of Madrid (Spain) with the aim of determining the importance of the vehicle routing problem (VRP), and the need to optimise a set of routes for a fleet. The results of this study have allowed us to propose a framework with which to dynamically implement traffic constraints. This framework consists of three main layers: the data layer, the prediction layer and the event generation layer. With regard to the data layer, a dataset has been generated from traffic data concerning the city of Madrid, and deep learning techniques have then been applied to this data. The results obtained show that there are interdependencies between several factors, such as weather conditions, air quality and the local event calendar, which have an impact on drivers’ behaviour. These interdependencies have allowed the development of an ontological model, together with an event generation system that can anticipate changes and dynamically restructure traffic restrictions in order to obtain a more efficient traffic system. This system has been validated using real data from the city of Madrid.