Easy knapsacks and the complexity of energy allocation problems in the smart grid

Motivated by the growing interest in the smart grid and intelligent energy management mechanisms we study two classes of domestic energy allocation problems. In the first case we work with a system that is tasked with scheduling the work on a number of appliances over a given time window. In the second one a collection of air conditioning appliances is used to control the temperature of a given domestic environment. Our framework for this case includes a simplified mechanism for modelling the heat exchange between the interior and the exterior of the given environment. We present various polynomial time algorithms and NP-hardness proofs. In particular the main result of the paper is a proof that although it is NP-hard to schedule the operation of a single air-conditioning unit, working at various temperature levels in a variable energy price regime, there is a polynomial time algorithm for controlling one such device working at a single temperature level, for houses with low thermal inertia. The algorithm analysis hinges on the properties of a polynomial time variant of the minimisation version of the knapsack problem which may be of independent interest.


Introduction
The last ten years have seen the rapid development of the concept of smart grid, and significant work in the area of demand side load management [10,17].With the increasingly large range of (renewable) energy sources and tariffs, optimization in energy management is more and more important.Koutsopoulos and Tassiulas [15] studied a type of optimization problem that is typical in this setting: an energy grid operator receives consumer requests with different power requirements, durations, and deadlines.The objective of the operator is to devise a scheduling policy that minimizes the grid operational cost, seen as a convex function of the total load, over a given time horizon.The authors showed that if power demands can be served preemptively then the allocation problem can be solved effectively, and if that is not the case then the problem is NP-hard.Arikiez et al. [3] studied a Micro-Grid scenario that generalizes Koutsopoulos et al's model.A set of houses and a set of (renewable) energy generators is given, fully connected to each other and connected to a national electricity generator (NEG).Each house has a set of appliances which must be run a certain number of times in specified time periods (must-use constraints).Additionally some appliances may be used to control the temperature in (part of) the house (comfort constraints).The time horizon is finite and subdivided in constant length time intervals.The collection of such intervals is identified with an initial segment T = {1, 2, . . ., τ } of the set of positive natural numbers ("0" often refers to a generic moment in time before the process of interest starts).The system state is only allowed to change, instantaneously, between successive time intervals.Hence we talk equivalently of "time (steps)" or "time intervals".Some of the system settings are described by finite sequences defined over T .For instance each generator r has an available energy function: P r (t) indicates how much electricity this generator can deliver during the t-th time (interval) and we assume that this stays constant during such interval.Also, a cost function γ r,h (t) is defined for each house-generator pair (h, r ) which indicates the unit price at which house h can buy electricity from generator r at time t.The NEG is represented by a cost function λ h (t) which indicates the unit price at which any house can buy electricity from NEG at time t.To avoid trivialities we assume that γ r,h (t) < λ h (t) for all r, h, and t.
The main purpose of this paper is to study the complexity of classes of optimization problems which can be defined within Arikiez's et al. framework.For this reason, in the rest of the paper, we restrict to systems formed by a single house, connected to NEG and to a single generator (hence we drop indices h and r from our notations).In this setting P1 (equivalent to the non-preemptive case studied by Koutsopoulos and Tassiulas) is the problem of finding an appliance schedule compatible with a given set of must-use constraints which minimizes the energy cost for the house, assuming no temperature controlling appliance is present.After describing a few polynomial time cases, we show that P1 is actually NP-hard in the strong sense even if a certain amount of renewable energy is available free of charge.The main contribution of this paper, though, is the first theoretical analysis of a second, much richer, variant which we call P2.Here there is no limit on how many times each appliance is run, but the house has internal temperature constraints and appliances are air-conditioning (AC) units used to keep the internal temperature within such constraints.In the forthcoming sections we investigate the effect of energy cost variability as well as the type and distribution of the AC units on the problem complexity.If there are many units the problem is NP-hard, in the variable cost scenario.Therefore the most interesting case is that of an apartment with a single unit.If the device can operate at many different temperature states the problem is NP-hard.However if the AC unit only has a single operating mode then the problem can be solved efficiently.This is simple if the energy cost is fixed, however, if the cost varies, we found that the existence of an efficient algorithm solution depends crucially on the house thermal inertia.Our main algorithmic result on the problem at hand involves the study of the properties of a minimization version of Knapsack, which may be of independent interest.
Variants of the allocation problem considered here have been studied before [5,9,13,16].In fact research in domestic energy management, technologies for the smart grid, and home automation is thriving with hundreds of papers published every year and dozens of conferences and journals devoted to these topics.However it seems that most of the effort concentrated on finding feasible allocation heuristics, while relatively little [1] attention has been given to the scalability of such heuristics or the problems complexity.Some of these problems are related to machine scheduling [4] and bin packing [15].But the way in which the appliances are used, their arrangement and different price strategies are specific features of the smart grid setting.Problem P2 is related to the minimum cost resource allocation studied in [7] and the capacitated covering problems of [6].However our hardness proofs hold in simpler cases than those considered in the cited papers, and nobody seems to have considered exact polynomial time algorithms for non-trivial special cases.
In the next Section we focus on P1.We define the problem and discuss its complexity.In Sect. 3 we work on P2.We start by providing all relevant definitions.Then we analyze the problem's complexity first in the case of many appliances (Sect.3.1) then looking at single room single appliance systems (Sects.3.2, 3.3).The main result of this paper is the design of a polynomial time strategy for the optimization problem P2 in the case of a single AC unit, with a single operating state, in a poorly isolated house.In all our complexity results if Π 1 and Π 2 are two computational problems then Π 1 ≤ Π 2 will stand for the statement "Π 1 is polynomial time reducible to Π 2 " in the sense that there is a polynomial time algorithm translating instances of Π 1 into instances of Π 2 that preserve solvability (the reader is referred to [12] for all basic complexity theoretic definitions and notations).

