A game-theoretic approach to assess peer-to-peer rooftop solar PV electricity trading under constrained power supply

The integration of distributed energy resources and the transition to smart cities are shifting the urban energy sector to a decentralized operating system. Blockchain-based microgrids, where small-scale operators trade electricity among each others, have gained remarkable attention recently. However, most of the proposed schemes study smart grids in prosperous cities. In this study, the performance of a solar-based power trading scheme is investigated in a shortage-prone context, Beirut City. Thus, we resort to a game-theoretic approach to model power trading as a repeated game between buildings at the urban scale. Results show that solar energy can cover up to 25% of the city electricity needs, depending on the rooftops area coverage. On the other hand, we found that deploying a peer-to-peer trading scheme has marginal impact since the energy demand in the city exceeds the supply and most buildings would prioritize self-consumption.


Introduction
The urban energy sector is undergoing face-paced transformations linked to the accelerated advancement in renewable energy systems and to the penetration of distributed energy resources. The main challenge of renewable energy resources is their variability under different weather conditions, which triggers the need for flexible and stable energy operations [11]. Further, there is a concomitant "digital transition" that the sector is witnessing due to the development of Information and Communication Technologies (ICT) and the penetration of smart energy services [39]. This emerging complexity of the energy systems calls for further research of decentralized and digitized approaches to optimize city-wide power management [3].
By scaling down from a centralized grid to a group of interconnected or individual microgrids, small-scale participants can trade energy within their communities, and control their energy generation and demand. However, such market urges the need for a secure and smart information system [29]. Blockchains are considered as a promising solution for decentralized market design, that ensure transparent, distributed, and secure transactions among energy consumers and producers [11,29,39]. A blockchain is a distributed public data-ledger maintained by achieving the consensus among a number of nodes in a peer-topeer (P2P) network [26]. The nodes perform some actions or strategies to maximize their own utility, and generally have conflicting interests. Moreover, some nodes may be malicious, and tend to form collisions and blow up the principle of decentralization [26]. To address these risks, game theory has been applied in the blockchain network [26]. Game theory provides efficient analytical tools to model interactions among entities (i.e, nodes) with conflicting interests in a distributed manner [9]. It can also be used to develop incentive mechanisms to encourage entities to perform certain behaviors or prohibiting them from executing other ones [26]. Nodes can learn and predict each other strategies which optimize the decision making strategies and reduce the security risks.
Several researchers have studied blockchain technology in the energy sector [29,34], and game theory methods within the context of the smart grid [1,2,14,20,23,27,30,[35][36][37]41]. Moreover, many prosperous countries have already implemented P2P energy trading technology in some of their cities [29,38,40]. A particular case, Tunisia, which is considered a developing country, has already started its transition to a smart electrical network, which requires the exploration of P2P energy trading potentials [28].
The blockchain technology and game-theory models are mostly investigated for a "3D" purpose: decarbonization, decentralisation and digitization of the energy market, considering advanced infrastructure and energy provision. However, in less developed context, in cities with poor or even collapsed infrastructure and deficient in energy provision with intermittent schedules over the day, could renewable energy be an alternative for the current production system? Would smart grid technologies integration with P2P energy trading be possible? And what would be their potential?
In this paper, we explore the potential of power trading in the city of Beirut. Beirut is a Mediterranean city, well known for its electricity challenges, and fragile energy sector. The city (and the whole country) is undergoing harsh rationing of electricity that is worsening year after year. On the other hand, Beirut has the potential to meet 8-50% of its power needs, thanks to its solar power potential, according to a previous study [32]. Therefore, it is important to consider the evaluation of a smart grid implementation and its outcomes in terms of energy savings. This examination would achieve a twofold goal: maximize, if possible, the solar power potential in Beirut, and expand the space where gametheoretic smart grids are tested. For this purpose, we build on a previous work [10] to develop an energy trading scheme, with a game theory approach to model the interaction between "prosumers", a term that refers to users who consume, produce, store and share energy with other grid users [18]. Despite being a case study, the presented analysis is relevant to many cities and communities around the world that face power supply challenges similar to Beirut City and are looking to maximize their distributed solar energy potential. This global relevance of the obtained results is examined in the discussion section.
This paper is structured as follows: in Sect. 2, we first present the essential data to build our model, and then proceed by formulating the game based on which the smart grid is developed. The results of the power trading platform are illustrated in Sect. 3, before moving to the discussion of the methodological observations and policy implications of the study in Sect. 4. And in the end, we conclude by listing limitations of the study and setting the ground for future work.

