Patricia Bouyer
email: bouyer@lsv.ens-cachan.fr

Nicolas Markey
email: markey@lsv.ens-cachan.fr

Mickaël Randour

Kim G Larsen

Simon Laursen

Mickael Randour
email: mickael.randour@ulb.ac.be

Average-energy games

à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d'enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

Game-theoretic formulations are a standard tool for the synthesis of provably-correct controllers for reactive systems [START_REF] Grädel | Automata, Logics, and Infinite Games: A Guide to Current Research[END_REF]. We consider two-player (system vs. environment) turn-based games played on finite graphs. Vertices of the graph are called states and partitioned into states of player 1 and states of player 2. The game is played by moving a pebble from state to state, along edges in the graph, and starting from a given initial state. Whenever the pebble is on a state belonging to player i, player i decides where to move the pebble next, according to his strategy. The infinite path followed by the pebble is called a play: it represents one possible behavior of the system. A winning objective encodes acceptable behaviors of the system and can be seen as a set of winning plays. The goal of player 1 is to ensure that the outcome of the game will be a winning play, whatever the strategy played by his adversary.

To reason about resource constraints and the performance of strategies, quantitative games have been considered in the literature. See for example [START_REF] Chakrabarti | Resource interfaces[END_REF][START_REF] Bloem | Better quality in synthesis through quantitative objectives[END_REF][START_REF] Randour | Automated synthesis of reliable and efficient systems through game theory: A case study[END_REF], or [START_REF] Randour | Synthesis in Multi-Criteria Quantitative Games[END_REF] for an overview. Those games are played on weighted graphs, where edges are fitted with integer weights modeling rewards or costs. The performance of a play is evaluated via a payoff function that maps it to the numerical domain. The objective of player 1 is then to ensure a sufficient payoff with regard to a given threshold value. Seminal classes of quantitative games include mean-payoff (MP), total-payoff (TP) and energy games (EG). In MP games [START_REF] Ehrenfeucht | Positional strategies for mean payoff games[END_REF][START_REF] Zwick | The complexity of mean payoff games on graphs[END_REF][START_REF] Jurdziński | Deciding the winner in parity games is in UP∩co-UP[END_REF], player 1 has to optimize his long-run average gain per edge taken whereas, in TP games [START_REF] Gimbert | When can you play positionnaly?[END_REF][START_REF] Gawlitza | Games through nested fixpoints[END_REF], player 1 has to optimize his long-run sum of weights. Energy games [START_REF] Chakrabarti | Resource interfaces[END_REF][START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF][START_REF] Juhl | Optimal bounds for multiweighted and parametrised energy games[END_REF] model safety-like properties: the goal is to ensure that the running sum of weights never drops below zero and/or that it never exceeds a given upper bound U ∈ N. All three classes share common properties. First, MP games, TP games, and EG games with only a lower bound (EG L ) are memoryless determined (given an initial state, either player 1 has a strategy to win, or player 2 has one, and in both cases no memory is required to win). Second, deciding the winner for those games is in NP ∩ coNP and no polynomial algorithm is known despite many efforts (e.g., [START_REF] Brim | Faster algorithms for mean-payoff games[END_REF][START_REF] Chatterjee | Looking at mean-payoff and total-payoff through windows[END_REF]). Energy games with both lower and upper bounds (EG LU ) are more complex: they are EXPTIME-complete and winning requires memory in general [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF].

While those classes are well-known, it is sometimes necessary to go beyond them to accurately model practical applications. For example, multi-dimensional games and conjunctions with a parity objective model trade-offs between different quantitative aspects [START_REF] Chatterjee | Energy parity games[END_REF][START_REF] Chatterjee | Strategy synthesis for multi-dimensional quantitative objectives[END_REF][START_REF] Velner | The complexity of multi-mean-payoff and multi-energy games[END_REF]. Similarly, window objectives address the need for strategies ensuring good quantitative behaviors within reasonable time frames [START_REF] Chatterjee | Looking at mean-payoff and total-payoff through windows[END_REF].

Average-energy games.

We study the average-energy (AE ) payoff function: in AE games, the goal of player 1 is to optimize the long-run average accumulated energy over a play. We introduce this objective to formalize the specification desired in a practical application [START_REF] Cassez | Automatic synthesis of robust and optimal controllers -an industrial case study[END_REF], which we detail in the following as a motivating example. Interestingly, it turns out that this payoff first appeared long ago [START_REF] Thuijsman | The bad match; a total reward stochastic game[END_REF], but it was not subject to a systematic study until very recently: see related work for more discussion.

In addition to being meaningful w.r.t. practical applications, AE games also have theoretical interest. In [START_REF] Chatterjee | Quantitative timed simulation functions and refinement metrics for real-time systems[END_REF], Chatterjee and Prabhu define the average debitsum level objective, which can be seen as a variation of the average-energy where the accumulated energy is taken to be zero in any point where it is actually positive (hence, it focuses on the average debt). They use the corresponding games to compute the values of quantitative timed simulation functions. In particular, they provide a pseudo-polynomial-time algorithm to solve those games, but the complexity of deciding the winner as well as the memory requirements are open.

Here, we solve those questions for the very similar average-energy objective.

Motivating example.

Our example is a simplified version of the industrial application studied by Cassez et al. in [START_REF] Cassez | Automatic synthesis of robust and optimal controllers -an industrial case study[END_REF]. Consider a machine that consumes oil, stored in a connected accumulator. We want to synthesize an appropriate controller to operate the oil pump that fills the accumulator, and by the effect of pressure, that releases oil from the accumulator into the machine with a (time-varying) rate according to desired production. In order to ensure safety, the oil level in the accumulator should be maintained at all times between a minimal and a maximal level. This part of the specification can be encoded as an energy objective with both lower and upper bounds (EG LU ). At the same time, the more oil (thus pressure) in the accumulator, the faster the whole apparatus wears out. Hence, an ideal controller should minimize the average level of oil in the long run. This desire can be formalized through the average-energy payoff (AE ). Overall, the specification is thus to minimize the average-energy under the strong energy constraints: we denote the corresponding objective by AE LU .

Contributions.

Our main results are summarized in Table 1. A) We establish that the average-energy objective can be seen as a refinement of total-payoff, in the same sense as total-payoff is seen as a refinement of meanpayoff [START_REF] Gawlitza | Games through nested fixpoints[END_REF]: it allows to distinguish strategies yielding identical mean-payoff and total-payoff.

