3.1.2. Entities, State Variables, and Scales

Agents represent individual prosumer and consumer households. Each consumer agent is assigned a lawn area to calculate irrigation demand and is assigned a time of day for exerting demand. Prosumer agents are each assigned a rainwater tank volume capacity, a catchment area, and a small pump with a given exit pipe diameter, length, and roughness coefficient to add harvested rainwater to the hydraulic network. Parameters are used as input to the model (Table 1). State variables are updated dynamically (Table 2). For each prosumer, tank storage is updated due to precipitation, flushing requirements, and water released into the network. The model operates on an hourly time scale.

Three system-level state variables are used to represent the depth of hourly precipitation (*Pt*), total precipitation depth over the preceding 24-h period (*BP*24), and the time step at which rain begins (*TR*).




**Table 2.** State variables for consumer and prosumer agents.

3.1.3. Process Overview and Scheduling

The following steps are executed at each hourly time step, *t*, of the simulation. The execution time step is labeled *tE*. The agent-based model requires hourly precipitation (*Pt*) as input.

**Step 1. Update system-level state variables.** Based on the value of *Pt*, the values for *BP*<sup>24</sup> and *TR* are updated. The precipitation over the preceding 24-h period (*BP*24) is a binary variable that takes a value of one if there is a precipitation greater than zero in 24-h period before the execution time:

$$BP\_{24} = \begin{cases} 1, & \text{if } \sum\_{t=t\_E-24}^{t\_E-1} P\_t > 0\\ 0, & \text{otherwise} \end{cases} \tag{1}$$

where *t* is the time step and *tE* is the current execution time step. Rain time, *TR*, is the first time step when the precipitation is greater than zero if the precipitation over the preceding 24-h period is zero.

$$TR = t\_{E\prime} \text{ if } P\_{l\_E} > 0 \text{ \& } BP\_{24} = 0 \tag{2}$$

**Step 2. Prosumer agents update rainwater storage values.** Each prosumer agent *g* calculates rainwater storage volume, *St*,*g*, at time *t* based on the runoff from the roof catchment and the volume of water flushed for the first flush diversion:

$$S\_{t\_{\sqrt[\xi]}} = \min(V, S\_{t-1, \mathbb{g}} + P\_t \times A - VF\_{t, \mathbb{g}}) \tag{3}$$

where *A* is the roof area; *V* is the capacity of the rainwater tank; *VFt*,*<sup>g</sup>* is the volume of water flushed from the rainwater tank at time step *t* for agent *g*. Prosumers can accumulate a maximum volume of water equivalent to the capacity of the rainwater tank (*V*); any excess volume is released as runoff. If no precipitation falls in the previous 24 hours before a distinct rain event begins, the prosumer agent is required to discard a first flush volume. The volume of rainwater that should be flushed (*VFt*,*g*) ensures that a prosumer agent flushes a volume equal to *F* × *A* after the rain event begins, where *F* is the required first flush rate, and *A* is the roof area. The agent can flush the total volume (*F* × *A*) over multiple time steps, if needed.

$$VF\_{t, \emptyset} = \begin{cases} \min(S\_{t, \emptyset'}, F \times A - \sum\_{t=TR}^{t\_E} VF\_{t, \emptyset}), & \text{if } \sum\_{t=TR}^{t\_E - 1} VF\_{t, \emptyset} < F \times A\\ 0, & \text{otherwise} \end{cases} \tag{4}$$

**Step 3. Consumer agents exert irrigation demands.** If no precipitation fell in the previous 24 h (*BP*<sup>24</sup> = 0), each consumer agent *c* exerts a daily irrigation demand (*D I*) at time step *T Ic*. The hourly demand exerted by each consumer agent *c* is assigned using Equation (5):

$$D\_{t, \varepsilon} = \begin{cases} DI, & \text{if } t = TI\_{\varepsilon} \text{ & } BP\_{24} = 0\\ 0, & \text{otherwise} \end{cases} \tag{5}$$

The value of *D I* is calculated to initialize the model, as described in Section 3.4.1.

**Step 4. Prosumer and consumer agents trade rainwater.** Each consumer agent with non-zero demand at time step *t* is randomly paired with a prosumer agent with *St*,*<sup>g</sup>* > 0. A consumer agent *c* receives traded water (*TWt*,*c*,*g*) from prosumer agent *g* up to its demand, *Dt*,*c*. If the consumer agent has a non-zero volume of unmet demand, it is randomly matched with other prosumer agents until the total volume of traded water it receives is equal to *Dt*,*c* or until no prosumers have stored rainwater. For time steps when prosumers cannot meet consumer demands, consumer demands are met using water that was reclaimed through the centralized treatment plant. The flow (*Qt*,*g*) that a prosumer pumps into the network at each time step is the sum of traded water (*TWt*,*c*,*g*) that is purchased by consumer agents.

$$Q\_{t, \emptyset} = \sum\_{c=1}^{C\_{t, \emptyset}} T\mathcal{W}\_{t, c, \emptyset} \tag{6}$$

where *Ct*,*<sup>g</sup>* is the number of consumers that prosumer *g* supplies at time step *t*. The total volume of water purchased by consumer agent *c* is supplemented by flows from the centralized system (*CQt*,*c*) at time step *t* to meet its demand:

$$\sum\_{\mathcal{S}=1}^{G\_{\mathcal{t},\mathcal{c}}} T \mathcal{W}\_{\mathcal{t},\mathcal{c},\mathfrak{F}} + \mathcal{C} \mathcal{Q}\_{\mathcal{t},\mathcal{c}} = D\_{\mathfrak{t},\mathcal{c}} \tag{7}$$

where *Gt*,*c* is the number of prosumers that sell water to consumer agent *c* at time step *t*.

**Step 5. Increase time step.** In this step, *tE* = *tE* + 1. The agent-based model is executed to simulate trades for a total of *T* time steps to simulate a one-month period. If the simulation time is reached (e.g., *tE* = *T*) go to Step 6. Otherwise, go to Step 1.

**Step 6. Execute hydraulic simulation model.** The dataset of negative demands (*Qt*,*<sup>g</sup>* for all prosumers) and positive demands (*Dt*,*c* for all consumers) are used as input for the hydraulic simulation model. Section 3.4.2 details the method for running the hydraulic simulation model.

**Step 7. Calculate hydraulic effects and energy consumption for the infrastructure system.** Methods for calculating energy consumption and water age are described in Sections 3.4.3 and 3.4.4, respectively.
