Development of Smart Advisor for optimized energy usage in Smart Grid Node

106
FAKULT ¨ AT F ¨ UR INFORMATIK DER TECHNISCHEN UNIVERSIT ¨ AT M ¨ UNCHEN Master’s Thesis in Informatics Development of Smart Advisor for optimized energy usage in Smart Grid Node Cheng Zhang

Transcript of Development of Smart Advisor for optimized energy usage in Smart Grid Node

FAKULTAT FUR INFORMATIKDER TECHNISCHEN UNIVERSITAT MUNCHEN

Master’s Thesis in Informatics

Development of Smart Advisor for

optimized energy usage in Smart Grid

Node

Cheng Zhang

FAKULTAT FUR INFORMATIKDER TECHNISCHEN UNIVERSITAT MUNCHEN

Master’s Thesis in Informatics

Development of Smart Advisor for optimized energy usage

in Smart Grid Node

Entwicklung eines Smart-Advisors fur die Optimierung des

Energieverbrauchs in einem Smart-Grid Knoten

Author: Cheng Zhang

Supervisor: PD Dr. rer. nat. habil. Bernhard Schatz

Advisor: M. Tech. Pragya Kirti Gupta

Date: 15.02.2015

Disclaimer

I assure the single handed composition of this master thesis only supported by declared

resources.

This thesis is part of a larger project, the Smart Living Lab demonstrator, being conducted

at Fortiss.

Munchen, 15th, Feb 2015 Cheng Zhang

Acknowledgment

I would like express my sincere gratitude to PD Dr. rer. nat. habil. Bernhard Schatz,

Pragya Gupta, Markus Duchon and Dagmar Koss for their engaged support and valuable

feedback.

Abstract

This thesis focuses on the development of a smart advisor which generates an optimized

schedule to reduce cost of energy usage in the fortiss smart energy living lab. For the

advisor, strategies are built for a short-term optimized schedule based on a forecast of

consumption and generation values in the smart energy living lab and dynamic energy

price (Time-Of-Use TOU or Real-Time-Pricing RTP price model) in the energy market.

Furthermore, properties of storage and connection between the smart grid node and the

grid are involved on generating the schedule. The optimized schedule consists of decisions

when to charge/discharge the battery and when to export energy to the grid and when to

shift load with appropriate electrical devices. The forecast of consumption and generation

values is generated by a forecast module of the smart energy living lab. The forecast could

be inaccurate especially the generation prediction that relies on the weather, an event will

be triggered to regenerate a new optimized schedule when the cumulative deviation from

previous forecasts exceeds a predefined threshold of the advisor. In my approach, when en-

ergy price is relatively high then discharge the battery, and when energy price is relatively

low or there is unused surplus generation then charge the battery. The cost of consumed

energy is calculated based on the optimized schedule with comparisons of a non-optimized

schedule and a dummy optimized schedule (charge the battery when there is surplus gener-

ation, discharge the battery when there is energy usage). An analysis of cost curves derived

from the three different schedules in a short-term is reported in this thesis. Additionally,

a suggestion of expected properties of storage is derived by the advisor through comparing

the total cost in different battery conditions, such as different maximum capacities of the

battery.

In conclusion, the advisor can find a schedule to maximize financial benefits and regener-

ate the optimized schedule when deviation exceeds predefined threshold through a greedy

algorithm.

Keywords

smart energy living lab, smart grid node, optimization of energy consumption, short-term

optimization, greedy algorithm

Contents

Acronyms and Abbreviations xiii

Glossary xiv

Nomenclature xv

1 Introduction 11.1 Schema of the Smart Grid node . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Possible Connections with the Grid . . . . . . . . . . . . . . . . . . . . . . . 31.3 Dynamic Energy Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.4 Load Shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.5 Greedy Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Problem Statement 52.1 Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1.1 Non-Export Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.2 Sell Renewable Scenario . . . . . . . . . . . . . . . . . . . . . . . . . 62.1.3 Sell Energy Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.1.4 Sell Storage Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2.1 Functional Requirements . . . . . . . . . . . . . . . . . . . . . . . . 82.2.2 Non-Functional Requirements . . . . . . . . . . . . . . . . . . . . . . 9

3 Related Work 103.1 Dynamic Energy Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.1.1 Time-Of-Use Pricing (TOU) . . . . . . . . . . . . . . . . . . . . . . . 103.1.2 Real-Time-Pricing (RTP) . . . . . . . . . . . . . . . . . . . . . . . . 103.1.3 Model A: Time-Of-Use Pricing (TOU) in Germany . . . . . . . . . . 113.1.4 Model B: Time-Of-Use Pricing (TOU) in North America by energy

provider Hydro-Ottawa . . . . . . . . . . . . . . . . . . . . . . . . . 123.1.5 Model C: Real-Time-Pricing (RTP) in Research . . . . . . . . . . . . 12

3.2 Battery Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.2.1 Round-trip Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . 133.2.2 Battery Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.3 Connection Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.3.1 Electrical Power Balance in the Smart Grid node . . . . . . . . . . . 14

vi

CONTENTS vii

3.3.2 Power Usage Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . 163.4 Power Demand from Battery & Power Supply to Battery . . . . . . . . . . 163.5 Financial Benefit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.6 Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.7 Existing System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.7.1 Information Broker . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.7.2 Prophet/Forecast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4 Conceptual Solution 214.1 Demand/Supply Energy at an Interval . . . . . . . . . . . . . . . . . . . . . 214.2 Demand/Supply Energy in a Price Period . . . . . . . . . . . . . . . . . . . 234.3 Greedy Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.3.1 Pool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.3.2 Pre Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.3.3 Situation Evaluation & Search Scope . . . . . . . . . . . . . . . . . . 304.3.4 Find Optimal Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.3.5 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.3.6 Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.3.7 Final Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.3.8 Decision Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.3.9 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

4.4 Powers at an interval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.5 Suggestion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.5.1 Expected Maximum Capacity . . . . . . . . . . . . . . . . . . . . . . 38

5 Component Architecture of the Optimizer 425.1 Advisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.2 Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.3 Order Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.4 Deviation Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.5 Listener . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

6 Advisor in the Optimizer 466.1 Preprocess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466.2 Decision Exploration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

6.2.1 Pre & Post Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . 476.2.2 Do Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

6.3 Post Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496.4 Cost Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506.5 Suggestion Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

CONTENTS viii

7 Implementation of the Optimizer 517.1 Optimizer API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517.2 Optimizer Impl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527.3 Optimizer Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537.4 Advisor Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547.5 Comparison Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

8 Evaluation 568.1 Algorithm Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

8.1.1 Time Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568.1.2 Space Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

8.2 Analysis & Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568.2.1 Non-Export Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . 578.2.2 Sell Energy Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . 598.2.3 Performance Comparison in Scenarios . . . . . . . . . . . . . . . . . 61

8.3 Efficiency of Batteries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

9 Conclusion & Future Work 659.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

Bibliography 68

A Digital Media 71

B Javadoc Code Documentation 72B.1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72B.2 Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73B.3 Dao . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74B.4 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

List of Figures

1.1 The schema of the fortiss smart energy living lab . . . . . . . . . . . . . . . 2

2.1 Power flow in non-export scenario . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Power flow in sell renewable scenario . . . . . . . . . . . . . . . . . . . . . . 62.3 Power flow in sell energy scenario . . . . . . . . . . . . . . . . . . . . . . . . 72.4 Power flow in sell storage scenario . . . . . . . . . . . . . . . . . . . . . . . 7

3.1 Model A: Time-Of-Use Pricing (TOU) in Germany . . . . . . . . . . . . . . 113.2 Model B: Time-Of-Use Pricing (TOU) in North America . . . . . . . . . . . 123.3 Model C: Real-Time-Pricing (RTP) in research recently . . . . . . . . . . . 123.4 Connection mode of the fortiss smart energy living lab . . . . . . . . . . . . 143.5 Power at intervals in a day . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.6 Architecture of the SMG system . . . . . . . . . . . . . . . . . . . . . . . . 19

4.1 Chart of Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.2 Chart of Price Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.3 Chart of Price Periods based on the TOU model . . . . . . . . . . . . . . . 264.4 Chart of Price Periods based on RTP model . . . . . . . . . . . . . . . . . . 264.5 EP Supply and EP Demand in Price Periods . . . . . . . . . . . . . . . . . . . 284.6 Pool in the algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.7 Exchange in the algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.8 Decision Path based on the Model A . . . . . . . . . . . . . . . . . . . . . . 314.9 Decision Path based on the Model B . . . . . . . . . . . . . . . . . . . . . . 324.10 Decision Path based on the Model C . . . . . . . . . . . . . . . . . . . . . . 334.11 Pools at all stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.12 Power at intervals in a day after optimization . . . . . . . . . . . . . . . . . 374.13 Demand and Supply of periods in non-export scenario . . . . . . . . . . . . 384.14 Pool status in non-export scenario . . . . . . . . . . . . . . . . . . . . . . . 394.15 Exchange energy in periods with the battery in non-export scenario . . . . 404.16 Optimized power in non-export scenario . . . . . . . . . . . . . . . . . . . . 41

5.1 Component of Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.2 Call order of the update event . . . . . . . . . . . . . . . . . . . . . . . . . . 43

6.1 Flowchart of Optimized Advisor . . . . . . . . . . . . . . . . . . . . . . . . 466.2 Flowchart of Preprocess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

ix

LIST OF FIGURES x

6.3 Flowchart of Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476.4 Flowchart of Pre Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476.5 Flowchart of Do Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486.6 Flowchart of Post Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496.7 Flowchart of Post Process at an interval . . . . . . . . . . . . . . . . . . . . 496.8 Flowchart of Cost Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . 506.9 Flowchart of Suggestion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

7.1 Class Diagram of the Optimizer API . . . . . . . . . . . . . . . . . . . . . . 517.2 Package Diagram of the Optimizer Impl . . . . . . . . . . . . . . . . . . . . 527.3 Class Diagram of the Unit Test . . . . . . . . . . . . . . . . . . . . . . . . . 537.4 Class Diagram of the Advisor . . . . . . . . . . . . . . . . . . . . . . . . . . 547.5 Class Diagram of the Comparison . . . . . . . . . . . . . . . . . . . . . . . . 55

8.1 Optimized cost in non-export scenario . . . . . . . . . . . . . . . . . . . . . 578.2 Comparison of optimized cost in non-export scenario . . . . . . . . . . . . . 588.3 Optimized cost in sell energy scenario . . . . . . . . . . . . . . . . . . . . . 598.4 Comparison of optimized cost in sell energy scenario . . . . . . . . . . . . . 608.5 Performance comparison in scenarios . . . . . . . . . . . . . . . . . . . . . . 618.6 Efficiency comparison in non-export scenario . . . . . . . . . . . . . . . . . 628.7 Efficiency comparison in sell energy scenario . . . . . . . . . . . . . . . . . . 638.8 Optimized power at intervals in sell energy scenario . . . . . . . . . . . . . . 64

List of Tables

2.1 Comparison of Scenarios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.1 Comparison of Dynamic Energy Price Models . . . . . . . . . . . . . . . . . 11

4.1 Intervals in a price period . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.2 Cumulative value interval by interval . . . . . . . . . . . . . . . . . . . . . . 244.3 Range of EP Demand

Max in each stage . . . . . . . . . . . . . . . . . . . . . 254.4 Cumulative value from end interval by interval . . . . . . . . . . . . . . . . 254.5 Range of EP Supply

Least in each stage . . . . . . . . . . . . . . . . . . . . . . 254.6 Demand and Supply in Price Periods . . . . . . . . . . . . . . . . . . . . . . 274.7 Demand and Supply in Price Periods . . . . . . . . . . . . . . . . . . . . . . 274.8 Demand & Supply of Price Periods . . . . . . . . . . . . . . . . . . . . . . . 334.9 Pools at all stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.10 Exchange at all stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

xi

Code Example

5.1 Query.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44B.1 Interval.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72B.2 Period.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72B.3 Tools.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73B.4 DatabaseDao.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74B.5 Advisor.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76B.6 Suggestion.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

xii

Acronyms and Abbreviations

AC alternating current

CPP Critical Peak Pricing (energy pricing)

DC direct current

W Watt

kWh kilowatt-hour

PV photovoltaic

RTP Real-Time-Pricing (energy pricing)

SMG smart micro grid

TOU Time-Of-Use (energy pricing)