Data collection and preprocessing
Beirut is located on the eastern shore of the Mediterranean sea with a stock of 17,742 buildings (in 2016). The power provider, Electricité du Liban (EDL), segments the city into 59 sectors, and the buildings are grouped accordingly. Each sector has a schedule of electricity provision and outages. Figure 1 shows the sectors distribution in Beirut. EDL divided the city into 79 sectors, which do not overlap with the city's districts. We thus use their shapefile of the sectors' division to assign building IDs, which allows the identification of outages schedules. More precisely, the buildings receive their electricity needs from the national power utility in Lebanon EDL, and from private diesel generators during daily systematic outages of 3 h in Beirut administrative area. Electricity bills from EDL are provided at the bimonthly level, which we have acquired for 13,317 buildings, and no records of electricity consumption with finer time resolution were provided or made available. On the other hand, diesel generators are not metered, but the outages schedules are provided at the daily level. Therefore, the average hourly electricity consumption can be calculated to estimate the potential energy demand during outages, before aggregating the results to the bimonthly level to ensure data consistency. For a better formulation of the trading scheme and its potential, data for two additional years (named 2016 and 2017 for simplicity) were randomly generated from the 2015 actual data, 1 3 by multiplying each building demand by a random number ranging between a lower and upper percentages.
As for the rooftop solar energy production, a previous study, Beirut solar map [32], estimated the aggregated bimonthly solar irradiation I at Beirut buildings rooftops. The findings of this study were used as inputs to the power trading model presented here. The solar production of each building's rooftop S i is calculated as follows: where A i is the rooftop area of the building i, r a is the ratio of covered area, r the solar panel efficiency, and PR is the performance ratio to account for losses. Their values are shown in Table 1, and all acronyms listed up to this point and beyond are given in the Appendix.
As we will see in the next section, the microgrids are grid-connected, which means they operate in conjunction with the main grid and supply a fraction of the (1)

3
A game-theoretic approach to assess peer-to-peer rooftop… total load provided by EDL [15]. However, due to the occurrence of outages, they have to switch to the islanded mode and undertake the job of supplying the loads [15]. This imposes control, protection, stability and safety issues, especially in case of unplanned islanding [12]. To account for the islanded mode, the scheme is modeled by disconnecting the solar generators from the grid accounting for the worst case scenario. In this case, the amount of solar energy is reduced by the average of 3 h of production. Therefore, this study reports results of a lower and upper bounds of solar production and trading.

Energy trading scheme
The system is modelled in such a way that each sector has its own microgrid P2P energy trading. Each microgrid consists of a set of prosumers, i.e. buildings, connected to a central power station controlled by EDL. They are also connected to each other through smart meters for communication and energy trading. Prosumers first satisfy their electricity needs from their own renewable energy production from rooftops solar PVs (without batteries). Then, they can assess their extra needs or remaining renewable energy to decide to cooperate through a power trading scheme. If additional electricity is still required even after cooperation, or the user decides not to cooperate at all, it can purchase its electricity needs from EDL. The models are formulated over a period of 3 years. At each time slot, in our case 2 months, each user has two values: its total electricity demand D i , and its harvested solar energy S i . By subtracting these two values, it can determine if it needs additional power or it has a surplus of renewable energy, and therefore will cooperate as a consumer or a producer at this time slot.