B) We show that deciding the winner in two-player AE games is in NP ∩ coNP whereas it is in P for one-player games. In both cases, memoryless strategies suffice (Thm. 8). Those complexity bounds match the state-of-the-art for MP and TP games [START_REF] Zwick | The complexity of mean payoff games on graphs[END_REF][START_REF] Jurdziński | Deciding the winner in parity games is in UP∩co-UP[END_REF][START_REF] Gawlitza | Games through nested fixpoints[END_REF][START_REF] Brim | Faster algorithms for mean-payoff games[END_REF]. Furthermore we prove that AE games are at least as hard as mean-payoff games (Thm. 10). Therefore, the NP ∩ coNP-membership can be considered optimal w.r.t. our knowledge of MP games. Technically, the crux of our approach is as follows. First, we show that memoryless strategies suffice in one-player AE games (Thm. 6): this requires to prove important properties of the AE payoff as classical sufficient criteria for memoryless determinacy present in the literature fail to apply directly. Second, we establish a polynomial-time algorithm for the one-player case: it exploits the structure of winning strategies and mixes graph techniques with local linear program solving (Thm. 7). Finally, we lift memoryless determinacy to the two-player case using results by Gimbert and Zielonka [START_REF] Gimbert | Games where you can play optimally without any memory[END_REF] and obtain the NP ∩ coNP-membership as a corollary (Thm. 9). C) We establish an EXPTIME algorithm to solve two-player AE games with lower-and upper-bounded energy (AE LU ) with an arbitrary upper bound U ∈ N (Thm. [START_REF] Chatterjee | Looking at mean-payoff and total-payoff through windows[END_REF]. It relies on a reduction of the AE LU game to a pseudo-polynomially larger AE game where the energy constraints are encoded in the graph structure. Applying straightforwardly the AE algorithm on this game would only give us NEXPTIME ∩ coNEXPTIME-membership, hence we avoid this blowup by further reducing the problem to a particular MP game and applying a pseudo-polynomial algorithm, with some care to ensure that overall the algorithm only requires pseudopolynomial time in the original AE LU game. Since the simpler EG LU games (i.e., AE LU with a trivial AE constraint) are already EXPTIME-hard [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF], the EXPTIMEmembership result is optimal. We also prove that pseudo-polynomial memory is both sufficient and in general necessary to win in AE LU games, for both players (Thm. [START_REF] Chatterjee | Quantitative timed simulation functions and refinement metrics for real-time systems[END_REF]. We show that one-player AE LU games are PSPACE-complete via the on-the-fly construction of a witness path based on the aforementioned reduction, answering a question left open in [START_REF] Bouyer | Average-energy games[END_REF]. For polynomial (in the size of the game graph) values of the upper bound U -or if it is given in unary -the complexity of the two-player (resp. one-player) AE LU problem collapses to NP ∩ coNP (resp. P) with the same approach, and polynomial memory suffices for both players. D) We provide partial answers for the AE L objective -AE under a lower bound constraint on energy but no upper bound. We show PSPACE-membership for the one-player case (Thm. 17), by reducing the problem to an AE LU game with a sufficiently large upper bound. That is, we prove that if the player can win for the AE L objective, then he can do so without ever increasing its energy above a well-chosen bound. We also prove the AE L problem to be at least NP-hard in one-player games (Thm. 17) and EXPTIME-hard in two-player games (Lem. 20) via reductions from the subset-sum problem and countdown games respectively. Finally, we show that memory is required for both players in two-player AE L games (Lem. 21), and that pseudo-polynomial memory is both sufficient and necessary in the one-player case (Thm. 18). The decidability status of two-player AE L games remains open as we only provide a correct but incomplete incremental algorithm (Lem. [START_REF] Filar | Competitive Markov decision processes[END_REF]). We conjecture that the two-player AE L problem is decidable and sketch a potential approach to solve it. We highlight the key remaining questions and discuss some connections with related models that are known to be difficult.

Observe that in many applications, the energy must be stocked in a finitecapacity storage for which an upper bound is provided. Hence, the model of choice in this case is AE LU .

Related work.

This paper extends previous work presented in a conference [START_REF] Bouyer | Average-energy games[END_REF]: it gives a full presentation of the technical details, along with additional results and improved complexities.

The average-energy payoff -Eq. ( 1) -appeared in a paper by Thuijsman and Vrieze in the late eighties [START_REF] Thuijsman | The bad match; a total reward stochastic game[END_REF], under the name total-reward. This definition is different from the classical total-payoff -see Sect. 2 -commonly studied in the formal methods community (see for example [START_REF] Gimbert | When can you play positionnaly?[END_REF][START_REF] Gawlitza | Games through nested fixpoints[END_REF]), which, despite that, has been referred in many papers as either total-payoff or total-reward equivalently. We will see that both definitions are indeed different and exhibit different behaviors.

Maybe due to this confusion, the payoff of Eq. ( 1) -which we call averageenergy thus avoiding misunderstandings -was not studied extensively until recently. Nothing was known about memoryless determinacy and complexity of deciding the winner. Independently to our work, Boros et al. recently studied the same payoff (under the name total-payoff ). In [START_REF] Boros | Markov decision processes and stochastic games with total effective payoff[END_REF], they study Markov decision processes and stochastic games with the payoff of Eq. ( 1) and solve both questions. Their results overlap with ours for AE games (Table 1). Let us first mention that our results were obtained independently. Second, and most importantly, our approach and techniques are different, and we believe our take on the problem yields some interest for our community. Indeed, the algorithm of Boros et al. entirely relies on linear programming in the one-player case, and resorts to approximation by discounted games in the two-player one. Our techniques are arguably more constructive and based on inherent properties of the payoff. In that sense, it is closer to what is usually deemed important in our field. For example, we provide an extensive comparison with classical payoffs. We base our proof of memoryless determinacy on operational understanding of the AE which is crucial in order to formalize proper specifications. Our technique then benefits from seminal works [START_REF] Gimbert | Games where you can play optimally without any memory[END_REF] to bypass the reduction to discounted games and obtain a direct proof, thanks to our more constructive approach. Lastly, while [START_REF] Boros | Markov decision processes and stochastic games with total effective payoff[END_REF] considers the AE problem in the stochastic context, we focus on the deterministic one but consider multi-criteria extensions by adding bounds on the energy (AE LU and AE L games). Those extensions are completely new, exhibit theoretical interest and are adequate for practical applications in constrained energy systems, as witnessed by the case study of [START_REF] Cassez | Automatic synthesis of robust and optimal controllers -an industrial case study[END_REF].

Recent work of Brázdil et al. [START_REF] Brázdil | Minimizing running costs in consumption systems[END_REF] considers the optimization of a payoff under energy constraint. They study mean-payoff in consumption systems, i.e., simplified one-player energy games where all edges consume energy but some states can atomically produce a reload of the energy up to the allowed capacity. We consider turn-based games played on graphs between two players denoted by P 1 and P 2 . A game is a tuple G = (S 1 , S 2 , E , w ) where (i) S 1 and S 2 are disjoint finite sets of states belonging to P 1 and P 2 , with S = S 1 S 2 , (ii) E ⊆ S × S is a finite set of edges such that for all s ∈ S, there exists s ∈ S such that (s, s ) ∈ E (i.e., no deadlock), and (iii) w : E → Z is an integer weight function. Given edge (s 1 , s 2 ) ∈ E , we write w (s 1 , s 2 ) as a shortcut for w ((s 1 , s 2 )). We denote by W the largest absolute weight assigned by function w . A game is called 1-player if

S 1 = ∅ or S 2 = ∅.
A play from an initial state s init ∈ S is an infinite sequence π = s 0 s 1 . . . sn . . . such that s 0 = s init and for all i ≥ 0 we have (s i , s i+1 ) ∈ E . The (finite) prefix of π up to position n gives the sequence π(n) = s 0 s 1 . . . sn, the first (resp. last) element s 0 (resp. sn) is denoted first(π(n)) (resp. last(π(n))). The set of all plays in G is denoted by Plays(G) and the set of all prefixes is denoted by Prefs(G). We say that a prefix ρ ∈ Prefs(G) belongs to P i , i ∈ {1, 2}, if last(ρ) ∈ S i . The set of prefixes that belong to P i is denoted by Prefs i (G). The classical concatenation between prefixes (resp. prefix and play) is denoted by the • operator. The length of a non-empty prefix ρ = s 0 . . . sn is defined as the number of edges and denoted by |ρ| = n.

Payoffs of plays.

Given a play π = s 0 s 1 . . . sn . . . we define its energy level at position n as

EL(π(n)) = n-1 i=0 w(s i , s i+1 ); -its mean-payoff as MP (π) = lim sup n→∞ 1 n n-1 i=0 w(s i , s i+1 ) = lim sup n→∞ 1 n EL(π(n));
its total-payoff as

TP (π) = lim sup n→∞ n-1 i=0 w(s i , s i+1 ) = lim sup n→∞ EL(π(n));
and its average-energy as

AE (π) = lim sup n→∞ 1 n n i=1   i-1 j=0 w(s j , s j+1 )   = lim sup n→∞ 1 n n i=1 EL(π(i)). (1)
We will sometimes consider those measures defined with lim inf instead of lim sup, in which case we write MP , TP and AE respectively. Finally, we also consider those measures over prefixes: we naturally define them by dropping the lim sup n→∞ operator and taking n = |ρ| for a prefix ρ ∈ Prefs(G). In this case, we simply write MP (ρ), TP (ρ) and AE (ρ) to denote the fact that we consider finite sequences.

Strategies.

A strategy for P i , i ∈ {1, 2}, is a function σ i : Prefs i (G) → S such that for all ρ ∈ Prefs i (G) we have (last(ρ), σ i (ρ)) ∈ E . A strategy σ i for P i is finitememory if it can be encoded by a deterministic Moore machine (M, m 0 , αu, αn) where M is a finite set of states (the memory of the strategy), m 0 ∈ M is the initial memory state, αu : M × S → M is an update function, and αn : M × S i → S is the next-action function. If the game is in s ∈ S i and m ∈ M is the current memory value, then the strategy chooses s = αn(m, s) as the next state of the game. When the game leaves a state s ∈ S, the memory is updated to αu(m, s). Formally, (M, m 0 , αu, αn) defines the strategy σ i such that σ i (ρ • s) = αn(αu(m 0 , ρ), s) for all ρ ∈ S * and s ∈ S i , where αu extends αu to sequences of states as expected. A strategy is memoryless if |M | = 1, i.e., it does not depend on the history but only on the current state of the game. We denote by Σ i (G), the sets of strategies for player P i . We drop G when the context is clear.

A play π = s 0 s 1 . . . is consistent with a strategy σ i of P i if, for all n ≥ 0 where last(π(n)) ∈ S i , we have σ i (π(n)) = s n+1 . Given an initial state s init ∈ S and strategies σ 1 and σ 2 for the two players, we denote by Outcome(s init , σ 1 , σ 2 ) the unique play that starts in s init and is consistent with both σ 1 and σ 2 . When fixing the strategy of only P i , we denote the set of consistent outcomes by Outcomes(s init , σ i ).

Objectives.

An objective in G is a set W ⊆ Plays(G) that is declared winning for P 1 . Given a game G, an initial state s init , and an objective W, a strategy σ 1 ∈ Σ 1 is winning for P 1 if for all strategy σ 2 ∈ Σ 2 , we have that Outcome(s init , σ 1 , σ 2 ) ∈ W. Symmetrically, a strategy σ 2 ∈ Σ 2 is winning for P 2 if for all strategy σ 1 ∈ Σ 1 , we have that Outcome(s init , σ 1 , σ 2 ) ∈ W. That is, we consider zero-sum games.

We consider the following objectives and combinations of those objectives.

-Given an initial energy level c init ∈ N, the lower-bounded energy

(EG L ) objective Energy L (c init ) = {π ∈ Plays(G) | ∀ n ≥ 0, c init + EL(π(n))
≥ 0} requires non-negative energy at all times.

-Given an upper bound U ∈ N and an initial energy level c init ∈ N, the lower-and upper-bounded energy (EG LU ) objective

Energy LU (U, c init ) = {π ∈ Plays(G) | ∀ n ≥ 0, c init + EL(π(n)) ∈ [0, U ]
} requires that the energy always remains non-negative and below the upper bound U along a play.

-Given a threshold t ∈ Q, the mean-payoff (MP) objective MeanPayoff (t) = {π ∈ Plays(G) | MP (π) ≤ t} requires that the mean-payoff is at most t. -Given a threshold t ∈ Z, the total-payoff (TP) objective TotalPayoff (t) = {π ∈
Plays(G) | TP (π) ≤ t} requires that the total-payoff is at most t. -Given a threshold t ∈ Q, the average-energy (AE ) objective AvgEnergy(t) = {π ∈ Plays(G) | AE (π) ≤ t} requires that the average-energy is at most t.

For the MP , TP and AE objectives, note that P 1 aims to minimize the payoff value while P 2 tries to maximize it. The reversed convention is also often used in the literature but both are equivalent. For our motivating example, seeing P 1 as a minimizer is more natural. Note that we define the objectives using the lim sup variants of MP , TP and AE , but similar results are obtained for the lim inf variants.

Decision problem.

Given a game G, an initial state s init ∈ S, and an objective W ⊆ Plays(G) as defined above, the associated decision problem is to decide if P 1 has a winning strategy for this objective.

We recall classical results in Table 1. Memoryless strategies suffice for both players for EG L [START_REF] Chakrabarti | Resource interfaces[END_REF][START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF], MP [START_REF] Ehrenfeucht | Positional strategies for mean payoff games[END_REF] and TP [START_REF] Filar | Competitive Markov decision processes[END_REF][START_REF] Gimbert | When can you play positionnaly?[END_REF] objectives. Since all associated problems can be solved in polynomial time for 1-player games, it follows that the 2-player decision problem is in NP ∩ coNP for those three objectives [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF][START_REF] Zwick | The complexity of mean payoff games on graphs[END_REF][START_REF] Gawlitza | Games through nested fixpoints[END_REF]. For the EG LU objective, memory is in general needed and the associated decision problem is EXPTIME-complete [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF] (PSPACE-complete for one-player games [START_REF] Fearnley | Reachability in two-clock timed automata is PSPACEcomplete[END_REF]).

Game values.

Given a game with an objective W ∈ {MeanPayoff , TotalPayoff , AvgEnergy} and an initial state s init , we refer to the value from

s init as v = inf{t ∈ Q | ∃ σ 1 ∈ Σ 1 , Outcomes(s init , σ 1 ) ⊆ W(t)}.
For both MP and TP objectives, it is known that the value can be achieved by an optimal memoryless strategy; for the AE objective it follows from our results (Thm. 8).

Average-Energy

In this section, we consider the problem of ensuring a sufficiently low average-energy.

Problem 1 (AE ) Given a game G, an initial state s init , and a threshold t ∈ Q, decide if P 1 has a winning strategy σ 1 ∈ Σ 1 for the objective AvgEnergy(t).

We first compare the AE objective with traditional quantitative objectives and study how they can be connected (Sect. 3.1). Then we want to establish that in AE games, memoryless strategies are always sufficient to play optimally, for both players. Interestingly, this result cannot be obtained by straightforward application of many well-known sufficient criteria for memoryless determinacy existing in the literature. We thus introduce some technical lemmas that highlight the inherent features of the AE payoff function (Sect. 3.2) and permit to prove the result for one-player AE games (Sect. 3.3). We then prove that one-player AE games can be solved in polynomial-time via an algorithm combining graph analysis techniques with linear programming. Finally, we consider the two-player case (Sect. 3.4). Applying a result by Gimbert and Zielonka [START_REF] Gimbert | Games where you can play optimally without any memory[END_REF], combined with our results on the one-player case, we derive memoryless determinacy of two-player AE games. This also induces NP ∩ coNP-membership of the AE problem by the P algorithm of Sect. 3.3. We conclude by proving that AE games are at least as hard as MP games, hence indicating that the NP ∩ coNP upper bound is essentially optimal with regard to our current knowledge of MP games (whose membership to P is a long-standing open problem [START_REF] Zwick | The complexity of mean payoff games on graphs[END_REF][START_REF] Jurdziński | Deciding the winner in parity games is in UP∩co-UP[END_REF][START_REF] Brim | Faster algorithms for mean-payoff games[END_REF][START_REF] Chatterjee | Looking at mean-payoff and total-payoff through windows[END_REF]).

Relation with classical objectives

Several links between EG L , MP and TP objectives can be established. Intuitively, P 1 can only ensure a lower bound on energy if he can prevent P 2 from enforcing strictly-negative cycles (otherwise the initial energy is eventually exhausted). This is the case if and only if P 1 can ensure a non-negative mean-payoff in G (here, he wants to maximize the MP ), and if this is the case, P 1 can prevent the running sum of weights from ever going too far below zero along a play, hence granting a lower bound on total-payoff. We introduce the sign-reversed game G in the next lemma, which is consistent with our view of P 1 as a minimizer with regard to payoffs (as discussed in Sect. 2).

Lemma 1 Let G = (S 1 , S 2 , E , w ) be a game and s init ∈ S be the initial state. The following assertions are equivalent.

A. There exists c init ∈ N such that P 1 has a (memoryless) winning strategy for objective Energy L (c init ). B. Player P 1 has a (memoryless) winning strategy for objective MeanPayoff (0) in the game G defined by reversing the sign of the weight function, i.e., for all (s 1 , s 2 ) ∈ E , w (s 1 , s 2 ) = -w (s 1 , s 2 ). C. Player P 1 has a (memoryless) winning strategy for objective TotalPayoff (t), with t = 2 • (|S| -1) • W , in the game G defined by reversing the sign of the weight function.

D. There exists t ∈ Z such that P 1 has a (memoryless) winning strategy for objective TotalPayoff (t), in the game G defined by reversing the sign of the weight function.

Proof Proof of A ⇔ B is given in [6, Proposition 12]. Proof of B ⇔ C ⇔ D is in [13, Lem. 1].
The TP objective is sometimes seen as a refinement of MP for the case where P 1 -as a minimizer -can ensure MP equal to zero but not lower, i.e., the MP game has value zero [START_REF] Gawlitza | Games through nested fixpoints[END_REF]. Indeed, one may use the TP to further discriminate between strategies that guarantee MP zero. In the same philosophy, the averageenergy can help in distinguishing strategies that yield identical total-payoffs. See Fig. 1. The AE values in both examples can be computed easily using the upcoming technical lemmas (Sect. 3.2). Fig. 1: Both plays have identical mean-payoff and total-payoff:

MP (π 1 ) = MP (π 1 ) = MP (π 2 ) = MP (π 2 ) = 0, TP (π 1 ) = TP (π 2 ) = 5
, and TP (π 1 ) = TP (π 2 ) = 1. But play π 1 has a lower average-energy:

AE (π 1 ) = AE (π 1 ) = 3 < AE (π 2 ) = AE (π 2 ) = 11/3.
In these examples, the average-energy is clearly comprised between the infimum and supremum total-payoffs. This remains true for any play.

Lemma 2 For any play π ∈ Plays(G), we have that

AE (π), AE (π) ∈ TP (π), TP (π) ⊆ R ∪ {-∞, ∞}.
Proof Consider a play π ∈ Plays(G). By definition of the total-payoff and thanks to weights taking integer values, we have that there exists some index m ∈ N 0 such that, for all n ≥ m, EL(π(n)) ∈ TP (π), TP (π) . By definition, the average-energy AE (resp. AE ) measures the supremum (resp. infinimum) limit of the averages of those partial sums, hence it holds that AE (π), AE (π) ∈ TP (π), TP (π) .

In particular, if the mean-payoff value from a state is not zero, its total-payoff value is infinite and the following lemma holds.

Lemma 3 Let G = (S 1 , S 2 , E , w ) be a game and s init ∈ S be the initial state.

1. If there exists t < 0 such that P 1 has a (memoryless) winning strategy for objective MeanPayoff (t), then P 1 has a memoryless strategy that is winning for AvgEnergy(t ) for all t ∈ Q, i.e., this strategy ensures that any consistent outcome π is such that AE (π) = AE (π) = -∞.

2.

If P 1 has no (memoryless) winning strategy for MeanPayoff (0), then, for any t ∈ Q, P 1 has no winning strategy for AvgEnergy(t ). In particular, P 2 has a memoryless strategy ensuring that any consistent outcome π is such that AE (π) = AE (π) = ∞.

Proof Consider the first implication. Assume P 1 has a memoryless strategy σ 1 ensuring that all outcomes π ∈ Outcomes(s init , σ 1 ) are such that MP (π) < 0. For any such outcome, it is guaranteed that all simple cycles have a strictly negative energy level. Thus, we have that TP (π) = -∞, and by Lem. 2, it implies that AE (π) = -∞, as claimed. Since AE (π) ≤ AE (π) by definition, the property holds. Now consider the second implication. Assume there exists no winning strategy for P 1 for the mean-payoff objective. By equivalence B ⇔ D of Lem. 1, and memoryless determinacy of total-payoff games (see for example [START_REF] Gimbert | When can you play positionnaly?[END_REF]), it follows that P 2 has a memoryless strategy σ 2 ensuring that all consistent outcomes π ∈ Outcomes(s init , σ 2 ) are such that TP (π) = ∞. By Lem. 2, this induces the claim.

Useful properties of the average-energy

In this subsection, we will first review some classical criteria that usually prove sufficient to deduce memoryless determinacy in quantitative games and discuss why they cannot be applied straight out of the box to the average-energy payoff. We will then prove two useful properties of this payoff that will later help us to prove the desired result.

Classical sufficient criteria.

We briefly discuss traditional approaches to prove memoryless determinacy in quantitative games. The first one is to study a variant of the infinite-duration game where the game halts as soon as a cycle is closed and then to relate the properties of this variant to the infinite-duration game. This technique was used in the original proof of memoryless determinacy for meanpayoff games by Ehrenfeucht and Mycielski [START_REF] Ehrenfeucht | Positional strategies for mean payoff games[END_REF], and in a following simpler proof by Björklund et al. [START_REF] Björklund | Memoryless determinacy of parity and mean payoff games: A simple proof[END_REF]. The connection between infinite-duration games and so-called first cycle games was recently streamlined by Aminof and Rubin [START_REF] Aminof | First cycle games[END_REF], identifying sufficient conditions to prove that first cycle games and their infinite-duration counterparts admit optimal memoryless strategies for both players. Among those conditions is the need for winning objectives to be closed under cyclic permutation (intuitively, swapping cycles in a play should not induce a better payoff) and under concatenation (intuitively, concatenating two prefixes should not result in a payoff better than the best of the two prefixes). Without further assumptions, the average-energy objective satisfies neither. Indeed, consider individual cycles represented by sequences of weights

C 1 = {-1}, C 2 = {1} and C 3 = {1, -2}. We see that AE (C 1 C 2 ) = (-1 + 0)/2 = -1/2 < AE (C 2 C 1 ) = (1 -0)/2 = 1/2,
hence AE is not closed under cyclic permutations. Intuitively, the order in which the weights are seen does matter, in contrast to most classical payoffs. For concatenation, see that

AE (C 3 ) = 0 while AE (C 3 C 3 ) = -1/2 < 0.
Here the intuition is that the overall AE is impacted by the energy of the first cycle which is strictly negative (-1). In a sense, the AE of a cycle can only be maintained through repetition if this cycle is neutral with regard to the total energy level, i.e., if it has energy level zero: we will formalize this intuition in Lem. 5.

Other criteria for memoryless determinacy or half-memoryless determinacy (i.e., holding only for one of the two players) respectively appear in works by Gimbert and Zielonka [START_REF] Gimbert | When can you play positionnaly?[END_REF] and by Kopczynski [START_REF] Kopczynski | Half-positional determinacy of infinite games[END_REF]. They involve checking that the payoff is fairly mixing, or concave. Again, both are false for arbitrary sequences of weights in the case of the average-energy, for essentially the same reasons as above. Nevertheless, we will be able to prove that memoryless strategies suffice for both players using similar ideas but first taking care of the problematic cases. Intuitively, when those cases are dealt with, we will regain a payoff that satisfies the above conditions. We also obtain monotonicity and selectivity of the payoff function as defined in [START_REF] Gimbert | Games where you can play optimally without any memory[END_REF].

Extraction of prefixes.

The following lemma describes the impact of adding a finite prefix to an infinite play. We prove that the average-energy over a play can be decomposed w.r.t. to the energy level of any of its prefixes and the average-energy of the remaining suffix.

Lemma 4 (Average-energy prefix) Let ρ ∈ Prefs(G), π ∈ Plays(G). Then, AE (ρ • π) = EL(ρ) + AE (π).
The same equality holds for AE .

Proof Let ρ = s 0 . . . s k ∈ Prefs(G) and π ∈ Plays(G) be a prefix and a play over a game G. We prove the property for AE . By definition and decomposition, we have that

AE (ρ • π) = lim sup n→∞ 1 n n i=1 EL((ρ • π)(i)) = lim sup n→∞   1 n • k i=1 EL(ρ(i)) + 1 n • n i=k+1 EL(ρ) + 1 n • n i=k+1 EL(π(i -k))   .
For clarity, we rewrite this expression as

AE (ρ • π) = lim sup n→∞ X 1 (n) + X 2 (n) + X 3 (n)
, maintaining the same order. Since k is fixed and finite, and EL(ρ(i)) is bounded for all i ≤ k, we have that lim sup n→∞ X 1 (n) = limn→∞ X 1 (n) = 0. Furthermore, for n ≥ k + 1, we rewrite the second term as

X 2 (n) = (n -k -1) • EL(ρ)/n, and it follows that lim sup n→∞ X 2 (n) = limn→∞ X 2 (n) = EL(ρ). Since both sequences X 1 (n) and X 2 (n) converge, we can write lim inf n→∞ X 1 (n) + lim inf n→∞ X 2 (n)+ lim sup n→∞ X 3 (n) ≤ AE (ρ • π) ≤ lim sup n→∞ X 1 (n) + lim sup n→∞ X 2 (n) + lim sup n→∞ X 3 (n).
Hence, by a small change of variable,

AE (ρ • π) = EL(ρ) + lim sup n→∞ X 3 (n) = EL(ρ) + lim sup n→∞ 1 n • n-k-1 i=1 EL(π(i)) = EL(ρ) + AE (π),
as, in the limit, the (k + 1) missing terms in the sum are negligible. The proof for AE is similar.

Extraction of a best cycle.

The next lemma is crucial to prove that memoryless strategies suffice: under well-chosen conditions, one can always select a best cycle in a play -hence, there is no interest in mixing different cycles and no use for memory. It holds only for sequences of cycles that have energy level zero: since they do not change the energy, they do not modify the AE of the following suffix of play, and one can decompose the AE as a weighted average over zero cycles.

Lemma 5 (Repeated zero cycles of bounded length) Let C 1 , C 2 , C 3 , . . . be an infinite sequence of cycles C i ∈ Prefs(G) such that (i) π = C 1 • C 2 • C 3 • • • ∈ Plays(G), 1 (ii) ∀ i ≥ 1, EL(C i ) = 0 and (iii) ∃ ∈ N >0 such that ∀ i ≥ 1, |C i | ≤ .
Then the following properties hold.

1. The average-energy of π is the weighted average of the average-energies of the cycles:

AE (π) = lim sup k→∞ k i=1 |C i | • AE (C i ) k i=1 |C i | . (2) 2. For any cycle C ∈ Prefs(G) such that EL(C) = 0, we have that AE (C ω ) = AE (C).
3. Repeating the best cycle gives the lowest AE :

inf i∈N>0 AE (C i ) = inf i∈N>0 AE ((C i ) ω ) ≤ AE (π)
. Similar properties hold for AE .

Observe that since we assume a bound ∈ N >0 on the length of cycles, and the game is played on a finite graph, Point 3 of Lem. 5 does actually allow to select a best cycle: the set of possible cycles of length at most is finite and the infimum is reached, hence can be replaced by the miminum.

Proof We prove the three points for AE , similar arguments can be applied for

AE . Consider Point 1. Let π = s 1 0 . . . s 1 |C1| s 2 1 . . . s 2 |C2| s 3 1 . . . where s i j denotes the j-th state of cycle C i , with C 1 = s 1 0 . . . s 1 |C1| and for all i > 1, C i = s i-1 |Ci-1| s i 1 . . . s i |Ci| . Essentially, s i-1
|Ci-1| is both the last state of C i-1 and the first one of C i : it can also be seen as

s i
0 and we later use both notations depending on the role we consider for this state.

Given index k ∈ N of a state s k in the classical formulation π = s 0 s 1 s 2 . . . such that s k denotes state s i j in our new formulation

π = s 1 0 . . . s 1 |C1| s 2 1 . . . s 2 |C2| s 3 1 .
. . , we define c(k) = i and p(k) = j, respectively denoting the index of the corresponding cycle and the position of state s k within this cycle. We can rewrite the definition of the average-energy of π as

AE (π) = lim sup n→∞ 1 n n k=1 EL(π(k)) = lim sup n→∞   1 n   c(n)-1 i=1 |Ci| j=1 EL(s 1 0 . . . s i j ) + p(n) j=1 EL(s 1 0 . . . s c(n) j )     . (3)
Observe that since all cycles are such that EL(C i ) = 0, we have that EL(s

1 0 . . . s i j ) = EL(s i 0 . . . s i j ) for all indices i ∈ N >0 , j ∈ {1, . . . , |C i |}.
In other words, the energy level in a given position only depends on the current cycle. Hence, for all i ∈ N >0 ,

|Ci| j=1 EL(s 1 0 . . . s i j ) = |Ci| j=1 EL(s i 0 . . . s i j ) = |C i | • AE (C i )
where the second equality follows by definition of AE (C i ). Therefore, Eq. ( 3) becomes

AE (π) = lim sup n→∞   1 n   c(n)-1 i=1 |C i | • AE (C i ) + p(n) j=1 EL(s c(n) 0 . . . s c(n) j )     .
Recall that, by hypothesis, there exists ∈ N >0 such that for all i ≥ 1,

|C i | ≤ .
Observe that the boundedness of cycles length implies that

(a) p(n) ≤ , (b) p(n) j=1 EL(s c(n) 0 . . . s c(n) j ) is bounded, (c) c(n)-1 i=1 |C i | ≤ n = c(n)-1 i=1 |C i | + p(n) ≤ c(n)-1 i=1 |C i | + .
Combining those three arguments, we obtain that

lim sup n→∞ c(n)-1 i=1 |C i | • AE (C i ) c(n)-1 i=1 |C i | + ≤ AE (π) ≤ lim sup n→∞ c(n)-1 i=1 |C i | • AE (C i ) c(n)-1 i=1 |C i | Hence, AE (π) = lim sup k→∞ k i=1 |C i | • AE (C i ) k i=1 |C i |
as claimed by Point 1. Now consider Point 2. For any cycle C ∈ Prefs(G) such that EL(C) = 0, all three hypotheses (i), (ii), and (iii) are clearly satisfied, with = |C|. Hence by Point 1, we have that

AE (C ω ) = lim sup k→∞ k • |C| • AE (C) k • |C| = AE (C).
Finally, we prove Point 3. The equality straightforwardly follows from Point 2. It remains to consider the inequality. By definition of the infimum, we have that, for all k ≥ 1,

inf i∈N>0 AE (C i ) = k i=1 |C i | • inf i∈N>0 AE (C i ) k i=1 |C i | ≤ k i=1 |C i | • AE (C i ) k i=1 |C i | .
Hence by taking the limit, we obtain

inf i∈N>0 AE (C i ) = lim sup k→∞ inf i∈N>0 AE (C i ) ≤ lim sup k→∞ k i=1 |C i | • AE (C i ) k i=1 |C i | = AE (π).
This concludes our proof.

One-player games

We assume that the unique player is P 1 , hence that S 2 = ∅. The proofs are similar for the case where all states belong to P 2 (i.e., S 1 = ∅). Similarly, we present our results for the AE variant, but they carry over to the AE one. Actually, since we show that we can restrict ourselves to memoryless strategies, all consistent outcomes will be periodic and thus both variants will be equal over those outcomes.

Memoryless determinacy.

Intuitively, we use Lem. 4 and Lem. 5 to transform any arbitrary path into a simple lasso path, repeating a unique simple cycle, yielding an AE at least as good, thus proving that any threshold achievable with memory can also be achieved without it.

Theorem 6 Memoryless strategies are sufficient to win one-player AE games.

Proof As a preliminary step, we check whether the graph contains a reachable strictly negative cycle, e.g., using the Bellman-Ford algorithm in O(|S| • |T |)-time.

If so, then P 1 can ensure a strictly negative mean-payoff, and by Point 1 of Lem. 3, a memoryless strategy exists to make the average-energy be -∞: such a strategy consists in reaching and repeating the negative simple cycle forever. Now, assume that the graph contains no (reachable) strictly negative cycle. If the graph also contains no zero cycle, then the energy level necessarily diverges to +∞, and the average-energy is +∞ along any run. Indeed, we are in the case of Point 2 of Lem. 3. Any strategy is optimal in that case: in particular, any memoryless strategy is.

For the rest of this proof, we consider the remaining case of graphs that contain no reachable strictly negative cycle, but that do contain zero cycles. We will prove that memoryless strategies suffice for P 1 in those games, by induction on the number of choices of

P 1 . Given a game G = (S 1 , S 2 = ∅, E , w ), we define d G = |E | -|S|.
Since we assume graphs to be deadlock-free, we have that d G ≥ 0 for any game G. We consider induction on the value d G . For every game G such that d G = 0 and initial state s init ∈ S, P 1 wins for the AE objective for threshold t ∈ Q iff he wins with a memoryless strategy: indeed, P 1 actually has no choice at all in G, which is reduced to a unique outcome from s init . Now assume that memoryless strategies suffice for P 1 in every game G such that d G ≤ m for some m ∈ N. We claim that they also suffice in every game G such that d G = m + 1. Observe that if this holds, we are done as it proves that memoryless strategies suffice for P 1 in all one-player AE games. Let G be such a game with d G = m + 1. Recall that in G = (S 1 , S 2 = ∅, E , w ) there is no strictly negative cycle by hypothesis. Let s be a state of G such that s has at least two outgoing edges. Such a state necessarily exists since d G ≥ 1. Consider a partition of the outgoing edges of s in two non-empty sets A, B such that

A B = {(s 1 , s 2 ) ∈ E | s 1 = s}.
According to this partition, we can define in the natural way two sub-games

G A = (S 1 , S 2 = ∅, E \ B, w ) and G B = (S 1 , S 2 = ∅, E \ A, w ) such that d G A ≤ m and d G B ≤ m.
By induction hypothesis, we know that memoryless strategies suffice to play optimally for the AE objective in those two sub-games. First, observe that if P 1 has a memoryless winning strategy σ in either G A or G B for threshold t ∈ Q, then this strategy remains winning in G. What we need to show is that if P 1 cannot win in both G A and G B , then he also cannot win in G, even using memory in s: in the following, we assume that P 1 is memoryless in any other state s = s (following the induction hypothesis) and we show that mixing cycles in s does not help him. By contradiction, assume that P 1 cannot win in both G A and G B , but he has a winning strategy σ in G, for the same threshold t. Let π be the outcome consistent with σ. Two cases are possible.

First, state s is seen finitely often along π. In this case, we apply Lemma 4 repeatedly on π to iteratively remove all cycles on s. Since there is no strictly negative cycle in G, we know that removing one cycle cannot increase the averageenergy of the play (it either stays the same if the cycle is a zero cycle, or decreases if it is a strictly positive one). Since s is seen finitely often, we eventually obtain a play π that sees s at most once. Therefore, this play either belongs to G A or G B (both if s is never visited). Furthermore, it has average-energy at most t by construction. This contradicts the claim that P 1 has no winning strategy in both sub-games and concludes the proof in this case.

Second, state s is seen infinitely often along π. Since P 1 is memoryless outside s, π only contains simple cycles and can be written as

π = ρ • C 1 • C 2 • C 3 • • •
where ρ is an acyclic prefix ending in s and for all i ≥ 1, C i is a simple cycle on s. Observe that every cycle C i belongs either to G A or to G B . Furthermore, since π is winning and there is no strictly negative cycle in G, only finitely many indices i 1 , . . . , i k may correspond to a strictly positive cycle. With the same reasoning as above (repeated application of Lemma 4), we have that the play

π = ρ • C i k +1 • C i k +2 • • • ,
obtained by removing the first cycles up to index i k , necessarily has a lower or equal average-energy: hence it is also winning. Now observe that the sequence of

cycles π = C i k +1 • C i k +2 • • • may still involve simple cycles from both G A and G B .
Still, as all cycles are of length at most |S|, and are zero cycles, we can apply Lemma 5 to extract one best cycle C j , j > i k . Putting all this together, we have that

π = ρ • (C j ) ω is such that AE (π ) ≤ AE (π)
. Furthermore, π is a simple lasso path that belongs either to G A or to G B (as it now uses a unique outgoing edge from s). Consequently, π describes a winning strategy in one of the sub-games, which contradicts our hypothesis and concludes our proof in this case too.

Polynomial-time algorithm.

We now know the form of optimal memoryless strategies: an optimal lasso path π = ρ • C ω w.r.t. the AE . We establish a polynomial-time algorithm to solve one-player AE games.

The crux of our algorithm consists in computing, for each state s, the bestw.r.t. the AEzero cycle Cs starting and ending in s (if any). This is achieved through linear programming (LP) over expanded graphs. For each state s and length k ∈ {1, . . . , |S|}, we compute the best cycle C s,k by considering a graph (Fig. 2) that models all cycles of length k from s and that uses k + 1 levels and two-dimensional weights on edges of the form (c, l • c) where c is the weight in the original game and l ∈ {k, k -1, . . . , 1} is the level of the edge. In the LP, we look for cycles C s,k of length k on s such that (a) the sum of weights in the first dimension is zero (thus C s,k is a zero cycle), and (b) the sum in the second one is minimal. Fortunately, this sum is exactly equal to AE (C) • k thanks to the l factors used in the weights of the expanded graph. Hence, we obtain the optimal cycle C s,k (in polynomial time). Doing this |S| times for each state s, we obtain for each of them the optimal cycle Cs (if one zero cycle exists). Then, by Lem. 4, it remains to compute the least EL with which each state s can be reached using classical graph techniques (e.g., Bellman-Ford), and to pick the optimal combination to obtain an optimal memoryless strategy, in polynomial time.

Theorem 7

The AE problem for one-player games is in P.

s s s 1 1 -1 -1 (a) Original game. (s,2) (s ,1) (s ,1) (s,0) (-1,-2) (1,2) (1,1) (-1,-1) (b) Expanded graph for k = 2.
Fig. 2: The best cycle C s,2 is computed by looking for a path from (s, 2) to (s, 0) with sum zero in the first dimension (zero cycle) and minimal sum in the second dimension (minimal AE ). Here, the cycle via s is clearly better, with AE equal to -1/2 in contrast to 1/2 via s .

Proof Let s init be the initial state and t ∈ Q be the threshold. From Thm. 6, we can restrict our search to memoryless strategies achieving average-energy less than or equal to t. As noted in the proof of Thm. 6, if a strictly negative simple cycle exists and can be reached from s init , then the answer to the AE problem is clearly Yes, as average-energy -∞ is achievable. Checking if such a cycle exists and is reachable can be done in cubic time in the number of states (e.g., using Bellman-Ford to detect negative cycles).

Hence, we now assume that no negative cycle exists. The main part of our algorithm consists in computing, for each state s, the least average-energy that can be achieved along a simple zero cycle starting and ending in s (if any). Indeed, strictly positive cycles should be avoided as there is no negative cycle to counteract them. Applying Lem. 4, it then remains to compute the least energy level with which each state s can be reached (simple paths are sufficient as there are no negative cycles), and to pick the optimal combination. Again, this last part can be solved by using classical graph algorithms in cubic time in |S|.

We now focus on computing the best zero cycle from a state s. This is achieved by enumerating the possible lengths, from 1 to |S| (simple cycles suffice). For a fixed length k, we consider a new graph G s,k , made of k + 1 copies of the original game G. The states of G s,k are pairs (u, l) with u ∈ S and 0 ≤ l ≤ k. The new graph is arranged in levels, indexed from l = k for the top one to l = 0 for the bottom one: l represents the number of steps remaining to close the cycle of length k. For each edge (u, u ) of G, with w(u, u ) = c, and for each 1 ≤ l ≤ k, except if both u = s and l < k (in order to rule out intermediary visits to s), there is an edge from (u, l) to (u , l -1). This edge carries a pair of weights (c, l • c). Our aim is to find a path in this graph from (s, k) to (s, 0) (hence this is a simple cycle of length k) such that the sum of the weights on the first dimension is zero (hence this is a zero cycle) and the sum on the second dimension is minimized (when divided by k, this sum is precisely the average-energy, if starting from energy level zero). This problem can be expressed as a linear program, with variables x u,u ,l for each edge u → u and each 1 ≤ l ≤ k. While they are not required to take integer values, these variables are intended to represent the number of times the edge from (u, l) to (u , l -1) is taken along a "path" in G s,k . The linear program is as follows: minimize

x u,u ,l • l • w(u, u ) subject to 1. 0 ≤ x u,u ,l ≤ 1 for all x u,u ,l ; 2. for all (u, l) with 1 ≤ l ≤ k -1, u x u ,u,l+1 = u x u,u ,l ; 3. u x s,u ,k = u x u ,s,1 = 1; 4.

x u,u ,l • w(u, u ) = 0; 5.

x u,u ,l ≥ 1.

Condition [START_REF] Björklund | Memoryless determinacy of parity and mean payoff games: A simple proof[END_REF] states that each state has the same amount of "incoming" and "outgoing" flow. Condition (3) expresses the fact that we start and end up in state s. Condition (4) encodes the fact that we are looking for zero cycles, and Condition (5) rules out the (possible) trivial solution where all variables are zero.

First observe that if this LP has no solution, then there is no zero cycle of length k from s. Now, assume it has a solution (x 0 u,u ,l ): this solution minimizes

x u,u ,l • l • w(u, u ). Consider a sequence of edges s = u k → u k-1 → • • • → u 1 → u 0 = s for which x u l ,u l-1 ,l > 0 for all l.
The existence of such a sequence easily follows from Conditions (2) and [START_REF] Bloem | Better quality in synthesis through quantitative objectives[END_REF]. Assume that this is not a zero cycle. As there are no negative cycles, then this must be a positive cycle. But in order to fulfill Condition (4), we would need a negative cycle to compensate for this positive cycle, hence implying contradiction. We conclude that any sequence of consecutive edges as selected above is a zero cycle. Similarly, there cannot be a zero cycle of length k from s with better average-energy, as this would contradict the optimality of this solution. We thus have obtained an average-energy-optimal simple zero cycle of length k from s, in polynomial time. Indeed, the LP is polynomial in the size of G s,k , itself polynomial in the size of the original game: the expanded graph has its size bounded by |S| • (k + 1) and all weights are bounded by k • W with k ≤ |S| and W the largest absolute weight in the original game.

As discussed above, this process can be repeated for each state s and each length k, 1 ≤ k ≤ |S|, hence at most |S| 2 times. For each state, we select the best cycle among the |S| possible ones (one for each length). Therefore, in polynomial time, we get a description of the best cycles w.r.t. the average-energy, for each s ∈ S. Clearly if no such cycle exists, then the answer to the AE problem is No, as all cycles are strictly positive and the average-energy of any play will be +∞. If some exist, we can find an optimal strategy by picking the best combination between such a cycle from a state s and a corresponding prefix from s init to s of minimal energy level. As presented before, this is achieved in polynomial time. Then the answer to the AE problem is Yes if and only if this optimal combination yields average-energy at most equal to t. This concludes our proof.

Two-player games

Memoryless determinacy.

We now prove that memoryless strategies still suffice in two-player games. As discussed in Sect. 3.2, most classical criteria do not apply. There is, however, one result that proves particularly useful. Consider any payoff function such that memoryless strategies suffice for both one-player versions (S 1 = ∅, resp. S 2 = ∅). In [START_REF] Gimbert | Games where you can play optimally without any memory[END_REF]Cor. 7], Gimbert and Zielonka establish that memoryless strategies also suffice in two-player games with the same payoff. Thanks to Thm. 6, this entails the next theorem.