Wh watt-hour

xiii

Glossary

Cost Reduction - reduce the cost of energy usage at a time by using storage that chargewith cheaper price.

Financial Benefit (Benefit) - Money received and/or cost avoided, due to use of energystorage and generation.

Generation - the amount of energy generation in the fortiss smart energy living lab

Greedy Algorithm - A greedy algorithm is an algorithm that follows the problem solv-ing heuristic of making the locally optimal choice at each stage with the hope of finding aglobal optimum.[1]

Increased Revenue - increase the worth of storage by export the stored energy witha higher energy price.

Power - Energy consumed or generated per unit of time.

Round-trip Efficiency - Ratio of total energy storage system output (discharge) di-vided by total energy input (charge) as measured at the interconnection point. [2]

Smart Grid - A concept involving a modernized electrical grid that delivers electric energyusing communications, control, and computer technology for improving efficiency, reliabil-ity and economics.[3]

Smart Grid node - see Smart Micro Grid

Smart Micro Grid - A Smart Micro Grid is a specific Smart Grid in a small-scaleversion such as a decentralized electricity system in a separate building.

Nomenclature

E Energy [Wh]

EDemand Energy demanded from the battery at an interval [Wh]

EP Demand Energy demanded from the battery in a price period [Wh]

EP Supply Energy supplied to the battery in a price period [Wh]

ESupply Energy supplied to the battery at an interval [Wh]

N Number

P Electric power [W]

PBat chMax Maximum permissible power for charging battery [W]

PBat dchMax Maximum permissible power by discharging power [W]

Pc Consumption power [W]

Pch Charging power [W]

PDemand Power demanded from the battery [W]

Pdch Discharging power [W]

Pfrom Power from the grid [W]

Pg Generation power [W]

Pgrid Exchanged power with grid [W]

PLineMax Maximum permissible power of the cable [W]

PSMG Aggregate power of the SMG [W]

PSupply Power supplied to the battery [W]

Pto Power to the grid [W]

Pw Waste power [W]

Price Energy price [€/kWh]

S(n) Space complexity

T Duration [Hour]

T (n) Time complexity

1 Introduction

Nowadays, the concept of renewable green power resources is overwhelming the world,increasing number of families, organizations and enterprises tend to introduce power pro-duction units such as PV generators. These micro grids gradually evolve into Smart MicroGrids/Smart Grid[3] nodes. An advisor is a part of the Smart Micro Grid, which analyzesthe energy usage in a period of time and generates suggestions to achieve the goals, costreduction and/or increased revenue.

At the moment, numerous advisors[4][5][6][7][8][9] related to the optimization of energyusage. There are two strategies to do the optimization, time-shifting[4][5][6] and loadmanagement[7][8][9]. In the strategy of time-shifting, concepts of “Average Cost of StoredEnergy”[4], “Bulk Electricity Price Arbitrage”[5] and “Electric Energy Time-shift”[6] areused for the same purpose that store inexpensive electricity and use or export stored energywhen the energy price is high. In the strategy of load management(load-shift), conceptsof “task schedule”[8] and “the profile of loads management”[9] are used to shift load fromthe on-peak to the off-peak. The time-shifting strategy seriously relies on the energy pricesat given hours in a short-term future provided by another component in the smart en-ergy living lab. In order to maximize profit, the advisor adopt the two strategies thatare time-shifting and load-shifting. Furthermore, in the time-shifting strategy a demanddriven greedy algorithm is introduced for achieving maximum financial benefit.

With the advisor in this thesis, the Smart Grid node can be more intelligent to storeenergy when energy price is appropriate and to use proper amount of stored energy ina proper period. In addition, due to the shortage of data analyses with the real data ofa specific “Smart Grid” node, the properties of current energy storage are probably thebottleneck to achieve the maximum financial benefit, e.g. maximum capacity, round-tripefficiency. The advisor can generate an expected properties of the energy storage besidesthe optimized schedule.

In order to fully understand the difference of the two strategies used in the thesis wefirst give a short description.

Time-shifting Strategy

• The consumption and the generation are fixed at given time.

• The source of energy consumed by the Smart Grid node or the destination of energyusage are adjustable.

1

CHAPTER 1. INTRODUCTION 2

• Charge the battery during off-peak periods or when the energy price is relatively lowor when there is unused surplus generation, it does not affect the consumption butprobably lead to more energy consumed from the grid.

• Discharge the battery during on-peak periods or when the energy price is relativelyhigh, it means the discharging energy substitute consuming energy from grid for theconsumption.

On aggregate, the energy is shifted from one time to another time through the battery inthe time-shifting strategy but the consumption and the generation are not shifted actually.

Load-shifting Strategy

• The consumption are adjustable.

• Reduce the load/tasks which are adjustable during on-peak periods or when theenergy price is relatively high.

• Increase the load/tasks which are adjustable during off-peak periods or when theenergy price is relatively low or when there is used surplus generation.

On aggregate, the amount of energy consumed during this time after optimization is thesame as that before optimization, but the running time of some load/tasks are changed.

1.1 Schema of the Smart Grid node

In this thesis, a Smart Grid node/Smart Micro Grid is the fortiss smart energy living lab.

Figure 1.1: The schema of the fortiss smart energy living lab

CHAPTER 1. INTRODUCTION 3

In the figure 1.1, the consumption represents all electrical devices that consume en-ergy such as computers, coffee machines, lights and so on, the generation consists of solarpanels (or wind turbines or other facilities produce energy) while the storage consists ofbatteries or other devices that can store energy. The power can flow from the grid to aSmart Grid node, and it can flow to the grid as well.

In a Smart Grid node, the green generated power replaces a part of energy usage fromthe grid or be stored in the energy storage facilities such as batteries. However, in theperspective of storage it can be charged from the grid or the generation and provide energyto the consumption or export energy to grid by discharging.

1.2 Possible Connections with the Grid

The condition of the connection between the “Smart Grid” node and the grid is an essentialfactor for the smart advisor in this thesis, since it determines the basic circuit properties.

Normally the “Smart Grid” node can consume energy from the grid, however increas-ing countries have laws allowing microgenerated electricity[10] to be sold into the grid, e.g.Canada(Alberta), The United Kingdom, Germany, Poland, Israel and the USA. Besidesthe generation the stored energy is also sold to the grid in the some regions of the USA.[11]Therefore there are several different types of connections in the world.

Finally four different scenarios are derived from these possible types of connections. Theywill be discussed in the following chapters.

1.3 Dynamic Energy Price

The dynamic energy price is the foundation of the advisor, since the time-shifting optimiza-tion completely depends on it. Furthermore, numerous dynamic energy price models[12]exist. In this thesis, time related price models will be considered, e.g. TOU[12] andRTP[12].

1.4 Load Shifting

Due to the physical connection and other restrictions such as the nominal power of cables inthe Smart Grid node, a part of generation are impossible to be used on some conditions evenwith the Time-shifting optimization which means Load-shifting optimization is required.For the waste energy, appropriate electrical devices should be used during the time thatthe wastage occurs.

CHAPTER 1. INTRODUCTION 4

1.5 Greedy Algorithm

In order to realize the Time-shifting optimization, the greedy algorithm is an appropriatechoice. Considering the real condition of a Smart Grid node, an analyzer should be involved,which can analyze the status of the battery at each stage and restrict the scope of choiceto next stage.

Organization of the Thesis

The second chapter discusses the potential problems in the optimization. In the thirdchapter, the related work used in the optimization are introduced besides the fundamentalenvironment of the advisor. The fourth chapter introduces a conceptual solution for theadvisor. In the fifth chapter, we discuss the component architecture of the optimizer used inthe SMG system. The sixth chapter states the logic of the advisor in detail. Chapter sevenpresents the implementation of the optimizer. The eighth chapter evaluates the advisorand reviews the results. Last but not least we discuss the overall conclusion and point outthe potential improvement of the advisor for the future work.

2 Problem Statement

2.1 Scenarios

Considering legal restrictions[10][11] in different regions and physical connections of a SmartGrid node and the grid, there are numerous scenarios. In terms of technical parameter, allsituations can be classified to the four scenarios in the following parts based on whetherenergy can be exported to grid and which kind of energy can be exported.

2.1.1 Non-Export Scenario

Figure 2.1: Power flow in non-export scenario

In this scenario, which occurs widely in the world, a Smart Grid node can only useenergy from the grid, but no power, neither from the generation nor from the storage, canflows to the grid. In this case, the generation can only be used in the Smart Grid nodewhich means it can be consumed directly by the consumption or be stored in the storage e.g.charge batteries. On the one side, when the generation is higher than the consumption in aSmart Grid node, it could be stored in the storage if storage is not full, otherwise it wouldbe lost. On the other side, when the generation is not enough to satisfy the consumption,the stored energy could be used if storage is not empty or directly consume energy fromthe grid.

5

CHAPTER 2. PROBLEM STATEMENT 6

2.1.2 Sell Renewable Scenario

Figure 2.2: Power flow in sell renewable scenario

In this scenario, a Smart Grid node can consume energy from grid and export energygenerated by PV system to the grid. Due to factors of law and grid restrictions, thegeneration can be delivered to grid, the stored energy excepted. Comparing with previousscenario, the only difference is that the generation can be exported to the grid besidesbeing stored and being consumed. Therefore, the Smart Grid node can consume morestored energy in order to export more generated energy in some time. In other words, themore energy consumed from storage, the more energy can be exported to grid. Additionally,there is no waste energy when storage is full but surplus generation occurs since it can beexported. Hence, the increase of generation can always lead to more economic benefit in acertain extent.

CHAPTER 2. PROBLEM STATEMENT 7

2.1.3 Sell Energy Scenario

Figure 2.3: Power flow in sell energy scenario

In this scenario, a Smart Grid node can use energy from grid and export both energygenerated by PV system and stored energy with batteries to the grid. This scenario is sim-ilar to sell renewable scenario but without restrictions, stored energy can also be exportedto the grid therefore the Smart Grid node has the most choice in this scenario. On the onehand, a Smart Grid node can deliver generated energy and stored energy to the grid, onthe other hand it can consume energy from the grid if necessary.

2.1.4 Sell Storage Scenario

Figure 2.4: Power flow in sell storage scenario

This scenario is evolved from sell renewable scenario. In this scenario, a Smart Grid

CHAPTER 2. PROBLEM STATEMENT 8

node can consume energy from grid and export stored energy to the grid instead of thegenerated energy. The surplus generation can only be stored when storage is not full,otherwise it will be lost. In this scenario, wastage is exist as non-export scenario, sincestorage can either be charged or be discharged at the same time.

Comparison of scenarios

Scenario Generation Export Storage Export Wastage

Non-Export Scenario No No Possible

Sell Renewable Scenario Yes No No

Sell Energy Scenario Yes Yes No

Sell Storage Scenario No Yes Possible

Table 2.1: Comparison of Scenarios

According to the table 2.1, there is waste generation possibly if generated energy can notbe export to grid in the non-export scenario and sell storage scenario, while all generatedenergy can properly be consumed in the sell renewable scenario and sell energy scenariosince the generation can be exported anyway. All flows do not always exist in scenariosand some flows conflict with each other. For example, either power flows to charge batteryor power flows from battery by discharging, and power flows either from the grid or to thegrid.

2.2 Requirements

2.2.1 Functional Requirements

The following requirements describe general functionalities that the advisor should pro-vide:

Req 1: Scenarios

The advisor must support all possible scenarios.

• In non-export scenario, a Smart Grid node can consume energy from grid, but im-possible to export any kind of energy.

• In sell renewable scenario, a Smart Grid node can consume energy from grid, andpossible to export generated energy.

• In sell energy scenario, a Smart Grid node can consume energy from grid, and possibleto export generated energy and stored energy.

CHAPTER 2. PROBLEM STATEMENT 9

• In sell storage scenario, a Smart Grid node can consume energy from grid, andpossible to export stored energy.

Req 2: Forecast

Datum of consumption, generation and energy price in the 24 hours are provided by aforecast module.

Req 3: Dynamic Energy Price

Energy price must be not stable in the optimization period, which means the advisor mustwork in dynamic energy price models.

Req 4: Deviation

When deviation exceed predefined threshold, the advisor must be triggered.

Req 5: Wastage

When unused energy occurs, the advisor must generate a load-shifting suggestion to usethe waste energy.