Allocating "must use" appliances
In this section we focus on problem P1.The given house contains n appliances, identified by the integers 1, . . ., n.The model presented in [3] is quite general but to simplify our presentation we restrict ourselves mainly to so called uniphase interruptible appliances: at each time step t each unit i is either "OFF" or it is "ON" and if it is "ON" it uses an amount of power equal to α i .Each appliance's state can be changed freely at any time.Given τ consecutive time steps the goal is to run each appliance exactly once for a single time step, minimizing the total energy cost for the house.The problem admits a natural Linear Program formulation.The total amount of electricity Fig. 1 Multiphase appliance, with three phases each running for four time steps, using power α 1 , α 2 , and α 3 respectively needed at time t is 1≤i≤n α i • x i (t) where, for each i ∈ {1, . . ., n}, x i (t) = 1 (resp. x i (t) = 0) if appliance i is ON (resp.OFF) at time t.Electricity may come either from the NEG or from the local renewable power generator.Let G(t) (resp.L(t)) denote the amount of power taken from the generator (resp.from the NEG) at time t.Problem P1 is then described as follows (bold typeface symbols denote vectors with τ components, so, for instance, P = (P(1), . . ., P(τ )), etc and notations like "x • y" have the usual algebraic interpretation): where the vector x i describes the state of appliance i at each time step, the first constraint forces x i (t) to be one at a single point t, the second one forces the required amount of renewable power not to be larger than the total renewable power available, the third constraint is an energy balance one, and the last one restricts the range of the vectors x i .Note that if the number of appliances is fixed the set of feasible solutions for instances of P1 can be enumerated in time polynomial in τ .In fact this is true also if we required each appliance to be used an arbitrary, but fixed, number of times, or if the appliances had any of the more complex energy usage patterns defined in [3] (Fig. 1 gives an example of the energy requirements for a multiphase non-interruptible appliance.)Also, if the system has no renewable power generator then, again, the allocation is easy as we can simply allocate everything at a time for which λ(t) is minimal.Conversely, if the number of appliances is large the problem is NP-hard, even for τ = 2 [1,3].Here we strengthen such result.Arikiez et al. [3] evaluate the performances of an exact algorithm for P1 and observe that they degrade rapidly if n or τ become large.However it is not clear whether a so called pseudo-polynomial [12,Chapter 4] algorithm may exist that allow P1 to be solved in time polynomial in the magnitude of the numbers involved in the problem instance (this has proved to be beneficial in practical contexts [2]).Our next result makes this rather unlikely.
The 3-partition problem is defined as follows (see [12]): data: a 1 , . . ., a 3m positive integers adding up to m B such that each a i satisfies B/4 < a i < B/2.solution: A partition of the given set of numbers into m blocks such that the sum of the elements in each block is equal to B.
It is well-known that 3-partition is NP-hard in the strong sense (see [12, p. 99]) and this in turns rules out the possibility of a pseudo-polynomial time algorithm for this problem (unless P=NP).We describe a reduction from 3-partition to the decision version of P1 that preserves strong NP-hardness.This leads to the following result.
Theorem 1 Problem P1 is NP-hard in the strong sense.
Proof We show that a generic instance of 3-partition can be reduced to the decision version of P1 with a pseudo polynomial transformation (as defined in [11]).Let a 1 , . . ., a 3m and B > 0 be an instance of 3-partition.Define an instance of P1 by taking τ = m, and using 3m appliances with α i = a i for each i ∈ {1, . . ., 3m}.
Assume that there is a single renewable power generator.Let γ (t) = 0, and P(t) = B, for all t ∈ T .Set λ(t) to be some arbitrary fixed positive value.
The transformation preserves strong NP-hardness since the largest numerical value of the resulting instance is B < 4 • a 1 .It is easy to see that if there is partition in m blocks then there is an appliance allocation over τ (= m) time steps that uses all renewable power available and costs nothing.Conversely, if there is no good partition then there must be a time step t in which we need more than P(t) energy (and hence we must pay for it, buying it from NEG).behaviour by the equation: where x s (t) is the average of the contributions of all appliances in the room that are ON at time t and ∈ [0, 1] is an inertia factor.A discussion on the validity of ( 1) is beyond the scope of this paper (the interested reader is referred to [14]).However it is instructive to understand how the formula works.The room temperature at time t is viewed as a linear combination of its temperature at time t − 1 and contributions from external sources, and that of the air conditioning appliances it contains.The coefficients of this combination depend on physical properties of the house, like its volume or the materials it is made of.Note that, if = 1, the internal environment is perfectly isolated from the outside and, in fact, we also have no way to control the internal temperature.On the other hand, if = 0, then there is no isolation and the system has no memory.At every moment in time the internal temperature is equal to the external one plus a value dependent on the contribution of the AC units.Therefore, to avoid trivialities, from now on we further assume that 0 < < 1.The problem of interest admits a natural mixed integer linear programming formulation: where y s,i j (t) is one (resp.zero) if the ith appliance in room s is in state j at time t.Binary variables y s,i j (t) are use to model the fact that each AC unit can only be in one of its n s,i states at any given time step.Discrete variables x s (t) model the temperature change in room s at time t.We are after an assignment to these variables that minimize the cost of the house appliances and keeps the temperature of room s in the comfort ranges [T s min (t), T s max (t)] for every t ∈ T and s ∈ S. The first four sets of constraints model the energy allocation process.The right-hand side of the second one is a vector describing the total amount of energy used by the house.Here η s i > 0 is the efficiency of unit i in room s, thus if the unit contributes T s,i j in a particular time step, then |T s,i j |/η s i is the amount of power needed by the unit during that step.The last three sets of constraints restrict the appliance choices at any given time to those that keep the room temperatures within the prescribed limits.Notice that the recursive contraints (1) have been solved and the internal temperature variables T s replaced by their values Here E and F are the following τ × τ matrices: Also, the bounds on the products E • x s , which, abusing notations, we still call T s min and T s max , are, in fact, the only part of this model that depends on the initial internal temperature, the comfort limits, and the outside temperature.They stand for, respectively and T T = T s (0) • ( ,2 , . . ., τ ).

