# Agreement Technologies for Coordination in Smart Cities
## 3 Applications
### Emergency Medical Service Coordination
#### Dynamic Reassignment  
The ambulance allocation problem consists of finding an assignment of (available) ambulances to the emergency patients that have to be attended to. In current EMA services, mostly a priority dispatching strategy is used, where patients are assigned in a sequential order of appearance and patients with a higher severity level are assigned first. In each case, usually the nearest idle ambulance \(a_{i}\in A^{I}\) is assigned. This can be seen as a first-call first-served (FCFS) rule, where patients with the same security level that called first are also assigned first to an ambulance. After an ambulance has been assigned to a patient, this assignment is usually fixed. The FCFS approach is not always optimal from a global perspective. First, if more than one patient has to be attended, it is not optimal in the sense that is does not minimise the response times to all patients. Furthermore, the dynamic nature of an EMA system implies that a given assignment of ambulances to patients at one point in time might not be optimal at a later point, for example, if new patients appear or if an ambulance that was occupied before is becoming available again. In order to reduce the average arrival time in the dynamic environment of an EMA service, the assignments of ambulances to patients could be optimised globally and the assignments should be recalculated whenever relevant events take place and a better solution may exist. Based on this idea, we propose a dynamic assignment mechanism of ambulances to patients, which optimises the assignments at a given point in time and recalculates optimal assignments when the situation changes. Given a set of patients to be attended \(P\) and a set of ambulances that are not occupied \(A^{A}\cup A^{I}\) at a specific moment, the optimal assignment of ambulances to patients is a one-to-one relation between the sets \(A^{A}\cup A^{I}\) and \(P\), that is, a set of pairs \(AS=\{<\)\(a_{k}\),\(p_{1}\)\(>\),\(<\)\(a_{s}\),\(p_{q}\)\(>\),... \(\}\) such that the ambulances and the patients are all distinct, and that fulfils the following conditions:  
* The maximum possible number of patients is assigned to ambulances, that is: \(\forall p_{j}\in P\): \(\exists\)\(<\)\(a_{i}\),\(p_{j}\)\(>\)\(\in\)\(AS\) if \(n\)\(\geq\)\(m\) and \(\forall a_{i}\)\(\in\)\(A^{A}\cup A^{I}\): \(\exists\)\(<\)\(a_{i}\),\(p_{j}\)\(>\)\(\in\)\(AS\) if \(n\)\(<\)\(m\)
* The total expected travel time of the ambulances to their assigned patients: \(\sum\limits_{<a_{i},p_{j}>\)\(\in\)\(AS}\)\(ETT(p(a_{i}),\ p(p_{j}))\) is minimised  
\(ETT(x,y)\) denotes the expected travel time for the fastest route from one geographical location \(x\) to another location \(y\). Calculating such an optimal assignment is a well-known problem which can be solved in cubic time, such as with the Hungarian method [46] or with [PERSON] auction algorithm [47]. We propose to use the second approach because it has a naturally decentralised character and can be optimised in settings, as the one analysed here. An optimal assignment \(AS\) at a moment \(t\), due to the dynamic nature of an EMA service, might become suboptimal at a time \(t^{\prime}\) (\(t^{\prime}>t\)). The following cases need to be considered:  
1. One or more new patients require assistance: in this case, the set of patients that have to be attended changes and the current assignment \(AS\) may not be optimal any more. 2. Some ambulances that have been occupied at time \(t\) have finished their mission and are idle at time \(t^{\prime}\). These ambulances could eventually improve the current assignment. Based on this analysis, we propose a dynamic system based on an event-driven architecture that recalculates the global assignment whenever one of the following events occur: _newPatient(\(p_{j}\))_ (a new patient has entered the set \(P\)) or _ambFinishedEvent(\(a_{i}\))_ (an ambulance that was occupied before is becoming idle again).