Req 6: Properties of Storage

All properties which impact storage performance must be given.

Req 7: Storage Suggestion

Based on the datum used in the advisor, expected properties of storage should be calcu-lated.

2.2.2 Non-Functional Requirements

Req 8: Interval

The advisor can support intervals with different durations.

Req 9: Flexibility

Accommodate all scenarios and all possible properties of batteries through configurations.

Req 10: Extensibility

Connection mode could extensible in order to adapt different electrical grids.

3 Related Work

In this chapter we discuss concepts used in the advisor. The advisor should based on dy-namic energy price through the battery do the time-shifting optimization and then do theload-shifting optimization. Furthermore, the advisor should take care of conditions of theSmart Grid node since it determines the feasibility of the optimized schedule.

We start by stating the dynamic energy price, followed by the battery specification. Af-terwards we describe the energy usage strategy and the energy balance of the Smart Gridnode. Finally, we present the existing system of the fortiss smart energy living lab.

3.1 Dynamic Energy Price

The purpose of the advisor in thesis is using stored energy in a proper period. To someextent, that means shifting current load to the time when energy was stored. Withoutdynamic energy price, this kind of operation makes no sense even results in additionalcost. In this thesis, we only consider two different dynamic energy price model, Time-Of-Use Pricing[12] and Real-Time-Pricing[12], since they are load independent. Otherdynamic energy price models are not considered, such as Critical Peak Pricing (CPP)[12]that is peak load related. In the following parts, we use three specific models, Model A, Band C applied in different regions, based on these dynamic energy price model.

3.1.1 Time-Of-Use Pricing (TOU)

Electricity prices in the TOU tariff based on the temporal structure of demand. On thebasis of historical load curves for prices can be determined, the seasonal, vary according tothe day or during the week demand and supply. For example, heaters are widely used inGermany in the morning and in the evening in the winter, while no huge demand at thesame time in the summer. TOU rates are generally long-term commitment with validityover several months or a year.

3.1.2 Real-Time-Pricing (RTP)

RTP model is the most flexible form of pricing in which the price per hour are adaptedto market conditions. Consequently, the electricity prices today by 20 clock may differdramatically from that on the following day by 20 clock. In addition, the price informationis conveyed either the day before for the next 24 hours or even only a daily basis for each

10

CHAPTER 3. RELATED WORK 11

next hour. In this model, the current electricity price reflects the current situation ofsupply and demand in the energy market.

Comparison of dynamic energy price models

Price Model Time Related Load Related Complexity

TOU Yes(Several hours) No Low

CPP No Yes Middle

RTP Yes(Hour) No High

Table 3.1: Comparison of Dynamic Energy Price Models

Comparing with the TOU model, the RTP price model is more complex for a frequentchange. Furthermore, the RTP price model can only provide energy price in 24 hoursnormally, while the energy price is clear in several months in the TOU model.

3.1.3 Model A: Time-Of-Use Pricing (TOU) in Germany

In this model, a rate of electricity price in tariffs depends on the time using energy. Forexample, a pilot project in Bad Staffelstein, the price level is divided into two segmentsaccording to the time. From the beginning of 7 clock to the end of 22 clock the price is23.38 cents/kwh as a normal rate, while it is 20.38 cents/kwh as discount rates from thebeginning of 23 clock to the end of 6 clock. [13]

Figure 3.1: Model A: Time-Of-Use Pricing (TOU) in Germany

The Model A would used in this thesis as a specific TOU model, the optimized schedulebased on this model would be relatively simple for the simplicity of this model.

CHAPTER 3. RELATED WORK 12

3.1.4 Model B: Time-Of-Use Pricing (TOU) in North America by energyprovider Hydro-Ottawa

The tariffs are divided into sections in summer, winter and on weekends. Reasons for thevarious divisions are seen on the day the various loads. During the summer from 11 to 17clock in the afternoon air conditioners are in use, while in winter more heat are neededat night. The price level is also divided into three segments namely by categorizing 5.1cents/kwh, 8.1 cents/kwh or 9.9 cents/kWh. [13]

Figure 3.2: Model B: Time-Of-Use Pricing (TOU) in North America

3.1.5 Model C: Real-Time-Pricing (RTP) in Research

Figure 3.3: Model C: Real-Time-Pricing (RTP) in research recently

In this thesis, we use a RTP model from a cooperation project with a german energyprovider. Energy prices in the future 24 hours are derived by the model, which changehour by hour. The figure 3.3 describes the energy price in a specific day based on the RTPmodel. In this day, the energy price is lowest from 6 am to 7 am while it is highest in thehour after 8 pm.

CHAPTER 3. RELATED WORK 13

3.2 Battery Specification

In the fortiss smart energy living lab, we use battery to store energy, therefore the propertiesof battery impact the final optimized schedule dramatically. The following properties arethe most important parameters used in the advisor.

3.2.1 Round-trip Efficiency

All energy transfer and conversion processes have losses, so does energy storage. Storagesystem round-trip efficiency reflects the amount of energy that comes out of storage relativeto the amount put into the storage.

Typical values for efficiency include the following[6]:

• 60% to 75% for conventional electrochemical batteries

• 75% to 85% for advanced electrochemical batteries

• 73% to 80% for CAES

• 75% to 78% for pumped hydro

• 80% to 90% for flywheel storage

• 95% for capacitors and SMES

In this thesis, we use ηch (charge efficiency) and ηdch (discharge efficiency) separately insteadof round-trip Efficiency since they are different generally.

3.2.2 Battery Power

The power of battery represent the speed to charge battery or discharge battery. We preferthat the battery can be charged or discharge as fast as possible, however these propertiescan not be infinite high for the physical character of batteries. In the smart energy livinglab, a sunny backup 5000 system[14] is used to manage the batteries. In the specificationof the sunny backup 5000 system, we can find the PBat ch

Max and PBat dchMax under

normal operating conditions. Normally the PBat dchMax and PBat ch

Max are provided inthe specification of batteries.

PchOriginal ≤ PBat ch

Max

PdchOriginal ≤ PBat dch

Max(3.1)

CHAPTER 3. RELATED WORK 14

3.3 Connection Mode

Figure 3.4: Connection mode of the fortiss smart energy living lab

The figure 3.4 shows the connection mode in the fortiss smart living lab. The PVgenerator represents all units that produce energy (Currently Solar Panels) and the loadembodies all electrical facilities that consume energy. The power flows from grid and togrid through different lines. In the figure, there are two switches which control the exportof energy from the battery and the PV generator, the connection of these switches dependson the chosen scenario.

Considering properties of cables connected with the grid, PtoOriginal and Pfrom

Original

should not greater than the PNominal (replaced by PLineMax in the following thesis) of

cables.

PtoOriginal ≤ PLine

Max (3.2)

PfromOriginal ≤ PLine

Max (3.3)

3.3.1 Electrical Power Balance in the Smart Grid node

According to the law of conservation of energy in physics, PgridOriginal should be equal the

summation of all power (PSMG) in the smart energy living lab. Since unused generation

CHAPTER 3. RELATED WORK 15

probably exists sometimes, the PgridOriginal is not greater than the PSMG. Therefore we can

get the equation 3.4, in the equation the PgridOriginal is replaced by Pfrom

Original minusPto

Original, and the PSMG is replaced by the aggregate power of PcOriginal, Pch

Original,Pg

Original and PdchOriginal.

PfromOriginal − Pto

Original ≥ PcOriginal + Pch

Original − PgOriginal − Pdch

Original (3.4)

In the perspective of the smart energy living lab, we treat the value of consumed powersas positive while the value of provided powers as negative in the following calculation. Itmeans values of Pc, Pch and Pto are positive since they are consumed power, while valuesof Pg, Pdch and Pfrom are negative since they are provided power.

Pc = PcOriginal Pch = Pch

Original Pto = PtoOriginal (3.5)

Pg = −PgOriginal Pdch = −Pdch

Original Pfrom = −PfromOriginal (3.6)

The equation (3.4) can be simplified as the equation (3.7) based on (3.5) (3.6).

Pfrom + Pto + Pg + Pch + Pdch + Pc ≤ 0 (3.7)

In the equation 3.7, the summation of the left is lower than zero when there is unusedgeneration. If we use Pw as the waste power, the equation (3.7) is transformed to theequation (3.8):

Pfrom + Pto + Pg + Pch + Pdch + Pc + Pw = 0 (3.8)

The Pw represent the power that can not be used based on current condition, however itdoes not mean that the Pw can not be avoid. Through load-shifting, for example increaseconsumption by using more electrical devices. In the following chapter, Pw will be used inthe load-shifting. If the value of Pw is zero, it means there is not waste energy.

Figure 3.5: Power at intervals in a day

In the figure 3.5, the aggregate power is always zero in this day, the blue line is theenergy price. There are waste powers in the noon of this day while the generated power ishigher than the consumed power and the generated power can not be used in other ways.

CHAPTER 3. RELATED WORK 16

3.3.2 Power Usage Strategy

• Consumption should be fulfilled first at any time, since export generation (if allowed)or storage (if allowed) to grid but use power from grid to satisfy the consumptionthat make no sense.

• Power from grid and power to grid do not exist at the same time, since it does notachieve financial benefit even lead to unnecessary loss.

3.4 Power Demand from Battery & Power Supply to Bat-tery

In the perspective of the battery, the power demand (PDemand) from battery represents theneeded power from battery through discharging battery. The power demand can be usedto satisfy the consumption of the smart living lab or export to the grid. However powersupply (PSupply) to battery represents the power supplied by the smart energy living labor the grid to battery through charging battery.

The PDemand and PSupply are capabilities of the exchanged power of the battery basedon the condition of the smart energy living lab, they are not the actual value of the ex-changed power.

As we mentioned in the last section, we treat the value of consumed powers as positivewhile the value of provided powers as negative. So there are following equations.

PDemand ≤ 0

PSupply ≥ 0(3.9)

The batteries can either be charged or be discharged at the same. When calculate thePDemand based on the equation (3.8), we can assume that Pch is zero and replace Pdch withPDemand and we can get PSupply similarly.

PDemand = −Pfrom − Pto − Pg − Pc − Pw (3.10)

PSupply = −Pfrom − Pto − Pg − Pc − Pw (3.11)

Since the Pg and Pc are given from a forecast in the smart energy living lab, the value ofPDemand depends on the value of Pfrom and Pto and Pw according to the equation (3.10),the value of PSupply depends on the value of Pfrom and Pto and Pw as well according tothe equation (3.11). For more economic benefits, there should be no waste power whencalculate PDemand, therefore Pw should be zero.

PDemand = −Pfrom − Pto − Pg − Pc (3.12)

PSupply = −Pfrom − Pto − Pg − Pc (3.13)

CHAPTER 3. RELATED WORK 17

According to the equations (3.2) (3.3) (3.5) (3.6) (3.12) (3.13), the maximum PDemand andPSupply can be simplified.

PDemandMax = −PLine

Max − Pg − Pc (3.14)

PSupplyMax = PLine

Max − Pc (3.15)

The equation (3.14) means that the maximum PDemand occurs when the smart energyliving lab export PLine

Max without using power from the grid. The equation (3.15) meansthat the maximum PDemand occurs when the power of the line in the smart living lab isthe maximum value (The power can be provided by the generation and/or the grid). Dueto constrains in different scenarios, the equation of PDemand

Max should be modified.

PDemandMax = −Pc − Pg (Non− ExportScenario)

(3.16)

PDemandMax = Max(0,−PLine

Max − Pg)− Pc (SellRenewableScenario)(3.17)

PDemandMax = −PLine

Max − Pc − Pg (SellEnergyScenario)(3.18)

PDemandMax = Pc + Pg < 0?− Pc − Pg : −PLine

Max − Pc − Pg (SellStorageScenario)(3.19)

• In the non-export scenario, power can not be exported, therefore there is no powerexported to the grid and the equation (3.14) should be changed to the equation (3.16).

• In the sell renewable scenario, generation can be exported, the generated powershould be exported as much as possible, and the consumed power minus the remaininggenerated power is the maximum demand power from battery. Therefore the equation(3.14) should be changed to the equation (3.17).

• In the sell energy scenario, no restriction of exported power, therefore the equation(3.18) is the same as the equation (3.14).