Many heathers
We first consider the case of a house containing many AC units.First assume that they are all part of a single room.Starting from [8], various authors have defined a natural minimization version of the classical Knapsack problem.For future reference denote by Minsack(w, p, M) an instance of such problem involving item weights w, profits p and knapsack bound M.This is exactly the problem we are interested in here where items correspond to appliances, and the allocation is over a single time step.Next, we will show that many single state heaters make P2 NP-hard even if the heaters are installed in different rooms in a variable energy price regime.In what follows Partition is the well-known NP-hard [12, Problem SP12] computational problem defined as follows: Data: a 1 , . . ., a n positive integers.Solution: a subset I ⊆ {1, . . ., n} such that i∈I a i = i∈{1,...,n}\I a i .
Proof Each instance of Partition is translated into an instance of P2 having τ = 2, n rooms, each equipped with a single heater having a single "ON" state.Value a s becomes the amount of energy needed by the unit in room s to run in a single time step.Thus for each s ∈ {1, . . ., n}, T s = η s • a s (the house and the rooms thermostatic parameters and η s can be chosen arbitrarily).For each s ∈ {1, . . ., n} we set T s min (1) is an arbitrary negative number and choose T s min (2) in the interval (0, T s ), Similarly we choose T s max (1) > T i and T s max (2) ∈ (T s , (1 + ) T s ).P(1) = P(2) = 1 and we assume that renewable energy costs nothing, whereas the energy from the grid has an arbitrary price λ.
To complete the proof we need to show that if a 1 , . . ., a n is a "YES" instance of Partition then the resulting instance of P2 can be solved with an allocation that has zero cost and if a 1 , . . ., a n is a "NO" instance of Partition any solution of P2 will have a positive cost.This will follow from a key property shared by all solutions to the instances of P2 under consideration: each solution requires each of the n heaters to be switched on exactly once.To prove this notice that the temperature constraints simplify to and the product in the middle, depending on the value y, is equal to 0 . But only the two middle values (corresponding to y s having only one of the two components equal to one) satisfy the stated inequalities.Suppose now that the given instance of Partition is a "YES" instance and let I be one of its solutions.Then scheduling all units in I to run at the same time step will result in a feasible solution for P2 with cost zero.Conversely if the given instance of Partition is a "NO" instance then any solution of P2 must have a positive cost.
The upshot of the analysis in this section is that P2 does not seem very easy to solve if the system contains a large number of AC units.In the rest of the paper we will concentrate on increasingly restricted versions of this problem.