Theorem 8 Average-energy games are determined and both players have memoryless optimal strategies.

Observe that this result is true for both variants of the average-energy payoff function, namely AE and AE . When both players play optimally, they can restrict themselves to memoryless strategies and both variants thus coincide as mentioned earlier.

Solving average-energy games.

Finally, consider the complexity of deciding the winner in a two-player AE game. By Thm. 8, one can guess an optimal memoryless strategy for P 2 and solve the remaining one-player game for P 1 , in polynomial time (by Thm. 7). The converse is also true: one can guess the strategy of P 1 and solve the remaining game where S 1 = ∅ in polynomial time. Thus, we obtain the following result.

Theorem 9

The AE problem for two-player games is in NP ∩ coNP.

We complete our study by proving that MP games can be encoded into AE ones in polynomial time. The former are known to be in NP ∩ coNP but whether they belong to P is a long-standing open question (e.g., [START_REF] Zwick | The complexity of mean payoff games on graphs[END_REF][START_REF] Jurdziński | Deciding the winner in parity games is in UP∩co-UP[END_REF][START_REF] Brim | Faster algorithms for mean-payoff games[END_REF][START_REF] Chatterjee | Looking at mean-payoff and total-payoff through windows[END_REF]). Hence, w.r.t. current knowledge, the NP ∩ coNP-membership of the AE problem can be considered optimal. The key of the construction is to double each edge of the original game and modify the weight function such that each pair of successive edges corresponding to such a doubled edge now has a total energy level of zero, and an average-energy that is exactly equal to the weight of the original edge. Then we apply decomposition techniques as in Lem. 5 to establish the equivalence.

