# Optimal Agent-Based Pickup and Delivery with Time Windows and Electric Vehicles
## 4 Agent-Based Simulation System
### Agent-Based Simulation Model  
The representation of each vehicle as an agent within the simulation offers several advantages. Each agent operates autonomously yet communicates and collaborates with other agents to achieve their goals. The agent-based approach allows for flexibility and scalability in the simulation. As the number of vehicles and orders increases, the model can easily accommodate without significant loss in performance. Each agent in the simulation processes information and makes decisions independently, reducing the computational overhead as in centralized approaches. The agents' autonomy and collaborative capabilities can lead to a more adaptive and resilient solution in optimizing plans for EVs in dynamic environments.  
The ABSM described below is required to handle the dynamic PDPTW-EV. We consider a set of initial orders assigned to each vehicle using a simple assignment strategy. Then, new incoming orders are inserted into the vehicle's initial route plan after establishing a consensus of each vehicle on how to deal with the order. In the context of solving the PDPTW-EV, we represent each vehicle, order, and charging station as agents in a grid environment. The agents and their interactions can be observed in Figure 2.  
Table 1 depicts the properties defining the order agent, including time-based properties, location properties, and links to partner order agents within the pickup and delivery context.  
The charging station agent is the agent that represents a charging station and it is characterized by the properties defined in Table 2. When a vehicle agent that requires recharging arrives at the charging station, it fully recharges at the defined _recharging_rate_.  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Order:** & \\ \hline unique\_id & A unique identifier for the order. \\ pos & Position of the order. \\ demand & The demand associated with the order. \\ ready\_time & The time when the order is ready. \\ due\_time & The due date for the order. \\ service\_time & The time taken to service the order. \\ partner\_id & Identifier for the partner associated with the order. \\ pickup & Indicates whether the order is a pickup or a delivery. \\ \hline \hline \end{tabular}
\end{table}
Table 1: Description of the order agent.  
Figure 2: Agent interactions in an agent-based simulation.  
Finally, Table 3 describes the properties of a vehicle agent. The vehicle agent represents an EV by properties such as speed, battery capacity, list of orders to be handled, transport capacity, and the plan.  
Figure 3 describes the simulation process as an activity diagram. The simulation starts by generating the orders. The first step generates a pair of pickup and delivery orders. Following, the order is assigned to a vehicle agent based on the chosen simulation strategy and is added to its order list. Next, the vehicles handle delivering considering constraints depicted by Equations (2)-(10), ensuring enough battery charging or reaching the charging station for a complete recharge to fulfill their assigned list of orders as stated by Equations (11)-(13). After finishing all their orders, the vehicles are returned to the depot. The simulation can be configured to handle two types of order assignation: \"Closest Allocation\", in which the order is allocated to the closest vehicle agent, and the \"Negotiation\" consensus mechanism, where the vehicle agents negotiate for handling the pickup and delivery orders pair.