# Optimal Agent-Based Pickup and Delivery with Time Windows and Electric Vehicles
## 5 Experiments and Results  
The experiments were conducted in a Mesa agent-based modeling framework in Python [22]. The ABSM was implemented to deal with the dynamic PDPTW-EV, where vehicle agents handle pickup and delivery orders in a grid-like environment to enhance the total distance traveled by vehicles.  
Based on the proposed model, we evaluate two consensus mechanisms. One involves exchanging some of the remaining orders between vehicles when a new order is generated,  
Figure 4: ABSM: negotiation mechanism.  
and the other entails assigning the order to the vehicle plan that is the most suitable to handle. The objective is to minimize the total traveled distance.  
In the experiments conducted, the charging stations were placed at the beginning of the simulation, and we did not employ any placement strategies. The charging stations can handle charging for any number of vehicles and have infinite charging capacity.  
The experiments aim to compare two different allocation strategies, \"Closest Allocation\" and \"Negotiation\", across 15 randomly generated scenarios. Algorithm 2 describes the scenario generation process. The orders are generated in a given distance range. The _GenerateValidPosition_ procedure guarantees that the generated order position is in the grid and the given range. To ensure that the generated order times are in future steps of the simulation and not in the past, the _CreateOrder_ procedure must define the range in terms of steps for the order's time-related properties and link the order to the corresponding one.  
The metrics used to evaluate the performance of these strategies include _Total Orders Generated_, _Remaining Orders_, _Orders Not Handled In Time_, _Total Distance Traveled_, _Number of Charges_, and _Total Redraging Cost_.  
```
1:\(Min\_Distance\leftarrow\) Minimum distance
2:\(Max\_Distance\leftarrow\) Maximum distance
3:\(S\leftarrow\) Number of simulation steps
4:\(O\leftarrow\) List of newly generated orders
5:for\(o\) in \(O\)do
6:\(Pickup\_Position\leftarrow\)GenerateValidPosition(\(\emptyset\))
7:\(Delivery\_Position\leftarrow\)GenerateValidPosition(\([Pickup\_Position]\))
8:\(Pickup\_Order\leftarrow\)CreateOrder(\(o\), \(Pickup\_Position\), \(true\))
9:\(Delivery\_Order\leftarrow\)CreateOrder(\(o\), \(Delivery\_Position\), \(false\))
10: Place \(Pickup\_Order\) on the grid
11: Place \(Delivery\_Order\) on the grid
12:endfor
13:functionGenerateValidPosition(\(ExistingPositions\))
14:\(Position\leftarrow\) Random position within the grid
15:while any position in \(ExistingPositions\) is within \(Min\_Distance\) of \(Position\)do
16:\(Position\leftarrow\) Random position within the grid
17:endwhile
18:return\(Position\)
19:endfunction
20:functionCreateOrder(\(o\), \(Position\), \(IsPickup\))
21:\(ID\leftarrow\) Increment current order ID
22:\(Demand\leftarrow\) Random demand within the given range for \(o\)
23: Set the ready time within the next \(S\) steps for \(o\)
24: Set the due date within \(S\) steps of the ready time for \(o\)
25: Set the service time within a given range for \(o\)
26:if\(IsPickup\)then
27:\(PartnerID\leftarrow\) ID + 1
28:else
29:\(PartnerID\leftarrow\) ID - 1
30:endif
31:returnOrder(\(ID\), \(Position\), \(Demand\), \(ReadyTime\), \(DueDate\), \(ServiceTime\), \(PartnerID\), \(IsPickup\))
32:endfunction
```  
**Algorithm 2** Order generation.