One heater, a hard case
From now on we focus on a further restriction, which we call PS, obtained by assuming that the house only contains one room, that there is always enough renewable power, and that the single AC unit can be used in n different states, all of them providing a positive temperature contribution.We start our analysis by showing that PS is still NP-hard if the electricity price varies and n is large.The SubsetSum problem [12, Problem SP13] is defined as follows: Data: a 1 , . . ., a n and M positive integers.Solution: a subset I ⊆ {1, . . ., n} such that i∈I a i = M. Theorem 3 SubsetSum ≤ PS.
Here PS denotes the decision version of the energy allocation problem at hand.The reduction translates each instance of SubsetSum to an instance of PS involving a single heater with many different (positive) temperature contributions.Let a 1 , a 2 , . . ., a n and M define an instance of Subset sum.We set τ = n.Furthermore set -= 1 2 min 1 τ max{a i } , 1 M ; -the energy prices γ (t) = τ −t for all t ∈ T , -the heater temperature contributions T j = a j / τ − j for all j ∈ {1, . . ., n}, and η = 1, and -finally set T min (t) = 0 for all t ∈ T \{τ } and T min (τ ) = M.
We argue that the SubsetSum instance is a "YES" instance if and only if the instance of PS admits a solution of cost M. First notice that with these choices we can easily see that the first τ − 1 temperature constraints are always verified since expressions 1≤i≤t 1≤ j≤n l ≥ a l / and since < 1/M this value is greater than M.So the objective function would also be greater that M. Now to the second step.Suppose we have found a solution such that = M and that for some t ∈ {1, . . ., n} we have x(t) = T l with l > t.Let A be the set of these t, we decompose in two sums: Note that since we already proved that for all t ∈ T we have x(t) / ∈ {T 1 , . . ., T t−1 } what we sum in the first sum are either 0s or a t s and the first sum is an integer.Let's take a closer look at the second sum: for all t ∈ A we have a l t such that x(t) = T l t with l t > t by definition, so we have: • a l t since 0 < <1 and l t , t are integers with l t > t hence, since < 1/τ max{a j }, this sum is less than 1, thus it is not an integer, and this in turns contradicts the fact that M and the first sum are integers.