Game formulation
A repeated game is considered to enable power exchange among players. At each stage of the game, the prosumer decides either to cooperate with one (or more) player in the microgrid to increase its monetary benefits, either to defect in case its opponent defect or if a certain benefit is not achieved. The monetary benefit or the utility u we applied herein is a non continuous utility function, which belongs to a class of discontinuous games such as price competition and congestion competition models. It is calculated as the difference between the power costs of the additional demands, which are fully purchased from EDL, and their costs when fully or partially purchased from the microgrid after participating in the energy trading scheme as a consumer. On the other hand, if the player is participating as a provider of electricity, its utility function becomes the total revenue from selling its solar power to other players. The utility function is defined in Eq. (2), where u i is the monetary benefit of player i, D i,EDL its electricity demand from EDL, S i,purchased its purchased solar energy from other player(s), c the price of electricity purchased from EDL, equivalent to the actual rates as provided by the company and shown in Table 2, and a the cost of buying solar energy from other players and its equivalent to 0.75 of the EDL prices.
The capital cost of the purchasing of PVs is not accounted for. We assume that PV modules are adopted following the distribution of solar systems on households as part of an international aid program due to the dire economic conditions in the country.

Matching algorithm
It is assumed that an algorithm is implemented in the players' smart meters to manage the game scheme. First, each user calculates its additional electricity demand or RE surplus, to indicate if it will participate in the trading scheme as consumer or producer. We ranked the matching players as function of the metric "demand-supply" to minimize the number of transactions. Then, each user ranks all other possible matching players based on a distance measure, which is a function of the difference between the player's additional demand/RE surplus and the other player's RE surplus/additional demand in the past time slot. The geometric distance between the two players is neglected. The euclidean distance for P2P energy trading between players i (consumer) and j (producer) is given in Eq. (3): After that, the ranking lists of all players are used as input to a nested algorithm, the Galey-Shapley algorithm or the "stable marriage" algorithm, to find the best matching pair from the pool of players. The output pairs by the Galey-Shapley algorithm will play and cooperate at the next time slot. At the end of each time slot (2 months), each player calculates its cost benefit and compares it with the cost benefit in the case of not cooperating and to the threshold of 50, 000 LBP, which is the share of an apartment to its building's monthly maintenance fee. A sensitivity analysis of an upper limit of 100, 000 LBP was performed and the results are given in Table 3, along with the values of the lower limit of 50, 000 LBP. If a cost benefit is not achieved or if it is less than the threshold, the player will no longer cooperate with its current pair, and will enter and his partner to the Galey-Shapley algorithm for matching for the next time slot, without the possibility to be matched together again. Two remarks had been considered: -Some players will not succeed to match since the number of producers may be less than that of consumers (or vice-versa). In this case, the unmatched players will be in a waiting list. -Players can play with many players, as much as they have RE to share or need to buy. Therefore, at each time slot, after the first pair matching, players with RE excess/energy deficit and in the waiting list enter the matching algorithm again. This process is repeated until no more producers or consumers to play.
The algorithm is oblivious about the identity of the players as long as their distance metric is minimized and thus it does not guarantee a unique solution of the game. For example, if player 1 and player 2 were matched, simultaneously with players 3 and 4 being a pair, it could equally converge to player 1 and 3 being matched and 2 and 4 as pairs, as long as the distance metric of both scenarios is exactly the same.

Market size
The presented methodology above can be used to assess the city-wide potential of rooftop solar PV power generation with and without allowing players (buildings) to engage in a peer-to-peer trading scheme. Figure 2 shows the percentage of the reduction in the yearly electricity demanded from the national power utility (in other words, the energy savings) as function of the percentage of buildings equipped with rooftop PV systems. Assuming only 50% of the buildings' rooftops can be occupied by PV panels (upper chart), the maximum annual savings of electricity would be around 101.5 million kWh, which is equivalent to 17% of the annual electricity demanded by the same set of buildings. If the rooftop area available is increased to 75% (lower chart), the maximum would increase to 145 million kWh, equivalent to 24.3% of the demand. 1 It should be noted that these maximum values can be considered as theoretical limits rather than realistic targets since they assume that all the buildings in the data set would install solar PV systems. In reality, only a fraction of the buildings would do so, depending on financial and regulatory incentives.

