# A Game Theoretic Approach for Energy Sharing in the Italian Renewable Energy Communities
## 3 Game Theoretic Approach for Value Redistribution
### Cooperative Game
#### 3.2.2 The Shapley Value  
All things considered, a solution based on the core may comprehend many possible values for each player and this payoff may not reflect the most fair way to allocate the grand coalition's value. In order to fairly allocate the coalition's value among the players of the game, the Shapley value takes into account the added value that each player brings to the coalition. In other words, it reflects the most fair payoff for the players in the grand coalition, taking into account the marginal contribution of each player. Shapley value \(\phi\) for user \(i\) is expressed as:  
\[\phi_{i}(v)=\sum_{S\subseteq N\setminus\{i\}}\frac{|S|!\ (n-|S|-1)!}{n!}(v(S \cup\{i\})-v(S)) \tag{39}\]  
in which the marginal contribution \((v(S\cup\{i\})-v(S))\) of the player \(i\) in the coalition \(S\) is weighted on the factor \(\frac{|S|!\ (n-|S|-1)!}{n! }\) that takes into account the possible orders in which player \(i\) can join the coalition \(S\). The Shapley value definition is bounded to four axioms:  
1. Pareto efficiency: \(\sum_{i\in N}\phi_{i}(v)=v(N)\), the total value of the grand coalition is redistributed among the players. 2. Symmetry: if \(v(S\cup i)=v(S\cup j)\) then \(\phi_{i}(v)=\phi_{j}(v)\), if two players contribute equally to the coalition, they receive the same payoff. 3. Additivity: being \(v\) and \(u\) value functions of two games, it holds \(\phi_{i}(v+u)=\phi_{i}(u+v)=\phi_{i}(v)+\phi_{i}(u)\)
4. Null player: if \(v(S)=v(S\cup i)\) then \(\phi_{i}(v)=0\), a player that does not contribute to the coalition, receives no payoff. One of the major drawbacks of the Shapley value is its computational burden as the number of players inside the coalition increases. It is not possible to evaluate the Shapley value for a set of hundreds of userslike it could be the one of an energy community. Furthermore, it has to be noted that the Shapley value does not necessary lie in the core. When considering academic literature in the domain of cooperative games, Nash bargaining is employed to provide incentives to individual users to share their excess energy. In [25], a Nash bargaining problem is set up to stimulate two users to share an energy storage device. The Nash Bargaining solution is used to determine a fair compensation that a user should receive, if the other user has discharged the battery that he had first charged. In a similar fashion, in [26] the authors design an incentive mechanism based on Nash bargaining to develop energy trading between interconnected microgrids. The Nash bargaining solution finds a price of electricity at which the microgrids can trade electricity that minimises the individual costs of electricity demand. As all the microgrids act as rational layers with the objective of minimizing their cost, the Nash bargaining solution also delineates the subset of microgrids willing to participate in active energy trading. On the other hand, coalition formation game theory can analyse which size of micro-grid is more convenient for the participants. As an example, the purpose of [27] is to form coalitions of microgrids comprising energy producers and energy buyers whose objective is to optimize the payoff of each participant. Users' costs are reduced by trading the power within the distribution and avoiding much power flowing through the macro station and the subsequent power losses. An algorithm based on coalition formation game theory is set up, that creates coalitions within a selected area bringing together in the same coalition buyers and producers whose production and demand curves are as similar as possible and whose distance does not create too many power losses. The algorithm iterates the creation of coalitions until the game becomes stable, so no user has an advantage to leave its coalition. Within canonical coalitional games, the Shapley value proves to be the most effective method applied in the literature to fairly divide the benefit resulted by forming a microgrid in which energy is shared.