• In the sell storage scenario, storage can be exported. When surplus generation occurs,there is no power demand, therefore the equation (3.14) should be changed to theequation (3.19).

If PDemandMax is greater than zero, which means there is no power demand but power

supply that is the least power should be charged. In this case, we introduce a PSupplyLeast

to represent it.

If we assume that at any time there is enough capacity to charge or enough stored en-ergy to discharge. In addition, the value of PDemand and PSupply could not lower than

CHAPTER 3. RELATED WORK 18

−PBat chMax and higher than PBat dch

Max based on the equations (3.1) (3.5) (3.6).

PDemandMax = Max(−PBat dch

Max,Min(0, PDemandMax)) (3.20)

PSupplyLeast = Max(0,Min(PBat ch

Max, PDemandMax)) (3.21)

PSupplyMax = Min(PBat ch

Max, PSupplyMax) (3.22)

3.5 Financial Benefit

Benefit =PriceHigher

PriceLower× ηch × ηdch (3.23)

If the result of equation (3.23) is greater than 100%, it means that we can save or earnmoney by charging the battery as the lower price and discharging the battery as the higherprice. Consequently the more efficient of batteries, the more financial benefit.

3.6 Cost

Cost =∑

(−Pfrom − Pto)× TInterval × PriceInterval (3.24)

Based on the Pfrom and Pto of all intervals, the cost during the optimized schedule can becalculated with the equation above.

CHAPTER 3. RELATED WORK 19

3.7 Existing System

Figure 3.6: Architecture of the SMG system

The figure 3.6 describes the architecture of the SMG system in the smart living lab.The optimizer which contains the smart advisor introduced in this thesis is a service com-ponent of the SMG system. All information such as forecast, price are transferred throughthe message bus from another components. The optimizer component provides an interfacefor other components to access.

Database as a persistent component in the SMG system can provide all necessary in-formation for the optimizer. However it is also possible to recalculate some data suchprice, forecast at any time with relative component in this system, in this case data aretransmitted on the message bus as binary JSON objects in order to increase performance.

3.7.1 Information Broker

The information broker is a component that encapsulate the basic database services asAPIs for other components to access database. Through the provided APIs other compo-nents can focus on the logic and delegate other operations related with database such asconnection construction and result parser to the information broker.

CHAPTER 3. RELATED WORK 20

The database of the SMG system is deployed on a mysql server. In the SMG system,there are access restrictions, that means a component in the system can access specificcomponents in order to reduce the reliability and complexity of the system. Componentsexport the generated data to the database for persistence, other components which needthe data can retrieve it from the database.

3.7.2 Prophet/Forecast

The forecast component in this system can predict the energy usage in the smart energyliving lab in the future, which bases on weather conditions, room occupancy and historicaldata.[15] The generated forecast are persisted in the database. Considering sudden changesof weather and some unpredictable event, this component is executed frequently to ensurethe accuracy of forecast.

4 Conceptual Solution

In this chapter we present a detailed description of the conceptual solution to the statedproblem. The solution consists of four parts, data preparation, optimized schedule genera-tion, schedule translation and data analysis. We describe the data preparation in the firsttwo sections, then state the optimized schedule generation in the third section. Howeverthe optimized schedule generated in the last step can not be directly, a schedule translationfor generating a concrete optimized schedule is presented in the fourth section. Finally westate the data analysis for deriving suggestions to achieve greater financial benefit in thelast section.

4.1 Demand/Supply Energy at an Interval

In the thesis, the input parameters, consumption, generation and energy price, are mea-sured in power at an interval every 15 minutes. Therefore the interval of the generatedoptimized schedule is 15 minutes as well.

The power of consumption and generation measured by watt is time dependent, whichmeans the calculation would be complicated. At an interval, we treat the power as anaverage value to simplify the calculation. Based on input parameters and properties of thestorage and connection mode, the values of PDemand

Max, PSupplyLeast and PSupply

Max canbe calculated with Pg, Pc through the equations (3.16) (3.17) (3.18) (3.19) (3.20) (3.21)(3.22). The values of Pfrom, Pto, Pch, Pdch are unknown currently, however they should begenerated by the advisor.

Since power are impossible to shift, actually we shift energy through the battery. ThePDemand

Max, PSupplyLeast and PSupply

Max should be transferred to the consumed energyor provided energy respectively. In the following algorithm, EDemand

Max, ESupplyLeast and

ESupplyMax are used for the advisor, the values of EDemand

Max, ESupplyLeast and ESupply

Max

can be calculated with the equation (4.1) (4.2) (4.3).

EDemandMax = PDemand

Max × TInterval (4.1)

ESupplyLeast = PSupply

Least × TInterval (4.2)

ESupplyMax = PSupply

Max × TInterval (4.3)

• EDemandMaxrepresent the maximum energy can be used by discharging batteries at

an interval.

21

CHAPTER 4. CONCEPTUAL SOLUTION 22

• ESupplyLeast represents the least energy should be stored in batteries at an interval.

• ESupplyMax represents the maximum energy can be stored in batteries at an interval.

Consider the Round-trip Efficiency of the battery, the equations (4.1) (4.2) (4.3) have tobe transformed to the following equations. The energy is the actual stored energy or usedenergy of the battery.

EDemandMax × ηdch = PDemand

Max × TInterval (4.4)

ESupplyLeast = PSupply

Least × TInterval × ηch (4.5)

ESupplyMax = PSupply

Max × TInterval × ηch (4.6)

In the equation (4.4) (4.5) (4.6), EDemandMax, ESupply

Least and ESupplyMax are the ac-

tual energy can be charged or should be discharged by the battery. Therefore the valueof EDemand

Max is larger than the exported energy and the values of ESupplyLeast and

ESupplyMax are smaller than the imported energy.

Figure 4.1: Chart of Intervals

Figure 4.1 shows values of EDemandMax, ESupply

Least and ESupplyMax at each interval,

the blue line is the energy price. According to the figure, the EDemand is zero when theESupply

Least exists at an interval. It means there are ESupplyLeast that have to be charged,

therefore the battery can not be discharged at this interval.

CHAPTER 4. CONCEPTUAL SOLUTION 23

4.2 Demand/Supply Energy in a Price Period

Price Period is a period that prices at all consecutive intervals in this period are thesame. It is used to replace interval for simplifying calculation in the following algorithm.

Since energy price is stable in a price period, we can adopt the same strategy at eachinterval in the price period. It does not achieve financial benefits that we apply the de-mand energy (EDemand) at one interval and apply the supply energy (ESuppy) at anotherinterval without ESupply

Least in the same price period, since the cost paid for the ESuppy

is the same as the benefit earned from the EDemand. This strategy even leads to more costdue to the Round-trip Efficiency. Therefore the consecutive intervals with the same energyprice can be merged into a price period.

Figure 4.2: Chart of Price Models

In figure 4.2, periods in 00:00 - 07:00, 07:00 - 22:00 and 22:00 - 24:00 are three priceperiods on the TOU pricing model. In comparison with the TOU pricing model, there aremore price periods on the RTP pricing model. More Precisely, each hour is a price periodin this day.

• EP DemandMax represents the maximum energy can be used by discharging batteries

in a price period, the energy should be stored in other price periods.

• EP SupplyLeast represents the least energy should be stored in batteries in a price

period, the energy can not be used in this price period anyway.

• EP SupplyMax represents the maximum energy can be stored in batteries in a price

period, the EP SupplyLeast should be subtracted from the energy.

• EP SupplyTotal represents the total least supply energy in batteries in a price period.

Calculation of Demand/Supply Energy in a Price Period

Due to the maximum capacity of the battery, the EP SupplyLeast can not be calculated by

summing all ESupplyLeast in a price period and so does the EP Demand

Max, we have to use

CHAPTER 4. CONCEPTUAL SOLUTION 24

the following strategy.

Interval No. 0 1 2 3

ESupplyLeast 10 0 80 0

EDemandMax 0 -20 0 -40

Table 4.1: Intervals in a price period

According to the table 4.1, we assume that there are 4 intervals in this period. In theexplanation, we use percentages to represent the value of ESupply

Least and EDemandMax

referring to the maximum capacity of battery. If ESupplyLeast > 100% or EDemand

Max

< -100%, replace them with 100% and -100% respectively since the battery can be fullcharged or discharged with the maximum capacity. Therefore values of the ESupply

Least,EDemand

Max ∈ [-100%, 100%].

There are 10% and 80% least supply energy to the battery at the first interval (I0) and thethird interval (I2) respectively, while there are -20% and -40% maximum demand energyfrom the battery at the second interval (I1) and (I3).

Interval No.0∑

n=0In

1∑n=0

In2∑

n=0In

3∑n=0

In

EDemandC 10 -10 70 30

Table 4.2: Cumulative value interval by interval

Then calculate the cumulative EDemandC with both ESupply

Least and EDemandMax in-

terval by interval shown in the table 4.2. In the calculation of EP DemandMax, we introduce

a range value [allowable, needed]. At the beginning the range of EP DemandMax is [-100,

0], it means the allowable value of the EP DemandMax is -100% while the needed value of

EP DemandMax is zero.

• The range value at each step depends on previous range value and EDemandC in

current stage.

• If the EDemandC < 0 and EDemand

C < range[needed], replace range[needed] withEDemand

C .

• If the EDemandC > 0 and 100 - EDemand

C > range[allowable], replace range[allowable]with 100 - EDemand

C .

• Finally if the range[allowable] is equal the range[needed], we can stop the iterationsince this range[needed] is the expected value. Otherwise, the range[needed] in thelast stage is the expected value.

CHAPTER 4. CONCEPTUAL SOLUTION 25

Stage Init 0 1 2 3

Range [-100, 0] [-90, 0] [-90, -10] [-30, -10] [-30, -10]

Table 4.3: Range of EP DemandMax in each stage

• In the stage 0, EDemandC is 10%, it means that this period should supply 10% energy

to the battery, so the range[allowable] have to increase since the battery have topreserve 10% capacity for this period.

• In the stage 1, EDemandC is -10%, it suggests that this period can demand 10% energy

from the battery, which supplied in other periods.

• According to the range value in the last stage, we use the range[needed] as the valueofEP Demand

Max in this period that is -10%.

Interval No.3∑

n=3In

2∑n=3

In1∑

n=3In

0∑n=3

In

ESupplyC -40 40 20 30

Table 4.4: Cumulative value from end interval by interval

In contrast, the process to calculate the EP SupplyLeast is roughly the same but cumulate

values from the end to beginning.

Stage Init 3 2 1 0

Range [0, 100] [0, 60] [40, 60] [40, 60] [40, 60]

Table 4.5: Range of EP SupplyLeast in each stage

According to the range value in the stage 0, the EP SupplyLeast in this period is 40%.

EP SupplyMax =

∑ESupply

Max − EP SupplyLeast (4.7)

The equation 4.7 describes the calculation of EP SupplyMax, it depends on the EP Supply

Least.Since the EP Supply

Least should be properly stored, but EP SupplyMax we can choose whether

it is used. Therefore, we subtract it from EP SupplyMax.

EP SupplyTotal =

∑ESupply

Least (4.8)

The equation 4.8 describes the calculation EP SupplyTotal, it is equal the summation of

ESupplyLeast of all intervals in this period.

CHAPTER 4. CONCEPTUAL SOLUTION 26

Figure 4.3: Chart of Price Periods based on the TOU model

Figure 4.3 shows values of EP DemandMax, EP Supply

Least and EP SupplyMax in each price

period based on the TOU model in Germany, the blue line is the energy price.

Figure 4.4: Chart of Price Periods based on RTP model

Figure 4.4 shows price periods with the same data as the figure 4.3 based on the RTPmodel, the blue line is the energy price. Compared with previous figure, there are moreprice periods.

4.3 Greedy Algorithm

The core algorithm of the advisor is derived from the greedy algorithm that follows theproblem solving heuristic of making the locally optimal choice at each stage with the hopeof finding a global optimum.[1] The locally optimal choice depends a series of decisionrules which is a rule engine in this advisor. Another variety is that this greedy algorithmsupports reverse searching when a false choice is chosen in previous stage. In this case,it jumps to another branch with another best choice since the stage that the false choiceoccurs.

This algorithm is driven by demand. It searches an unsatisfied demand with highest pricethen matches the demand with proper supplies.

CHAPTER 4. CONCEPTUAL SOLUTION 27