Theorem 10 Mean-payoff games can be reduced to average-energy games in polynomial time.

Proof Let G = (S 1 , S 2 , E, w) be a game, and t ∈ Q be the threshold for the meanpayoff problem. From G, we build another game G = (S 1 , S 2 , E , w ) such that -S 1 = S 1 ∪ E and S 2 = S 2 ; -E contains two types of edges:

-(s, e) ∈ E iff there exists s such that e = (s, s ) ∈ E. Then w (s, e) = 2 • w(e).

-(e, s ) ∈ E for any e = (s, s ) ∈ E. Then w (e, s ) = -2 • w(e).

We claim that P 1 has a strategy ensuring objective MeanPayoff (t) in G if and only if the answer for the AE problem in G is Yes for the same threshold t. A similar construction is used in [START_REF] Boros | Markov decision processes and stochastic games with total effective payoff[END_REF]. With a prefix ρ = (s i ) i≤n in G, we can associate a prefix ρ = (s i ) i≤2n in G as follows: for all k ≤ n, s 2k = s k , and for all k < n, s 2k+1 = (s k , s k+1 ). The mean-payoff along ρ then equals the average energy along ρ (assuming initial energy 0 for ρ ). Indeed, applying the same decomposition arguments as for Lem. 5 and by definition of the weight function w , we have that

AE (ρ ) = 1 n n-1 i=0 2 • w (s i , (s i , s i+1 )) + w ((s i , s i+1 ), s i+1 ) 2 = 1 n n-1 i=0 4 • w(s i , s i+1 ) -2 • w(s i , s i+1 ) 2 = 1 n n-1 i=0 w(s i , s i+1 ) = MP (ρ).
Conversely, with a prefix ρ = (s i ) i≤2n in G starting and ending in a state in S 1 ∪ S 2 , we can associate a prefix ρ = (s i ) i≤n in G such that s k = s 2k for all k ≤ n. Again, assuming the initial energy is zero in ρ , the average energy along ρ equals the mean payoff along ρ. Now, assume that P 1 has a winning strategy σ in G from some state s ∈ S 1 ∪ S 2 , achieving mean-payoff less than or equal to t. Consider the strategy σ for G defined as σ (ρ ) = σ(ρ) if ρ ends in S 1 . If ρ ends in a T -state of the form (s, s ), then we let σ (ρ ) = s , which is the only possible outgoing edge. We see that the outcomes of σ correspond to the outcomes of σ, so that, assuming that the initial energy level is zero, σ enforces that the average-energy is below t for any infinite outcome. Conversely, given a strategy σ for G whose outcomes have average-energy below t, the strategy defined by σ(ρ) = σ (ρ ) for all finite paths ρ in G secures a mean-payoff below t. Observe that the equivalence holds both between AE and MP , and between AE and MP . Indeed, we have seen that for both MP and AE games, memoryless strategies suffice and decision problems for both variants coincide. We extend the AE framework with constraints on the running energy level of the system. Such constraints are natural in many applications where the energy capacity is bounded (e.g., fuel tank, battery charge). We first study the case where the energy is subject to both a lower bound (here, zero) and an upper bound (U ∈ N).

We study the problem for the fixed initial energy level c init := 0. In this case, the range of acceptable energy levels is by definition constrained to the interval [0, U ]. Our approach benefits from this: we solve the AE LU problem by considering an AE problem (and subsequently, an MP problem) over an expanded game that explicitly accounts for the lower and upper bounds on the energy.

Formally, we want to decide if P 1 can ensure a sufficiently low AE while keeping the EL within the allowed range.

Problem 2 (AE LU ) Given a game G, an initial state s init , an upper bound U ∈ N, and a threshold t ∈ Q, decide if P 1 has a winning strategy σ 1 ∈ Σ 1 for the objective Energy LU (U, c init := 0) ∩ AvgEnergy(t).

Again, we present results for the supremum variant AE but they also hold for the infimum one AE .

Illustration.

Consider the one-player game in Fig. 3. The energy constraints force P 1 to keep the energy in [0, 3] at all times. Hence, only three strategies can be followed safely, respectively inducing plays π 1 , π 2 and π 3 . Due to the bounds on energy, it is natural that strategies need to alternate between both a positive and a negative cycle to satisfy objective Energy LU (U, c init := 0) (since no simple zero cycle exists). It is yet interesting that to play optimally (play π 3 ), P 1 actually has to use both positive cycles, and in the appropriate order (compare plays π 2 and π 3 ). This type of alternating behavior is more intricate than for other classical conjunctions of objectives. Consider for example energy parity [START_REF] Chatterjee | Energy parity games[END_REF] or multi-dimensional energy games [START_REF] Chatterjee | Strategy synthesis for multi-dimensional quantitative objectives[END_REF][START_REF] Velner | The complexity of multi-mean-payoff and multi-energy games[END_REF]. It is usually necessary to use different cycles in such games: intuitively, one needs one "good" cycle for each dimension and one for the parity objective, and a winning strategy needs to alternate between those cycles. Fig. 3: Example of a one-player AE LU game (U = 3) and the evolution of energy under different strategies that maintain it within [0, 3] at all times. The minimal average-energy is obtained with play π 3 : alternating in order between the +1, +2 and -3 cycles.

