{'fraction_non_alphanumeric': 0.04197974099243493, 'fraction_numerical': 0.00712911911783562, 'mean_word_length': 3.831619378020072, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Efficient Energy Distribution in a Smart Grid using Multi-Player Games

Algorithms and models based on game theory have nowadays become prominent techniques for the design of digital controllers for critical systems. Indeed, such techniques enable automatic synthesis: given a model of the environment and a property that the controller must enforce, those techniques automatically produce a correct controller, when it exists. In the present paper, we consider a class of concurrent, weighted, multi-player games that are well-suited to model and study the interactions of several agents who are competing for some measurable resources like energy. We prove that a subclass of those games always admit a Nash equilibrium, i.e. a situation in which all players play in such a way that they have no incentive to deviate. Moreover, the strategies yielding those Nash equilibria have a special structure: when one of the agents deviate from the equilibrium, all the others form a coalition that will enforce a retaliation mechanism that punishes the deviant agent. We apply those results to a real-life case study in which several smart houses that produce their own energy with solar panels, and can share this energy among them in micro-grid, must distribute the use of this energy along the day in order to avoid consuming electricity that must be bought from the global grid. We demonstrate that our theory allows one to synthesise an efficient controller for these houses: using penalties to be paid in the utility bill as an incentive, we force the houses to follow a pre-computed schedule that maximises the proportion of the locally produced energy that is consumed.


Introduction
A recent and well-established research direction in the field of the design of digital controller for critical systems consists in applying concepts, models and algorithms borrowed from game theory to perform automatic synthesis (construction) of correct controllers. The contributions of the present article are part of this research effort. In the setting of automatic synthesis, the controller we want to build is a player (using the vocabulary of game theory), and the specification that the controller should satisfy is cast as a game objective that the controller player should enforce at all times, regardless of the behaviour of the environment. The environment itself is modeled as another player (or a set of players). Thus, computing automatically a correct and formally validated (with respect to the specification) controller boils down to computing a winning strategy for the controller, i.e. a strategy that ensures this player to win the game whatever the other players play. System synthesis through a game-based approach has nowadays reached a fair amount of maturity, in particular thanks to the development of several tools (such as UppAal TiGa [1], UppAal Stratego [7] and Prism Games [5]) that have been applied successfully to real life case studies (see for instance [6,4,10]). Until recently, however, the research has mainly focused on two-player games, where the players (the system and the environment) have antagonistic objectives. This approach allows one to model and reason on centralised control only. Although multi-player games have been studied from an algorithmic point of view, strategic forms of those games have been mainly considered, and the study of multi-player games played on graphs-the kind of model we need in our setting-is relatively recent. This research direction is part of the CASSTING project 1 , whose aim is to propose new techniques for the synthesis of collective adaptive systems. Such systems are decentralised and consist of several modules/agents interacting with each other. While the idea of using games remains, using multi-player games for synthesis of collective adaptive systems represents a huge leap in game theory for synthesis. Indeed, in adversarial games the main goal is to find winning (or optimal in a quantitative setting) strategies, whereas in multi-player games, one wants to synthesise controllers by computing equilibria (such as Nash equilibria [11]) characterising an adequate behaviour of each agent.
In this article, we consider a class of quantitative multi-player games that are well-suited to model systems where a quantity grows or decreases along the plays (this quantity can model some energy level, economic gain/loss, or any other measurable resource). More precisely, the game models a multi-state system where the players choose their actions concurrently (at the same time), and the next state is a function of the current state and the players' actions. Going from one state to another can result in a positive or negative cost for the players. One can give two semantics to these games, either an infinite horizon semantics where the plays are infinite and the players want to minimize the limit (inferior/superior) of the partial sum of the costs; or a finite horizon semantics where the goal of each player is to reach some target state, and minimize the sum of the costs paid before reaching the target. In the following, we focus on the latter semantics, more fitted to the case study, we will be interested in.
We start by establishing some properties of these games. Although there may not always exist Nash equilibria in these games, we describe a subclass in which there always exist some. First we observe that when several players play at the same time concurrently, one can encounter a situation similar to the rock-paper-scissor game, in which there is no (pure) Nash equilibrium. However, even in a turn-based game (i.e. a game in which, in each state, only one player is in charge of choosing the next state), there may not always exist a Nash equilibrium. More precisely, we show that-unlike in some other classes of games-it is possible that each player cannot independently guarantee his cost to decrease arbitrarily, while a coalition of all players can achieve this goal. We then show that this is the only situation that prevents Nash equilibria from existing in those games: we prove that, when the cost of any play is bounded from below by a fixed threshold, then a Nash equilibrium exists in the game.
We demonstrate the applicability of this theory in a practical situation. We consider a case study introduced by an industrial partner of the CASSTING project, and model it in a game formalism in order to build a controller fulfilling a specific set of goals. The case study consists of a local grid of eight houses equipped with solar panels. The solar panels produce different amounts of energy during the day. When they need to consume energy, the houses can either rely on energy produced by the solar panels (their own or one of the seven other houses') or buy it from the global grid. The aim of the case study is to minimise the use of energy bought from the global grid as a whole, while preserving the incentive of each house to share the energy produced by their solar panel with others, if not used directly by them. We assume that the energy produced by the solar panel has to be used within a small interval of time and can not be stored (a provision for storage of energy could be added at little increase of modelling complexity). Concretely, we want to generate a controller producing a schedule of the different tasks of the houses, such that each house has no incentive to deviate from this schedule. For this, we assume that there are two types of controllers. One global controller which has information about all the houses, their requirements and their production. Also, there are local controllers in every house communicating with the global controller and controlling the tasks that take place in this house. Local controllers have no information about the consumption or production of the other houses: they are only aware of the energy produced by their own solar panels and the energy requirement of the house at any specific interval of the day. In our experiments, this schedule is computed as a strategy in a multi-player concurrent game that: 1. minimises the energy bought from outside; and 2. minimises the bill to be paid by each house. We also assume that the houses are not bound to follow the schedule and can deviate from it. However, such deviations could lead to a severe increase in the overal consumption from the global grid (if, for instance, a house decides to use its own energy locally instead of injecting it on the local grid as prescribed by the schedule, then the total amount of energy available on the local grid might be too low, and energy might have to be bought from the global grid). For this reason, we devise proper incentive and a penalty mechanism ensuring that the houses would not have any interest in deviating from the proposed schedule.

Theoretical background
We first introduce the class of multi-player games we are interested in. We fix a number N of players and let {1, . . . , N} be the set of players. A concurrent min-cost reachability (MCR) game is a tuple is a mapping such that for all v and a 1 , . . . , a N , Next(v, a 1 , . . . , a N ) ∈ E(v), ω i : E → Z is the weight function for player i, associating an integer weight with each edge. Without loss of generality, we assume that every graph is deadlock-free, i.e. for all vertices v, E(v) = / 0. In the following we let A = ∏ i N A i . A finite play is a finite sequence of vertices π = v 0 v 1 · · · v k such that for all 0 i < k, (v i , v i+1 ) ∈ E. A play is an infinite sequence of vertices π = v 0 v 1 · · · such that every finite prefix v 0 · · · v k , denoted by π[k], is a finite play.
The total-payoff of a finite play π = v 0 v 1 · · · v k for player i is obtained by summing up the weights along π, i.e. TP i (π) = ∑ k−1 ℓ=0 ω i (v ℓ , v ℓ+1 ). The total-payoff of a play π is obtained by taking the limit over the partial sums, i.e. TP i (π) = lim inf k→∞ TP i (π[k]). The cost of a play, cost i (π) is +∞ if π does not visit any target, and TP i (v 0 v 1 · · · v ℓ ) otherwise, with ℓ the least index such that v ℓ ∈ F: it reflects that players want to minimise their cost, subject to the imperative of reaching the target as a primary objective.
A strategy for player i is a mapping σ : V + → A i . A play or finite play π = v 0 v 1 · · · conforms to a strategy σ of player i if for all k, there exists (a 1 , · · · , a N ) ∈ A such that a i = σ (v 0 , . . . , v k ), and v k+1 = Next(v, (a 1 , . . . , a N )). A profile of strategies is a tuple (σ 1 , . . . , σ N ) where for all i, σ i is a strategy of player i. For all profiles of strategies σ = (σ 1 , . . . , σ N ), for all vertices v, we let Play(v, σ ) be the outcome of σ, defined as the unique play conforming to σ i for all i, and starting in v, i.e. the play v 0 v 1 · · · such that v 0 = v and for all ℓ, v ℓ+1 = Next(v ℓ , (a 1 , . . . , a N )) where a i = σ i (v 1 · · · v ℓ ).
A profile of strategies σ = (σ 1 , . . . , σ N ) is a (pure) Nash equilibrium from vertex v, if for all players i, and for all strategies σ ′ i , cost i (Play(v, (σ 1 , . . . , σ ′ i , . . . , σ N ))) cost i (Play(v, σ )). Observe that we assume that the objective of every player is to minimise its cost; thus, intuitively, a profile of strategies is a Nash equilibrium if no player has an incentive to deviate.
We say that a vertex v belongs to some player i if he is the only one to choose the next ver- Figure 1: A game without pure Nash equilibrium representing the strategic game described by the matrix on the right: we do not depict the actions on the loops over targets for conciseness. tex, i.e. for all pairs of actions (a 1 , . . . , . A game is said to be turned-based if each vertex belongs to some player. When considering turned-based games, instead of actions, we say that the players to whom the current vertex belongs chooses directly the next vertex.

Nash equilibria do not always exist. . .
A natural question is the existence of Nash equilibria in the min-cost reachability games we have just defined. In order to understand precisely what are the conditions that prevent the existence of Nash equilibria, we present some examples of min-cost reachability games in which we can show that no such equilibria exist. We also recall previous results identifying classes of games where such equilibria are guaranteed to exist. We start with a game that is not turn-based and admits no Nash equilibria. Figure 1 with four target vertices t (a,a) , t (a,b) , t (b,a) , t (b,b) , and one additional vertex s. Assume that there are two players, and each has two possible actions: a and b. From s the pair of actions (α 1 , α 2 ) leads to t (α 1 ,α 2 ) . If both players choose the same action, the cost for player 1 is 1 and the one for player 2 is 0; if both players choose different actions, the cost for player 1 is 0 and the one for player 2 is 1. There is clearly no (pure) Nash equilibrium in this game from s since for all profiles of strategies, either player 1 or player 2 would pay less with another strategy 2 .

Example 1. Consider the game in
In a turn-based setting, one can also easily exhibit examples with no pure Nash equilibria.

Example 2.
Consider a one player game with two vertices v 1 and v 2 where the latter is the only target. The set of edges is In other words, from v 1 , the player can either choose to loop, and get a reward (since he seeks to minimise his cost); or to reach the target v 2 (in which case the play formally continues with no influence on the cost). In this game, a strategy from vertex v 1 can thus be described by the number of times he will loop on v 1 before going to v 2 . If he never reaches v 2 , he pays +∞ which is clearly bad. If he loops n times, a strictly better strategy would be to loop n + 1 times, therefore there is no Nash equilibrium in that game.
In [12,3], the authors introduce a large class of turn-based games for which they prove that a pure Nash equilibrium always exists. In particular, this result can be used to show that every turned-based min-cost reachability game with only positive costs admits a (pure) Nash equilibrium. From Example 2, we already know that when there are negative costs, this result does not hold anymore. In this example, the (only) player has a family of strategies that allows him to secure a cost which is arbitrary low, hence, the absence of Nash equilibria is not too surprising. Let us now exhibit a third, two-player example in which no player has a strategy to guarantee, individually, an arbitrary low cost; but still arbitrary low costs can be secured when the players cooperate. Again, this phenomenon forbid the existence of Nash equilibria.
Note that here, we only look at pure Nash equilibria. In the general setting of mixed strategies, i.e. where the players pick randomly a strategy according to some probability distribution over the set of pure strategies, there is a Nash equilibrium in this game. Indeed if we let σ n the strategy consisting in looping n − 1 times around v 1 and then going to v 2 (ensuring a cost of −n), the distribution consisting in picking σ n with probability 6 (πn) 2 (one can easily check that it is a distribution) ensures an expected cost of −∞. Example 3. Let G be a turn-based game with two players 1 and 2, and three vertices A, B, and C. Vertex C is the only target. A and C belong to player 1 and B belongs to player 2. The edges and the weight function are depicted in Figure 2 (e.g. ω 1 (A,C) = 0 and ω 2 (A,C) = −1).

Proposition 1. There is no pure Nash equilibrium in the game G, neither from A nor from B.
Proof. We do the proof for plays starting in A, it is easily adapted to the other case. Note that the set of finite plays ending in A is A(BA) * and the set of finite plays ending in B is (AB) + . Let (σ 1 , σ 2 ) be a profile of strategies and let π be its outcome. We consider several cases for π: 1. If π = (AB) ω then Cost 1 (π) = Cost 2 (π) = +∞. Then, let σ ′ 1 be the strategy of player 1 defined by σ ′ 1 (A(BA) n ) = C for all n and σ ′ 1 (πC) = C for all finite play π, then the outcome of (σ ′ 1 , σ 2 ) is AC ω and Cost 1 (AC ω ) = 0, which is strictly better than +∞, and player 1 has an incentive to deviate. 2. If π = (AB) n C ω for some n, then Cost 2 (π) = −n. Let σ ′ 2 be the strategy obtained from σ 2 by letting σ ′ 2 ((AB) n ) = A and σ ′ 2 ((AB) n+1 ) = C. One can easily check that the outcome of (σ 1 , σ ′ 2 ) is either (AB) n+1 C ω or (AB) n AC ω , and in both cases, the cost of this play for player 2 is −(n + 1) which is strictly better than +∞, hence he has an incentive to deviate. 3. Finally, if π = A(BA) n C ω for some n then Cost 1 (π) = −n. Let σ ′ 1 be the strategy obtained from One can easily check that the outcome of (σ ′ 1 , σ 2 ) is either (AB) n+1 C ω or (AB) n+1 AC ω , and in both cases, the cost of this play for player 1 is −(n + 1), hence, again, player 1 has an incentive to deviate. We conclude that, in all cases, one of the players has an incentive to deviate, hence no profile of strategies (σ 1 , σ 2 ) is a Nash equilibrium.

Lower-bounded set of costs
As already outlined, the intuition behind the absence of Nash equilibria in Examples 2 and 3 is the existence of plays with arbitrary low costs (even if these plays can not be enforced by a single player, as shown by Example 3). We will now show that this is indeed a necessary condition for the absence of Nash equilibria. In other words: in a min-cost reachability game (with arbitrary weights), if the set of possible total-payoffs of finite plays is bounded from below, then a Nash equilibrium is guaranteed to exist. Theorem 1. Let G be a turn-based MCR game respecting the following condition: for all players i, there exists b i ∈ N such that all finite plays π satisfy TP i (π) −b i . Then there exists a pure Nash equilibrium from all vertices in G.
We now prove this theorem. For that purpose, let G = (V, {t}, (A j ) j N , E, Next, (ω j ) j N ) be a concurrent MCR game (we will restrict ourselves to a turn-based game when necessary). For the sake of simplicity, we assume here that there is a unique target t for all players, and the only outgoing edge from t is the loop (t, t). Note that the following construction would hold for multiple targets as well.
In the following, we fix a player i, and we assume that there exists b i ∈ N such that for all finite plays π, TP i (π) −b i . We will show how to translate the game G in a game G ′ with only non-negative weights for player i, with a relationship between strategies of i in both games. This will in particular preserve the existence of Nash equilibria. The game . . , −1, 0}: we keep the negative part of the current total-payoff in the vertex for player i, and add a fresh target vertex t; For all a, Next((t, c), a) = t.

Lemma 1. For all finite plays v
• there exists j k such that c k = TP i (v j · · · v k ) in G (note that if j = k this is equal to 0), and in G ′ Proof. The first point is proven by induction as for all j, c j is either equal to 0 or to c j−1 + ω(v j−1 , v j ).
The second point is a consequence of the first. As c k is the weight of a partial play ending in v k , c k + ω(v k , v k+1 ) is the weight of a partial play ending in v k+1 thus min(0, c k + ω(v k , v k+1 )) b i .
As a consequence, for all plays or finite plays π = v 1 v 2 · · · in G, there exists a unique play or fi- Following this, one can map every strategy σ in G to a strategy σ of the same player in G ′ satisfying σ (π) = σ (π) for all finite plays π. Furthermore, for all strategies σ in G ′ , there exists a unique strategy σ ⋆ for the same player in G such that σ ⋆ (π) = σ (π), for all finite plays π. Proposition 2.
As a consequence, there is a Nash equilibrium from v in G if and only if there is a Nash equilibrium from (v, 0) in G ′ . Note that we could not have reached this result simply by shifting the weights above 0, as we need a device to simulate the fact that the sum of the weights can also decrease during the computation.
By applying this construction for all players, we can show that if there exists a lower bound on the total-payoff of the finite plays for all players (i.e. the hypothesis of Theorem 1 is fulfilled), then one can construct a game G ′ with only non-negative weights such that there is a Nash equilibrium in G ′ if and only if there exists a Nash equilibrium in G. From the fact that all turn-based MCR-games with nonnegative weights have a pure Nash equilibrium [12], one obtains the proof of Theorem 1 in the special case where G is turn-based (since G ′ is also turn-based in this case).

Characterising Nash equilibria outcomes
In this section we present a very handy characterisation of Nash equilibria that has recently been used in several works [9,3]. This intuitive characterisation, in the spirit of the folk theorem for repeated games, has been formally stated in [8], and a more general and more involved version can be found in [2]. Roughly speaking, this characterisation amounts to reducing the computation of a Nash equilibrium in an n-player games to the computation of the Nash equilibria in n versions of 2-player games, obtained by letting each player of the original game play against a coalition of all the other players. The usefulness of this technique stems from the fact that 2-player (zero-sum turn based) games have been widely studied and there exists many algorithms and tools to solve them.
Thus, we first introduce a variant of our games, called 2-player zero-sum MCR games. Such a game is very similar to a 2-player MCR game, the only difference is while one of the players has the same objective as in a standard game (i.e. reaching a target while minimising its cost), the second player has a completely antagonistic goal, i.e. either avoiding the targets or maximising the cost for the first player. In those games, we are interested at the infimum cost that the first player can ensure, that we call the value of the game, denoted value(G) for a game G, supposing that an initial vertex is described in G.
Then, we introduce the notion of coalition games. Given an MCR-game G, a player i, and a finite play π ending in vertex v, the coalition game G i,π is the 2-player zero-sum turned-based MCR game played on G from v, where i is the player who wants to reach the target while minimising his costs; and his adversary, denoted −i, has the same actions as the product of all players except i, and its goal is antagonistic to the one of i. Furthermore, to obtain a turn-based game, we assume that −i chooses its actions before i (see [8] for a formal definition). It matches the intuition that player −i is a coalition of all players but i, and whose goal is to make i pay the most.
The characterisation we present works in the case of action-visible MCR-game, i.e. in a game where we assume that the players know the actions that have been played by everyone. A similar result holds in the general case [2], but we do not need it here as the games introduced in the next section are all action-visible. More precisely to be action visible, we assume that for all v, v ′ , there exists at most one vector of actions a such that Next(v, a) = v ′ . Now, assume an action-visible MCR-game, a player i and a play π = v 1 v 2 · · · . An i-deviation from π is a finite play π ′ = v 1 · · · v ℓ v ′ such that if we let a and a ′ be the vectors of actions satisfying Next(v ℓ , a) = v ℓ+1 and Next(v ℓ , a ′ ) = v ′ , then a i = a ′ i and a j = a ′ j for all j = i. Intuitively, this means that all players have agreed to play according to π, and an i-deviation describes a finite play in which player i has betrayed the other players. One can now state the theorem from [8].
Theorem 2. Let G be an action-visible MCR-game and π = v 1 v 2 · · · . Then π is the outcome of a Nash equilibrium, if and only if, for all players i and for all i-deviations π ′ = v 1 · · · v ℓ v ′ : In other words, this theorem allows us to say that a Nash equilibrium can be characterised by (i) a play that all players agree to follow; and (ii) a set of coalition strategies that the faithful players will apply in retaliation if one player deviates. It also provides a heuristic to construct a Nash equilibrium by solving a sequence of 2-player zero-sum turn-based games. It works as follows: (i) compute for each player i, a strategy σ i ensuring the least possible cost against a coalition of all other players; (ii) consider the outcome π of the profile σ = (σ 1 , . . . , σ N ); (iii) check that all deviations satisfy the above property; and (iv) if it is the case, compute coalition strategies in case of a deviation.
Note that this construction does not always work, as the outcome π could fail to satisfy the property of Theorem 2, but it has been proved to always succeed in many known classes of games [3,12]. We use this technique in the case study, as described in the following section.

Modelling
In this section, we model the CASSTING case study described in the introduction via a concurrent MCR game. Recall that the problem consists of: 1. a group of houses H = {H 1 , H 2 , · · · , H N } in a cluster with solar panels; 2. a production function giving the (probabilistic) distribution of amount of solar energy produced throughout the day; 3. a list of tasks that the houses need to perform throughout the day. For the sake of modelling, we divide each day into 15 minutes intervals. Thus, we have 96 time intervals. We take the production function prod : [1, 96] → Z giving the production of energy from each house at any given time interval within the day. We assume that for each house there is a local controller and one global controller for all the houses together. The local controller submits a list of tasks along with favourable time interval (deadline) of the day for the task, and receives a schedule indicating which task to perform when. The global controller gathers a list of tasks from houses and computes a schedule of the tasks so that it achieves the goal; it also sends the respective schedules to the local controllers. Note that the local controllers have no information about other houses and their consumption.

Tasks
We assume that, at the beginning of the day, each house submits a list of tasks that should be performed at preferred interval of time. Let the list of tasks be given as T = {T 1 , T 2 , . . . , T m } for some m. Without loss of generality, we assume that each task can be completed within only one time interval. The energy consumed by a task during each interval is given by the function E T : T → Z. The task list submitted by each house H i is of the form T L i = ( t 1 , I 1 , t 2 , I 2 , . . . , t k , I k ) where t i ∈ T and I i is an interval of [1,96] for all i ∈ {1, . . . , k}. For the sake of simplicity, we suppose that lists of tasks of different houses are disjoint. We denote by Tasks(T L i ) = {t 1 ,t 2 , . . . ,t k }, the tasks in the task list of house H i . The goal of the houses is to complete each task within the given preferred interval and minimise  ( t 1 , [1, 2] ) and that of H 2 be ( t 2 , [1,2] ) where the energy required for tasks are E T (t 1 ) = 4, E T (t 2 ) = 5.

Concurrent MCR game to minimise the energy
We first consider our primary goal being to minimise the amount of imported energy used during the day. To model this situation, we use a concurrent MCR game G with N players representing the local controllers of each house, as follows: • V = [1, 96] × (∏ i∈H 2 Tasks(T L i ) ) contains the current timeslot and the set of tasks already performed in the past; • F = [1, 96] × (∏ i∈H Tasks(T L i )) describe that every task has been performed; • A i = Tasks(T L i ) is the set of tasks, for all players i; , p), (p 1 , p 2 , . . . , p N )) = (d + 1, p ∪ p 1 ∪ p 2 ∪ · · · ∪ p N ) if all tasks of p i are associated to an interval including d in the task list T L i (other actions are not fireable); • ω i is defined as E T for all tasks of house H i performed in the current time, while taking into account the solar energy production, i.e. ω i ((d, p), A negative weight implies a use of energy produced outside the house (either by other houses or outside the local grid), while positive weight induces an excedent of solar energy in the house. Note that by construction G is an acyclic graph (always incrementing the interval component of the vertex). We will consider thereafter only this game starting in the initial vertex v 0 = (1, / 0, . . . , / 0). For each edge, the sum of the weights incurred by all the houses represent the amount (positive or negative) of solar energy excedent after the perfomance of all the tasks of the current time. Since we want to reduce the amount of energy bought from outside the local grid, we use as a global weight function the negative part of this sum of weights: ω((d, p), (d + 1, p ′ )) = min 0, ∑ t∈p ′ \p E T (t) − N × prod(d) .
A negative weight implies a use of energy produced outside the local grid, while a null weight induces an excedent of solar energy in the local grid.
We decide first to interpret the previous game as a one-player game, by supposing that all houses play in coalition to achieve the common target of finishing all the tasks within the given interval and reducing the usage of non-solar energy. This is a one-player MCR game with the weight function ω. The coalition strategy obtained will actually be a schedule for the tasks of each house respecting the intervals that minimises the amount of non-solar energy used (or even maximise the solar energy excedent produced by the local grid to be exported).

Example 5.
For the example developed above, the optimal schedule in the coalition game is to perform task t 2 at interval 1 and perform task t 1 at interval 2 in which case no energy from outside is required. On the contrary, an excedent of 3 units of energy is produced which can sold to the external grid causing lowering of electric bill.

Billing function
Even though the schedule obtained from G gives the optimal use of non-solar energy and hence a priori low billing costs as a whole for the houses, the bill obtained may not be favourable for the houses taken individually. Thus, all houses might not have a strong incentive to collaborate to the common good. We start by defining properly the billing function we use in our model.
Given a tuple of sets of tasks performed by each house at any specific time point d ∈ {1, . . . , 96}, we will compute the bill incurred by house H i on the interval [d, d + 1). The total bill for H i would then be the sum of bill incurred by this house for each interval of the day.
Consider a tuple of set of tasks performed by all the houses at a specific time point d, T P = ( t 1 1 ,t 1 2 , · · · ,t 1 k 1 , · · · , t N 1 ,t N 2 , · · · ,t N k N ). We denote the tasks performed by H i as Tasks i (T P ). Let the price of buying energy from other houses be P in and the price of buying energy from outside be P out . The energy produced by each house is given by prod(d). Now, for each house H i , the excess energy used by the house is given by ∑ t∈Tasks i (T P ) E T (t) − prod(d). Thus, the total energy bought by all the houses individually (either from the local grid or from the outside) is On the other hand, the energy bought (negative or positive) from outside the grid is The total bill for all the houses is then B Tot = (Tot C − Tot O ) × P in + Tot O × P out . Since each house pays its own share of this total bill, the price that will be billed to house Note that if a house produces more energy at a specific interval than it consumes, the bill is negative signifying income from selling the excess solar energy. Now that we have the billing function fixed, we can present the example where the optimal energy schedule might not give the minimum bill for an individual house. Example 6. The optimal schedule for the total energy presented in the previous example (Example 5) is not optimal with respect to the bill paid by house H 1 . For example, if H 1 performs task t 1 at interval 1, it does not have to pay anything. Whereas, with optimal scheduling, H 1 has to pay for two units of energy to H 2 and receives the price of only one unit of energy from H 2 .
Thus, our next goal will be to modify the weights of the game G to take into account the bill rather than the energy. The new weight function is now given by ω i ((d, p), where T P is the list of tasks performed in p ′ \ p. We call G ′ this new game. The hope is to find that the need for the households to minimise their utility bill is an incentive to minimise the global energy consumption from the grid (thereby encouraging sharing of locally produced energy). More formally, we need to compare the energy consumed by a Nash equilibrium of G ′ to the optimal energy consumption found in the optimal coalition strategy of G.
As the game is concurrent there is in general no Nash equilibrium. Therefore we start by transforming G ′ in a turn-based game G ′ t , adopting a round-Robin policy for the choice of actions. This can be achieved by enhancing the set of vertices with {1, . . . , N}, and decomposing an edge into a sequence of N edges, where each house now plays in turns. In the last step, we have all the information to compute the bill for each house. Since the game G ′ t is acyclic, there are only finitely many plays, thus their costs for each players are bounded. As a consequence of Theorem 1, we know that there exists (pure) Nash equilibria in G ′ t . 3 Thus we can follow the heuristic for constructing Nash equilibria presented in Section 2.3 to construct the Nash equilibrium strategy profile. We construct coalition two-player MCR games G ′ i for each house H i , where H i plays in order to minimise its bill against the coalition of all other houses. Solving every such game G ′ i , we obtain the optimal strategy σ i for each house H i . In addition to that, we follow the construction by detecting when a player deviates from its optimal strategy and then changing other players' strategy to a punishment strategy.
From the point of view of the case study, even though the strategies (σ i ) 1 i N are generated by the global controller, they are executed by local controllers and thus, each house can not detect whether some other house has deviated from its optimal strategy or not. Hence, for our case, we only take the strategy profile (σ i ) 1 i N (without the deviation punishment) and, while computing the bill, we add the provision for the global controller to add a penalty to the bill. This is done by modifying the weight function to incorporate such changes: we add an extra integer to the bill of house H i that is equal to the minimum bill that can be ensured by H i according to the strategy σ i whenever H i deviates from σ i . This ensures that any deviation from H i will result in at least twice the minimal bill that can be ensured by H i .

Implementation
We implemented the model using PRISM. PRISM has introduced a module for solving (turn-based) Stochastic Multi-Player Games (SMG). We use this module in order to solve different non-stochastic games and extract optimal cost strategies out of them. The PRISM module is also used to check the performance (consumption, wastage and bill) of a strategy over an instance of the game.
We have first implemented the one player game version of an instance where all houses play in coalition towards the common goal of maximising the utilisation of solar energy. Here, the behaviour of each house is modeled using a module in the PRISM representation. Each module contains the constraints of the houses with respect to tasks as transitions. The favorable interval of the task is denoted as guards on the transition and the energy cost for the task is reflected using an update to the global energy variable. We solve the game and obtain a bound of the maximum possible utilisation of the solar energy among all the houses. Note that, as shown by the example in the previous section, this schedule does not ensure that the bill paid by each of the houses is minimum. We allow PRISM to solve such a one-player game to figure out the minimum possible collective energy requirement of the houses (E min ).
Next we have implemented the methodology with multi-player turn-based MCR games. Recall that the houses do not have information about consumption and requirement of energy by other houses. The natural way of modelling such scenarios is through concurrent games where each player plays a move without the knowledge of other players moves. Since PRISM can handle only turn-based games, we try to implement a random order among the houses at each step of the game. We then compute the separate games G ′ i for each house H i and find optimal strategy σ i for house H i such that the bill for H i is minimised (bill i ). Even though generating strategy is included in PRISM, it does not allow storing the strategy output in a proper format for further usage from the command interface. We modified it to include that property. The outcome of this strategy profile (σ i ) 1 i N is then used to compute the final strategy for the controller. Finally, we formulate another game where any deviating move by house H i from σ contains a modification of the billing function of H i as an addition of integer value equal to bill i . At the end, the final strategy is loaded in PRISM and the values (energy consumption, billing. . . ) corresponding to the strategy are computed. The final game with the strategy profile (σ i ) 1 i N again results in various different values for total collective energy consumption, and bills for each house H i for completing all the tasks. These values are compared with the original game to compare the performance of the strategy profile. The table below shows the result for different numbers of houses and tasks. For each such pair, we have taken 10 examples and presented the average of values obtained. The table represents the average difference of bills (in percent) between two strategies -one where the houses collectively reduce the total energy consumed in coalition and the other where the houses minimizes their own bill. Note that the bill is computed for each house by taking into account the cost of excess energy used in any interval. However, the amount each house gets from excessive production of energy is not accounted for in the bill. As shown in Table 1, the collective energy with the strategy profile obtained, remains the same as the minimum energy required to complete all the tasks. Moreover, the result shows that on average there is a decrease in bill paid by each house in the case where every house follows the Houses Tasks Number of cases  Total energy difference Average bill difference  2  3 Table 1: Results of the implementation over the case study strategy profile and does not deviate from it. This also shows that there is (hopefully) less inclination towards deviating from the suggested strategy by each house.