Period TOU Price Possible Demand Least Supply Max Supply

0 to 27 20.38 -36344.00 0.00 90000.00

28 to 87 23.38 -41914.00 0.00 90000.00

88 to 95 20.38 -6997.00 0.00 31679.00

Table 4.6: Demand and Supply in Price Periods

Table 4.6 shows an example, the EP SupplyMax, EP Supply

Least and EP DemandMax in

each price period are given.

Period TOU Price Possible Demand Least Supply Max Supply Exchange

0 to 27 20.38 -36357.68 0.00 90000.00 40914.00

28 to 87 23.38 -41914.00 0.00 90000.00 -41914.00

88 to 95 20.38 -6997.00 0.00 31679.00 0.00

Table 4.7: Demand and Supply in Price Periods

Table 4.7 shows the decision generated by the algorithm. The algorithm would derivethe exchanged energy of the battery. If the value of the exchange is positive, it meanscharge battery in this price period for the future periods, otherwise discharge battery inthe period by using energy charged in previous periods. On condition that the valueof exchange is zero, the battery should be discharge with the energy that is charged atintervals had ESupply

Least in this period. In this example, there is 1000 Wh initial capacityof batteries.

4.3.1 Pool

The pool stores the capacities of the battery at the beginning and the end of each priceperiod. Therefore the number of nodes in this pool should be larger than that of priceperiods.

NPool = NPeriod + 1 (4.9)

The value of Pooln is the current capacity of battery at the beginning of Periodn (n <NPeriod) or at the end of Periodn−1 (n > 0).

Purpose of the Pool

In this algorithm, a decision at each stage depends on the condition of the remainingchoices and current situation. The current situation is reflected by the values in the pool.A situation evaluator[16] is used in analyzing the situation at each stage.

CHAPTER 4. CONCEPTUAL SOLUTION 28

Usage of the Pool

• If the EP Supply of a price period is applied, we have to add the supply energy to thevalues in the pool after this price period since the supplied energy is increased in thisprice period which can be used in the future.

• If the EP Demand of a price period is applied, we have to subtract the demand energyfrom the values in the pool after this price period since the demanded energy isincreased in this price period which can not be used in the future.

Through analyzing the pool, we can know current situation. On different situations, thereare different guidances to solve the problem and go further stage.

Figure 4.5: EP Supply and EP Demand in Price Periods

Figure 4.6: Pool in the algorithm

The figure 4.6 shows changes of the pool in a process based on the data in the figure 4.5.The initial pool is derived at the beginning of this algorithm with the initial capacity ofbattery and EP Supply

Least of all periods. According to the figure, there is 1000 Wh energyat the beginning since the initial capacity is 1000 Wh. For the EP Supply

Least of periodsfrom 12 to 16, there is 16569 Wh energy would be charged in the battery that exceeds the

CHAPTER 4. CONCEPTUAL SOLUTION 29

maximum capacity of battery which is 10000 Wh. However it is impossible to over chargedbattery more than the maximum capacity. Therefore the pool after pre decision decreasesdown. After the post decision the last value of the pool is zero, it means all energy storedin batteries are used. Through the curve of the final pool in the figure 4.6, we can discoverthat battery is full charged after the period 5 and period 14, then battery is discharged,finally the capacity of the battery goes to be zero.

4.3.2 Pre Decision

Figure 4.7: Exchange in the algorithm

The figure 4.7 shows the energy exchange of price periods after the pre decision (containsstep 1 and step 2) and the final exchange as well. The positive value of column representsthe energy supplied to the battery, while the negative value refers to the energy demandedfrom the battery. From this figure, in the periods from 11 to 14 the battery should bedischarged in the process of pre decision, and in the periods form 17 to 19 the batteryshould be discharged as well in the process of post decision.

Step 1

The purpose of this process is that fix all values in supply pool beyond maximum capacity.Therefore we need to find a price period before the point that the value of this point exceedsthe maximum capacity. In this process, we use the greedy strategy, find the period withhighest price and EP Demand

Max in this scope. Then update the pool with this decision.Redo this operation until there is no exceeding value. In some case, it is unable to find aprice period then we have to assume that there is a wastage energy at the exceeding point.

Step 2

The purpose of this process is that use extra stored energy in order to make the last valueof the pool to be zero. Like the pre decision, find a price period before to use the extra

CHAPTER 4. CONCEPTUAL SOLUTION 30

energy. Since the EP SupplyLeast is free, we have no need to consider the financial benefit.

In the pre process, values in the pool should always be positive.

4.3.3 Situation Evaluation & Search Scope

Based on the pool in each stage, we can know the current situation. According the situation,search scope can be found.

Situation:

• Over demand situation, values in the pool are lower than zero or values in the poolplus relevant exchange value are lower than zero.

• Balanced situation, values in the pool are not lower than zero and values in the poolplus relevant exchange value are not lower than zero and the last value of the pool iszero.

Search Scope in the over demand situation

• The end of this scope is the first value of the consecutive values that the values arelower than zero or the values plus relevant exchange value is lower than zero.

• The beginning of the scope is the first value that the value is lower than the maximumcapacity forward from the end of this scope.

Search Scope in the balanced situation

The search scope in the balanced situation is the whole scope of price periods.

4.3.4 Find Optimal Choice

Based on the search scope and situation in current stage, find an optimal choice.

• In the over demand situation, find a price period as supply price period in the searchscope with the lowest energy price and EP Supply

Max, additionally this period couldnot be used before as a demand price period.

• In the balanced situation, find a price period as demand price period in the searchscope with the highest energy price and EP Demand

Max, as well this period could notbe used before as a supply price period.

• When use a price period as supply price period, it should have financial benefit bycomparing with the last chosen demand price period.

CHAPTER 4. CONCEPTUAL SOLUTION 31

4.3.5 Recursion

In each stage, use an appropriate value of EP SupplyMax or EP Demand

Max of the chosenperiod to update the pool, then go to next stage. Finally decisions can be generated bythis recursion.

4.3.6 Regression

If there is no further choice at a stage and it is in the over demand situation, go back tothe stage that involves the last demand. Fix the used value of demand in that stage, thenswitch a new branch and continue the algorithm.

4.3.7 Final Decision

If there is no further choice at a stage and it is in the balanced situation, this stage isthe final stage. The choices at previous stages constitue the finally decision. Through thedecision, we can know that when to charge or discharge battery and the amount of theenergy.

4.3.8 Decision Path

Figure 4.8: Decision Path based on the Model A

The figure 4.8 shows the path to find the final decision based on the Model A. Thetable 4.7 describes the final decision from this decision tree. Nodes with red color in thefigure represent the price period used as demand price period, and nodes with orange colorrepresent the price period used as supply price period. The number on the left of the figureis the search depth of the recursion and the number on an arrow is the stage number.

• Stage 0, after pre & post decision the pool is in the balanced situation, therefore finda period as demand with the highest price that is the price period 1 [28 to 87].

CHAPTER 4. CONCEPTUAL SOLUTION 32

• Stage 1, the pool is in the over demand situation, then find a period as supply withthe lowest price that is the price period 0 [0 to 27].

• Stage 2, the pool is in the balanced situation, then find a remaining period as demandwith the highest price that is the price period 2 [88 to 95].

• Stage 3, according to the energy price of price period 2, there is no other price periodas a supply can achieve financial benefit. So no future choice and current situationis over demand situation, then give up the choice in the last stage.

• Stage 4, current situation is in the balanced situation without further choice, exportthe decision.

With the same original data but different price model, the decision tree would changed asthe figure 4.9.

Figure 4.9: Decision Path based on the Model B

The figure 4.9 shows the path to find the final decision based on the Model B, thenumber on the left of the figure is the search depth of the recursion and the number on anarrow is the stage number. Price period 0 appears several times in the decision tree sinceeach time it is needed only to satisfy the demand in the previous stage.

CHAPTER 4. CONCEPTUAL SOLUTION 33

Figure 4.10: Decision Path based on the Model C

The figure 4.10 shows the path to find the final decision based on the Model C, thenumber on the left of the figure is the search depth of the recursion and the number onan arrow is the stage number. On aggregate, we use only the price period 10 as demandprice period and price period 5 as supply price period. But we have to travel anyway allpossible paths to verify that there is no other solutions. Numerous price periods are usedas a demand price period, however non of them can be supplied by other price periods.

4.3.9 Example

The following is an example to find a decision. In the explanation, we use percentages torepresent the value of EP Demand

Max and EP SupplyMax referring to the maximum capacity

of battery. Furthermore, we use demand and supply instead of the EP DemandMax and

EP SupplyMax respectively.

Price Period Price Demand Supply Exchange

0 16.38 -10 80 80

1 23.38 -60 100 -60

2 20.38 -30 60 50

3 25.38 -70 30 -70

Table 4.8: Demand & Supply of Price Periods

The table 4.8 shows the demand and supply of each price period, the column exchangeis the optimized schedule that when to charge/discharge the battery in a price period withthe exchanged energy.

CHAPTER 4. CONCEPTUAL SOLUTION 34

Pool Init Stage 1 Stage 2 Stage 3 Stage 4 Stage 5

0 0 0 0 0 0 0

1 0 0 70 70 80 80

2 0 0 70 10 20 20

3 0 0 70 10 20 70

4 0 -70 0 -60 -50 0

Table 4.9: Pools at all stages

The table 4.9 shows the pool after each stage based on the algorithm. Initial value ofthe pool represents the value at the beginning of the algorithm.

Exchange Init Stage 1 Stage 2 Stage 3 Stage 4 Stage 5

0 0 0 70 70 80 80

1 0 0 0 -60 -60 -60

2 0 0 0 0 0 50

3 0 -70 -70 -70 -70 -70

Table 4.10: Exchange at all stages

The table 4.10 shows the exchange value of each price period at the end of each stage.If the exchange value of a price period is positive means the period is used as a supply,otherwise it is used as a demand. The value of the exchange represent the cumulativeexchanged energy of a price period after a stage. When a period is used as demand orsupply, it can not be changed as supply or demand respectively.

Figure 4.11: Pools at all stages

For explanation, we introduce the figure 4.11. Each curve represents the pool status atthe end of each stage.

• Stage 1, current situation is balanced situation, find a demand price period with the

CHAPTER 4. CONCEPTUAL SOLUTION 35

highest price that is price period 3. Update the pool, then the last value of the poolis -70.

• Stage 2, current situation is over demand situation, find a supply price period in theprice periods [0, 1, 2, 3] with the lowest price that is price period 0. Update the poolby adding 70 from the end of the price period 0.

• Stage 3, current situation is balanced situation, find a demand period with the highestprice exclude period 3 that is period 1. Update the pool by adding -70 from the endof the price period 1.

• Stage 4, current situation is over demand situation, find a supply period in the periods[0, 1, 2, 3] with the lowest price that is period 0. Update the pool by adding 10 fromthe end of the price period 0, but the last value of the pool is -60 since the chosensupply in this stage is not enough.

• Stage 5, current situation is over demand situation, find a supply period in the period[0, 1, 2, 3] with the lowest price that is period 2 while period 0 is used up. Updatethe pool by adding 50 from the end of the price period 2. No further choice, exportcurrent decision.

Normally when we demand energy from the battery in a price period, we have to finda price period that can supply energy to the battery before this demand price period. Butin this example, the price period 1 is chosen as a demand price period then the period 2is chosen as a supply price period for the price period 1. It means we use energy in thefuture. Actually the price period 1 consumes energy stored before but we use the supply ofthe price period 2 to compensate the usage. In the pool, when the value in a price period ispositive, the period can borrow this energy and give back before the scheduled price periodthat consume this energy.

4.4 Powers at an interval

Situations in a Price Period

Finally an exchange value of each price period and the capacity of battery at the beginningof the period is derived by the greedy algorithm in this thesis. It means that the batteryhave to be charged or discharged with the exchange value on aggregate. Based on theexchange value, there are three different situations. Therefore the strategies to calculateexchanged energy with the battery at each interval are different.

Charging Situation

EP Exchange > 0 (4.10)

CHAPTER 4. CONCEPTUAL SOLUTION 36

In this situation, batteries should be charged EP Exchange plus EP SupplyLeast. On the

condition that EP Exchange + EP SupplyLeast > EP Supply