3
A game-theoretic approach to assess peer-to-peer rooftop… Another aspect that is highlighted in Fig. 2 is the impact of peer-to-peer trading. If a micro-grid is employed and energy trading among sectors and among buildings is enabled, the electricity savings are expected to be higher since buildings which have excess of energy can trade it with other buildings that need power. However, in the case of Beirut City, the impact of electricity trading remains marginal. When trading is enabled, the savings increases between 1 and 5% compared to the baseline case without trading. The main reason for this is that most of the generated power is preferentially deployed for self-consumption since the electricity demand within the city, at any time, far exceeds the supply by the national utility. While in principle peer-to-peer trading should lead to significant savings, for the mechanism itself to work it needs some prerequisites such as modern infrastructure, smart metering, robust gird with low losses as well as an enabling regulatory environment.
Another prominent problem that faces distributed power generation in Lebanon is the "islanding" effect due to the frequent power outages [5]. Despite outages, power supply in Beirut is better than other regions in Lebanon. While outages can be to 16 h/day in some inland regions, Beirut only suffers from 3 to 6 h of outages 2 . Figure 3 shows the bimonthly potential electricity that can be generated by rooftop PV systems with and without outages. The bimonthly accounting, which also shows the seasonal variation, is because data is only available in such a time frame.
As expected, the presence of a 3-h outages per day in Beirut decreases the city's rooftop solar PV potential by an average of 5.8%. Such a low impact of the islanding effect is quite logical given that little trading is possible to start with in the current Fig. 3 Power demand before and after solar production (50% roofs area for upper figure, and 75% roofs area for lower figure), considering 3 daily hours of solar energy disconnection (lb) and full solar production (ub), with energy trading environment. Clearly, if another city, where power supply is uninterrupted, is being modeled these outages would likely have a much more substantial impact.

Market efficiency
Besides estimating the market size for rooftop PV electricity potential in Beirut, the developed model could also be leveraged to assess market efficiency through examining its levels of competitiveness. Figures 4 and 5 show the level of competitiveness in July-August among producers and consumers, respectively. According to Fig. 4, more than two thirds of consumer buildings have less than 10 possible matches among producers (upper chart: 50% availability factor). A match is a building with the "energy" distance to the player (described in the matching algorithm above) is less than 1000 KWh. In the lower chart of Fig. 4 (75% availability factor), the percentage of buildings that have less than 10 matches is slightly lower at 63%. Further, one third of consumer buildings are capable to match with only one player.
As shown in Fig. 5, while most of the consumers have less than 10 possible matches, 83 and 82% of producers have between 2 and 100 possible consumers, at 50 and 75 rooftop availability factor, respectively. Competitiveness among Fig. 4 Distribution of the number of matching producers per consumer (50% roofs area for upper histogram, and 75% roofs area for lower histogram) consumers to find a matching producer is very high, while it is much weaker among producers looking to find a matching consumer.
If we assume that 100% of buildings are equipped with PV systems and willing to participate in the trading scheme, percentage of participants is expected to reach 42 and 58% at 50 and 75% rooftop availability factors, respectively. These are peak values during the May-June period as shown in Fig. 6. The number of participants drops by only a few percentage points during the fall and winter months. Over the entire year, the consumers outnumber the producers by 30%.

Sector-level analysis
The building data set utilized in this paper also maps buildings to specific sectors within the city. Although the geometric distance between two matching players is not a criterion in the developed matching algorithm, assigning buildings to specific sectors is relevant in the case of Beirut since the power outages scheme is sector-based. At any given time during the day, a number of sectors receives electricity from the national utility while other sectors do not. Figure 7 shows the annual power consumption of each sector in the current situation and after the PV installation with different rooftop area availability factors. It is interesting In order to find if there are any specific commonalities between sectors with similar power reduction percentages, sectors were clustered based on average and standard deviation of monthly power consumption, average and standard deviation of monthly solar energy, total rooftop areas, and number of buildings (among the 13,317 buildings examined in this study). We applied k-means algorithm to cluster the sectors, and the number of clusters, three in this case, was defined based on an optimization procedure. The correlation among these variables is shown in Fig. 8. Each dot represents a cluster of sectors. As the plots of the figure illustrate, clusters can be easily distinguished, which reveals that the sectors in each cluster have particular characteristics compared to the ones in other clusters. For example, sectors