Polynomial time algorithms
So far we have discovered that instances of PS involving variable energy costs and heaters with many temperature levels may be hard to solve.We complete this section by describing a variant of PS that can be solved in polynomial time.If the electricity price is fixed (ie wlog γ = 1), there is a single heater which can either be "OFF" or in a single "ON" state contributing some value T to the house temperature, then we claim that Algorithm Greedy can be used to find an optimal solution for the problem above in polynomial time.The idea is to solve the τ constraints E • y ≥ T min iteratively, one by one.The algorithm while loop has the task of trying to build a vector y that satisfy the temperature constraints.It is easy to argue (formally by induction on t) that after the t-th iteration of the main for loop, if we did not enter the if on line 8, then y(1), . . ., y(t) is a minimal solution of the problem.Note that the left-hand side of the t-th inequality, 1≤x≤t y(x) • τ −x , is just y(t) • τ −t plus the left-hand side of the t − 1-th inequality.Hence if the process reached stage t either 1≤x≤t−1 y(x) • τ −x ≥ T min (t), in which case the same assignment will be picked up in the while loop in stage t or 1≤x≤t−1 y(x) • τ −x < T min (t), in which case a different assignment will be computed.The new assignment will satisfy all previous constraints because of the order in which variables y(x) are set (starting from the ones multiplying the largest monomials τ −x ).
The analysis so far leaves the variable energy cost case open.While we are not able to answer this in full in the reminder of this section we present a polynomial time strategy to solve the problem above provided is a positive constant smaller than 1/2.In what follows we denote this problem as PS( 12 ).The result hinges on a particular property of the sequence τ , as defined in (2), and on the computational feasibility of a class of Knapsack instances involving sequences of this type.The main result of this section is the following: Theorem 4 PS( 12 ) can be solved in polynomial time.A sequence of non-negative real numbers w = (w(1), . . ., w(a)) is left independent if for all positive integers j ≤ a we have Proof The first claim is trivial.Suppose S 1 = S 2 , we will show that v(S 1 ) = v(S 2 ).Let t = max S 1 ΔS 2 , where S 1 ΔS 2 is the symmetric difference of S 1 and S 2 .Without loss of generality we may assume that t ∈ S 2 .Then by the left independence of The result now follows by the first part of the statement as v(S 1 ) < v(S 2 ).
We now argue about the final claim.If there exists a t as stated such that ) by the first statement which is not possible by hypothesis.Hence If M is a positive real number, we call -decomposition of M the subset S (M) of T such that: Thus v(S (M)) is the smallest number greater than M which can be written as a sum of powers of for ∈ T .Note that S (M) can be computed as Minsack( τ , τ , M).
We are now ready to complete the proof of Theorem 4. We claim that algorithm Main takes T min , the cost function γ and as arguments and returns an optimal solution to the given instance of PS( 12 ) in time polynomial in τ .The process starts by creating the -decompositions of the numbers T min (t) and stores them in the array Sol (at the same time checking whether the given problem is trivially unfeasible).The second loop is the main part of the algorithm.In the tth iteration we focus on Sol[t] (assuming it is not empty).Thanks to the left independence of the rows of E , Algorithm Main Require: T min , γ , 1: let Sol be an array of sets all initialized to ∅ 2: let Aux := ∅ 3: for t = 1 to τ do 4: let Sol[t] be the -decomposition of T min (t)   instead of searching the minimal combination satisfying the first t constraints among all the possible combinations, we can concentrate on a set of less than τ possibilities.Then we update the rest of Sol in order to simplify the search of solutions in the next iterations.
Note that all the set operations, computations of γ [S], v(S), and S (T min (t)) can be done (using algorithm EKP as a subroutine) in time O(τ ); all loops have at most τ iterations and we have a maximum of two interlocked loops.Hence Algorithm Main runs in O(τ 3 ).
Next we argue that Algorithm Main returns a solution if and only if the given instance I of PS( 12 ) is feasible.This can be seen through the following chain of equivalences: there is a solution ⇐⇒ T is a solution (by definition of -decomposition) ⇐⇒ Main returns a solution (by left independence), To complete the proof of the Theorem we need to argue that if S is returned by Main it is an optimal solution to I. In what follows, given an instance I of PS( 12 ), for t ∈ T , denote by I t the sub-problem of obtained using (E ) t , the sub-matrix of E formed by the first t rows and columns, and the prefixes (T min ) t and γ t .Note that I coincides with since, for each j ∈ {1, . . ., k}, only the first j elements of the jth row of E are non-zero.
Assume that we ran Main and that the algorithm returned a solutions.We will show by induction on t that Sol[t] (seen as a set in [1 . . .t]) is a solution to the sub-problem of size t.The case t = 1 is obvious.We suppose now that Sol[k] is a solution to the sub-problem of size k for 1 ≤ k < t and we want to show that Sol[t] is a solution to the sub-problem of size t.
First show that we have . By construction we have ) since otherwise we would have j < m because of the for loop on lines 17-20 in Algorithm Main, which isn't possible since m ≤ k ≤ j.So, by induction hypothesis,