Total, all surplus generation haveto be charged. Furthermore, the shortfall have to be charged from grid. On the otherconditions, the extra charged energy from surplus generation have to be consumed in thisperiod.

Discharging Situation

EP Exchange < 0 (4.11)

In this situation, batteries should be discharged EP Exchange. When there is ESupplyLeast

at an interval, charge the battery with the ESupplyLeast. Otherwise, discharge the battery

on condition that the capacity of the battery at this interval is higher than the capacity ofthe battery at the beginning of this price period minus EP Exchange since this price periodcan only consume energy with the value of EP Exchange.

Stable Situation

EP Exchange = 0 (4.12)

In this situation, batteries should be charged if there is ESupplyLeast at an interval and

batteries can be discharged. The battery should be discharged on condition that thecapacity of the battery at this interval is higher than the capacity of the battery at thebeginning of this price period since the increased energy is stored in this price period.

Exchange at an interval

The exchanged energy at an interval could be derived from the exchanged energy in aprice period. According to the exchanged energy at an interval, the power of charging anddischarging could be calculated by the following equations.

ηch × Pch × TInterval = Max(0, EExchange) (4.13)

Pdch × TInterval = Min(0, EExchange)× ηdch (4.14)

• If the value of the EExchange at an interval is positive, it means the battery should becharged with the energy EExchange. The equation 4.13 shows that if battery shouldbe charged with the energyEExchange it should be charged with the power Pch.

• If the value of the EExchange at an interval is negative, it means the battery should bedischarged with the energy EExchange. The equation 4.14 shows that if battery shouldbe discharged with the energyEExchange it should be discharged with the power Pdch.

CHAPTER 4. CONCEPTUAL SOLUTION 37

Based on the scenario and connection mode of the smart living lab, the Pfrom and Pto canbe calculated with the equations (4.15) (4.16) (4.17) (4.18) (4.19) (4.20).

Pgrid = Min(0,−Pg − Pch − Pdch − Pc) (Non− ExportScenario) (4.15)

Pgrid = Min(−Pg,−Pg − Pch − Pdch − Pc)) (SellRenewableScenario) (4.16)

Pgrid = −Pg − Pch − Pdch − Pc (SellEnergyScenario) (4.17)

Pgrid = Min(−Pdch,−Pg − Pch − Pdch − Pc) (SellStorageScenario) (4.18)

Pfrom = Max(−PLineMax,Min(0, Pgrid)) (4.19)

Pto = Min(PLineMax,Max(0, Pgrid)) (4.20)

Figure 4.12: Power at intervals in a day after optimization

The figure 4.12 shows the power at each interval in a day in non-export scenario. Thereis wastage at the intervals from 2 pm to 3 pm due to the surplus generation. According tothe equation (4.15) (4.20), the Pto is zero in scenarioa, therefore the equation (3.8) shouldbe balanced with a Pw at these intervals in this scenario.

CHAPTER 4. CONCEPTUAL SOLUTION 38

4.5 Suggestion

Based on the existing data, the advisor can give some suggestion of the expected propertiesof the smart energy living lab for more economic benefit.

4.5.1 Expected Maximum Capacity

As we know, the maximum capacity of batteries impacts the performance of the optimizedschedule dramatically. We attempt to amplify this property in order to find a more opti-mized schedule on condition that keep other properties the same. When the cost does notdecrease, it means current maximum capacity is the expected maximum capacity.

(a) 1 times maximum capacity

(b) 5 times maximum capacity

Figure 4.13: Demand and Supply of periods in non-export scenario

The figure 4.13 shows that the energy demand and supply in each price period with 5times maximum capacity and the original maximum capacity. Comparing the figure 4.13(a)and the figure 4.13(b), we can discover that the EP Demand

Max and EP SupplyMax of most

price period increase along with the increasing of maximum capacity since we limit the valueof EP Demand

Max and EP SupplyMax within the maximum capacity during the calculation.

However, it does not increase unlimited due to other properties of the smart energy livinglab. When the maximum capacity is high enough, it reaches the peak value.

CHAPTER 4. CONCEPTUAL SOLUTION 39

(a) 2 times maximum capacity

(b) 3 times maximum capacity

(c) 5 times maximum capacity

Figure 4.14: Pool status in non-export scenario

The figure 4.14 shows the pool status at 4 significant points. Comparing the final poolstatus, we can discover that the advisor attempt to charge more energy in the price period6 according to the figure 4.14(b), however it is impossible due to the maximum capacityof the battery. When the maximum capacity increases, the curve of the final pool statusmove up since more energy can be charged at the relative low price and more energy can bedischarged at the relative high price. Finally, when the maximum capacity of the battery ishigh enough as the figure 4.14(c), the final pool does not move up anymore since no furtheroptimization can be done based on current condition, e.g. PBat ch

Max and PBat dchMax.

CHAPTER 4. CONCEPTUAL SOLUTION 40

(a) 1 times maximum capacity

(b) 5 times maximum capacity

Figure 4.15: Exchange energy in periods with the battery in non-export scenario

In more detail, we can see the battery exchange in the figure 4.15(a). It is obviouslythat there are some price periods with high energy price, the EP Demand

Max of these periodcould be satisfied by supplies with low energy price, since the maximum capacity of thebattery is not large enough. Consequently, the optimization can be better with a largermaximum capacity that is shown in the figure 4.15(b). The figure 4.15(b) is the optimaloptimization we expected. The battery can be charged enough energy with the lowest pricefor all usages with higher energy price.

CHAPTER 4. CONCEPTUAL SOLUTION 41

(a) 1 times maximum capacity

(b) 5 times maximum capacity

Figure 4.16: Optimized power in non-export scenario

The figure 4.16 describes the optimized power at intervals with different maximumcapacities of the battery. The battery is charged at 7 am when the maximum capacity ofthe battery is 10000 Wh, then the battery have to be discharged at 11 am even thoughthe energy price is not so high at this time, since surplus generation occurs in next hour.In contrast, when the maximum capacity of the battery is huge enough, the battery canbe charged with enough energy from 4 am to 7 am while there are a great deal of usagein the following hours with a high price. Additionally, the unused surplus generation canbe charged as well. In non-export scenario, the schedule can not be optimized any morewhen there is no power consumed from the grid with high energy price even with a biggerbattery.

5 Component Architecture of the Optimizer

Figure 5.1: Component of Optimizer

Besides the advisor discussed in the previous chapters, the optimizer contains a parser.Furthermore, an external component evaluator is involved to accompany the performanceof the optimizer. The evaluator consists of a listener, a deviation analyzer and an orderconstructor. The figure 5.1 states the structures of the optimizer and the evaluator.

42

CHAPTER 5. COMPONENT ARCHITECTURE OF THE OPTIMIZER 43

Figure 5.2: Call order of the update event

Figure 5.2 shows the behavior sequence when an update event is received such as therefreshing of forecast. First the listener asks the Deviation Analyzer whether the Advisorshould be triggered (1). Then the Listener calls the Advisor to do optimization (2). In theAdvisor, it fetches data through the Parser (3) which would be forwarded to the Informationbroker (4). After the optimization process, the Advisor saves the generated schedule andrelevant data through the Parser (5). Finally the Advisor notifies the Order Constructorthat a new schedule is generated (7).

5.1 Advisor

The advisor generates an optimized schedule based on the intervals parsed by the parserand properties of the smart energy living lab. The logic will be discussed detailedly in thenext chapter.

5.2 Parser

In the SMG 2 system, message bus and persistent storage service are supported thatmeans the optimizer can acquire data from other components in SMG 2 or fetch data froma database.

CHAPTER 5. COMPONENT ARCHITECTURE OF THE OPTIMIZER 44

Database parser parses data fetched from database with a SQL statement to parame-ters used in the optimizer. The following code is an example that queries the forecast ofconsumption and generation with the relevant price in the future one day from a specificdate. Each record of the return result represents an interval, the duration of the intervalis calculated in the query statement.

Code Example 5.1: Query.sql

SELECT timestamp , duration , price , consumption , generation

FROM ( SELECT timestamp , ( SELECTTime_to_sec ( Timediff ( Min (B . timestamp ) , A . timestamp ) ) / 3600

FROM ( SELECT priceforecast . timestamp timestamp ,Round ( priceforecast . value , 4) price ,dailyforecastconsumption . value consumption ,dailyforecastgeneration . value generation

FROM priceforecast , dailyforecastconsumption ,dailyforecastgeneration

WHERE priceforecast . timestamp=dailyforecastconsumption . timestampAND priceforecast . timestamp=dailyforecastgeneration . timestampAND priceforecast . forecasttime =

( SELECT Max ( forecasttime ) FROM priceforecast

WHERE forecasttime <= ’2014-11-26 00:00:00’ )AND priceforecast . timestamp BETWEEN ’2014-11-26 00:00:00’

AND ’2014-11-26 00:00:00’ + interval 1 day

ORDER BY timestamp ASC ) B WHERE B . timestamp > A . timestamp )duration , price , consumption , generation

FROM ( SELECT priceforecast . timestamp timestamp ,Round ( priceforecast . value , 4) price ,dailyforecastconsumption . value consumption ,dailyforecastgeneration . value generation

FROM priceforecast , dailyforecastconsumption ,dailyforecastgeneration

WHERE priceforecast . timestamp=dailyforecastconsumption . timestampAND priceforecast . timestamp=dailyforecastgeneration . timestampAND priceforecast . forecasttime =

( SELECT Max ( forecasttime ) FROM priceforecast

WHERE forecasttime <= ’2014-11-26 00:00:00’ )AND priceforecast . timestamp BETWEEN ’2014-11-26 00:00:00’

AND ’2014-11-26 00:00:00’ + interval 1 day

ORDER BY timestamp ASC ) A ) C WHERE duration > 0 ;

CHAPTER 5. COMPONENT ARCHITECTURE OF THE OPTIMIZER 45

5.3 Order Constructor

The constructor is a functional module that generate executable order for the electricalfacilities to control the usage of energy. In addition it would generate order for the listenerto observe specific properties or specific facilities such as battery capacity. The constructorgenerated two things based on the optimized schedule, Log and Order.

• Log. The log consists of the activities of the optimizer and the evaluator.

• Order. The order contains the command to control devices in the smart energy livinglab and the task that the listener has to do.

5.4 Deviation Analyzer

The analyzer can compare real-time status of the smart energy living lab such as the batterystatus with the expected status at this time based on the optimized schedule. Then theevaluate the deviation and return the decision whether the optimizer should be triggeredto generate a new schedule.

5.5 Listener

The listener listens some event that impact the optimized schedule in the SMG system,for example a new forecast generated. It can also observe some properties of the smartenergy living lab such as current capacity of the battery. When the observed propertiesare modified or an event is received by the listener, the listener knows whether currentoptimized schedule is correct through the deviation analyzer. If the schedule is incorrect,the listener can trigger the optimizer to generate a new optimized schedule. The listener isexecuted each minute. During the execution, it can check the following things, Schedule,event and observed object.

• Todo list. The todo list records all tasks that the listener have to do in a specifictime. When the time of a task is coming, the listener need to do the task and thenremove the one time task from the todo list.

• Event. The event occurs in the SMG system, such as forecast execute event. Whenthe listened event is coming, call relevant function.

• Observed object. The listener can observe some properties of the smart energy livinglab through the SMG system. When the value of these properties changed, relevantfunction would be triggered by the listener.

6 Advisor in the Optimizer

Figure 6.1: Flowchart of Optimized Advisor

The advisor consists of five sub modules, preprocess, decision exploration, post process,performance evaluation and suggestion generation. Modules execute sequentially in theadvisor with an internal relationship. Intervals and properties of the smart energy livinglab are the parameters used for the advisor. Finally the advisor can derive an optimizedschedule and suggestions to guide the energy usage of the smart energy living lab.

6.1 Preprocess

Figure 6.2: Flowchart of Preprocess

Based on Pc and Pg through the equations (3.16) (3.17) (3.18) (3.19) (3.20) (3.21)(3.22) (4.4) (4.5) (4.6), the ESupply

Least, EDemandMax and ESupply

Max at all intervals arecalculated. However different equations would be used according to the chosen scenario.Considering the price of intervals, the intervals can be merged as price periods. Then theEP Demand

Max, EP SupplyLeast and EP Supply

Max of price periods can be derived with themethodology in the section [Demand/Supply Energy in a Price Period].