Methodological observations
Among Beirut's buildings, 75% were used in this study, which constitute a wellrepresentative sample of the buildings. We obtained the yearly electricity consumption of these buildings from EDL at the bi-monthly level. Yet, smart grid technologies consist of smart meters generating data at finer time intervals (hourly and daily). To better study the implementation of a power trading scheme, Fig. 7 Actual annual electricity consumption by sector, and its simulated values after implementation of PV over buildings' rooftops. The sector IDs are set by EDL the electricity consumption at hourly or daily resolution is more effective. Participants would have the chance to better manage their electricity consumption, and negotiate as traders the price. At a later stage, traders can negotiate for extended future time horizons [29]. Therefore, the presented study can be considered as a first-order analysis of P2P energy trading potential in Beirut.
We adopted a simple broadband pricing mechanism, based on the official prices from EDL that vary relatively to the amount of consumed electricity and the building type. However, a more sophisticated pricing scheme can be applied. An energy cost model can define the different costs of the same load at different times of the day that optimize the electricity price for minimization of the energy cost of all users [31]. This is considered as a top-down approach, where prices are specified by a third-party. However, engaging prosumers in the electricity market would empower them and allow them to efficiently manage their electricity consumption and production and minimize their economic expenses. A way for that could be to consider a dynamic pricing that takes into account the fluctuated nature of RE and builds upon real-time information and day-ahead pricing schemes [21], or that maximizes social welfare or guarantees players' rationality  [33]. Market-driven pricing can also be investigated. In some cases, a price competition or bidding could occur and modelled based on game-theory [22].

Policy implications
The expansion of distributed energy is one of the global trends in electricity provision [24]. Distributed power generation brings in several benefits compared to the traditional model of centralized generation. First, since distributed sources are often close to the consumer, they allows for higher energy access without the need for expensive investments in power transmission and distribution infrastructure [7]. Second, they offer better energy security against both natural disasters and deliberate attacks [19]. The economics of the deployment of distributed energy systems have been constrained by the so-called "economies of scale", which favors large power plants [13]. However, the dramatic reduction in the cost of renewable energy technologies, particularly solar PV over the last decade has initiated a paradigm shift in the way governments and the public perceive the role of renewable distributed energy systems. Moreover, the capacity constraints and capital cost of large centralised plants when considering the installation, distribution, transmission and carbon costs, make them not optimal and may lead them to an end [8]. While the role of distributed solar PV systems in powering remote communities is well-established, their potential to power urban context presents an exciting opportunity to shift towards a more sustainable energy future.
One of motivations of this paper is to test advanced approaches such as P2P trading of solar PV-based generation in a developing context with major structural challenges. Beirut city represents a perfect example to conduct such an analysis because of its widely known electricity provision issues [4]. Three major structural challenges characterize the integration of renewable distributed power generation in Beirut (and in Lebanon in general): frequent power outages, poor transmission and distribution network, and lack of RE-friendly legal and regulatory frameworks. While the absence of regulations does not impact our technical analysis as we have ignored it, power outages and network quality are two essential components for the technical and economic viability of the integration of on-grid solar PV systems.
The results outlined above show the impact of power outages and poor service delivery in limiting Beirut's potential for deploying on-grid rooftop PV systems. The impact is driven by three major effects of power outages. First, power cuts create an energy deficit that would naturally encourage the deployment of solar PV systems for self-consumption. Second, the poor state of the network and its high losses further weakens the economics of any trading potential. Total (technical and non-technical) network losses are estimated at around 34% in Lebanon [17]. This means that for every kWh that is exported to the distribution grid, 0.66 kWh would be delivered to the consumer. Third, and most importantly, the prevalence of power outages mean that the network may not be able to absorb solar generation and pass it on from producers to consumers in the first place.
The reported results have shown that electricity provision around the clock, particularly during the day time, is paramount for the success of any P2P energy scheme that is based on solar energy. As shown in the case of Beirut, P2P trading potential to increase the city's solar energy penetration is rather modest. However, and despite these challenges, a pilot model can still be implemented, but on the sector level rather than on the building level. One major observation from the results is large disparity between the solar PV potential in different sectors within the city. This could potentially lead to two major policy recommendations: (1) in the shortterm, sectors with the highest solar PV potential should be prioritized with power supply during the day to allow for the national network to absorb all of their available solar electricity that can be fed into the grid. Power outages in these sectors can take place during the evenings. (2) The buildings in the targeted sectors could be prioritized with the deployment of smart meters, a step that is essential for ongrid distributed systems, and thus energy trading, to work. So far, the use of smart meters is very limited in Lebanon but there is a plan to expand their use as part of a modernization plan of the national power utility. Given their high cost and gradual deployment plans, we recommend that the early wave of deployments to target sectors with the highest solar PV potential.
On the financial side, the economics of P2P trading is more complex than the typical policy frameworks, which include exporting solar PV electricity to the grid such as net-metering or feed-in-tariff. While all of these policy instruments require serious grid, metering and policy upgrades, P2P requires sophisticated mechanism that would balance the interests of consumers, producers, and the national power utility. Producers (or developers) would need to see a positive net present value for their investments, a short pay-back period. Consumers would need to see savings vis-à-vis the status quo scenario. As for the national power utility, it can expect P2P to offer substantial reduction of losses in the short-term and a minimal (if not positive) impact on its revenue model post-tariff adjustment and cost recovery through the imposition of grid charges. Optimizing a tariff structure that can simultaneously achieve these interests on both sides is not straightforward and would require careful economic assessment and experimentation.