However, there is no need to use two different cycles that are "good" w.r.t. the same part of the objective. In the case of AE LU games, we see that it is sometimes necessary to use two (or more) different cycles even though they impact the sum of weights in the same direction (e.g., several positive cycles). This gives a hint of the complexity of AE LU games.

Pseudo-polynomial algorithm and complexity bounds

We first reduce the AE LU problem to the AE problem over a pseudo-polynomial expanded game, i.e., polynomial in the size of the original AE LU game and in U ∈ N. By Thm. 9 and Thm. 7, this reduction induces NEXPTIME ∩ coNEXPTIMEmembership of the two-player AE LU problem, and EXPTIME-membership of the one-player one. We improve the complexity for two-player games by further reducing the AE game to an MP game: this yields EXPTIME-membership, which is optimal (Thm. 13). We also improve the one-player case by observing that a witness lasso path in the MP game can be built on-the-fly, and the mean-payoff of this path can be computed using only polynomial space in the original game, hence we end up with PSPACE-membership which we also prove optimal in Thm. [START_REF] Chatterjee | Looking at mean-payoff and total-payoff through windows[END_REF].

Observe that if U is encoded in unary or if U is polynomial in the size of the original game, the complexity of the AE LU problem collapses to NP ∩ coNP for two-player games and to P for one-player games thanks to our reduction to an AE problem and the results of Thm. 9 and Thm. 7.

The reductions.

Given a game G = (S 1 , S 2 , E, w), an initial state s init , an upper bound U ∈ N, and a threshold t ∈ Q, we reduce the AE LU problem to an AE problem as follows. If at any point along a play, the energy drops below zero or exceeds U , the play will be losing for the Energy LU (U, c init := 0) objective, hence also for its conjunction with the AE one. So we build a new game G over the state space (S × {0, 1, . . . , U }) ∪ {sink}. The idea is to include the energy level within the state labels, with sink as an absorbing state reached only when the energy constraint is breached. We now consider the AE problem for threshold t on G . By putting a self-loop of weight 1 on sink, we ensure that if the energy constraint is not guaranteed in G, the answer to the AE problem in G will be No as the average-energy will be infinite due to reaching this positive loop and repeating it forever. Hence, we show that the AE LU objective can be won in G if and only if the AE one can be won in G (thus avoiding the sink state). The result of the reduction for the game in Fig. 3a is presented in Fig. 4.

(a, 0) (a, 1) (a, 2) (a, 3) (b, 0) (b, 1) (b, 2) (b, 3) (c, 0) (c, 1) (c, 2) (c, 3) sink 1 | 0 1 | 1 1 | 2 0 | 0 0 | 1 0 | 2 0 | 3 1 | 0 1 | 1 1 | 2 1 | 3 1 | 2 0 | 0 0 | 1 0 | 2 0 | 3 -3 | 3 2 | 0 2 | 1
Fig. 4: Reduction from the AE LU game in Fig. 3a to an AE game and further reduction to an MP game over the same expanded graph. For the sake of succinctness, the weights are written as c | c with c the weight used in the AE game and c the one used in the MP game. We use the upper bound U = 3 and the average-energy threshold t = 1 (the optimal value in this case). The optimal play π 3 = (acaab) ω of the original game corresponds to an optimal memoryless play in the expanded graph.

Lemma 11

The AE LU problem over a game G = (S 1 , S 2 , E, w), with an initial state s init , an upper bound U ∈ N, and a threshold t ∈ Q, is reducible to an AE problem for the same threshold t ∈ Q over a game G = (S 1 , S 2 , E , w ) such that |S | = (U + 1) • |S| + 1 and W = max {min {W, U }, 1}, i.e., the largest absolute weight in G is at most the same as in G, or equal to constant 1.

Proof Consider the game G = (S 1 , S 2 , E, w), with initial state s init , upper bound U ∈ N and threshold t ∈ Q. We define the expanded game G = (S 1 , S 2 , E , w ) as follows.

-S 1 = (S 1 × {0, 1, . . . , U }) ∪ {sink}.

-S 2 = S 2 × {0, 1, . . . , U }.

-For all (u, v) ∈ E, (u, c) ∈ S , we have that:

1. if d = c + w(u, v) ∈ [0, U ], then e = (u, c), (v, d) ∈ E and w (e) = w(u, v), 2
. else e = (u, c), sink ∈ E and w (e) = 1. -(sink, sink) ∈ E and w(sink, sink) = 1.

The game G starts in state (s init , 0) and edges are built naturally to reflect the changes in the energy level. Whenever the energy drops below zero or exceeds U , we redirect the edge to sink, where a self-loop of weight 1 is repeated forever.

We claim that P 1 has a winning strategy σ 1 for the AE LU objective in G if and only if he has a winning strategy σ 1 for the AE objective in G , for the very same average-energy threshold t.

First, consider the left-to-right implication. Assume σ 1 is winning for objective Energy LU (U, c init := 0)∩AvgEnergy(t) in G. The very same strategy can be followed in G , ignoring the additional information on the energy in the state labels. Precisely, for any prefix ρ = (s 0 , c 0 )(s 1 , c 1 ) . . . (sn, cn) in G , we define σ 1 (ρ ) = (s, c) where s = σ 1 (ρ) for ρ = s 0 s 1 . . . sn and c = cn + w(sn, s). Obviously, playing this strategy ensures that the special state sink is never reached, as otherwise it would not be winning for Energy LU (U, c init := 0) in G, by construction of G . Since all weights are identical in both games except on edges entering the sink state, we have that any consistent outcome π of σ 1 in G corresponds to a consistent outcome π of σ 1 in G such that AE (π ) = AE (π), and conversely. Therefore, σ is clearly winning for objective AvgEnergy(t) in G .

Second, consider the right-to-left implication. Assume σ 1 is winning for objective AvgEnergy(t) in G . Then this strategy ensures that sink is avoided forever. Otherwise, there would exist a consistent outcome π reaching sink, and such that AE (π ) = ∞ > t because of the strictly positive self-loop. Thus the strategy would not be winning. Hence by construction of G , this strategy trivially ensures Energy LU (U, c init := 0) in G . From σ 1 , we build a strategy σ 1 in G in the natural way, potentially integrating the information on the energy within the memory of σ 1 . Again, there is a bijection between plays avoiding sink in G and plays in G, such that σ 1 is winning for Energy LU (U, c init := 0) ∩ AvgEnergy(t) in G.

Hence we have shown the claimed reduction. For the sake of completeness, observe that the reduction holds both for AE and AE variants of the averageenergy. It remains to discuss the size of the expanded game. Observe that |S | = (U + 1) • |S| + 1. Furthermore, if W is the largest absolute weight in G, then W = max {min {W, U }, 1} is the largest one in G . Indeed, W is upper-bounded by U by construction (as all edges of absolute weight larger than U can be redirected directly to sink) and it is lower-bounded by 1 due to edges leading to sink. So the state space of G is polynomial in the state space of G and in the value of the upper bound U , while its weights are bounded by either the largest weight W , the upper bound U or constant 1.

We now show that the AE game G can be further reduced to an MP game G by modifying the weight structure of the graph. Essentially, all edges leaving a state (s, c) of G are given weight c in G , i.e., the current energy level, and the self-loop on sink is given weight ( t + 1). This modification is depicted in Fig. 4. We claim that the AE problem for threshold t ∈ Q in G is equivalent to the MP problem for the same threshold in G . Indeed, we show that with our change of weight function, reaching sink implies losing, both in G for AE and in G for MP , and all plays that do not reach sink have the same value for their average-energy in G as for their mean-payoff in G .

Lemma 12

The AE problem over the game G = (S 1 , S 2 , E , w ) defined in Lem. 11 is reducible to an MP problem for the same threshold t ∈ Q over a game G = (S 1 , S 2 , E , w ) sharing the same state space but with largest absolute weight W = max{U, t + 1}, where U is the energy upper bound of the original AE LU problem.

Proof Let G = (S 1 , S 2 , E , w ) be the game defined in Lem. 11, as a reduction from the original game G for the AE LU problem with upper bound U ∈ N and average-energy threshold t ∈ Q. We now build the game G = (S 1 , S 2 , E , w ) by simply modifying the weight function of G . The changes are as follows:

-For all edge e = ((s, c), (s , c )) ∈ E , its weight in G is w (e) = c -c and we now set it to w (e) = c in G . Recall that by construction of G , the value c represents the current energy level for any prefix ending in (s, c). This is the value we now use for the outgoing edge. Also, this value is constrained in [0, U ] by definition of G . -For all edge e = ((s, c), sink) ∈ E , its weight in G is w (e) = 1 and we now set it to w (e) = c in G for the sake of consistency (the actual value over this type of edges will not matter eventually).

-For the self-loop e = (sink, sink) ∈ E , its weight in G is w (e) = 1 and we now set it to w (e) = t + 1 in G . That is, reaching sink will imply a mean-payoff higher than the threshold.

Before proving the claim, we show that for all plays π ∈ Plays(G ) = Plays(G ) that do not reach sink, we have that AE G (π) = MP G (π), where the subscript naturally to the change of weight function. Let

π = s 0 s 1 s 2 . . . = (s 0 , c 0 )(s 1 , c 1 )(s 2 , c 2 ) . . .
be such a play, where for all i ≥ 0, s i ∈ S and (s i , c i ) ∈ S × [0, U ] ∩ N is its corresponding label. By definition of G , we have that,

∀ n ≥ 0, w (s n , s n+1 ) = cn = EL G (π(n)).
Hence by definition of the mean-payoff and the average-energy,

MP G (π) = lim sup n→∞ 1 n n-1 i=0 w (s i , s i+1 ) = lim sup n→∞ 1 n n-1 i=0 EL G (π(i)) = AE G (π). ( 4
)
For the sake of completeness, observe that this equality does not hold for plays reaching sink, as they have infinite average-energy in G but finite mean-payoff in G . We proceed by proving the claim that P 1 has a winning strategy σ 1 for the AE objective in G if and only if he has a winning strategy σ 1 for the MP objective in G , for the very same threshold t.

First, consider the left-to-right implication. Assume σ 1 is winning for objective AvgEnergy(t) in G . We apply the same strategy in G straightforwardly as the underlying graph is not modified. Since this strategy is winning for the AE objective in G , it necessarily avoids sink both in G and G (as otherwise the AE would be infinite). Hence by Eq. ( 4), we have that σ 1 is also winning for MeanPayoff (t) in G .

Second, consider the right-to-left implication. Assume σ 1 is winning for objective MeanPayoff (t) in G . Since the self-loop on sink has weight t + 1, it is necessary that σ 1 never reaches sink otherwise it would not be winning. Hence we apply the same strategy in G and by Eq. ( 4), we have that σ 1 is also winning for AvgEnergy(t) in G . This proves correctness of the reduction. The same reasoning can be followed for AE (thus using MP ) instead of AE . We end by discussing the size of G . Clearly, the state space S is identical to S , hence |S | = (U + 1) • |S| + 1. However, the largest absolute weight in G is W = max{U, t + 1}. Indeed, the self-loop on sink has weight ( t + 1) and all other edges have weight bounded by the energy upper bound U by construction.

Illustration.

Consider the AE LU game G depicted in Fig. 3a. We have seen that the optimal strategy is π 3 = (acaab) ω . Now consider the reduction to the AE game, and further to the MP game, depicted in Fig. 4. The optimal (memoryless) strategy in both the AE game G and the MP game G is to create the play π = ((a, 0)(c, 1)(a, 1)(a, 3)(b, 0)) ω , which corresponds to the optimal play π 3 in the original game. It can be checked that

AE G (π 3 ) = AE G (π ) = MP G (π ).
Complexity.

The reduction from the AE LU game to the AE one induces a pseudo-polynomial blow-up in the number of states. Thanks to the second reduction and the use of a pseudo-polynomial algorithm for the MP game [START_REF] Zwick | The complexity of mean payoff games on graphs[END_REF][START_REF] Brim | Faster algorithms for mean-payoff games[END_REF], we get EXPTIME-membership, which is optimal for two-player games thanks to the lower bound proved for EG LU [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF]. The complexity is reduced when the bound U is given in unary or is polynomial in the size of the game, matching the one obtained for AE games without energy constraints.

For the one-player case, we also use the reduction to an MP game. By [START_REF] Ehrenfeucht | Positional strategies for mean payoff games[END_REF], optimal memoryless strategies exist, hence it suffices to non-deterministically build a simple lasso path in G , and to check that it satisfies the mean-payoff constraint. It can be done using only polynomial space through on-the-fly computation. Proof Let G = (S 1 , S 2 , E, w) be the original AE LU game, W ∈ N its largest absolute weight, U ∈ N the upper bound for energy and t ∈ Q the threshold for the AE LU problem. By Lem. 11, this AE LU problem is reducible to an AE problem for the same threshold t over a game G = (S 1 , S 2 , E , w ) such that |S | = (U +1)•|S|+1 and W = max {min {W, U }, 1}. By Lem. 12, the AE LU problem can be further reduced to an MP problem for the same threshold t over a game G = (S 1 , S 2 , E , w ) sharing the same state space as G but with largest absolute weight W = max{U, t + 1}. We start by proving the complexity upper bounds.

First, consider the one-player case. Combining Thm. 7 and the reduction to an AE game, we obtain that one-player AE LU games can be solved in pseudopolynomial time, i.e., polynomial in |S| but also in the value of U (hence exponential in the size of its binary encoding). This both gives EXPTIME-membership of oneplayer AE LU games with arbitrary upper bounds, and P-membership of the same games with polynomial or unary upper bounds. For arbitrary bounds, we improve the complexity from EXPTIME to PSPACE. To do so, we consider the further reduction to an MP game, but we do not completely build the MP game G which is known to be of exponential size. Instead, we build non-deterministically a witness lasso path (thanks to memoryless determinacy [START_REF] Ehrenfeucht | Positional strategies for mean payoff games[END_REF], they are sufficient) and check on-the-fly that the path is winning or not, using only polynomial space. Recall that we consider a game G such that S 2 = ∅. Our non-deterministic algorithm answers Yes if P 1 has a winning strategy in G (and hence in G thanks to Lem. 11 and Lem. 12), No otherwise, and is as follows:

1. Guess a state s r ∈ S 1 = (S 1 × {0, 1, . . . , U }) ∪ {sink} that will be the starting (and ending) state of the cycling part of the lasso path. For the following, we assume that s r = sink otherwise the lasso path that we are trying to build is clearly losing (see proof of Lem. 12) and the algorithm answers No. Thus, store state s r = (sr, m) for some m ∈ {0, . . . , U }. 2. Check that s r is reachable from the initial state (s init , 0). This can be done in NLOGSPACE w.r.t. the size of G (see e.g., [START_REF] Sipser | Introduction to the theory of computation[END_REF]), hence NPSPACE w.r.t. the original problem. If it is not, then the answer is No. 3. Build step by step2 a lasso path by constructing a simple cycle in G starting in s r . This construction is non-deterministic: if at any point, the sink state is reached, the algorithm returns No. The construction stops as soon as s r is reached, or after |S |+1 steps if s r is not reached: in the latter case, the answer is also No (after |S | + 1 steps, we know for certain that a cycle was created hence our lasso path is complete). While constructing the cycle, we make on-the-fly computations: at each step, the next state is chosen non-deterministically and the only information that is stored -except from state s r used to determine the end of the cycle -is the number of steps from leaving s r , and the sum of the weights seen along the cycle. 4. Assume s r is reached (otherwise we have seen that the answer is No). Let s 0 s 1 . . . s l be the sequence of states visited along the construction, with s 0 = s l = s r . We have stored the length l and the sum of weights

γ = l-1 i=0 w (s i , s i+1 ).

Now, we check if

γ l ≤ t: this quantity is the mean-payoff of the lasso path we have constructed. If yes, then the answer is Yes, thanks to Lem. 11 and Lem. 12: the lasso path describes a winning strategy. Otherwise, the answer is No as this lasso path represents a losing strategy, by the same lemmas.

The correctness of this algorithm is guaranteed by Lem. 11 and Lem. 12. It remains to argue that it only uses polynomial space in the original AE LU problem. Observe that our on-the-fly computations only need to record the state s r , the current state, the current length and the current sum. We have that both states belong to S 1 × {0, 1, . . . , U }, that l < |S | = (U + 1) • |S| + 1 and that the sum is bounded by l • W = l • max{U, t + 1}. Hence, encoding those values only requires a polynomial number of bits w.r.t. the input of the AE LU problem (i.e., logarithmic in the upper bound U , the largest weight W and the threshold t). This proves that our algorithm lies in NPSPACE, and by Savitch's theorem [START_REF] Sipser | Introduction to the theory of computation[END_REF] we know that NPSPACE = PSPACE: hence we proved the upper bound for the one-player AE LU problem.

Second, consider two-player AE LU games. In this case, we solve the MP problem over G using a pseudo-polynomial algorithm such as the one presented in [START_REF] Brim | Faster algorithms for mean-payoff games[END_REF], whose complexity is O(|S * | 3 • W * ) for a game with |S * | states and largest absolute weight W * ∈ N. Therefore, the complexity of solving the original AE LU problem is

O |S | 3 • W = O (U + 1) • |S| + 1 3 • max{U, t + 1} ,
which is clearly pseudo-polynomial. Hence we obtain EXPTIME-membership for two-player AE LU games. If the upper bound U ∈ N is polynomial in the size of the game or encoded in unary, it is sufficient to solve the polynomially-larger AE game G using Thm. 9 to obtain NP ∩ coNP-membership. Now consider lower bounds. The AE LU problem trivially encompasses the lowerand upper-bounded energy problem EG LU , i.e., the AE LU without consideration of the average-energy. Indeed, consider a game G with an objective Energy LU (U, c init := 0), for some U ∈ N. Assume P 1 has a winning strategy for this objective. Then this strategy ensures that along any consistent outcome π, the running energy at any point is at most equal to U . By definition, this implies that AE (π) ≤ AE (π) ≤ U . Hence this strategy is also winning for the AE LU objective written as the conjunction Energy LU (U, c init := 0) ∩ AvgEnergy(t := U ). The converse is also trivially true. Ergo, any lower bound on the complexity of the EG LU problem also holds for the AE LU one. The EXPTIME-hardness of the two-player EG LU problem was proved in [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF], the PSPACE-hardness of the one-player version was proved in [START_REF] Fearnley | Reachability in two-clock timed automata is PSPACEcomplete[END_REF] (in the equivalent setting of reachability in bounded one-counter automata). Note that those results clearly rely on having an upper bound U larger than polynomial (w.r.t. the size of the game) and encoded in binary, as we have already shown that in the opposite case the complexity of the problem is reduced.

Finally, observe that the same reduction and complexities also hold if we use AE instead of AE to define the AE LU problem. This concludes our proof.

Remark 1 One could argue that the reduction from AE games to MP games presented in Lem. 12 could be used to solve AE games without resorting to the specific analysis of Sect. 3. Indeed, in the case where the mean-payoff value is zero, any memoryless strategy (which we know to suffice) that is winning should only create zero cycles: the energy can be constrained in the range [-2

• |S| • W, 2 • |S| • W ]
along any winning play. However, applying a pseudo-polynomial MP algorithm on this new game would only grant EXPTIME-membership for AE games (because of the polynomial dependency on W ), in contrast to the NP ∩ coNP and P results obtained with the refined analysis for two-player and one-player AE games respectively.

Memory requirements

We prove pseudo-polynomial lower and upper bounds on memory for the two players in AE LU games. The upper bound follows from the reduction to a pseudopolynomial AE game and the memoryless determinacy of AE games proved in Thm. 8. Observe that winning strategies obtained via our reductions have a natural form: they are memoryless w.r.t. configurations (s, c) denoting the current state and the current energy level. As noted before, when the upper bound on energy U ∈ N is polynomial or given in unary, the expanded game is only polynomial in size, and the memory needs are also reduced.

The lower bound can be witnessed in two families of games asking for strategies using memory polynomial in the energy upper bound U ∈ N to be won by P 1 (Fig. 5a) or P 2 (Fig. 5b) respectively. It is interesting to observe that those families already ask for such memory when considering the simpler EG LU objective (i.e., bounded energy only). Sufficiency of pseudo-polynomial memory for EG LU games follows from [START_REF] Bouyer | Infinite runs in weighted timed automata with energy constraints[END_REF] but to the best of our knowledge, it was not proved in the literature that such memory is also necessary. (b) P 2 needs to increase the energy up to U using (a, c) to force P 1 to take (g, d) then make him lose by taking (a, b).

Fig. 5: Families of games witnessing the need for pseudo-polynomial-memory strategies for EG LU (and AE LU ) objectives. The goal of P 1 is to keep the energy in [0, U ] at all times, for U ∈ N. The left game is won by P 1 and the right one by P 2 but both require memory polynomial in the value U to be won. instead of the AE one (or equivalently with the AE objective for threshold t = U ). Thus, with regard to the binary encoding of U , strategies require exponential memory in general. For the special cases of unary encoding or polynomially bounded value U , polynomial memory suffices. Note that as usual, these arguments are true for both the AE and the AE versions of the objective. We now discuss the two families of games witnessing that pseudo-polynomial memory is also a lower bound for both players.

First, consider the one-player game depicted in Fig. 5a and parametrized by the value U ∈ N. Assume the objective is EG LU , asking for the energy to remain within [0, U ] at all times. Recall that the initial energy level is fixed to c init := 0. It is easy to see that there is only one acceptable strategy for P 1 : playing (s, s ) exactly U times, then playing the self-loop (s, s) once, and repeating this forever. Indeed, any other strategy eventually leads the energy outside the allowed range. Hence, to win this game, P 1 needs a strategy described by a Moore machine whose memory contains at least (U + 1) states. This proves that pseudo-polynomial memory is required for P 1 in EG LU games. Furthermore, the same argument can be applied on this game with objective AE LU by considering the average-energy threshold t := U which is trivially ensured by strategies satisfying the EG LU objective.

Second, consider the two-player3 EG LU game depicted in Fig. 5b. Again this game is parametrized by the energy upper bound U ∈ N and the initial energy level is fixed to c init := 0. This game can be won by P 2 using the following strategy: if the energy level is in [1, U ], play (a, c), otherwise play (a, b). Note that this strategy again requires at least (U + 1) states of memory in its Moore machine (to keep track of the energy level).

This strategy is indeed winning. Observe that P 1 can only decrease the energy by using edge (g, d) of weight -U , and this edge can only be used safely if the energy level is exactly U . In addition, the energy is bound to reach or exceed U eventually (as it will increase by 1 or 2 between each visit of a). If it exceeds U , then P 2 wins directly. Otherwise, assume that the energy is U when the game is in state g. If P 1 plays (g, f ), he loses (the energy reaches U + 1). If he plays (g, e), P 2 wins by playing (a, c) (the energy also reaches U + 1). And if P 1 plays (g, d), P 2 wins by playing (a, b) (the energy reaches -1). Hence, P 2 wins the game against all strategies of P 1 . Now, observe that P 2 cannot win if he uses a strategy with less memory states in its Moore machine. Indeed, any such strategy cannot keep track of all the energy levels between 0 and U and play (a, c) a sufficient number of times in a row before switching to the appropriate choice (depending on the energy being 0 or U ). Therefore, if P 2 uses such a strategy, P 1 can maintain the energy in the allowed range by simply reacting to edge (a, b) with (g, f ) and to edge (a, c) by choosing between (g, d) (if the energy is U ) and (g, e) (otherwise). Such choices are safe for P 1 as the strategy of P 2 does not have enough memory to distinguish the resulting energy levels from the intermediate ones.

This proves that P 2 also needs pseudo-polynomial memory in EG LU games. Finally, we remark that this reasoning also holds for the AE LU objective with threshold t := U , as for the previous game.

Average-Energy with Lower-Bounded Energy

We conclude with the conjunction of an AE objective with a lower bound (again equal to zero) constraint on the running energy, but no upper bound. This corresponds to an hypothetical unbounded energy storage. Hence, its applicability is limited, but it may prove interesting on the theoretical standpoint.

Problem 3 (AE L ) Given a game G, an initial state s init and a threshold t ∈ Q, decide if P 1 has a winning strategy σ 1 ∈ Σ 1 for objective Energy L (c init := 0) ∩ AvgEnergy(t).

This problem proves to be challenging to solve: we provide partial answers in the following, with a proper algorithm for one-player games but only a correct but incomplete method for two-player games. As usual, we present our results for the supremum variant AE .

Illustration.

Consider the game in Fig. 3. Recall that for AE LU with U = 3, the optimal play is π 3 , and it requires alternation between all three different simple cycles. Now consider AE L . One may think that relaxing the objective would allow for simpler winning strategies. This is not the case. Some new plays are now acceptable w.r.t. the energy constraint, such as π 4 = (aabaaba) ω , with AE (π 4 ) = 11/7 and π 5 = (aaababa) ω , with AE (π 5 ) = 18/7. Yet, the optimal play w.r.t. the AE (under the lower-bound energy constraint) is still π 3 , hence still requires to use all the available cycles, in the appropriate order. This indicates that AE L games also require complex solutions.

One-player games

We assume that the unique player is P 1 . Indeed, the opposite case is easy as for P 2 , the objective is a disjunction and P 2 can choose beforehand which sub-objective he will transgress, and do so with a simple memoryless strategy (both AE and EG L games admit memoryless optimal strategies as seen before). We show that one-player AE L problems lie in PSPACE by reduction to AE LU problems for a well-chosen upper bound U ∈ N and then application of Thm. 13.

The reduction.

Given a game G = (S 1 , S 2 = ∅, E, w) with largest weight W ∈ N, an initial state s init , and a threshold t ∈ Q, we reduce the AE L problem to an AE LU problem with an upper bound U ∈ N defined as U := t + N 2 + N 3 , with N = W • (|S| + 2). Observe that the length of the binary encoding of U is polynomial in the size of the game, the encoding of the largest weight W and the encoding of the threshold t. The intuition is that if P 1 can win a one-player AE L game, he can win it without ever reaching energy levels higher than the chosen bound U , even if he is technically allowed to do so. Essentially, the interest of increasing the energy is making more cycles available (as they become safe to take w.r.t. the lower bound constraint), but increasing the energy further than necessary is not a good idea as it will negatively impact the average-energy. To prove this reduction, we start from an arbitrary winning path in the AE L game, and build a witness path that is still winning for the AE L objective, but also keeps the energy below U at all times. Our construction exploits a result of Lafourcade et al. that bounds the value of the counter along a path in a one-counter automaton (stated in [START_REF] Lafourcade | Intruder deduction for AC -like equational theories with homomorphisms[END_REF] and proved in [START_REF] Lafourcade | Intruder deduction for AC-like equational theories with homomorphisms[END_REF]Lem. 42]). We slightly adapt it to our framework in the next lemma. The technique is identical, but the statement is more precise. In the following, we call an expanded configuration of the game G a couple (s, c) where s ∈ S is a state and c ∈ Z a level of energy.

Lemma 15 Let g ∈ Z. Let (s, c) and (s , c ) be two expanded configurations of the game G such that there exists an expanded path ρexp = (s 0 , c 0 ) . . . (sm, cm) in G from (s, c) to (s , c ) with c i ≥ g for every 0 ≤ i ≤ m. Then, there is a path ρ exp = (s 0 , c 0 )(s 1 , c 1 ) . . . (s n , c n ) in G from (s, c) to (s , c ) such that:

-for every 0 ≤ i ≤ n, g ≤ c i ≤ max{c, c , g} + N 2 + N 3 , where N = W • (|S| + 2),
with W the maximal absolute weight in G;

there is an (injective) increasing mapping ι : {1, . . . , n} → {1, . . . , m} such that for every 1 ≤ i ≤ n, s i = s ι(i) and c i ≤ c ι(i) .

Furthermore, for any two expanded paths ρ 1 and ρ 2 , with last(ρ 1 ) = (s, c) and first(ρ

2 ) = (s , c ), if AE (ρ 1 • ρexp • ρ 2 ) ≤ g, then it also holds that AE (ρ 1 • ρ exp • ρ 2 ) ≤ AE (ρ 1 • ρexp • ρ 2 ) ≤ g.
Proof We write α = W • (|S| + 1), β = (α + W ) • (α + W -1) -1 and K = max c, c , g + (α + W ) 2 . We apply inductively a transformation that removes similar ascending and descending segments of the path. The segments are selected such that their composition is neutral w.r.t. the energy.

Pick a subpath ρexp[k, k + h] = (s k , c k ) . . . (s k+h , c k+h ) of ρexp, if it exists, such that:

(a) c k ≤ K and c k+h ≤ K; (b) for every 0 < < h, c k+ > K; (c) there is 0 < < h such that c k+ > K + W • (|S| + 1) • β.
If such a subpath does not exist, then this means that the cost along ρexp is overall bounded by K + W • (|S| + 1) • β (since condition (a) is not restrictivec, c ≤ K), which then concludes the proof. Hence, assume such a subpath exists for the following steps.

