*2.2. Modelling Approach*

The calculations were performed using Island System LCOEmin Algorithm (ISLA), an in-house microgrid optimization software written in Python 3. The solar PV, diesel, Li-ion BESS, and desalination modules in ISLA were used. Microgrid energy system optimizations were validated with HOMER Pro® (HOMER Energy LLC: Golden, CO, USA). The software simulates the interaction of energy and water components for one representative year in hourly resolution and calculates the levelized cost of electricity (LCOE), levelized cost of water (LCOW), and net present costs (NPC) as shown in Equations (1)–(3), respectively [42]:

$$\text{LCOE} = \frac{\text{CRF} \cdot \sum\_{\text{el}} C\_i}{\sum\_{t=0}^{8759} P\_{ld}(t) \Delta t},\tag{1}$$

$$\text{LCOW} = \frac{\text{CRF} \cdot \sum\_{\text{wt}} C\_i + \text{LCOE} \cdot \sum\_{t=0}^{8759} P\_{dc}(t) \Delta t}{\sum\_{t=0}^{8759} \dot{V}\_{ld}(t) \Delta t} \,\tag{2}$$

$$\text{NPC} = \sum \mathcal{C}\_{i\nu} \tag{3}$$

In the equations above, *Pld*(*t*) is the electrical load, . *Vld*(*t*) is the water demand, *Pde*(*t*) is the power entering the desalination unit, el *Ci* is the total annualized cost of electrical components, wt *Ci* is the total annualized cost of water components, and *Ci* is the total annualized cost of all components. The capital recovery factor (CRF) is defined in Equation (4), wherein *i* is the discount rate and *ts* is the project lifetime [y] [42]:

$$\text{CRF} = \frac{i(1+i)^{t\_s}}{(1+i)^{t\_s} - 1},\tag{4}$$

ISLA finds the component sizes *Si* that minimize the NPC as shown in Equation (5). The optimization is constrained such that both electricity and water demand are always satisfied during the representative year. These are formalized in Equations (6) and (7). In these equations, *PPV*(*t*), *PLi*(*t*), and *Pds*(*t*) are the power outputs of solar PV, Li-ion BESS, and diesel genset, respectively. *Vtank*(*t*) is the volume of water in storage. These variables are subject to additional constraints based on the component models and sizes *Si*. The models for energy and water components are discussed in Appendix A and Section 2.3, respectively.

$$\text{minimNPC}(S\_i)\_\prime \tag{5}$$

$$P\_{PV}(t) + P\_{Li}(t) + P\_{ds}(t) \ge P\_{ld}(t) + P\_{dc}(t) \quad \forall t \in [0, \ 8759], \ t \in \mathbb{N} \tag{6}$$

$$
\dot{V}\_{\text{tank}}(t) \ge \dot{V}\_{\text{Id}}(t)\Delta t \quad \forall t \in [0, \ 8759], \ t \in \mathbb{N} \tag{7}
$$

The optimization process is performed using an iterative search space algorithm as demonstrated in Figure 6. Sets of component sizes are generated, and the NPC of each combination is calculated. The combination with the lowest NPC is selected, and a finer search space is generated from this combination. The generation of the initial search space is crucial to obtain a proper optimum value, which is discussed further in Appendix B.

**Figure 6.** Iterative search space algorithm used by Island System LCOEmin Algorithm (ISLA) on a hypothetical PV-Diesel system. N/A values in the figure indicate a technically infeasible system and are ignored. LCOE: levelized cost of electricity.