Relevance to other cities
The poor state of power supply in the city of Beirut (and in Lebanon) is not uniquenumerous other cities are in the same position. According to a 2019 report by the International Finance Corporation, 1.5 billion people around the world live in cities with weak electricity grid and experience blackouts for hundreds and sometimes thousands of hours [25]. For example, major cities in Nigeria (Lagos), Pakistan (Karachi), Iraq (Baghdad), and Yemen (Sanaa) to name just a few, have the same power supply shortages problem that Beirut faces. As such, the presented analysis is relevant to those cities in their pursuit of reducing the use of diesel generators.
In addition to the structural similarities of poor power infrastructure in many cities around the world, the shift to citizen-led distributed power generation is also motivated by deepening economic crises, especially in the wake of the COVID-19 pandemic. Pressing economics and constrained fiscal space strengthen the case for distributed renewable energy while achieving important energy security and environmental benefits. Consequently, cities that are in the same situation as Beirut should start designing and implementing the needed legal framework to facilitate the deployment of distributed energy solutions. Another factor that could also accelerate the transition is removing power subsidies, which would expose the real cost of fossil fuel-based power generation [6].

Conclusion
This paper explored the potential of solar PV-based P2P electricity trading in the city of Beirut using a game-theoretic approach. The analysis estimates the maximum technically-feasible annual savings of electricity in Beirut to range between 17 and 24.3% of the electricity demanded by the studied set of buildings. The impact of electricity trading was found to be marginal since it only increased savings by a maximum of 5%, highlighting the role of power sector's structural challenges in prohibiting advanced concepts such as RE-based P2P schemes in developing countries.
It is worth noting that this formulated game and the algorithms used for matching and optimization do not ensure non-degenerate solutions and thus the recommendation of the matched pairs is not unique.
The presented analysis is limited to operational costs only, i.e. capital costs of the solar PV systems have not been included in the game formulation. This approach was followed because of the existing economic crisis in Lebanon where wide adoption of distributed solar systems would not be possible without an external aid either in the form of grants or provision of solar kits (similar to the World Bank's Program in Yemen). Given the high capital cost of solar systems compared to the hugely devalued Lebanese currency, paying for them would be a barrier. Finally, building on the limitations of the current study, additional exploration can be carried out to apply the game at the sector level, instead of the building level, improving on the current formulation by including PV costs, and taking it to the level of dynamic pricing.