Ascent part. Let k ≤ 0 ≤ • • • ≤ β ≤ k + h be indices such that: -c i > K + i • W • (|S| + 1); -for every k ≤ < i , c ≤ K + i • W • (|S| + 1). Fix 0 ≤ i ≤ β. Then it holds that c i ≤ K + i • W • (|S| + 1) + W and thus c i+1 -c i > K+(i+1)•W •(|S|+1)-(K+i•W •(|S|+1)+W ) = W •(|S|+1)-W = W •|S|.
Let J i be a subset of [ i ; i+1 ] defined by i ∈ J i , and if j ∈ J i , then let j ≤ i+1 be the smallest index larger than j (if it exists) such that c j > c j . Obviously we have c j < c j ≤ c j + W . Hence the cardinal of

J i is at least 1 + W •|S| W ≥ |S| + 1.
Hence there is a state s (i) and two indices j i,1 < j i,2 ∈ J i with (s ji,1 , c ji,1 ) = ( s (i) , α 1 ) and (s ji,2 , c ji,2 ) = (

s (i) , α 2 ) with c i ≤ α 1 < α 2 ≤ c i+1 , hence using previous computed bounds, 0 < α 2 -α 1 ≤ c i+1 -c i < W • (|S| + 2) = α + W . We write d (i) = α 2 -α 1 .
The segment between indices j i,1 and j i,2 is a candidate for being removed. Due to the value of β, there is d ∈ { d (i) | 0 ≤ i ≤ β} that appears (α + W ) times in that set.

Descent part.

We do a similar reasoning for the "descent" part. There must exist indices k ≤ m 0 ≤ • • • ≤ m β ≤ k + h such that:

-cm i > K + (β -i) • W • (|S| + 1); -for every m i < m ≤ k + h, cm ≤ K + (β -i) • W • (|S| + 1).
Note that we obviously have β < m 0 .

Then we apply the same combinatorics as for the ascent part. There is some value 0 < d < α + W which appears at least α + W times in potential cycles within the segment ρexp[k, k + h].

Transformation.

The algorithm then proceeds by removing d segments that increase the cost by d within ρexp[ 0 , β ] and d segments that decrease the cost by d within ρexp[m 0 , m β ]. This yields another path ρ exp and an obvious injection of ρ exp into ρexp which satisfies all the mentioned constraints. The sum of all energy levels along ρ exp is smaller than that along ρexp, and any energy level along ρ exp is obtained from that along ρexp by decreasing by at most 0

< d • d < (α + W ) 2 .
By assumption on segment ρexp[k, k + h] and bound K, we get that the cost along ρ exp is always larger than or equal to g, c and c .

We iterate this transformation to get a uniform upper bound. We finally notice that the obtained upper bound K + W • (|S| + 1) • β is bounded itself by max{c, c , g} + N 2 + N 3 , where N = W • (|S| + 2). This implies the expected result.

We build upon this lemma to define an appropriate transformation leading to the witness path and derive a sufficiently large upper bound U ∈ N for the AE LU problem.

Lemma 16

The AE L problem over a one-player game G = (S 1 , S 2 = ∅, E, w), with an initial state s init and a threshold t ∈ Q, is reducible to an AE LU problem over the same game G, for the same threshold t and upper bound U :

= t + N 2 + N 3 , with N = W • (|S| + 2).
Proof We prove that we can bound the energy along a witness of the one-player AE L problem. Let σ be a winning strategy of P 1 for objective Energy L (c init := 0) ∩ AvgEnergy(t) and π = s 0 s 1 . . . sn . . . be the corresponding outcome.

We build another strategy σ with corresponding play π such that for every n, 0 ≤ c init + EL( π(n)) ≤ c init + t + N 2 + N 3 , where N = W • (|S| + 2) (W is the maximal absolute weight in G), and such that AE ( π) ≤ AE (π). We actually build the play π directly, and infer strategy σ.

From π, we build the expanded play πexp = (s 0 , c 0 )(s 1 , c 1 ) . . . (sn, cn) . . . such that c i = EL(π(i)) for every i ≥ 0. Since π is a witness satisfying the objective Energy L (c init )∩AvgEnergy(t), it holds that c i +c init ≥ 0 for every i ≥ 0. We now show that some pair (s, c) is visited infinitely often along πexp. Toward a contradiction, assume that it is not the case. Then since energy levels are bounded from below along π, this means that lim infn→∞ cn = TP (π) = +∞, and by Lem. 2, that AE (π) = +∞ which contradicts the play being winning for the AE objective with threshold t ∈ Q. Now select the smallest energy c and state s such that (s, c) is visited infinitely often along πexp. Pick n 0 such that (1) (sn 0 , cn 0 ) = (s, c), (2) π[≥ n 0 ] = sn 0 s n0+1 . . . only visits states that are visited infinitely often along π, and (3) for every (s , c ) along πexp[≥ n 0 ], it holds that c ≥ c.

We can then write πexp as πexp[≤ n 0 ] • C 1 • C 2 . . . where each C i ends at configuration (s, c) (hence C i forms a cycle), and each configuration (s , c ) along some C i satisfies c ≥ c. We write γ i for the projection of C i on states (without energy level) -it forms a cycle as well. We obviously have

AE (π) = EL(π(n 0 )) + AE (π[> n 0 ]) = c + AE (π[> n 0 ])
by Lem. 4, and since AE (π) ≤ t, there must be some cycle C i such that AE (γ i ) ≤ t-c. We write γ for such a γ i , and we define = π(n 0 ) • γ ω : it is a lasso-shaped play which also satisfies the objective Energy L (c init ) ∩ AvgEnergy(t).

We will now modify the play , so that the energy does not grow too much along it. We write exp for the expanded version of : it is of the form

exp[≤ n 0 ] • exp[n0 + 1, n 0 + p] ω ,
where exp[n0 + 1, n 0 + p] projects onto γ when the energy information is removed (note that the last configurations of exp[≤ n 0 ] and of exp

[n0 + 1, n 0 + p] are s 1 a 1 ¬a 1 s 2 a 2 ¬a 2 s n a n ¬a n end 0 a 1 0 0 0 a 2 0 0 0 a n 0 -v -v
Fig. 6: Reduction from the subset-sum problem for target v ∈ N to a one-player

(U + 1) • |S| + 1 3 • max{U, t + 1} = O t + W 3 • |S| 3 4 • |S| 3 ,
which is still pseudo-polynomial in the size of the original AE L problem (i.e., polynomial in the number of states and in the values of the largest absolute weight and of the average-energy threshold). Second, we prove that the one-player AE L problem is NP-hard. Consider the subset-sum problem for the set A = {a 1 , . . . , an} such that for all i ∈ {1, . . . , n}, a i ∈ N, and target v ∈ N. Deciding if there exists a subset B ⊆ A such that ai∈B a i = v is well-known to be NP-complete [START_REF] Garey | Computers and intractability: a guide to the Theory of NP-Completeness[END_REF]. We reduce this problem to an AE L problem over the game G depicted in Fig. 6. Observe that this game has polynomially as many states as the size of A, and that its largest absolute weight is equal to the maximum between the largest element of A and the target v. It is clear that there is a bijection between choices of subsets of A and plays in G. Let us fix threshold t := v for the average-energy. Recall that Lem. 4 implies that the average-energy of any play is exactly its energy level at the first visit of end (because afterwards the zero self-loop is repeated forever). Hence, we have that 1. a play π in G is winning for Energy L (c init := 0) if and only if the corresponding subset B is such that ai∈B a i ≥ v; 2. a play π in G is winning for AvgEnergy(t := v) if and only if the corresponding subset B is such that ai∈B a i ≤ v.

Therefore, P 1 has a winning strategy for the AE L objective Energy L (c init := 0) ∩ AvgEnergy(t := v) in G if and only if there exists a subset B for which the sum of elements is exactly equal to the target v.

This proves the reduction from the subset-sum problem and the NP-hardness result. Observe two things. First, the hardness proof relies on having set elements and a target value that are not polynomial in the size of the input set A. Indeed, the subset-sum problem is solvable with a pseudo-polynomial algorithm, hence in P for polynomial values. Second, our reduction also holds for the AE variant of the average-energy.

Memory requirements.

Recall that for P 2 , the situation is simpler and memoryless strategies suffice. By the reduction to AE LU , we know that pseudo-polynomial memory suffices for P 1 . This bound is tight as witnessed by the family of games already presented in Fig. 5a. To ensure the lower bound on energy, P 1 has to play edge (s, s ) at least U times before taking the (s, s) self-loop. But to minimize the average-energy, edge (s, s ) should never be played more than necessary. The optimal strategy is the same as for the AE LU problem: playing (s, s ) exactly U times, then (s, s) once, then repeating, forever. As shown in Thm. 14, this strategy requires pseudo-polynomial memory.

Theorem 18 Pseudo-polynomial-memory strategies are both sufficient and necessary to win for P 1 in one-player AE L games. Memoryless strategies suffice for P 2 in such games.

Two-player games

For the two-player AE L problem, we only provide partial answers, as open questions remain. We first discuss decidability: we present an incremental algorithm that is correct but incomplete (Lem. [START_REF] Filar | Competitive Markov decision processes[END_REF]) and we draw the outline of a potential approach to obtain completeness hence decidability. Then, we prove that the two-player AE L problem is at least EXPTIME-hard (Lem. 20). Finally, we show that, in contrast to the one-player case, P 2 also requires memory in two-player AE L games (Lem. 21).

Decidability.

Assume that there exists some U ∈ N such that P 1 has a winning strategy for the AE LU problem with upper bound U and average-energy threshold t. Then, this strategy is trivially winning for the AE L problem as well. This observation leads to an incremental algorithm that is correct (no false positives) but incomplete (it is not guaranteed to stop).

Lemma 19 There is an algorithm that takes as input an AE L problem and iteratively solves corresponding AE LU problems for incremental values of U ∈ N. If a winning strategy is found for some U ∈ N, then it is also winning for the original AE L problem. If no strategy is found up to value U ∈ N, then no strategy of P 1 can simultaneously win the AE L problem and prevent the energy from exceeding U at all times.

While an incomplete algorithm clearly seems limiting from a theoretical standpoint, it is worth noting that in practice, such approaches are common and often necessary restrictions, even for problems where a complete algorithm is known to exist. For example, the existence of an initial energy level sufficient to win in multi-dimensional energy games can be decided [START_REF] Chatterjee | Strategy synthesis for multi-dimensional quantitative objectives[END_REF] but practical implementations resort to an incremental scheme that is in practice incomplete because the theoretical bound granting completeness is too large to be tackled efficiently by software synthesis tools [START_REF] Bohy | Synthesis from LTL specifications with mean-payoff objectives[END_REF]. In our case, we have already seen that if such a bound exists for the two-player AE L problem, it needs to be at least exponential in the encoding of problem (cf. one-player AE L games). Hence it seems likely that a prohibitive bound would be necessary, rendering the algorithm of Lem. 19 more appealing in practice.

Nevertheless, we conjecture that the AE L problem is decidable for two-player games and that, similarly to the one-player case, an upper bound on the energy can be obtained. Unfortunately, this claim is much more challenging to prove for two-player games. Clearly, the approach of Lem. 16 has to be generalized: while in one-player games we could pick a witness winning play and transform it, we now have to deal with tree unfoldings -describing sets of plays -because of the uncontrollable choices made by P 2 .

A potentially promising approach is to define a notion close to the self-covering trees used in [START_REF] Chatterjee | Strategy synthesis for multi-dimensional quantitative objectives[END_REF] for energy games. Roughly, take any winning strategy of P 1 in a two-player AE L game. Without further assumption, this strategy could be infinite-memory. It can be represented by its corresponding infinite tree unfolding where in nodes of P 1 , a unique child is given by the strategy, and in nodes of P 2 , all possible successors yield different branches. Every rooted branch of this tree is infinite and describes a winning play. Then, we would like to achieve the following steps.

1. Prove that all branches of this unfolding can be cut in such a way that the resulting finite tree describes a finite-memory strategy that is still winning for the AE L objective. 2. Reduce the height of this finite tree by compressing parts of the branches: deleting embedded zero cycles seems to be a good candidate for the transformation to apply. 3. Derive an upper bound on the height of the compressed tree and, consequently, on the maximal energy level reached along any play consistent with the corresponding strategy. 4. Use this upper bound to reduce the AE L problem to an AE LU problem.

Sadly, some challenges appear on the technical side when trying to implement this approach, mainly for items 1 and 3. Intuitively, the additional difficulty (when compared to the approach developed in [START_REF] Chatterjee | Strategy synthesis for multi-dimensional quantitative objectives[END_REF] and similar works) arises from the fact that describing what is a good cycle pattern for the AE L objective is much more intricate than it is for a simple EG L objective (in which case we simply look for zero cycles). This makes the precise definition of an appropriate transformation of branches, and the resulting tree height analysis, more tedious to achieve.

We also mention that the AE L problem could be reduced, following a construction similar to the one given in Sect. 4.1, to a mean-payoff threshold problem over an infinite arena, where states of the expanded graph are arranged respectively to their energy level, ranging from zero to infinity, and where weights would also take values inside N ∪ {∞} (as they reflect the possible energy levels). To the best of our knowledge, it is not known if mean-payoff games over such particular structures are decidable. If so, an algorithm would have to fully exploit the peculiar form of those arenas, as it is for example known that general models such as pushdown games are undecidable for the mean-payoff [START_REF] Chatterjee | Mean-payoff pushdown games[END_REF].

Finally, one could envision to fill the gap between one-player and two-player AE L games by using a general result similar to [START_REF] Gimbert | Games where you can play optimally without any memory[END_REF]Cor. 7]. Recall that we used it to derive memoryless determinacy in the two-player case from memoryless determinacy of both one-player versions (S 1 = ∅ and S 2 = ∅). However, we here have that in one-player games, P 1 requires pseudo-polynomial memory. Therefore, it is necessary to extend the result of Gimbert and Zielonka to finite-memory strategies: that is, to show that if we have a bound on memory valid in both one-player versions of a game, then this bound, or a derived one, is also valid in the two-player version. This is not known to be the case in general, and establishing it for a sufficiently general class of games seems challenging.

Complexity lower bound.