46

CHAPTER 6. ADVISOR IN THE OPTIMIZER 47

6.2 Decision Exploration

Figure 6.3: Flowchart of Decision

The decision exploration consists of three steps, pre decision, post decision and dodecision. After the preprocess, the price periods are generated. In the decision exploration,we only consider price periods, all choice are based on the price period.

6.2.1 Pre & Post Decision

Figure 6.4: Flowchart of Pre Decision

The figure 6.4 describes the logic of pre decision. The pool is initialized with theEP Supply

Least of all price periods and the initial capacity of batteries. Then check thepool whether any value in the pool exceeds the maximum capacity of battery. If thereis this value, find a price period with highest price form the price periods with unusedEP Demand

Max before the first exceeding point. The amount of EP DemandMax can de used

depend on the exceeding value and the capacity of battery at the beginning of this period.

CHAPTER 6. ADVISOR IN THE OPTIMIZER 48

When no period could be found, it means the extra supply is waste so use a wastage toupdate the pool. Finally this process can be stopped when all values in the pool are notgreater than the maximum capacity of the battery.

The process of post decision is similar as the pre decision, but there is not pool initial-ization. The violation check of the post decision is to check whether the last value of thepool is greater than zero.

6.2.2 Do Decision

Figure 6.5: Flowchart of Do Decision

The figure 6.5 shows the logic of the process do decision. Firstly, check current situationbased on the pool status. According to the situation, a strategy is chosen to find the scopeof next price period. If a period could be found, calculate the amount of EP Demand

Max

or EP SupplyMax can be used, otherwise set the decision is found and return the decision

if current situation is balanced situation. Based on the chosen period and usage of theperiod, update the pool then recursively call do decision. Check the result of do decision, ifthe decision is found then exit, otherwise analyze the violation information. If the violationcan be fixed by current chosen period, recalculate the usage then go back to the recursion.

CHAPTER 6. ADVISOR IN THE OPTIMIZER 49

Additionally, if the usage of current chosen period is zero, it means this period can not beused actually, therefore exclude this period to find another period in the scope.

6.3 Post Process

In this step, the Pfrom, Pto, Pch, Pdch of intervals should be calculated based on theEP Exchange of each period that generated by the decision exploration.

Figure 6.6: Flowchart of Post Process

The figure 6.6 shows the the logic of post process in a price period. According to valueof EP Exchange the price period can be classified to three situations (4.10) (4.11) (4.12). Ifthe price period is on the charging situation with shortfall, calculate the EExchange

Figure 6.7: Flowchart of Post Process at an interval

When the value of EExchange at an interval is calculated, the Pch and Pdch can be derivedaccording the equations (4.13) (4.14), and then the Pfrom and Pto can be calculated basedon the Pch and Pdch at this interval with the equation (4.15) (4.16) (4.17) (4.18) (4.19)

CHAPTER 6. ADVISOR IN THE OPTIMIZER 50

(4.20). Finally sum all powers at an interval, if the result is lower than zero, there is awastage power.

6.4 Cost Calculation

Figure 6.8: Flowchart of Cost Calculation

In this process, we calculate the cost of each interval through the equation (3.24), thensum all cost.

6.5 Suggestion Generation

Figure 6.9: Flowchart of Suggestion

In this process, we amplify the maximum capacity of battery, then execute the advisor(the Preprocess, Decision Exploration and Post Process) again. Finally if the cost cannot be reduced the value of current maximum capacity is the expected value, otherwisecontinue to execute the advisor with larger maximum capacity.

7 Implementation of the Optimizer

In this chapter, we discuss the implementation of the optimizer which is a component ofthe SMG system in the smart energy living lab. For the optimizer, there are two parts,API Bundle and Implement Bundle. In the API Bundle, the possible accessed API aredefined. The logic functionality are implemented in the Implement bundle.

7.1 Optimizer API

Figure 7.1: Class Diagram of the Optimizer API

The figure 7.1 describes the relationship of the OptimizerInterface and the Optimizer-Impl. There is an public method can be used, that is doOptimized(). In the implementationof the interface, when user want to optimize energy usage in a specific day, a beginningtime should be assigned. Otherwise, the optimizer loads the data in the future 24 hours.

51

CHAPTER 7. IMPLEMENTATION OF THE OPTIMIZER 52

7.2 Optimizer Impl

Figure 7.2: Package Diagram of the Optimizer Impl

There are three layers defined in the optimizer implementation, implement layer, algo-rithm layer and fundamental layer. The package in the higher level can access packages inthe lower level. The implementation layer contains all functionality related to the bundle.However the algorithm layer focus on the algorithm of the advisor. In this layer, thereis a comparison package that simulate the algorithm of other advisors. The fundamentallayer consists of the package related to the data structure and functional utils such asmathematic formula and database access utils.

CHAPTER 7. IMPLEMENTATION OF THE OPTIMIZER 53

7.3 Optimizer Test

Figure 7.3: Class Diagram of the Unit Test

The optimizer test bundle is a unit test bundle for testing functions of the optimizer.For simulating the runtime environment, a mockup bundle instance is used which contain amocked context. The TestOptimizer is the test unit, which contains several test case. Dur-ing the execution, a local information broker should be injected to the optimizer instancefor replace the default information broker with default configuration.

CHAPTER 7. IMPLEMENTATION OF THE OPTIMIZER 54

7.4 Advisor Implementation

Figure 7.4: Class Diagram of the Advisor

The Preprocess, Decision and Postprocess class encapsulate all functionalities relatedto the process. Finally, they provide an method for the advisor respectively, through thesemethods the advisor can construct the sequence for optimization. The Suggestion classhave to use the Evaluation class to evaluate the schedule generated by the Advisor andthen derive a proper suggestion.

CHAPTER 7. IMPLEMENTATION OF THE OPTIMIZER 55

7.5 Comparison Implementation

Figure 7.5: Class Diagram of the Comparison

The OptimizerImpl class can use the three classes that implement different algorithmsto optimize the usage of battery, with the Evaluation class the performance of the generatedschedule can be evaluated. The Advisor class use the greedy algorithm discussed in thisthesis. And the Dummy class use a dummy algorithm.

8 Evaluation

In this chapter we present the evaluation of the advisor. The evaluation contains two parts,complexity analysis of the greedy algorithm used in the advisor and performance analysiswith other algorithms.

8.1 Algorithm Complexity

8.1.1 Time Complexity

The algorithm iterates maximum 2n times. At every iteration one situation checking andone scope searching is performed. The two operations take O(logn) in each iteration.

T (n) = O(nlogn) (8.1)

8.1.2 Space Complexity

The algorithm needs to store the pool array and exchange array of each price period ineach iteration. The two arrays take O(n) space in each iteration.

S(n) = O(n2) (8.2)

8.2 Analysis & Comparison

On different scenarios, there are different features of the cost curves. In the following para-graph, we choose the non-export scenario and sell energy scenario to explain the changesof cost curves based on the optimized schedules.

56

CHAPTER 8. EVALUATION 57

8.2.1 Non-Export Scenario

(a) Non-optimized cost

(b) 1 times maximum capacity

(c) 6 times maximum capacity

Figure 8.1: Optimized cost in non-export scenario

The cost in the figures 8.1(a) 8.1(b) 8.1(c) increase in this day. The cost curve in thefigure 8.1(a) increases gradually and the final value is greater than others. In contract, thecost curve in the figure 8.1(b) increases faster than that at beginning in the figure 8.1(a)and then it becomes stable, the final cost of the figure 8.1(b) is lower than that of thefigure 8.1(a). If we use a large enough battery, the cost curve would like the the figure 8.1(c).At the beginning, the cost increases rapider than others for charging battery, then there

CHAPTER 8. EVALUATION 58

is no more cost since the battery can match the energy consumption in the future hours,therefore the total cost is lowest.

Figure 8.2: Comparison of optimized cost in non-export scenario

By comparing the cost curve generated by the advisor with different maximum capac-ities in the figure 8.2, we can find that the larger maximum capacity that means the moreenergy can be stored in the relative low price, the more financial benefits can be earned.When the capacity is large enough, the optimized cost goes to the peak.

CHAPTER 8. EVALUATION 59

8.2.2 Sell Energy Scenario

(a) Dummy optimization

(b) 1 times maximum capacity

(c) 14 times maximum capacity

Figure 8.3: Optimized cost in sell energy scenario

In the sell energy scenario, the cost curve is totally different with that in the non-exportscenario. Due to the export of energy, we can earn money by exporting extra energy. Formore financial benefit, this process should be done when the energy price is relative high.In the figure 8.3(a), when there is surplus energy export it, therefore in the noon of this daythe cost curve decreases. But in the figure 8.3(b), as the optimized schedule the batteryis charged when energy price is low, when the energy price goes up, the stored energy is

CHAPTER 8. EVALUATION 60

exported to the grid. Furthermore, the surplus generation is not exported directly sincethe price is not high enough at that time, therefore store the energy and then discharge itwhen the energy price increases. If the maximum capacity of battery is huge enough, bulkelectricity can be exported for arbitrage. Therefore, we can earn lots of money in this dayshown in the figure 8.3(c).

Figure 8.4: Comparison of optimized cost in sell energy scenario

The figure 8.4 is similar as the figure 8.2 in non-export scenario, however the cost curvecan decrease in this scenario. Since the storage and dynamic energy price, the optimizedschedule can achieve financial benefits by charging cheap energy from grid and exportingthe stored energy at a expensive price. The larger maximum capacity of battery, the morefinancial benefit can be obtained.

CHAPTER 8. EVALUATION 61

8.2.3 Performance Comparison in Scenarios

(a) In non-export scenario

(b) In sell energy scenario

Figure 8.5: Performance comparison in scenarios

The figure 8.5 describes the optimized effort in non-export scenario and sell energyscenario with different maximum capacities. Due to the arbitrage, normally the optimizedschedule can achieve a higher financial benefit with large enough battery.

CHAPTER 8. EVALUATION 62

8.3 Efficiency of Batteries

(a) 1 times maximum capacity

(b) 5 times maximum capacity

Figure 8.6: Efficiency comparison in non-export scenario

The figure 8.6 shows the cost curve based on different storage efficiency. We can discoverthat the lower storage efficiency, the closer to the non-optimized curve. It means whenstorage efficiency is small, the optimized schedule does not achieve financial benefits.

CHAPTER 8. EVALUATION 63

(a) 1 times maximum capacity

(b) 14 times maximum capacity

Figure 8.7: Efficiency comparison in sell energy scenario

The storage efficiency seriously affects the cost when the usage of the battery increasesshown in the figure 8.7. The cost curve with more storage efficiency would be far awayfrom the non-optimized cost curve. Therefore, it can achieve more financial benefit.

CHAPTER 8. EVALUATION 64

(a) 0.95 storage efficiency

(b) 0.9 storage efficiency

Figure 8.8: Optimized power at intervals in sell energy scenario

In detail, we can compare the optimized power in the figure 8.8. In the figure 8.8(b)the battery is not charged at the first hour and it is discharged fewer energy at 12 amcomparing with the figure 8.8(a), since the energy price is not low enough at 0 am thanthe energy price at 12 am considering the storage efficiency.

9 Conclusion & Future Work

Our purposes will be reviewed and our results in terms of our objectives will be discussedin this chapter. Furthermore, we have a closer look at some points that can be improvedin order to facilitate the performance of the advisor.

9.1 Conclusion

A smart advisor in the smart energy living lab to generate an optimized schedule wasintroduced in this thesis. To achieve this purpose we first identified the possible scenariosrelated to Smart Grid nodes. Furthermore, all factors that determine the generation ofoptimized schedules were involved as parameters for the advisor. In the optimization, time-shifting is the theoretical basis which seriously relies on the dynamic energy price. Thereforedifferent dynamic energy price models were considered in the implementation. Last butnot least, we did a further analysis based on the real data for generating suggestions relatedto the storage that can facilitate the economic benefit.

Develop an advisor to optimize the schedule of energy usage

An smart advisor is an important functionality of Smart Grid nodes that can optimize theenergy usage, however it does not exist in current SMG system of the fortiss smart energyliving lab. So we developed an advisor based on the greedy algorithm with all neededdatum from the SMG system to generate an optimized schedule. The advisor containstwo different optimization strategies, time-shifting and load-shifting. First an optimizedschedule is generated by time-shifting then the advisor can verify the schedule whether aload-shifting optimization is needed.