Conclusion
We studied a number of energy allocation optimization problems which may occur in domestic buildings.Two broad cases were considered: a "must-use" scenario where a set of appliances must be scheduled over a given time horizon, and a "comfort-aware" scenario where the appliances help to satisfy a predefined environment comfort level.In all cases we were interested in minimal energy cost solutions.Our main goal was to investigate the computational complexity of the relevant problems and characterize the border between polynomial-time tractability and NP-hardness.We studied the effect of the number of appliances on the complexity of problems of the first type, and that of the type and distribution of the AC units, as well as the energy price and the thermal properties of the given environment on problems of the second type.The main result of the paper is a proof that although it is NP-hard to schedule the operation of a single air-conditioning (AC) unit, working at various temperature levels in a variable energy price regime, there is a polynomial time algorithm for controlling one such device working at a single temperature level, for houses with low thermal inertia.The proof of such result uses the algorithmic properties of a variant of the well-known Knapsack problem.
\{τ } are non-negative.Denote by the problem's objective function.The last temperature constraint actually implies that a "YES" instance of PS must have = M.The next lemma states a property that can be used to complete the proof of Theorem 3.
Lemma 1 If y is a solution of our reduced problem then for all t ∈ T we have x(t) = T t or x(t) = 0. Proof We will show that for all t ∈ T we have x(t) / ∈ {T 1 , . . ., T t−1 } and then that x(t) / ∈ {T t+1 , . . ., T τ }.The first step just comes from the fact that if we have a t such as x ]) for any S ⊂ [1 . . .t − 1] = v(S 2 ) again by the first statement Conversely, let t = max S 1 ΔS 2 .Then it must be t ∈ S 2 since otherwise by definition of the symmetric difference we would have S 1 \[1 . . .t] = S 2 \[1 . . .t] and so, by the same argument used to prove the other implication, we would have ] with m being the minimum of Sol[t] at the begining of the tth iteration.Therefore, by induction hypothesis (T min