We now prove that the two-player AE L problem would require at least exponential time to solve. Our proof is by reduction from countdown games. A countdown game C is a weighted graph (V, E), where V is the finite set of states, and E ⊆ V × N \ {0} × V is the edge relation. Configurations are of the form (v, c), v ∈ V, c ∈ N. The game starts in an initial configuration (v init , c 0 ) and transitions from a configuration (s, c) are performed as follows. First, P 1 chooses a duration d, 0 < d ≤ c such that there exists e = (v, d, v ) ∈ E for some v ∈ V. Second, P 2 chooses a state v ∈ V such that e = (v, d, v ) ∈ E. Then the game advances to (v , c -d). Terminal configurations are reached whenever no legitimate move is available. If such a configuration is of the form (v, 0), P 1 wins the play, otherwise P 2 wins. Deciding the winner given an initial configuration (v init , c 0 ) is EXPTIME-complete [START_REF] Jurdziński | Model checking probabilistic timed automata with one or two clocks[END_REF].

Our reduction is depicted in Fig. 7. The EL is initialized to c 0 , then it is decreasing along any play. Consider the AE L objective for AE threshold t := 0. To ensure that the energy always stays non-negative, P 1 has to switch to stop while the EL is no less than zero. In addition, to ensure an AE no more than t = 0, P 1 has to obtain an EL at most equal to zero before switching to stop (as the AE will be equal to this EL thanks to Lem. 4 and the zero self-loop on stop). Hence, P 1 wins the AE L objective only if he can ensure a total sum of chosen durations that is exactly equal to c 0 , i.e., if he can reach a winning terminal configuration for the countdown game. The converse also holds. Proof Given a countdown game C = (V, E) and an initial configuration (v init , c 0 ), we build a game G = (S 1 , S 2 , E, w) with initial state s init such that P 1 has a winning strategy in G for the AE L objective for threshold t := 0 if and only if he has a winning strategy in C to reach a terminal configuration with counter value zero. The construction is depicted in Fig. 7. Formally, the game G is built as follows.

-S 1 = V ∪ {start, stop}.

-

S 2 = (v, d) ∈ V × N \ {0} | ∃ v ∈ V, (v, d, v ) ∈ E .
s init = start.

-For each (v, d, v ) ∈ E, we have that (v, (v, d)) ∈ E with w(v, (v, d)) = -d and ((v, d), v ) ∈ E with w((v, d), v ) = 0. -Additionally, (start, v init ) ∈ E with w(start, v init ) = c 0 , (stop, stop) ∈ E with w(stop, stop) = 0 and for all v ∈ V, (v, stop) ∈ E with w(v, stop) = 0.

First, consider the left-to-right direction of the claim. Assume P 1 has a winning strategy for the AE L objective in G. As noted before, such a strategy necessarily reaches the energy level zero then switches to stop directly. Hence, applying this strategy in the countdown game ensures that the sum of durations will be exactly equal to c 0 (recall that we start our AE L game by initializing the energy to c 0 then decrease it at every step by the duration chosen by P 1 ). Thus, this strategy is winning in the countdown game C.

Second, consider the right-to-left direction. Assume that P 1 has a winning strategy in the countdown game C. Playing this strategy in G ensures to reach a state v ∈ S 1 with energy level exactly equal to zero. Thus a winning strategy for the AE L objective is to play the countdown strategy up to this point then to immediately take the edge (v, stop). Indeed, any consistent outcome will satisfy the lower bound on energy (as the energy will never go below zero), and it will have an average-energy equal to t = 0 (because the energy level when reaching stop will be zero).

This shows both directions of the claim and concludes our proof. Observe that this reduction is also true if we consider the AE variant of the average-energy.

Memory requirements.

We close our study of two-player AE L games by discussing the memory needs. First note that we cannot provide upper bounds: if we had such bounds, we could derive a bound on the energy along any consistent play and reduce the AE L problem to an AE LU one as discussed before, hence proving its decidability. Second, we already know by Thm. 18 that pseudo-polynomial memory is necessary for P 1 . Finally, we present a simple game (Fig. 8) where P 2 needs to use memory in order to prevent P 1 from winning. Lemma 21 Pseudo-polynomial-memory strategies are necessary to win for P 1 in twoplayer AE L games. Memory is also required for P 2 in such games.

Proof We only have to prove that P 2 needs memory in the game of Fig. 8. Consider the AE L objective for the average-energy threshold t := 1 on this game. Assume that P 2 is restricted to memoryless strategies. Then, there are only two possible strategies for P 2 . If P 2 always takes the self-loop (s 2 , s 2 ), then the only consistent play is s 1 (s 2 ) ω : it has AE equal to 1, and satisfies the lower bound constraint on energy, thus P 1 wins. If P 2 always takes (s 2 , s 3 ), then P 1 can win by producing the following play: s 1 s 2 (s 3 s 2 s 3 ) ω . It also has AE equal to 1, and satisfies the energy constraint. Hence P 2 cannot win this game with a memoryless strategy. Nonetheless, he has a winning strategy that uses memory. Let this strategy be the one that plays (s 2 , s 3 ) once then chooses the self-loop (s 2 , s 2 ) forever. When this strategy is used by P 2 , P 1 has to pick (s 3 , s 2 ) in the first visit of s 3 otherwise he loses because the energy goes below zero. But if P 1 picks this edge, the unique outcome becomes s 1 s 2 s 3 (s 2 ) ω , whose average-energy is 2 > t, hence also losing for P 1 . Thus, the defined strategy is winning for P 2 .

Conclusion

We presented a thorough study of the average-energy payoff. We showed that average-energy games belong to the same intriguing complexity class as meanpayoff, total-payoff and energy games and that they are similarly memoryless determined. We then solved average-energy games with lower-and upper-bounded energy: such a conjunction is motivated by previous case studies in the literature [START_REF] Cassez | Automatic synthesis of robust and optimal controllers -an industrial case study[END_REF]. Lastly, we provided preliminary results for the case of average-energy with a lower bound but no upper bound on the energy. Following the publication of [START_REF] Bouyer | Average-energy games[END_REF], Larsen et al. adressed a different problem in [START_REF] Larsen | Limit your consumption! Finding bounds in average-energy games[END_REF]: they proved that deciding if there exists a threshold t ∈ Q such that P 1 can win a two-player game for objective Energy L (c init := 0) ∩ AvgEnergy(t) can be done in doubly-exponential time. This is indeed equivalent to deciding if there exists an upper-bound U ∈ N such that P 1 can win for the objective Energy LU (U, c init := 0), which is known to be in 2EXPTIME [START_REF] Juhl | Optimal bounds for multiweighted and parametrised energy games[END_REF]. Unfortunately, this approach does not help in solving Problem 3, where the threshold t ∈ Q for the average-energy is part of the input: solving two-player AE L games is still an open question.

We believe that the average-energy objective and its variations model relevant aspects of systems in practical applications as hinted by the aforementioned case study. Hence, we would like to extend our knowledge of this objective to more general models such as stochastic games, or games with multi-dimensional weights. Of course, the open questions regarding the AE L objective are intriguing. Finally, we would like to implement our techniques in synthesis tools and assess their applicability through proper case studies.

AE =11/ 3 (

 3 Play π 1 sees energy levels (1, 3, 5, 3) ω . d) Play π 2 sees energy levels (1, 3, 5, 5, 5, 3) ω .

4

  Average-Energy with Lower-and Upper-Bounded Energy

  Play π 3 = (acaab) ω .

Theorem 13

 13 The AE LU problem is EXPTIME-complete for two-player games and PSPACE-complete for one-player games. If the upper bound U ∈ N is polynomial in the size of the game or encoded in unary, the AE LU problem collapses to NP ∩ coNP and P for two-player and one-player games, respectively.

  P 1 needs to take U times (s, s ) before taking (s, s) once and repeating.

Fig. 7 :

 7 Fig.7: Reduction from a countdown game C = (V, E) with initial configuration (v init , c 0 ) to a two-player AE L problem for average-energy threshold t := 0.

2 Fig. 8 :

 28 Fig.8: Simple two-player AE L game witnessing the need for memory even for P 2 .

Table 1 :

 1 Complexity of deciding the winner and memory requirements for quantitative games: MP stands for mean-payoff, TP for total-payoff, EG L (resp. EG LU ) for lower-bounded (resp. lower-and upper-bounded) energy, AE for average-energy, AE L (resp. AE LU ) for average-energy under a lower bound (resp. and upper bound U ∈ N) on the energy, c. for complete, e. for easy, and h. for hard. Results without reference are proved in this paper.

	Game objective	1-player	2-player	memory
	MP	P [28]	NP ∩ coNP [38]	memoryless [17]
	TP	P [19]	NP ∩ coNP [21]	memoryless [22]
	EGL	P [6]	NP ∩ coNP [11, 6]	memoryless [11]
	EGLU	PSPACE-c. [18]	EXPTIME-c. [6]	pseudo-polynomial
	AE	P	NP ∩ coNP	memoryless
	AELU , polynomial U	P	NP ∩ coNP	polynomial
	AELU , arbitrary U	PSPACE-c.	EXPTIME-c.	pseudo-polynomial
	AEL	PSPACE-e. / NP-h.	open / EXPTIME-h.	open (≥ pseudo-p.)

  Theorem 14 Pseudo-polynomial-memory strategies are both sufficient and necessary to win in EG LU and AE LU games with arbitrary energy upper bound U ∈ N, for both players. Polynomial memory suffices when U is polynomial in the size of the game or encoded in unary. Proof We first prove the upper bound on memory. The expanded game G built in the reduction from the AE LU to the AE problem (Lem. 11) has a state space of size |S | = (U + 1) • |S| + 1, over which memoryless strategies suffice, by Thm. 8. Thus, winning for the AE LU objective only requires memory that is polynomial in the original number of states and the upper bound value U ∈ N. The same reduction holds for EG LU games with an even simpler safety objective (never reaching sink)

  AE L problem for average-energy threshold t := v. Theorem 17 The AE L problem is in PSPACE and at least NP-hard for one-player games. Proof First, consider the claim of PSPACE-membership. Let G = (S 1 , S 2 = ∅, E, w) be a game with initial state s init . Consider the AE L problem for a given averageenergy threshold t ∈ Q. By Lem. 16, this problem is reducible to the AE LU problem with upper bound U:= t + N 2 + N 3 , with N = W • (|S| + 2). Hence, U is of order O(t + W 3 • |S| 3 ), and its encoding is polynomial in the encoding of the original AE L problem (including thresholds and weights, not only in the number of states of the original game!). Following the complexity analysis presented in Thm. 13, we thus conclude that the one-player AE L problem is indeed in PSPACE. In terms of time, by using the MP reduction and the pseudo-polynomial algorithm, we have an algorithm for the one-player AE L problem that takes time of order

	O

We slightly abuse the notation as we see cycles as sequences of edges. The concatenation of cycles Ca = s s . . . s and C b = s s . . . s is to be understood as its natural interpretation Ca • C b = s s . . . s s . . . s: the origin state s only appears once in the middle and not twice as it would with Ca and C b seen as true sequences of states.

Observe that given a state in G , it is indeed possible to build any neighboring state using only E and w from the original game: one can effectively build the graph G on-the-fly.

In EG LU games with only P 2 (i.e., S 1 = ∅), P 2 does not need memory to play as he can pick beforehand which of the energy bounds (lower or upper) he will transgress, and then do so with a memoryless strategy.

Work partially supported by European project CASSTING (FP7-ICT-601148) and ERC project EQualIS (StG-308087). Mickael Randour is an F.R.S.-FNRS Postdoctoral Researcher.

(s, c)). We will do two things: (i) first we will work on the cycle γ; and (ii) then we will work on the prefix [≤ n 0 ], to build a witness with a fixed upper bound on the energy. For the rest of the proof, we assume that exp = (s 0 , c 0 )(s 1 , c 1 ) . . . so that (sn, cn) = (s, c) for every n = n 0 + b • p for some integer b.

First consider point (i). Let us notice that c ≤ t, otherwise the average-energy along could not be at most t (remember that the cost along the expanded version of γ starting at (s, c) is always larger than or equal to c by construction). We pick the first maximal subpath exp[k, k + h] of exp with [k, k + h] ⊆ (n 0 , n 0 + p), such that c k+ > t for every 0 ≤ ≤ h. By maximality of exp[k, k + h], it is the case that c k-1 ≤ t and c k+h+1 ≤ t. We infer that t < c k ≤ t + W and t < c k+h ≤ t + W , where W is the maximal absolute weight in the game G. We apply Lem. 15 to the path exp[k, k + h] with g = t, and we get that we can build an expanded path

exp which is shorter than exp[k, k + h] and such that:

at all positions of

and the energy at position i of (k) exp is smaller than or equal to c ι(i) .

In particular, we have a new witness for the objective Energy L (c init ) ∩ AvgEnergy(t), which is the play

ω , where (k) is the projection of

exp over the states of the game G. We iterate this transformation over all relevant segments of γ (this will happen only a finite number of times), and we end up with a new lasso-play = [≤ n 0 ] • (γ ) ω such that:

-

Now, consider point (ii). It remains to work on the prefix [≤ n

0 ] (which is still a prefix of ). We apply Lem. 15 to the prefix [≤ n 0 ] with g = 0, and we get an appropriately bounded witness.

Summing up, our construction proves that if there exists a winning play for Energy L (c init := 0) ∩ AvgEnergy(t) in the one-player game G, then there exists one for Energy LU (U, c init := 0) ∩ AvgEnergy(t), with U := t + N 2 + N 3 . Since the converse implication is obvious (as the second objective is strictly stronger), this concludes the proof of the reduction to an AE LU game.

Complexity.

Plugging this bound U in the PSPACE algorithm for one-player AE LU games (Thm. 13) implies PSPACE-membership for one-player AE L games also. In terms of time complexity, we saw that this problem can thus be solved in pseudo-polynomial time. We prove that no truly-polynomial-time algorithm can be obtained unless P = NP as the one-player AE L problem is NP-hard. We show it by reduction from the subset-sum problem [START_REF] Garey | Computers and intractability: a guide to the Theory of NP-Completeness[END_REF]: given a finite set of naturals A = {a 1 , . . . , an} and a target natural v, decide if there exists a subset B ⊆ A such that ai∈B a i = v. The reduction is sketched in Fig. 6: a play corresponds to a choice of subset. In order to keep a positive energy level, P 1 has to pick a subset that achieves a sum at least equal to v, but in order to satisfy the AE threshold, this sum must be at most v: hence P 1 must be able to pick a subset whose sum is exactly the target v.