Support different Smart Grid scenarios

The advisor provides four possible scenarios to simulate the possibilities currently. There-fore the user is able to freely choose the scenario based on the connection to grid and localregulations. Furthermore, the scenarios module of the advisor is extendable for all kindsof scenarios.

In this thesis we simulated all provided scenarios based on real datum from the smartenergy living lab. Additionally this module is easy to be extended for further changeswhen scenario is changed.

65

CHAPTER 9. CONCLUSION & FUTURE WORK 66

Support different Dynamic Energy Price Models

In the time-shifting optimization, dynamic energy price is the keynote. We used two dif-ferent dynamic energy price models, TOU pricing model and RTP pricing model. Actuallytime related price models are supported by the time-shifting optimization.

In this thesis three specific models derived from the TOU or RTP were used to verifythe advisor.

Support different properties of Batteries

In the time-shifting optimization, performance of the battery seriously affects the finaloptimized schedule. Furthermore, some key features of the battery are decaying alongwith the increasing of life cycle of the battery. With the help of various settings, theadvisor can be fixed for generating correct schedule.

Integrate the advisor with the SMG system

The advisor is a part of the optimizer which is integrated with the SMG system. Weimplemented the optimizer to access other components for retrieving needed datum andexporting the optimized schedule to other components.

9.2 Future Work

The Smart Grid node scenarios and the optimized schedule can be probably improved.Although we build the foundation of an smart advisor to generate optimized schedules inthis thesis, there are still some limitations.

• In the algorithm of the advisor, all price periods should be traveled. However, somestages would be regressed directly in next stage. It means, these periods should beexclude before make a choice in this stage. Therefore, a filter can be used to facilitatethe algorithm by reducing redundant recursions.

• In the current version of the advisor, intermediate datum are not saved or exported.However some of them are useful for further analyses. The optimizer should providemore APIs for other components to gain them.

• At the moment, we considered only one connection mode in each scenario. In reality,different Smart Grid nodes have different connection modes even in the same scenario.Therefore we have to provide extension point for various connection modes.

• A possible improvement could be the profile of devices. In the load-shifting optimiza-tion, performance of electrical devices should be considered carefully. It means a morecomplexity strategy for choosing appropriate load during the time with wastage.

CHAPTER 9. CONCLUSION & FUTURE WORK 67

• More restrictions should be considered such as temperature that would affects theperformance of the battery. A generic interface for the injection of restrictions isneeded in the advisor. The usage of more restrictions can fix the optimized schedulemore closer to the reality.

• The regeneration mechanism of the optimized schedule should be improved. Cur-rently the deviation analysis is not useful since the missing of evaluating deviationbetween the real value and the expected value. Furthermore, the threshold of devia-tion depends on long term data analysis.

With this thesis, we have provided a smart advisor based on time-shifting and load-shifting strategies with high extensibility.

Bibliography

[1] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. In-troduction to Algorithms. MIT press, 1990.

[2] U.S. Department of Energy. Discussion of data for smart grid metrics and benefits,2010.

[3] U.S. Department of Energy. Smart grid, 2014.

[4] Yann Riffonneau. System modelling and energy management for grid connected pvsystems with storage. 23rd European Photovoltaic Solar Energy Conference and Ex-hibition, 2008.

[5] James M. Eyer and Joseph J. Iannucci. Energy storage benefits and market analysishandbook. Sandia National Laboratories, 2014.

[6] Jim Eyer and Garth Corey. Energy storage for the electricity grid: Benefits and marketpotential assessment guide. Sandia National Laboratories, 2010.

[7] Armin Wolf, Steffen Unger, and Marc Schultz. Eigenverbrauchs- und kostenopti-mierung zur untersuchung des einflusses dynamischer stromtarife auf die netznutzung.Fraunhofer, 2014.

[8] Tiansong Cui. Concurrent optimization of consumer’s electrical energy bill and pro-ducer’s power generation cost under a dynamic pricing model. Innovative Smart GridTechnologies (ISGT), 2012.

[9] Hadi Goudarzi. Demand-side load scheduling incentivized by dynamic energy prices.Smart Grid Communications, 2011.

[10] UK Government. Microgeneration strategy: Power from the people, 2005.

[11] Michael Kintner-Meyer. Regulatory policy and markets for energy storage in northamerica. Proceedings of the IEEE, 2014.

[12] Elisabeth Dutschke, Michael Unterlander, and Martin Wietschel. Variable stromtarifeaus kundensicht – akzeptanzstudie auf basis einer conjoint- analyse. Fraunhofer, 2012.

[13] Christoph Reske and Steven Waegenaer. Mogliche szenarien fur stromabrech-nungsmodelle mit hilfe von smart meters fur den deutschen markt, 2010.

[14] SMA Technologie AG. Sunny Backup 5000 Installations- und Bedienungsanleitung.

68

BIBLIOGRAPHY 69

[15] Orest Tarasiuk. Forecasting of external energy usage in a smart living lab by predictingenergy generation and consumption. Master’s thesis, TUM, 2013.

[16] Xiaoyan Wang. Research of einstein wurfelt nicht! monte carlo algorithm based onoptimized evaluation. Control and Decision Conference, 2014.

Appendix

70

A Digital Media

CD Content:

• The Smart Advisor (Source Code)

• Tested the Smart Advisor (Source Code)

• Digital Copy of the Thesis (Source Code)

71

B Javadoc Code Documentation

In this chapter we want to present several snippet codes, which are the basic functionalitiesof the Optimizer generating the schedule.

B.1 Data

Intervals are the input parameters of the advisor that initialized by the Interval class, itconsists of all known attributes from original data such as date, duration, price, consump-tion and generation. The powers of charge, discharge, fromGrid and toGrid that shouldbe derived by the advisor are included as well.

Code Example B.1: Interval.java

public class Interval {// Att r ibute sprivate Date date ;private double duration ;private double price ;private double consumption ;private double generation ;private double charge ;private double discharge ;private double fromGrid ;private double toGrid ;

}

Periods are the internal parameters used in the advisor, each of them is a instance form thePeriod class. As we mentioned, intervals should be transformed to periods for simplifyingthe calculation. Each period instance contains all intervals which belongs to this period,then other attributes would be derived in the execution.

Code Example B.2: Period.java

public class Period implements Cloneable {// Att r ibute sprivate double price ;private Interval [ ] intervals ;private double [ ] demands ;private double [ ] supplies ;

72

APPENDIX B. JAVADOC CODE DOCUMENTATION 73

private double possibleDemand ;private double leastSupply ;private double maximumSupply ;private double expectedStorage ;private double neededStorage ;private int first , last ;private double exchange ;

}

B.2 Tool

The Tools class is a utils collection that contains all basic mathematic calculations anda part of the logical calculations used in the advisor. The following example shows thefunctionalities to calculate energy and power and to check benefit of prices.

Code Example B.3: Tools.java

public class Tools {/∗ Calcu la te the energy exchange ∗/public static double capacity ( double power , double elapsedTime ,

double chargeEfficiency , double dischargeEfficiency ) {if ( power > 0) {

return power ∗ elapsedTime ∗ chargeEfficiency ;} else {

return power ∗ elapsedTime / dischargeEfficiency ;}

}

/∗ Calcu la te the power exchange ∗/public static double power ( double capacity , double elapsedTime ,

double chargeEfficiency , double dischargeEfficiency ) {if ( capacity < 0) {

return capacity ∗ dischargeEfficiency / elapsedTime ;} else {

return capacity / chargeEfficiency / elapsedTime ;}

}

/∗ Check whether the re i s a f i n a n c i a l b e n e f i t ∗/public static boolean hasBenefit ( double sourcePrice , double

destPrice ,

APPENDIX B. JAVADOC CODE DOCUMENTATION 74

double chargeEfficiency , double dischargeEfficiency ) {if ( destPrice ∗ chargeEfficiency ∗ dischargeEfficiency /

sourcePrice > 1)return true ;

return false ;}

}

B.3 Dao

The DatabaseDao class is database access object for the advisor, which encapsulates allrelationships to map the data structures of the advisor to database tables. It provides APIfor other classes in the bundle of the OptimizerImpl to query data from database or savedata in database.

Code Example B.4: DatabaseDao.java

public class DatabaseDao {// S ing l e ton Patternprivate static DatabaseDao databaseDao = null ;// Database brokerprivate IDatabase database ;// Forecast Datapublic static final String DB_NAME_PRICE = "PriceForecast" ;public static final String DB_NAME_CONSUMPTION = "

DailyForecastConsumption" ;public static final String DB_NAME_GENERATION = "

DailyForecastGeneration" ;// SMG Conf igurat ion Datapublic static final String DB_NAME_SPECIFICATION = "

Optimizer_Specification" ;// Derived Datapublic static final String DB_NAME_INTERVAL = "

Optimizer_Intervals" ;public static final String DB_NAME_PERIOD = "Optimizer_Periods"

;public static final String DB_NAME_PATH = "Optimizer_Paths" ;/∗ Get databasedao in s t ance ∗/public static DatabaseDao getDatabaseDao ( ) {

if ( databaseDao == null ) {databaseDao = new DatabaseDao ( ) ;

APPENDIX B. JAVADOC CODE DOCUMENTATION 75

}return databaseDao ;

}/∗ Fetch i n t e r v a l s ∗/public Interval [ ] loadIntervals ( Date start ) throws

TimeoutException {if ( start == null )

start = new Date ( ) ;String sql = getIntervalSQL ( start ) ;List<Map<String , Object>> resultSet = database . getSQLResults (

sql ) ;// Trave l s r e s u l t s e treturn getIntervals ( resultSet ) ;

}

/∗ Save schedu le ∗/public void writeArray ( Object objects , String executetime )

throws TimeoutException {if ( objects == null )

return ;if ( objects instanceof Interval [ ] ) {

Interval [ ] intervals = ( Interval [ ] ) objects ;for ( int i = 0 ; i < intervals . length ; i++) {

executeQuery ( getSQL ( intervals [ i ] , i , executetime ) ) ;}

} else if ( objects instanceof Period [ ] ) {Period [ ] periods = ( Period [ ] ) objects ;for ( int i = 0 ; i < periods . length ; i++) {

executeQuery ( getSQL ( periods [ i ] , i , executetime ) ) ;}

} else if ( objects instanceof Chosen [ ] ) {Chosen [ ] chosens = ( Chosen [ ] ) objects ;for ( int i = 0 ; i < chosens . length ; i++) {

executeQuery ( getSQL ( chosens [ i ] , i , executetime ) ) ;}

}}

}

APPENDIX B. JAVADOC CODE DOCUMENTATION 76

B.4 Algorithm

The Advisor class encapsulates the logic of the algorithm for the optimization and providesan API to do optimize.

Code Example B.5: Advisor.java

public class Advisor {/∗ Do opt imiza t i on ∗/public static void doOptimize ( Interval [ ] intervals ) {

setExecuteTime ( ) ;Period [ ] periods = toPeriods ( intervals ) ;// Preproces s per iodpreProcess ( periods ) ;// Find a d e c i s i o nif ( ! findDecision ( periods ) )

return ;// Update r e l e v a n t datapostProcess ( periods ) ;

}

}

Due to the encapsulation of the Advisor class, the Suggestion class just needs to modify theconfiguration and then uses the API of the advisor to execute the algorithm and comparesthe cost with previous.

Code Example B.6: Suggestion.java

public class Suggestion {/∗ Get sugge s t i on ∗/public static double getSuggestion ( Interval [ ] intervals , double

cost ) {if ( intervals == null | | intervals . length == 0)

return −1;double leastCapacity = getSpecification ( ) . getMaximumCapacity

( ) ;do {

getSpecification ( ) . setMaximumCapacity (leastCapacity + getSpecification ( ) . getMaximumCapacity ( )

) ;Interval [ ] newIntervals = Interval . copy ( intervals ) ;Advisor . doOptimize ( newIntervals ) ;

APPENDIX B. JAVADOC CODE DOCUMENTATION 77

double comparable = cost ( newIntervals ) ;if ( cost == comparable ) {

break ;}cost = comparable ;

} while ( true ) ;return getSpecification ( ) . getMaximumCapacity ( ) ;

}}