An optimal home energy management scheme

47 downloads 0 Views 2MB Size Report
Dec 9, 2009 - thermore, energy management controller (EMC) is also installed for ...... 2429 figures\hourly_load ','eps ');. 2430. 111. Thesis by: Sheraz Aslam ...
An optimal home energy management scheme considering grid connected microgrids with day-ahead weather forecasting using artificial neural network

By

Sheraz Aslam CIIT/FA16-RCS-031/ISB

MS Thesis In Computer Science

COMSATS University Islamabad, Islamabad - Pakistan

Spring, 2018 i

COMSATS University Islamabad

An optimal home energy management scheme considering grid connected microgrids with day-ahead weather forecasting using artificial neural network

A Thesis Presented to

COMSATS University Islamabad

In partial fulfillment of the requirement for the degree of

MS (Computer Science)

By

Sheraz Aslam CIIT/FA16-RCS-031/ISB

Spring, 2018 ii

An optimal home energy management scheme considering grid connected microgrids with day-ahead weather forecasting using artificial neural network

A Post Graduate Thesis submitted to the Department of Computer Science as partial fulfilment of the requirement for the award of Degree of MS (Computer Science).

Name

Registration Number

Sheraz Aslam CIIT/FA16-RCS-031/ISB

Supervisor:

Dr. Nadeem Javaid, Associate Professor, Department of Computer Science, COMSATS University Islamabad, Islamabad, Pakistan

Co-Supervisor:

Dr. Zahoor Ali Khan, Assistant Professor, Computer Information Science, Higher Colleges of Technology, Fujairah, United Arab Emirates iii

Final Approval This thesis titled

An optimal home energy management scheme considering grid connected microgrids with day-ahead weather forecasting using artificial neural network

By Sheraz Aslam CIIT/FA16-RCS-031/ISB has been approved For the COMSATS University Islamabad, Islamabad

External Examiner: Dr. Muhammad Hasan Islam Associate Professor, CASE Islamabad, Pakistan

Supervisor: Dr. Nadeem Javaid Associate Professor, Department of Computer Science, COMSATS University Islamabad, Islamabad

Co-Supervisor: Dr. Zahoor Ali Khan, Assistant Professor, Computer Information Science, Higher Colleges of Technology, Fujairah, United Arab Emirates

HoD: Dr. Majid Iqbal Khan Associate Professor, Department. of Computer Science, COMSATS University Islamabad, Islamabad iv

Declaration I Sheraz Aslam (Registration No. CIIT/FA16-RCS-031/ISB) hereby declare that I have produced the work presented in this thesis, during the scheduled period of study. I also declare that I have not taken any material from any source except referred to wherever due that amount of plagiarism is within acceptable range. If a violation of HEC rules on research has occurred in this thesis, I shall be liable to punishable action under the plagiarism rules of the HEC.

Date: June, 2018 Sheraz Aslam CIIT/FA16-RCS-031/ISB

v

Certificate It is certified that Sheraz Aslam (Registration No. CIIT/FA16-RCS-031/ISB) has carried out all the work related to this thesis under my supervision at the Department of Computer Science, COMSATS University, Islamabad and the work fulfils the requirement for award of MS degree.

Date: June, 2018

Supervisor:

Dr. Nadeem Javaid Associate Professor, Department of Computer Science

Co-Supervisor:

Dr. Zahoor Ali Khan Assistant Professor, Computer Information Science, Head of Department:

Dr. Majid Iqbal Khan Department of Computer Science

vi

DEDICATION

Dedicated to my mentor Dr. Nadeem Javaid, Ms. Zaib-ul-Nisa Khosa and loving Parents, who equipped me with pearls of knowledge and showed me the way of spiritual and personal enlightenment in this world and the world hereafter.

vii

ACKNOWLEDGEMENT First of all, thanks to Allah Almighty who give me strength and confidence to complete this dissertation. After that, I would like to express my profound appreciation to many people who supported me during my MS and who helped me to complete my thesis. Their generous support made this research work possible Firstly, I would like to express my sincere gratitude to my advisor Dr. Nadeem Javaid for the continuous support of my MS study and related research, for his patience, motivation and immense knowledge. His guidance helped me in all the time of research and writing of this thesis. I could not have imagined having a better advisor and mentor for my MS study. I am truly indebted to him for his knowledge, thoughts and friendship. I gratefully acknowledge the funding source that made my MS work possible. I was funded by the HEC PAK-USAID merit-based scholarship for my MS studies at COMSATS University Islamabad (CUI), Islamabad. I would like to thank my parents and my fiance Kainat Mustafa for their continuous support, understanding and assistance whenever I needed them throughout my MS studies and research work. Furthermore, I would like to thank my brothers Shehzad Aslam, Shehbaz Aslam and my loving sisters Arshia Sana and Arooj Mustafa. I believe that without their motivation, it is not possible to succeed throughout my life. I am always grateful to them for their encouragement and support. Last but not the least, I am greatly thankful to Director of ComSens Lab and all of my colleagues at CUI for providing me the warm and friendly atmosphere.

viii

ABSTRACT An optimal home energy management scheme considering grid connected microgrids with day-ahead weather forecasting using artificial neural network Demand response (DR) strategy provides an opportunity to electricity consumers to participate in making power system reliable by managing their electricity consumption. Due to increasing population, a lot of energy is consumed in the residential sector. Therefore, in this thesis, we propose an optimal scheme to systematically manage the energy consumption in residential area. Electricity cost and peak to average ratio reduction are the main goals of this study. Furthermore, reduction in imported electricity from the external grid is also the objective of this study. The proposed scheme schedules smart appliances and electrical vehicle (EV) charging/discharging optimally according to the consumers’ preferences. Each consumer has its own grid-connected microgrid for electricity generation; which consists of wind turbine, solar panel, micro gas turbine and energy storage system (ESS). On the other hand, a real time forecasting of wind speed and temperature has been performed using an artificial neural network for efficient energy management. Furthermore, the scheduling problem is mathematically formulated and solved by mixed integer linear programming (MILP). We also provide the comparison of the optimal solutions, while considering EV with and without discharging capabilities. Findings from simulations affirm our proposed scheme in terms of above-mentioned objectives. After solving home energy management and EV charging/discharging problem using MILP, power trading problem is considered in this thesis to earn maximum profit and proper utilization of renewable energy sources (RES). This problem is solved using two well-known heuristic approaches: the cuckoo search algorithm (CSA) and strawberry algorithm (SA). In our proposed scheme, a smart home decides to buy or sell electricity from/to the commercial grid for minimizing electricity costs and PAR with earning maximization. It makes a decision on the basis of electricity prices, demand and generation from its own microgrid. In this case, the microgrid also consists of a wind turbine and solar panel. Electricity generation from the solar panel and wind turbine is intermittent in nature. Therefore, ESS is also considered for stable and reliable power system operation. We test our proposed scheme on a set of different case studies. The simulation results affirm our proposed scheme in terms of electricity cost and PAR reduction with profit maximization. Furthermore, a comparative analysis is also performed to show the ix

legitimacy and productiveness of CSA and SA.

x

Journal Publications 1 Aslam, Sheraz, Zafar Iqbal, Nadeem Javaid, Zahoor Ali Khan, Khursheed Aurangzeb, and Syed Itaza Haider. ”Towards Efficient Energy Management of Smart Buildings Exploiting Heuristic Optimization with Real Time and Critical Peak Pricing Schemes.” Energies 10, no. 12 (2017): 2065. Download 2 Aslam, Sheraz, Nadeem Javaid, Farman Ali Khan, Atif Alamri, Ahmad Almogren, and Wadood Abdul. ”Towards Efficient Energy Management and Power Trading in a Residential Area via Integrating a Grid-Connected Microgrid.” Sustainability 10, no. 4 (2018): 1245. Download 3 Iqbal, Zafar, Nadeem Javaid, Saleem Iqbal, Sheraz Aslam, Zahoor Ali Khan, Wadood Abdul, Ahmad Almogren, and Atif Alamri. ”A Domestic Microgrid with Optimized Home Energy Management System.” Energies 11, no. 4 (2018): 1002. Download

xi

Conference Proceedings 1 Aslam, Sheraz, Rasool Bukhsh, Adia Khalid, Nadeem Javaid, Ibrar Ullah, Itrat Fatima, and Qadeer Ul Hasan. ”An Efficient Home Energy Management Scheme Using Cuckoo Search.” In International Conference on P2P, Parallel, Grid, Cloud and Internet Computing, pp. 167-178. Springer, Cham, 2017. Download 2 Aslam, Sheraz, Nadeem Javaid, Muhammad Asif, Zafar Iqbal and Mian Ahmer, ”A mixed integer linear programming based optimal home energy management scheme considering grid-connected microgrids ”, 14th IEEE International Wireless Communications and Mobile Computing Conference (IWCMC), 2018. Download 3 Aslam, Sheraz, Sakeena Javaid, Nadeem Javaid, Syed Muhammad Mohsin, Saad Sulman Khan, and Mariam Akbar, ”An efficient home energy management and power trading in smart grid”, in 12-th International Conference on Innovative Mobile and Internet Services in Ubiquitous Computing (IMIS2018). Download 4 Komal Parvez, Sheraz Aslam, Arje Saba, Syeda Aimal, Zunaira Amjad, Sikandar Asif, Nadeem Javaid, ”Scheduling of Appliances in HEMS using Elephant Herding Optimization and Harmony Search Algorithm”, 12th International Conference on Broadband Wireless Computing, Communication and Applications (BWCCA), 2017. Download 5 Ihsan Ali, Sheraz Aslam, Kashif Khan, Waqas Ahmad, Hazrat Abubakar Sadiq, Nadeem Javaid, ”Using Meta-heuristic And Numerical Algorithm Inspired by Evolution Differential Equation and Strawberry Plant for Demand Side Management in Smart Grid”, 12th International Conference on P2P, Parallel, Grid, Cloud and Internet Computing (3PGCIC), 2017. Download 6 Anwar Ur Rehman, Sheraz Aslam, Zain Ul Abideen, Asma Zahra, Waqar Ali, Muhammad Junaid, Nadeem Javaid, ”Efficient Energy Management System using Firefly and Harmony Search Algorithm”, 12th International Conference on Broadband Wireless Computing, Communication and Applications (BWCCA), 2017. Download 7 Javaid, Sakeena, Nadeem Javaid, Sohail Iqbal, Sheraz Aslam, and Muhammad Hassan Rahim. ”Optimizing energy consumption of air-conditioning systems with the fuzzy logic controllers in residential buildings: Optimizing xii

energy consumption of air-conditioning systems in residential buildings.” In Computing, Mathematics and Engineering Technologies (iCoMET), 2018 International Conference on, pp. 1-9. IEEE, 2018. Download 8 Samuel, Omaji, Nadeem Javaid, Muhammad Hassan Rahim, and Sheraz Aslam. ”Harmony search optimization technique for home management system in smart grid: HSA technique for HEMS.” In Computing, Mathematics and Engineering Technologies (iCoMET), 2018 International Conference on, pp. 1-9. IEEE, 2018. Download 9 Iqra Fatima, Nadeem Javaid, Sundas Shafiq, Sikandar Asif, Muhammad Hassan Rahim and Sheraz Aslam, ”Comparative study of meta-heuristic approaches towards utilization of home energy management”, in 2018 International Conference on Computing, Mathematics and Engineering Technologies (iCoMET-2018). Download 10 Abid, Mian Muhammad Naeem, Nadeem Javaid, Muhammad Hassan Rahim, and Sheraz Aslam. ”Demand side management for residential areas using hybrid bacterial foraging and bat optimization algorithm: Demand side management using hybrid bacterial foraging and bat optimization algorithm.” In Computing, Mathematics and Engineering Technologies (iCoMET), 2018 International Conference on, pp. 1-8. IEEE, 2018. Download 11 Samuel, Omaji, Nadeem Javaid, Sheraz Aslam, and Muhammad Hassan Rahim. ”JAYA optimization based energy management controller for smart grid: JAYA optimization based energy management controller.” In Computing, Mathematics and Engineering Technologies (iCoMET), 2018 International Conference on, pp. 1-8. IEEE, 2018. Download 12 Ahmed, Adnan, Muhammad Hassan Rahim, Fozia Feroze, Ayesha Zafar, Itrat Fatima, Sheraz Aslam, and Nadeem Javaid. ”Swarm Intelligence Based Home Energy Management Controller Under Dynamic Pricing Scheme.” In International Conference on Broadband and Wireless Computing, Communication and Applications, pp. 256-266. Springer, Cham, 2017. Download 13 Fahim Ahmed, Sheraz Aslam, Muhammad Hassan Rahim, and Nadeem Javaid, ”Energy Efficien Buildings based on Occupants Behaviour: A survey”, in International Conference on Power, Energy and Smart Grid (ICPESG2018). Download

xiii

14 Sundas Shafiq, Nadeem Javaid, and Sheraz Aslam, ”Optimal power flow control in a smart micro-grid using bird swarm algorithm”, in 5th International Multi-Topic ICT Conference (IMTIC-2018). Download 15 Aqib Jamil, Nadeem Javaid, and Sheraz Aslam, ”An Efficient Home Energy Optimization by Using Meta-Heuristic Techniques While Incorporating Game-theoretic Approach for Real-time Coordination Among Home Appliances”, in 5th International Multi-Topic ICT Conference 2018 (IMTIC-18). Download 16 Muhammad Usman Khalid, Nadeem Javaid, and Sheraz Aslam, ”A Game Theoretic-based Approach for Appliances Scheduling with Real-time Coordination in Smart Grid”, in 5th International Multi-Topic ICT Conference (IMTIC-2018). Download

xiv

TABLE OF CONTENTS Dedication

vii

Acknowledgements

viii

Abstract

ix

Journal Publications

xi

Conference Proceedings

xii

List of Figures

xvii

List of Tables

xviii

List of Symbols

xix

1 1.1

Introduction . . . . . . . . . . . . . 1.1.1 Background and motivation 1.1.2 Smart grid . . . . . . . . . . 1.1.3 Thesis contributions . . . . 1.1.4 Organization of thesis . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

1 2 2 3 5 6

. . . .

7 8 11 11 12

. . . . . . . . . . . . . .

13 14 15 16 17 17 18 20 21 21 22 23 24 25 25

2 2.1 2.2

Literature review . . . . . . Problem statement . . . . . 2.2.1 Problem statement 1: 2.2.2 Problem statement 2:

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

3 3.1

3.2

System model 1: . . . . . . . . . . . 3.1.1 Home appliances . . . . . . 3.1.2 Microgrid . . . . . . . . . . 3.1.2.1 Wind turbine . . . 3.1.2.2 Solar panel . . . . 3.1.3 ESS . . . . . . . . . . . . . 3.1.4 EV . . . . . . . . . . . . . . 3.1.5 MGT . . . . . . . . . . . . . 3.1.6 Electricity consumption cost 3.1.7 Problem formulation . . . . System model 2: . . . . . . . . . . . 3.2.1 Microgrid . . . . . . . . . . 3.2.1.1 Solar panel . . . . 3.2.1.2 Wind turbine . . . xv

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

3.2.2 3.2.3 3.2.4

3.3

3.4

ESS . . . . . . . . . . . . . . . . . . Household electricity load . . . . . . Categorization of load . . . . . . . . 3.2.4.1 Shiftable appliances . . . . 3.2.4.2 Non-interruptible appliances 3.2.4.3 Base-load appliances . . . . 3.2.5 Electricity tariff and bill calculation . Proposed schemes . . . . . . . . . . . . . . . 3.3.1 CSA . . . . . . . . . . . . . . . . . . 3.3.2 SA . . . . . . . . . . . . . . . . . . . Case studies . . . . . . . . . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

4

25 25 26 27 27 28 29 31 31 32 33 35

4.1

4.2

5 5.1 5.2

An optimal home energy management considering microgrid with real-time weather forecasting . . . . . . . . . . . . . . . . . . . . . . 4.1.1 HEM without microgrid . . . . . . . . . . . . . . . . . . . . 4.1.2 HEM with microgrid . . . . . . . . . . . . . . . . . . . . . . An optimal home energy management and power trading in gridconnected microgrids . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2.1 Case 1: home without energy management and microgrid . . 4.2.2 Case 2: home with energy management but without microgrid 4.2.3 Case 3: home with energy management and microgrid . . . . 4.2.4 Performance comparison . . . . . . . . . . . . . . . . . . . .

36 36 38 45 45 46 49 51

53 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6

56

Appendices .A Detail of Appendices . . . . . . . . . . . . . . . . . .B Implementation of proposed solution for problem 1: .B.1 MILP function . . . . . . . . . . . . . . . . .B.2 RES generation function . . . . . . . . . . . .B.3 Uper lower bound function . . . . . . . . . . .B.4 IV curve function . . . . . . . . . . . . . . . .B.5 MILP function for supply side . . . . . . . . .C Implementation of proposed solution for problem 2: .C.1 RES generation function . . . . . . . . . . . .C.2 IV curve function . . . . . . . . . . . . . . . .C.3 Cuckoo search algorithm function . . . . . . .C.4 Crossover function . . . . . . . . . . . . . . .C.5 Mutate function . . . . . . . . . . . . . . . .

xvi

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

. . . . . . . . . . . . .

64 65 66 75 78 79 80 82 84 116 117 118 127 128

LIST OF FIGURES 3.1 3.2 3.3 3.4 3.5 3.6

Proposed system model . . . . . . . . . . . . . Electricity generation and cut-in, cut-out wind I-V curve. . . . . . . . . . . . . . . . . . . . . Proposed system model. . . . . . . . . . . . . Status of appliances’ execution pattern. . . . . Hourly electricity purchasing and selling rates.

. . . . . .

. . . . . .

14 18 19 24 26 29

Hourly electricity consumption . . . . . . . . . . . . . . . . . . . . Hourly electricity cost . . . . . . . . . . . . . . . . . . . . . . . . Total electricity cost . . . . . . . . . . . . . . . . . . . . . . . . . PAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Microgrid generation . . . . . . . . . . . . . . . . . . . . . . . . . Wind speed prediction for wind turbine generation using ANN . . Temperature prediction for solar generation using ANN . . . . . . Electricity demand and generation . . . . . . . . . . . . . . . . . Hourly imported electricity and optimal demand . . . . . . . . . . Total electricity imported with and w/o EV discharging . . . . . . EV charging/discharging with electricity generation . . . . . . . . Hourly EV and ESS contribution . . . . . . . . . . . . . . . . . . Optimal demand and MGT contribution in minimizing PAR . . . Pricing signals and electricity consumption. . . . . . . . . . . . . Hourly electricity cost. . . . . . . . . . . . . . . . . . . . . . . . . Total cost. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hourly electricity consumption. . . . . . . . . . . . . . . . . . . . PAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Electricity generation from wind turbines and solar panels. . . . . Relationship between electricity generation from wind turbines and wind speed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.21 Relationship between electricity generation from solar panels and temperature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.22 Sold and imported electricity with pricing signals. . . . . . . . . . 4.23 Cost and earnings against imported and sold electricity. . . . . . .

. . . . . . . . . . . . . . . . . . .

37 38 38 39 39 40 41 41 42 43 43 44 44 46 47 47 48 48 49

4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 4.12 4.13 4.14 4.15 4.16 4.17 4.18 4.19 4.20

xvii

. . . . . . speed [55] . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. 50 . 50 . 51 . 51

LIST OF TABLES 3.1 3.2 3.3 3.4 3.5

Parameters of appliances . . . . . Parameters of appliances . . . . . Parameters of CSA. . . . . . . . . Parameters of SA. . . . . . . . . . Input parameters for case studies.

4.1

Performance comparison. . . . . . . . . . . . . . . . . . . . . . . . . 52

xviii

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

16 26 32 33 34

List of Symbols

U u T t A a AP Psh AP Pns Γtsh ΓTsh Γtns ΓTns αsh αns γsh γns αmgt ζt ζT Φt ΦT δt δT α β η EPt Et ET

Set of electricity users/homes Each user in U Total time slots in a day Single time interval Set of all appliance in home u Each appliance in home u Set of shiftable appliances Set of non-shiftable appliances Hourly electricity consumption against AP Psh Per day electricity consumption against AP Psh Hourly electricity consumption against AP Pns Per day electricity consumption against AP Pns ON/OFF status of shiftable appliances ON/OFF status of non-shiftable appliances Power rating of shiftable appliances Power rating of non-shiftable appliances ON or OFF status of MGT Hourly electricity consumption cost Total electricity consumption cost for one day Hourly imported electricity Total imported electricity for T Hourly cost against imported electricity Total cost against imported electricity for whole day Earliest starting time of each appliance a Least finishing time of each appliance a Actual execution period of each appliance a Electricity price against single time slot Microgrid generation against single time interval Microgrid generation for whole day xix

εm pwt t Cp V cut−in V cut−out Vtwt ppv t η pv Apv Irrt T empt EVe ψe αe ρEVae ρEVde max EVdis SE EStch ESS t EStdis αess

Electricity generation from single microgrid source Power generation from wind turbine Power co-efficient of wind turbine Cut-in speed Cut-out speed Hourly wind velocity Power generation from solar panel Solar panel efficiency Solar panel area Irradiation for interval t Temperature of the day Electricity consumption against EV Charging/discharging of EV in (kWh) Charging/discharging or remaining idle status of EV Energy storage level at EV arrival time Energy storage level at EV departure time Maximum EV discharging limit Stored electricity in ESS ESS charging at slot t Total electricity storage in ESS ESS discharging at time t Charging or discharging status of ESS

xx

Chapter 1 Introduction

1

CHAPTER 1.

1.1

1.1. INTRODUCTION

Introduction

In this section of thesis, the background and motivation, introduction of smart grid, contributions and organization of thesis have been presented.

1.1.1

Background and motivation

The present electric system depends on few large-scale fossil fuel plants for electricity generation. Electricity is generated at a single location which is far from the consumers; then it is transmitted and distributed among the consumers via transmission lines. Many current studies have shown that existing electric grid is facing power losses due to long distance generation, transmission and distribution of electricity [1]. Almost 90% blackouts occur due to the failure of the traditional transmission and distribution lines. However, the traditional power system is not feasible to fulfill the future requirement of electricity consumers. Furthermore, the existing power systems cause high carbon emissions due to heavy dependency on fossil fuels. Approximately, 41% of the greenhouse gases are produced from power sector around the globe. On the other side, our transportation system is totally dependent on fossil fuels. Therefore, transportation sector is also the significant emitter of the greenhouse gases which produces 23% of all over the world gases [2]. World increasing population, global warming, the rise in carbon emissions and increasing electricity demand create an alarming situation for electricity producing and distributing companies as well as for governments to take any strong action against these alarming situations. The electricity producing companies are detained from integrating renewable energy sources (RESs) to overcome global warming and carbon emissions [3, 4, 5]. The present fossil fuel based electric grid is working on the centralized approach: only a few large electricity producing plants are operating at 50 Hz or more. High-power electricity plants are operating at very high voltage (i.e., 400 kV or more). Then, the produced electricity from large plants is distributed to the electricity consumers. A large number of supply lines supply the high voltage load to heavy industries and low voltage load to residential consumers and small-scale industries. The power flow in the present power system is unidirectional due to the centralized approach. Electricity consumers are considered just passive users; they cannot play any role in the stability and reliability of the electric grid. According 2

Thesis by: Sheraz Aslam

CHAPTER 1.

1.1. INTRODUCTION

to [6, 7, 8, 9], more than 65% of total electricity is wasted during generation, transmission and distribution of electricity. The basic reasons behind electricity wastage are that the present electricity system has unidirectional communication and a lack of monitoring technologies. The novel approach is distributed based on bidirectional communication. It provides the widely and higher distributed intelligence in electric power generation, distribution and flow of information. Furthermore, the novel approach provides the multiple opportunities for electricity consumers to manage their electricity consumption for bill reduction and reliable grid operation.

1.1.2

Smart grid

The novel approach is a smart grid and integration of cost-efficient RESs hold promise to tackle the above-discussed problems in the traditional electric grid. In the smart grid, electricity is generated via cheaper and efficient resources and then distributed to electricity consumers through smart transmission lines. Electricity prosumers are the consumers they can utilize as well as produce the electricity from their own local microgrid, which consists of multiple RESs, i.e., solar panel, wind turbine, hydro power plant, etc. They utilize electricity from their own generation and are also interconnected with the commercial grid. In case of less electricity generation, as compared to load demand, they purchase electricity from utilities or neighbors. If the electricity production from their own microgrid is more than the load demand, then the excess electricity is sold back to the commercial grid or stored in batteries for future use when electricity generation is low. The batteries may discharge only when electricity production from the microgrid is low or per unit electricity price is high. At present, RESs generate few kilowatts (kW) or megawatts (mW) of electricity in residential areas and integration of RESs on a large-scale is widely diffused around the globe. Furthermore, electricity generation via RESs and integration of storage systems are enabling smart homes and small-scale industries to gain profit by selling excess electricity to the grid or neighbors. Moreover, end users may purchase energy when electricity tariffs are low and sell back electricity when prices are high. In addition, approximately 10–30% electricity consumption can be saved through demand side management (DSM) [10]. There are many dynamic pricing schemes (to calculate electricity consumption cost) for consumers’ motivation to alleviate their electricity consumption in ON-peak hours. These pricing schemes include 3

Thesis by: Sheraz Aslam

CHAPTER 1.

1.1. INTRODUCTION

real-time pricing (RTP), time of use (ToU), critical peak pricing (CPP) and critical peak rebate (CPR) [11]. Electricity consumers have the option to select the best electricity tariff according to their satisfaction. The energy crises and management problems are addressed with the evolution of smart microgrids. A smart microgrid is a small version of future power grid which performs all power system functionalities, i.e., generate, distribute and regulate the electricity flow to the end users. Microgrid has two modes: grid-connected mode and islanded mode. In grid-connected mode, the microgrid is able to import or export electricity from/to external grid. However, islanded mode restricts the microgrid and external grid to share energy with each others. Microgrid generates electricity from cheaper generation sources, i.e., renewable energy sources (RESs). RESs include wind turbine, solar panel, fuel cells, micro gas turbine (MGT), etc. Furthermore, RESs are stochastic in nature, therefore, energy storage system (ESS) is also installed in microgrid as a backup source for reliable grid operation. ESS is charged in high electricity generation hours of microgrid. By contrast, when power generation from microgrid is low as compared to power demand, the power system automatically switches to use electricity stored in ESS or imports from the external grid. For earning profit, the electricity can be exported to other microgrids, neighbors or external grid in case of excess power generation. In another front, due to many advantages, i.e., clean environment, energy efficiency and lower cost; interests in electrical vehicles (EVs) have become larger for last few years [12, 13, 14]. Furthermore, unlike traditional vehicles, EVs can not only charge but also discharge according to user requirements. However, EVs have two significant impacts on the power grid. First, the large-scale integration of EVs may cause for peak formation while being charged. Load demand of consumers is also increased which creates serious problems for the power grid. The power grid meet the user demand using high-cost electricity generation sources, i.e., diesel turbines which are the main reason for carbon emission. Second, EVs can facilitate the electric grid or consumers via discharging their stored electricity in batteries. In ON-peak hours, consumers can utilize electricity from EVs discharging instead of purchasing from electric grid against high electricity rates. In smart grid, demand response (DR) plays a significant role for cost-efficient and reliable power system operation [15]. The DR programs motivate the electricity consumers to manage their electricity consumption or provide incentives for electricity cost and peak load reduction. The end users can minimize electricity cost and improve satisfaction level by the scheduling of home appliances. The DR 4

Thesis by: Sheraz Aslam

CHAPTER 1.

1.1. INTRODUCTION

programs considering the residential electricity usage have been widely studied. In [16], DR problem has been studied considering multiple homes with the same living patterns. However, it is not practically possible for multiple homes to have the same appliances with the same power rating (kW) and length of operational time (LOT). In [17], a scheduling scheme is presented which considers the EVs and home appliances under the grid-connected microgrids. The basic objectives of this study are to reduce the electricity cost and optimal scheduling of EVs charging/discharging. An efficient scheduling scheme can optimally determine the schedule of appliances consumption and EV charging/discharging. As a result, the scheduling pattern depicts the same behaviour as the microgrid electricity generation pattern. In this way, the imported electricity from external grid and electricity cost are reduced. Furthermore, an efficient scheduling may provide reliable and stable microgrid operation.

1.1.3

Thesis contributions

In our proposed work, we consider the residential household, which has multiple smart appliances with different parameters. Resident also has its own microgrid which consists of solar panel, wind turbine and ESS. Microgrid is also connected with external grid and EV. Static storage is also installed for electricity storage in this work. MGT is installed as a backup source of electricity and an artificial neural network (ANN) is used for more accurate weather forecasting instead of day ahead assumed weather information. We formulate this scheduling problem as a mixed integer linear programming (MILP) problem to schedule the home appliances and EV charging/discharging according to electricity generation from own microgrid and electricity tariff. Furthermore, the contributions in solving power trading problem are explained below. We consider a smart home that not only utilizes electricity from the commercial grid but is also capable of generating electricity from its own microgrid and storing electricity for future use. Furthermore, the smart home is independent from making autonomous decisions for electricity cost and PAR reduction with revenue maximization in each hour. Therefore, maximizing the revenue generated from power trading is also the objective of this work. A smart home makes decisions according to electricity tariffs. When prices are high, the home tries to reduce load demand and excess electricity is sold back to the commercial grid. The home 5

Thesis by: Sheraz Aslam

CHAPTER 1.

1.1. INTRODUCTION

purchases electricity in low price time slots while minimizing the PAR. Furthermore, two different RTP schemes are considered for electricity cost calculation in terms of purchasing and selling electricity. At the end, a comparative analysis is performed to show the performance of the cuckoo search algorithm (CSA) and strawberry algorithm (SA). Our main contributions in this work are as follows: • Two heuristic approaches CSA and SA are implemented to schedule appliances for efficient power trading. • An analysis is performed to investigate the fact that CSA and SA are adaptable and capable of making autonomous decisions for effective scheduling of an appliance and optimal power trading with a commercial grid. • We enable a smart home to interact with the grid and make autonomous decisions for selling power to the grid for getting financial benefits. • In order to validate the effectiveness of CSA and SA, extensive simulations are performed in MATLAB (2017a) and the performance parameters are total cost and PAR along with earnings. • Simulation results show that our proposed scheme significantly reduces the electricity cost and PAR with earning maximization.

1.1.4

Organization of thesis

The remainder of the thesis is organized as follows: related studies are presented in Chapter 2. System model and mathematical formulations alog with proposed methodology are demonstrated in Chapter 3. Chapter 4 describes the simulation results of our proposed schemes. Finally, the findings of this work along with future directions are presented in Chapter 5.

6

Thesis by: Sheraz Aslam

Chapter 2 Literature review and problem statement

7

CHAPTER 2.

2.1

2.1. LITERATURE REVIEW

Literature review

In the last few decades, numerous DR techniques have been proposed by research community for alleviation in electricity cost, peak to average ratio (PAR) and imported electricity from external grid. In this section, there have been few studies on the advantages of DR schemes in the residential community. A household tasks scheduling problem is investigated in [18, 19, 20] for electricity bill and peak load reduction. For energy pricing, time of use (ToU) and inclined block rate (IBR) schemes are investigated. Three meta-heuristic algorithms are used for appliances scheduling and problem is formulated by multiple knapsack problem (MKP). Simulation results show the effectiveness in terms of electricity bill and peak load reduction. In [22, 21], a game theory based appliances’ scheduling scheme is adopted. The main objectives of their work are electricity cost and PAR reduction. Their proposed scheme efficiently achieves the defined objectives. However, user comfort is ignored in this work. Another optimization scheme is proposed using heuristic algorithm in [23]. Particle swarm optimization (PSO) is implemented for household appliances’ scheduling. Appliances are shifted from ON-peak to OFF-peak hours and as a result, electricity bill is reduced along with low computational cost. In [24], the authors proposed a scheduling technique along with ToU pricing signals. This scheme reduces the electricity cost, however, it can be implemented only in small areas due to high computation cost. Luna Adriana et al. proposed an energy management system for electricity expenses’ reduction and RESs integration [25]. The basic purpose of RESs integration is to minimize the electricity imported from external grid. Solar panel and wind turbine with battery storage system are considered in their work as a RESs. Simulation results validate their proposed system model, however, RESs installation cost is not considered in this work. A real time pricing (RTP) based DR management scheme is presented using stochastic and robust optimization [26]. They perform monte-carlo simulations and consider time slot 5-minutes for each interval. Results validate their proposed scheme in terms of electricity bill reduction. In [27], a cost minimization scheme is adopted using PL-generalized benders algorithm in residential sector. Multiple homes with multi types of appliances are considered in this work. Simulation results show that their proposed scheme achieves objective efficiently.

8

Thesis by: Sheraz Aslam

CHAPTER 2.

2.1. LITERATURE REVIEW

In [28, 29, 30], an optimal scheduling for smart buildings is proposed. MILP is used in [28] for buildings’ heating and electricity generation are considered simultaneously in this work. The proposed scheme efficiently achieves the defined objectives. An optimization technique which is based on genetic algorithm (GA) and MILP, is proposed to tackle the unit commitment and economic dispatch problem in [31]. Both techniques show high performance, however, computation time of MILP increases when constraints are increased. However, GA performs efficient as compared to MILP for maximum constraints. A dispatch model based on cost saving is presented in [32]. They consider electricity selling from residential sector to office building which is generated from microgrid. EVs are also taken into account in their work. Numerical results show that their proposed model not only reduces the electricity cost, it also maximizes the earning from electricity dispatching to the office building. The microgrid charges EVs in OFF-peak hours and sell the electricity in ON-peak hours by discharging EVs. In [33, 34, 35], a dynamic programming (DP) based electricity cost reduction scheme was proposed. Electricity costs are reduced through scheduling of home appliances from ON-peak to OFF-peak time intervals. Furthermore, the game theory based approach is adopted to interact with the electricity consumers with extra electricity generation. In [36], the electricity cost optimization problem under the ToU environment is presented. Furthermore, they categorize the total load into three categories known as: interruptible load, shiftable load and weather based load. The authors of [37] considered three main objectives for the optimization problem, which are scheduling preference optimization, cost minimization and climatic comfort maximization. The demand response (DR) policy is presented in [38] and intends to obtain PAR reduction and electricity cost savings via scheduling of smart appliances according to hourly electricity prices. The home energy management system is presented in [39] using MILP to adjust the load demand among the PV panel, electric grid, ESS and electric vehicles. An electricity cost minimization scheme using GA was presented in [40], with RES and ESS integration. The ESS is used to balance the electricity supply and load demand. Experimental analysis shows the efficacy of their proposed scheme. An intelligent home energy management scheme was presented in [41] for PAR and electricity cost minimization with the integration of RESs. In [42], an MILP based cost reduction and load balancing scheme is presented in a residential area. A MILP based home energy management system (HEMS) [43] considers electricity users as prosumers. They proposed HEMS for a single smart home and for a community of 39 prosumers. Each smart home has its own PV panel for electricity 9

Thesis by: Sheraz Aslam

CHAPTER 2.

2.1. LITERATURE REVIEW

generation and is also connected with a commercial grid to meet the load demand. The prosumers store electricity in batteries when they have more generation than the requirements. However, they are not able to export electricity in high price hours for maximizing profit. In [44], a scheme is presented for cost minimization via integrating distributed energy sources. Moreover, each consumer has its own solar panel for electricity generation along with battery storage. Electricity consumers are able to sell or purchase electricity according to price signals. A RTP scheme is used in their work for electricity cost calculation. However, this work only considers non-interruptible appliances, which is not realistic for a smart home because there are appliances that can be interrupted, for instance, TV, etc. The authors of [45] studied the trading problem in smart grids. Electricity consumers are able to generate, purchase and sell electricity. However, they put their excessive amount of electricity on an auction market for bidding instead of selling to the main grid or single utility. The authors of [46] proposed a home energy management (HEM) scheme for cost and peak load reduction for single household. They also integrate distributed energy sources, i.e., solar panel and wind turbine in their work, for cost reduction and reliable grid operation. However, weather information is known day ahead in this work. Another cost-efficient scheme is presented in [47], where wind turbine is integrated and wind speed is assumed in advance for one day. In [17], an EV and home appliances scheduling scheme is proposed under the microgrid which is connected with commercial grid. EV is considered as a mobile storage in their work. A building energy management scheme is proposed in [48] for peak load reduction, EV is also integrated as a mobile storage in their work to enhance the performance of their proposed scheme. In [49], the authors presented a scheme which formulate the hybrid renewable energy system, consisting of solar panel, wind turbine, battery storage and diesel generator as a backup source for electricity generation. However, a diesel generator generates electricity very costly and emits a lot of carbon. Real-time weather forecasting is taken into account in their work. The work proposed in [46]-[49] either focused on specific production application or failed to take full advantages from the smart grid factors to design DR techniques. The motivation of this work is to devise an optimal HEM scheme to manage the smart homes activities, which is connected with its own microgrid and EVs charging/discharging. Unlike previous work, we investigate a residential sector with microgrid; consisting of wind turbine and solar panel, which is connected to the external electric grid. MGT is installed instead of diesel generator as a backup 10

Thesis by: Sheraz Aslam

CHAPTER 2.

2.2. PROBLEM STATEMENT

resource for fuel cost and carbon emission minimization. We install mobile storage (EV) as well as the static storage simultaneously, because, EV is intermittent in nature. When EV is not available then demand is met by the static batteries. Furthermore, a day-ahead weather forecasting model based on ANN is implemented for more accurate wind speed and temperature prediction.

2.2

Problem statement

This section presents the problem statement of the thesis. Moreover, the main problem is divided into three subproblems which are presented below.

2.2.1

Problem statement 1:

The authors of [46] proposed a home energy management (HEM) scheme for cost and peak load reduction for single household. They also integrate distributed energy sources, i.e., solar panel and wind turbine in their work, for cost reduction and reliable grid operation. However, weather information is known day ahead in this work. Another cost-efficient scheme is presented in [47], where wind turbine is integrated and wind speed is assumed in advance for one day. In [17], an EV and home appliances scheduling scheme is proposed under the microgrid which is connected with commercial grid. EV is considered as a mobile storage in their work. A building energy management scheme is proposed in [48] for peak load reduction, EV is also integrated as a mobile storage in their work to enhance the performance of their proposed scheme. In [49], the authors presented a scheme which formulate the hybrid renewable energy system, consisting of solar panel, wind turbine, battery storage and diesel generator as a backup source for electricity generation. However, a diesel generator generates electricity very costly and emits a lot of carbon. Real-time weather forecasting is taken into account in their work. The work proposed in [46]-[49] either focused on specific production application or failed to take full advantages from the smart grid factors to design DR techniques. The motivation of this work is to devise an optimal HEM scheme to manage the smart homes activities, which is connected with its own microgrid and EVs charging/discharging. Unlike previous work, we investigate a residential sector with microgrid; consisting of wind turbine and solar panel, which is connected to the external electric grid. MGT is installed instead of diesel generator as a backup resource for fuel cost and carbon emission minimization. We install mobile storage 11

Thesis by: Sheraz Aslam

CHAPTER 2.

2.2. PROBLEM STATEMENT

(EV) as well as the static storage simultaneously, because, EV is intermittent in nature. When EV is not available then demand is met by the static batteries. Furthermore, a day-ahead weather forecasting model based on ANN is implemented for more accurate wind speed and temperature prediction.

2.2.2

Problem statement 2:

An intelligent home energy management scheme was presented in [41] for PAR and electricity cost minimization with the integration of RESs. In [42], an MILP based cost reduction and load balancing scheme is presented in a residential area. An MILP based home energy management system (HEMS) [43] considers electricity users as prosumers. They proposed HEMS for a single smart home and for a community of 39 prosumers. Each smart home has its own PV panel for electricity generation and is also connected with a commercial grid to meet the load demand. The prosumers store electricity in batteries when they have more generation than the requirements. However, they are not able to export electricity in high price hours for maximizing profit. In [44], a scheme is presented for cost minimization via integrating distributed energy sources. Moreover, each consumer has its own solar panel for electricity generation along with battery storage. Electricity consumers are able to sell or purchase electricity according to price signals. A RTP scheme is used in their work for electricity cost calculation. However, this work only considers non-interruptible appliances, which is not realistic for a smart home because there are appliances that can be interrupted, for instance, TV, etc. The authors of [45] studied the trading problem in smart grids. Electricity consumers are able to generate, purchase and sell electricity. However, they put their excessive amount of electricity on an auction market for bidding instead of selling to the main grid or single utility. Nevertheless, the ability of electricity consumers to generate electricity, store electricity and adjust their demand according to electricity tariffs, and selling excess electricity back to the electric grid simultaneously has not been considered in [44, 42, 43, 45]. Here, we propose a novel energy management scheme using CSA and SA to tackle the above-mentioned problems.

12

Thesis by: Sheraz Aslam

Chapter 3 System model and proposed methodology

13

CHAPTER 3.

3.1. SYSTEM MODEL 1:

Solar energy Solar energy gateway

Commercial grid Wind energy Static batteries Solar energy invertor

Wind energy gateway

Invertor Smart meter

MGT Home appliances DC line

…. EVs

Home 1.

Home 2.

AC line Communication line Home n.

Figure 3.1: Proposed system model

3.1

System model 1:

We consider a system model (to tackle the problem 1 which is presented in section 2.2.1) having the features of smart grid with two-way communication. In this work, a smart home u with different smart appliances according to consumer’s needs is considered. Further, the categorization of appliances is explained in the next sub-section. Smart meter is installed at each residence to share price signal and load demand between the utility company and electricity consumers. A microgrid, which consists of solar panel and wind turbine is also considered. Furthermore, energy management controller (EMC) is also installed for appliances’ scheduling according to pricing signals and electricity generation from microgrid. The dynamic electricity tariff, RTP scheme is adopted for electricity cost calculation. The entire time interval is denoted by T and assumed one day in this work. Further, one day is divided into sub-intervals shown by t and each of which has equal time interval. Furthermore, this work is the extension of [50] and the proposed system model is depicted in Fig. 3.4.

14

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1.1

3.1. SYSTEM MODEL 1:

Home appliances

In this section, we explain and categorize the home appliances. Each user u  U has set of smart appliances A and each appliance of smart home a  A. Appliances parameters are taken from [51] and every appliance is scheduled to perform its operation or remained idle in each time slot (hour). Furthermore, these appliances are divided into two main categories: shiftable appliances and non-shiftable appliances denoted by Appsh and Appns , respectively. Shiftable appliances are soft appliances which are easily scheduled from high price to low price hours. We consider vacuum cleaner, dish washer and laptop as shiftable appliances. The hourly and total electricity consumed in a day by all shiftable appliances Appsh are calculated as:

Γtsh =

X

(λsh . αsh (t))

(3.1)

Appsh

ΓTsh =

T X X

(λsh . αsh (t))

(3.2)

t=1 Appsh

where T = 24 and λsh is the power rating of each appliance in shiftable class. αsh (t) denotes the ON or OFF status of each appliance in every time interval (hour).  1 If a is ON sh αsh (t) = (3.3) 0 If a is OF F. sh The second category of appliances consider non-shiftable appliances which are neither shifted nor interrupted during their execution. These type of appliances may not contribute for electricity management or load scheduling. Non-shiftable appliances must perform execution according to predefined pattern. We assume refrigerator and interior lighting as a non-shiftable appliances in our work. The per hour and total electricity consumption (kWh) in a day against such type of appliances is calculated by the equation (3.4) and (3.5), respectively. Γtns =

X

(λns . αns (t))

(3.4)

Appns

ΓTns

=

T X X

(λns . αns (t)).

(3.5)

t=1 Appns

15

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1. SYSTEM MODEL 1: Table 3.1: Parameters of appliances

Appliance category

Shiftable appliances

Nonshiftable appliances

Appliance name Cooker hub Cooker oven Microwave Laptop Desktop Vacuum cleaner Electrical car Dish washer Lighting Refrigerator

γ (kW)

α (h)

β (h)

3 4 1.7 0.1 0.3 1.2

6 15 6 18 18 9

10 20 10 24 24 17

LOT (h) 1 1 1 2 3 1

3.5

18

8

3

3.5 0.84

18 16

8 24

3 6

0.3

1

24

24

Where λns and αns denote the power rating and ON/OFF status of each nonshiftable appliance appns  Appns . αns (t) is explained below:  1 If a is ON ns αns (t) = 0 If a is OF F. ns

3.1.2

(3.6)

Microgrid

A microgrid with couple of RESs is considered in this work for electricity generation. The microgrid consists of solar panel and wind turbine with ESS. The total electricity produced from all RESs m  M in a time slot t  T is calculated by equation (3.2.1). X Et = εm(t). (3.7) mM

Where εm expresses the energy generation from single RES. The total electricity generation from microgrid for whole day is calculated by equation (3.8). T

E =

T X X

εm(t).

(3.8)

t=1 mM

Furthermore, the RESs are intermittent sources of electricity generation; therefore, an ANN is implemented in this work for future prediction. Our proposed system 16

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1. SYSTEM MODEL 1:

model is able to predict wind speed and temperature for the next T slots (day) on the basis of historical data. The detail explanation of RESs is presented in the next section.

3.1.2.1

Wind turbine

The electricity generation from wind turbine is calculated by the equation (3.9). Pt wt = 1/2.Cp .(λ).ρ.A.(Vt wt )3 .

(3.9)

Where Pt wt shows the electricity generation from wind turbine. Wind turbine generates electricity on the basis of air density ρ, area swept by rooter blades A and Vtwt (wind speed). Electricity generation from wind turbine is directly proportional to the wind speed Pt wt ∝ V explained in equation (3.9). When the wind speed increases then the electricity generation from wind turbine also increases and vice versa. The electricity generation is 0 when wind speed Vtwt is less than and grater than cut-in and cut-out speed, respectively. The cut-in speed 3-5 m/s is considered in this study and when wind speed exceeds than 20 m/s, the wind turbine shut down for safety reason and consider cut-out speed [52, 53, 54]. Usually, the wind speed is high in the daytime, and on the other hand, wind speed is slow at nighttime [61]. The relationship between wind speed and electricity generation from wind turbine is depicted in Fig. 3.2. Wind turbine generates constant and maximum electricity at cut-out speed. All wind turbine constraints are presented below:

3.1.2.2

V cut−in ≤ Vtwt ≤ V cut−out

(3.10)

0 = Vtwt ≥ V cut−out ∀t  T

(3.11)

0 = Vtwt ≤ V cut−in ∀t  T.

(3.12)

Solar panel

Electrical energy is produced from solar energy using a system (solar panel) which converts the sunlight into electricity. Solar panel generates electricity in form of 17

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1. SYSTEM MODEL 1:

Power (KW) Rated speed

Cut-out speed

Output power Output power

0

5

15 10 Wind speed (m/s)

20

Figure 3.2: Electricity generation and cut-in, cut-out wind speed [55]

direct current (DC) then converted to alternating current (AC) using invertor. The electricity generated from solar panel is calculated as follows [56, 57, 58]: Ptpv = η pv × Apv × Irrt (1 − 0.005(T empt − 25))

(3.13)

here, Ptpv shows the total hourly electricity generation from solar panel. Solar panel efficiency and area is denoted by η pv and Apv , respectively. Irrt and T empt represent the solar irradiation and temperature, respectively for time slot t. Furthermore, Photovoltaic cells performance models are integrated to obtain a maximum power point (MPP) and current-voltage (I-V) curve, which can help to optimize the photovoltaic cells. Figure 3.3 depicts the I-V curve and MPP.

3.1.3

ESS

ESS is also taken into account for efficient and reliable grid operation. Each smart home u  U equipped with ESS having the storage capability of 3 kWh. ESS stores electricity when microgrid has maximum generation and discharges only when microgrid has minimum generation. However, minimum and maximum charging levels are considered as constraints in advance denoted by ESSmin and ESSmax , respectively. ESS discharges only with in limit due to safety reasons and 18

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1. SYSTEM MODEL 1:

6

MPP 5

Current

4

3

2

1

09:00 12:00 15:00

0 0

5

10

15

20

25

30

35

40

45

50

Voltage

Figure 3.3: I-V curve.

ESS must have minimum 10% electricity in any situation. The stored electricity in ESS is expressed below [62]: SE(t) = SE(t − 1) + k.η ESS .ES ch (t) − k.ES dis (t)/η ESS

(3.14)

EStch ≤ ES(max)

(3.15)

ESStch < ESS(upl)

(3.16)

EStdis ≥ ES(min).

(3.17)

where:

In equation (3.14), SE is the stored electricity in (kWh) at time interval ‘t’, η ESS is the ESS efficiency, ES ch is charging to ESS at time ‘t’ and ES dis is the discharging from ESS at time ’t’.

19

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1.4

3.1. SYSTEM MODEL 1:

EV

We consider the EV as a mobile storage in this work. EV follows a poisson process pattern with randomly distributed energy level for arrival and departure. The EV stays at home for random time interval and then departs for driving. At residence, an EV charges its battery to the maximum storage level EVmax . EV discharges only when electricity generation from microgrid is minimum, ESS have no electricity storage and electricity price is high. The maximum discharging level EVdis also defined for discharging limit. Because, EV must has some charging in emergency situation; so, it can departs to the nearest hospital or emergency center. Furthermore, EV is considered a special type of shiftable load, which can be shifted to any time interval t, i.e., charging, discharging or remaining idle. If the arrival time of EVe is tea and the energy storage level at arrival time is ρEVae , the departure time is ted and the energy storage level is ρEVde . Then the energy consumption of EV e between arrival and departure is calculated as: e

td X EVe = (ψe (t) × αe (t))

(3.18)

t=tea

where, ψe denotes the charging or discharging (Ah) in time slot t and status of EV expressed by αe . If the αe is 1, EV is charging, -1 means discharging and 0 means remain idle, which is expressed below:    1 If EV is charging   αe (t) = 0 If EV is idle    −1 If EV is discharging.

(3.19)

Furthermore, when we consider EV without discharging capabilities then we neglect the -1 status from αe expressed below:   1 If EV is charging αe (t) =  0 If EV is idle.

20

(3.20)

Thesis by: Sheraz Aslam

CHAPTER 3.

3.1.5

3.1. SYSTEM MODEL 1:

MGT

MGTs are electricity generators with easy installation and usually their capacity ranges are 15 to 300 (kW) [59]. We consider MGT as a shiftable energy generation system in this work. It performs operation according to users requirements. Furthermore, MGT generates electricity with minimum cost as compared to diesel generator because natural gas is cheaper as compared to diesel [31]. MGTs also play a significant role for minimizing in carbon emissions as compared to other fossil fuels electricity sources. It is important to note when MGT operates, it generates constant electricity 2kW otherwise 0.

3.1.6

Electricity consumption cost

We define per unit electricity price EPt which is different in each time interval t. RTP scheme is adopted in this work for electricity cost calculation. Electricity consumer tries to alleviate electricity cost by managing electricity consumption. When load is shifted from high price to low price hours, the total cost is automatically reduced. In this work, consumers manage their load in this way, where first, electricity is utilized by microgrid, then storage systems, then external grid and in critical situation of peak demand sometimes load is met by MGT. The per hour electricity consumption cost without microgrid is expressed below:

ζt = [Γtns + Γtsh ] × EPt

(3.21)

where Γtsh and Γtns express the electricity demand against shiftable and nonshiftable appliances, respectively. The total electricity cost for one day is given below: T X ζT = [Γtns + Γtsh ] × EPt . (3.22) t=1

Furthermore, when we consider the microgrid with ESS, EV and MGT, the imported electricity is calculated as:

Φt = [(Γtns + Γtsh ) − (E t + EV t .αev + ESS t .αess + M GT t .αmgt )]

  Φ If Φ > 0 t t Φt =  0 otherwise. 21

(3.23)

(3.24) Thesis by: Sheraz Aslam

CHAPTER 3.

3.1. SYSTEM MODEL 1:

In equation (3.23), Γtns and Γtsh express the total load against shiftable and nonshiftable appliances, respectively. If φt > 0, the electricity is imported from external grid otherwise no electricity would be imported. The total imported electricity per day is calculated in equation (3.25). ΦT =

T X

Φt .

(3.25)

t=1

The hourly and total electricity cost for a day T paid to the external grid is calculated by the equation (3.26) and (3.27), respectively. δt = [Φt × EP t ]

(3.26)

T X δT = [Φt × EP t ].

(3.27)

t=1

3.1.7

Problem formulation

To achieve minimum daily electricity cost and imported load for smart home while integrating microgrid as well as EV and MGT, we can express the objective function of our problem as:

minimize

T X

(Γtsh + Γtns − E t − ESS t − EV t − M GT t ) × EPt (3.28)

t=1

Subject to: E t = Ptpv + Ptwt

(3.29)

Γtns + Γtsh = (E t + EV t + ESS t + M GT t + Φt )

(3.30)

n X

η = LOT (a)

(3.31)

a=1 n X

α≤η≤β

(3.32)

a=1

22

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

Φt ≤ Kl

(3.33)

V cut−in ≤ Vtwt ≤ V cut−out , ∀ t  T

(3.34)

0 < Irrt < Kc, ∀ t  T

(3.35)

0 < ESSmin < ESSmax , ∀ t  T

(3.36)

e e EVmin ≤ ρEVae + EVe ≤ EVmax .

(3.37)

Our formulated model contains multiple decision variables i.e., integer and linear. Therefore, this problem forms a MILP model. We can achieve the optimal schedule for home appliances and EVs according to electricity generation from microgrid. Our proposed model shifts the load from OFF-peak to ON-peak hours and as a result, total electricity cost is reduced. The formulated MILP problem is solved on computer system intel core i7 with RAM of 8 GB and processor 2.8 under the MATLAB environment.

3.2

System model 2:

This work investigates a design of future smart grids that targets the reduction of electricity costs for consumers in a residential area, make electric grid stable and minimize the overall peak load during electric grid operation. Furthermore, this system model is developed for problem statement 2 which is indicated in the section 2.2.2. The smart home equipped with multiple smart appliances with different power ratings and length of operational time (LOT). Furthermore, we consider an electric grid having the features of smart grid (bidirectional communication, efficient monitoring, etc.) with the single utility company. The single utility company provides electricity to the multiple consumers. Each consumer has multiple electricity consuming smart appliances and is also

23

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

equipped with their own distributable energy generation system (EGS), i.e., microgrid. The microgrid consists of the wind turbine and solar panel. These distributed EGSs are intermittent in nature; therefore, to fulfill the load requirements of consumers, ESS is also installed, i.e., batteries. Electricity consumers meet electricity requirements by their own microgrid and the deficit load is imported from the utility or ESS. Sometimes, electricity consumers have surplus power from their usage. In this situation, electricity consumers are able to sell out the surplus electric power to the commercial grid. The proposed optimization model, which is presented in Figure 3.4, is explained below. Solar energy Solar energy gateway

Commercial grid Wind energy Solar energy invertor

Invertor Smart meter Wind energy gateway EMC

Two-way electricity flow

Home appliances

DC line

…. Energy storage system

Home 2.

Home 1.

AC line Communication line Home n.

Figure 3.4: Proposed system model.

3.2.1

Microgrid

We consider the local microgrid with m renewable energy sources, i.e., photovoltaic cells and wind turbine. The total electricity produced by microgrid in time slot t  T and total generation in a day T is expressed by Equations (3.38) and (3.39), respectively: X E(T ) = εm (t), (3.38) mM

E=

T X X t

εm (t).

(3.39)

mM

24

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

In Equations (3.38) and (3.39), t and T represent the single time slot and maximum time slots, respectively. One thing that is important to note is that RESs are intermittent in nature [60]. A lot of statical models exist to predict the future electricity generation from RESs. We explain the components of microgrids briefly in the next section.

3.2.1.1

Solar panel

A solar panel along with constraints is described in detail in section 3.1.2.2.

3.2.1.2

Wind turbine

Please refer to section 3.1.2.1.

3.2.2

ESS

ESS is explained with all system constraints in section 3.1.3.

3.2.3

Household electricity load

In this work, we consider 24 h for implementation, 1 h for each time slot, expressed as: T = {t1 , t2 ......., ........, t24 }. The total time slots in a day represented by T and t shows the single time slot. Furthermore, the household consists of multiple appliances that are further categorized into three main categories: shiftable appliances (as ), non-interruptible appliances (ani ) and base-load appliances (ab ), where as , ani and ab  An (An is the combination of all appliances). Every appliance is further connected with the internet and capable of communicating with the energy management controller (EMC). EMC is also connected with the internet via WiFi, which shifts the appliances operation according to our fitness function. In our system model, every smart appliance must complete its length of operational time. Figure 3.5 represents the appliances’ execution pattern. Where the α describes the possible earliest starting time for each appliance, β presents the possible least ending time for each appliance and η describes the time interval when an appliance performs its execution. Furthermore, the categorization of home appliances is presented in the next section and the parameters regarding appliances are presented in Table 3.2. 25

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

Waiting Time

LOT

w

Figure 3.5: Status of appliances’ execution pattern. Table 3.2: Parameters of appliances

Appliance category

Shiftable appliances

Noninterruptible appliances Base load appliances

3.2.4

Appliance name

Power (kW)

Earliest Starting (h) 6 15 6 18 18 9

Least Finishing (h) 10 20 10 24 24 17

Cooker hub Cooker oven Microwave Laptop Desktop Vacuum cleaner Electrical car Dish washer Washing machine Spin dryer Lighting Refrigerator

3 4 1.7 0.1 0.3 1.2

1 1 1 2 3 1

3.5 3.5 1.5

18 18 7

8 8 12

3 3 2

2.5 0.84 0.3

13 16 1

18 24 24

1 6 24

LOT (h)

Categorization of load

In this section, the categorization of home appliances is uncovered. We have considered a smart home with multiple home appliances in this work [63]. Later, the appliances are divided into three main categories/classes named shiftable, noninterruptible and base load appliances. Each category of appliances has different behaviors and constraints that are explained in detail in the next section.

26

Thesis by: Sheraz Aslam

CHAPTER 3. 3.2.4.1

3.2. SYSTEM MODEL 2:

Shiftable appliances

In this section, shiftable appliances are defined and these types of appliances can be shifted or interrupted in any of the given time period depending upon their necessity. Shiftable appliances class includes the electrical car, vacuum cleaner, laptop, etc. A set of all shiftable appliances are demonstrated by As and as ∈ As demonstrates each appliance in the shiftable category. In Equation (3.40), the power rating for shiftable smart appliances is shown by λs . εs shows the total electricity consumption from the commercial grid or microgrid against shiftable appliances in a day, and is calculated by the equation given below: εs =

X T X t=1

 λs × αs (t) .

(3.40)

as As

The per hour electricity cost that is paid to the commercial grid for all shiftable appliances as can be expressed below: σAt s =

X

(λs × ρ(t) × αs (t)).

(3.41)

as As

The total electricity cost for one day that is paid to the commercial grid for all shiftable appliances As is calculated by: δAT sotal

=

X T X t=1

 (λs × ρ(t) × αs (t)) .

(3.42)

as As

Here, αs (t) shows the ON/OFF (i.e., in form of 1 or 0) states of each shiftable appliances.  1, If a is ON, s αs (t) = (3.43) 0, If a is OF F. s

3.2.4.2

Non-interruptible appliances

In this section, we define the second category of appliances named non-interruptible appliances. This type of appliance may not be interrupted when execution starts but shifted to any time slot before starting their execution. The operation time of non-interruptible appliances cannot be changed. However, this type of appliance may be scheduled between possible earliest starting and possible least ending time. Let ani ∈ Ani represent each appliance in this category. The λni and εni express 27

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

the power rating and electricity consumption of these types of appliances, respectively. The electricity consumption per day against these types of appliances is calculated in Equation (3.44): εni =

T  X X t=1

 (λni × αni (t)) .

(3.44)

ani An i

The hourly and per day total electricity cost can be calculated using Equations (3.45) and (3.46), respectively: X

σat ni =

(λni × ρ(t) × αni (t)),

(3.45)

ani An i

δaTniotal

=

T  X X t=1

 (λni × ρ(t) × αni (t)) .

(3.46)

ani Ani

Here, αb (t) presents the ON/OFF (i.e., in form of 1 or 0) states of non-interruptible appliances.  1, If a is ON, ni αb (t) = (3.47) 0, If a is OF F. ni

3.2.4.3

Base-load appliances

The base-load appliances Ab are such types of appliances that cannot be shifted or interrupted while performing their operations. Generally, these appliances considered the main load of any household; these appliances are also called non-shiftable and non-interruptible appliances. We consider interior lighting and refrigerators as base load appliances. Let ab ∈ Ab represent a single appliance from the base-load appliances’ category. The λb presents the power rating of each appliance in this category and total consumed electricity εb in a day is calculated as: εb =

T  X X t=1

 (λb × αb (t)) .

(3.48)

ab Ab

The hourly and per day cost against consumed electricity is calculated by Equations (3.49) and (3.50), respectively: σat b =

X

(λb × ρ(t) × αb (t)),

(3.49)

ab Ab

28

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

δaTbotal

=

T  X X t=1

 (λb × ρ(t) × αb (t)) .

(3.50)

ab Ab

In Equation (3.49), the ON/OFF status of base load appliances is presented by αb (t):  1, If a is ON, b (3.51) αb (t) = 0, If a is OF F. b

3.2.5

Electricity tariff and bill calculation

An Electricity tariff is another dynamic attribute of our proposed system model. The utility company provides different electricity tariffs for consumers’ motivation to manage their load requirements. In this work, we consider the RTP signals to calculate the electricity consumption cost. There are two different electricity rates for each time slot (hour); one rate is for electricity purchasing EP pur and the other rate for excess electricity selling EP sell to the commercial grid. However, the electricity selling rate is 90% of the purchasing rate in each hour [64], calculated in Equation (3.52). The selling and purchasing electricity tariff is presented in Figure 3.6: EP sell = EP pur × 0.90. (3.52) The consumers pay the total costs to utilities against consumed electricity. The 30 Buy from Utility Sell to Utility

Electricity Price (cents)

25

20

15

10

5 0

4

8

12

16

20

24

Time (hours)

Figure 3.6: Hourly electricity purchasing and selling rates.

electricity cost for a single time interval (hour) without and with microgrid integration is calculated by Equations (3.53) and (3.54), respectively. First, the 29

Thesis by: Sheraz Aslam

CHAPTER 3.

3.2. SYSTEM MODEL 2:

consumer utilizes electricity from the microgrid in any hour. Then, the remaining electricity demand is purchased from the commercial grid: σt =

X (λan × ρ(t) × α(t)),

(3.53)

an

 X   ς = (λan × α(t)) − E(t) × EP pur (t). t

(3.54)

an

Similarly, the total cost per day without microgrid and with microgrid is computed by Equations (3.55) and (3.56), respectively: δ

T otal

=

X 24 X t=1

ς

T otal

(λan

 × ρ(t) × α(t)) ,

 X  24 X  = (λan × α(t)) − E(t) × EP pur (t). t=1

(3.55)

an

(3.56)

an

The decision is taken at the start of each hour against selling, purchasing or storing the electricity. When the electricity rate is cheaper, the smart home tries to purchase electricity for load demand. The generated electricity from microgrids is stored in ESS for future trading. In ON-peak hours, the smart home meets the load from the microgrid or ESS and excess electricity is sold back to the commercial grid calculated in Equation (3.57): η sell (t) =

X

 (λAn × α(t)) − [E(t) + ESS],

(3.57)

an

where η sell (t) =

 η sell (t),

If η sell (t) < 0,

0,

otherwise.

(3.58)

The total amount of exported electricity to the local grid is computed by the following Equation (3.59): T X T η = [η sell (t)]. (3.59) t=1

The earnings from a commercial grid hourly basis and total for a day is presented in Equations (3.60) and (3.61), respectively: %earn (t) = η sell (t) × EP sell (t),

30

(3.60)

Thesis by: Sheraz Aslam

CHAPTER 3.

3.3. PROPOSED SCHEMES

%T =

T X

[η sell (t) × EP sell (t)].

(3.61)

t=1

3.3

Proposed schemes

A smart meter is installed at every residence (smart home) in the smart grid environment and further EMC is connected with the smart meter. Two-way communication is only possible between electricity consumers and utilities via smart meters. In this work, we investigate the heuristic approaches to solve scheduling and trading problems. CSA and SA are implemented for cost and PAR minimization along with profit maximization. These algorithms make decisions on the basis of electricity generation from the microgrid, price and load in that hour. First, a detailed introduction of SA and CSA is uncovered in this section, and then procedures of SA and CSA in our scheduling and trading problem are explained.

3.3.1

CSA

CSA belongs to a nature-inspired meta-heuristic algorithm family proposed in [65]. CSA solves the optimization problems on the basis of the breading behavior of some cuckoo species, features of L`evy flights of some birds and fruit flies. Some cuckoo species put their eggs in the other birds’ nests, which are randomly chosen and these nests are called host nests. The owners of these nests may discover the eggs laid by other cuckoos for breeding. CSA has some rules and finds the best solution via the following rules mentioned below: • Every cuckoo lays only one egg in the randomly chosen nest. • Only the high-quality nests with the high quality eggs are considered for the next generation. • Host nests are fixed and the host birds discover the eggs. In this work, CSA begins finding the best solution locally from randomly laid eggs (1,0). Each egg laid by cuckoos shows possible solutions and the egg pattern (1,0) shows the ON/OFF status of the appliances, respectively, in each time slot. Every egg (that shows possible solutions) is evaluated in terms of our fitness function: PAR and cost alleviation with maximum earnings. After searching for local solutions (hourly solutions), CSA performs a regeneration step, which is performed 31

Thesis by: Sheraz Aslam

CHAPTER 3.

3.3. PROPOSED SCHEMES

on the basis of the best quality of eggs (best local solutions). The discovering probability rate is 0.250 and the parameters of CSA in our work are presented in Table 3.3. For searching for the best global solution, new solutions X (t+1) are reproduced via L`evy flights for a cuckooi [65]: (t+1)

Xi

(t)

= Xi + α ⊕ Levy(λ).

(3.62)

Birds or animals search for their food randomly by nature. The randomization has a significant role in the population based techniques. A L`evy flight is a random walk in which step lengths are distributed by a high probability distribution. To search for the best global solution as well as generate randomness in the next reproduction, L`evy flight is performed. Table 3.3: Parameters of CSA.

3.3.2

Parameters

Values

Host nests Iterations Discovery-rate n

50 2000 0.250 12

SA

SA is meta-heuristic nature inspired algorithm which is based on the strawberry plant presented in [66]. Sometimes SA is also called plant propagation algorithm (PPA). Plants are very intelligent species and plants propagate via runners. Plants manage its survival on the basis of nutrients, light, water and toxic substances. If a plant is in good location/place where it finds enough water, nutrients, etc. then it will never leave this place. In another case, if the plant is in a location, where water, light and nutrients are minimum then it would try to change the location of offspring by sending long runners for finding the optimal location for its survival. The process of sending long runners is called exploration. The plants send few long runners because long runners need maximum sources calculated in Equation (3.63). It is difficult to provide sources to runners especially when the plant is in a not good location with no light and other requirements. Environmental factor decides the location, whether it is good or bad. This underlying propagation strategy is developed for plant survival. Therefore sometimes this is also called PPA which imitates the propagation of plants. A set of some parameters required 32

Thesis by: Sheraz Aslam

CHAPTER 3.

3.4. CASE STUDIES

in SA which are explained in Table 3.4. The population generation in SA is performed via Equation (3.64): r2 = [r1 + drunner ∗ (rand(m, N ) − .5)r1 + droot ∗ (rand(m, N ) − .5)], (3.63)

r1 = ul + (uh − ul). ∗ rand(m, N ).

(3.64)

In our work, SA generates population in the form of 1 and 0 using Equation (3.64). Each binary number shows a solution for a particular time slot and the binary number represents ON or OFF status of appliances. The SA starts finding the local solution (best locations) via runners on the basis of our defined fitness function, which is cost and PAR reduction with earnings maximization. SA then tries to search for global solutions by performing reproduction steps on the basis of local solutions (best locations). Table 3.4: Parameters of SA.

3.4

Parameters

Values

Population size Runners Roots Iterations n

100 50 10 2000 12

Case studies

In this section, three case studies are presented to demonstrate the performance of our proposed scheme from both the perspectives of the smart home/consumer and the electric grid while solving problem 2, presented in section 2.2.2. In the first case study, the home has no intelligence capabilities; put simply, we consider a conventional home and the electric grid. The home purchases and utilizes the electricity conventionally without knowing the electricity tariff. In the other two cases, households with different properties are considered (i.e., integration of wind turbine, solar panel and ESS) and compared with each other from both customer and electric grid perspectives. Each case study has a transient phase in which every smart home makes autonomous decisions in interaction with the electric grid; the smart home can purchase, sell, store the electricity or shift the load. 33

Thesis by: Sheraz Aslam

CHAPTER 3.

3.4. CASE STUDIES

Eventually, the overall performance of the proposed system will reach equilibrium. Multiple parameters defined for our case studies are shown in Table 3.5, where cap cap are average hourly electricity generation from a wind windcap h , solarh and ESS turbine, solar panel and average storage capacity of ESS, respectively. V cut−in and V cut−out show the cut-in and cut-out speed of wind where the wind turbine generates minimum and maximum electricity, respectively. Furthermore, we also consider assumptions for the operation of ESS. The minimum remaining storage, maximum charging level and rate of charging/discharging are the constraints that are considered in this work. Table 3.5: Input parameters for case studies.

Parameters

Values

windcap solarcap V cut−in V cut−out ESS cap SOC η ESS

2 kW 1 kW 5 25 5 kW 90% 95%

34

Thesis by: Sheraz Aslam

Chapter 4 Simulation results and discussions

35

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING

4.1

An optimal home energy management considering microgrid with real-time weather forecasting

To show legitimacy and productiveness of our proposed methodology, we have performed simulations in order to show an optimal scheduling for home appliances as well as for EVs. This section tackles the problem which is identified in section 2.2.1. The effectiveness of our proposed work is evaluated in terms of electricity cost and PAR minimization with the optimal utilization of electricity generated from own microgrid. A MILP technique is implemented to analyze the performance of our proposed system. We design a system model for a smart home; comprising of 10 smart appliances, where each appliance is connected with the EMC via internet (WIFI) and EMC takes decision against each appliance according to electricity tariff to turn ON or OFF . Furthermore, these 10 smart appliances are categorized into 2 different categories explained in detail in section 3.1.1. All the smart appliances with their parametric values which are considered in our simulations are shown in table 3.2. Nonshiftable appliances do not play any significant role to manage load and reduce electricity cost because these are not scheduled and must perform their operation in defined time intervals which is defined by electricity consumers. Shiftable appliances may contribute a huge part for reducing PAR and electricity cost via shifting from high price to low price hours. Additionally, we consider 24 hours for simulations. We have examined our proposed scheme in 2 case studies: (I) HEM without microgrid and EVs (II) HEM with microgrid and EVs. In the next subsection, the simulation results of the first case are uncovered.

4.1.1

HEM without microgrid

In this section, we uncover the simulation results of HEM without microgrid, where we minimize the electricity cost and PAR without integrating microgrid. We reduce the electricity cost via scheduling the home appliances from ON-peak to OFF-peak hours. The Fig. 4.17 depicts the hourly electricity consumption with and without proposed technique. The pricing signals are also presented in Fig. 4.17 and it is clearly examined that electricity consumption is high in ON-peak hours when the scheme 36

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 30

15

10

10

5

cents/kWh

20

0 0

5

10

15

20

Electricity load (kWh)

RTP signals MILP w/o microgrid load Unscheduled load

0 25

Time (hours)

Figure 4.1: Hourly electricity consumption

is not implemented. However, our proposed scheme minimizes the electricity consumption in ON-peak hours via efficiently shifting the load towards OFF-peak hours. Note that our proposed scheme only shifts the category A load which consists of shiftable appliances. The time slots 8-11 are ON-peak hours and the Fig 4.17 depicts that all shiftable appliances are turned OFF, only non-shiftable appliances are turned ON. The Fig. 4.15 represents the hourly electricity cost for both cases unscheduled and with our proposed scheme without microgrid integration. We reduce the hourly electricity cost while minimizing the hourly peaks and as a result, we achieve optimal scheduling for the smart home. The electricity cost for one day is shown in Fig. 4.16. The results show that the electricity cost is low using our proposed technique as compared to unscheduled electricity consumption. The proposed scheme minimizes the 45% electricity cost which is favorable for electricity consumers. Furthermore, the proposed scheme also minimizes the PAR which is beneficial for reliable grid operation. The PAR result of the proposed scheme and unscheduled consumption is depicted in Fig. 4.18. The results clearly demonstrate that PAR is minimum as compared to the unscheduled case and the PAR reduction is approximately 48% through implementing the proposed scheme.

37

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 350 Unscheduled cost MILP cost w/o microgrid

300

Cost (cents/kWh)

250

200

150

100

50

0 0

5

10

15

20

25

Time (hours)

Figure 4.2: Hourly electricity cost

1200

Total Cost (cents)

1000

800

600

400

200

0 Unschedule cost

MILP w/o RES cost

MILP with RES cost

Figure 4.3: Total electricity cost

4.1.2

HEM with microgrid

In this section, we further carry out the simulation for the scenario HEM with microgrid and the simulation results are uncovered. The objective function of this study is explained in equation (3.63) and further constraints of this work are 38

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 4.5 4 3.5

PAR

3 2.5 2 1.5 1 0.5 0 Unscheduled

MILP w/o microgrid

MILP with microgrid

Figure 4.4: PAR

presented in equation (3.29)-(3.37). We have considered wind turbine and solar panel with MGT and ESS in microgrid. Wind turbine and solar panel are intermittent in nature and depending on wind speed and solar irradiation respectively. The Fig. 4.19 demonstrates the hourly electricity generation from wind turbine and solar panel. The results show that electricity generation is high in day time

2.5 Wind generation PV generation

Electricity generation (kWh)

2

1.5

1

0.5

0 0

5

10

15

20

25

Time (hours)

Figure 4.5: Microgrid generation

39

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING when solar has high irradiation. On the other side, electricity generation is 0 or minimum at night time or when solar has low irradiation. Moreover, wind turbine generates maximum electricity when wind speed is maximum, however, less than the cut-out speed. The cut-in speed and cut-out speed are explained in Section 3.1.2.1. Furthermore, day-ahead temperature and wind speed is predicted using an ANN for accurate energy management. Fig. 4.6 and 4.7 show the predicted and real time values of wind speed and temperature, respectively. Results present that our proposed historical based ANN model shows high accuracy in terms of wind speed and temperature prediction. The Fig. 4.8 presents the optimal load demand and electricity generation from the solar panel and wind turbine. The results demonstrate that electricity demand is low during high price hours by our proposed optimal technique and in that hours electricity generation from microgrid is also maximum. Our proposed scheme meet total demand in ON-peak hour from microgrid generation. Nevertheless, in whole day our proposed scheme utilizes electricity from microgrid and remaining demand is met by the utility company. 18 ANN forecast Real value

16

Wind speed (m/s)

14 12 10 8 6 4 2 0 0

5

10

15

20

25

Time (hour)

Figure 4.6: Wind speed prediction for wind turbine generation using ANN

The Fig. 4.9 shows the hourly electricity purchased from external grid and total electricity demand for single home. The results clearly demonstrate that when the electricity price is high, our proposed scheme minimizes the load and the total load is met by the microgrid. When electricity rates are low then our proposed scheme purchases the electricity from the external grid. Furthermore, Fig. 4.9 depicts the 40

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 24 ANN forecast Actual value

23

Temperature (C)

22

21

20

19

18

17 0

5

10

15

20

25

Time (hour)

Figure 4.7: Temperature prediction for solar generation using ANN

Electicity generation/demand (kWh/h)

6

Optimal demand

Wind turbine

Solar panel

5

4

3

2

1

0 5

10

15

20

25

Time (hour)

Figure 4.8: Electricity demand and generation

RES contribution curve which demonstrates the RES contribution while meeting the electricity demand for the whole day. We minimize the imported load and as a result, reduce electricity cost and load burden on the external grid. The Fig. 4.10 represents the total demand, imported electricity with and without EV discharging. Hourly electricity generation from wind turbine is also depicted 41

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 6 Optimal demand Imported electricity

Electricity/load (kWh)

5

4

3

2

1

0 0

5

10

15

20

25

Hours in a day

Figure 4.9: Hourly imported electricity and optimal demand

in Fig. 4.10. Results clearly show that our proposed scheme minimize the imported electricity in On-peak hours. Furthermore, when EV is considered with discharging capabilities then the imported electricity is more reduced as compared to considering EV without discharging features. In addition, EV is considered for both driving and mobile storage purposes. Therefore, EV goes for driving randomly and other time performs functionalities of mobile storage. The Fig. 4.11 shows the EV charging and discharging as well as total electricity generation from all sources of microgrid. It is clearly seen from Fig. 4.11, the EV performs charging operation when electricity generation is maximum. On the other side, EV performs discharging operation when electricity generation is minimum from microgrid. Furthermore, in first hour, we consider EV has full charging which is seen in Fig. 4.11. The contribution EV and ESS in minimizing the electricity cost and PAR is depicted in Fig. 4.12. The results demonstrate that the EV and ESS contribute in those hours when demand is high or microgrid has minimum electricity generation. The consumer utilizes load from ESS or EV instead of purchasing from external grid. As a result, electricity cost and PAR are reduced. Furthermore, MGT is considered for peak load reduction. However, when MGT is ON, the electricity generation from MGT is 2kW otherwise 0. MGT performs its operation only when the demand is greater than the defined threshold Kl of importing load in any time slot. It is clearly seen from Fig. 4.13, MGT is ON in 16, 22 and 24 time slots, 42

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 6 Load Imported electricity w/o EV discharging Imported electricity with EV discharging Wind generation

Electricity/load (kWh)

5

4

3

2

1

0 0

5

10

15

20

25

Hours in a day

Figure 4.10: Total electricity imported with and w/o EV discharging

3 Charging and discharging Electricity generation from RES

2.5

Electricity (kWh)

2 1.5 1 0.5 0 -0.5 -1 0

5

10

15

20

25

Time (hours)

Figure 4.11: EV charging/discharging with electricity generation

when load demand is greater than defined threshold ki and due to this, PAR is minimized.

43

Thesis by: Sheraz Aslam

4.1. AN OPTIMAL HOME ENERGY MANAGEMENT CONSIDERING CHAPTER 4. MICROGRID WITH REAL-TIME WEATHER FORECASTING 6 Load EV contribution ESS contribution

Electricity/load (kWh)

5

4

3

2

1

0 0

5

10

15

20

25

Hours in a day

Figure 4.12: Hourly EV and ESS contribution

6 Total demand Generater contribution

Electricity/load (kWh)

5

4

3

2

1

0 0

5

10

15

20

25

Hours in a day

Figure 4.13: Optimal demand and MGT contribution in minimizing PAR

44

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS

4.2

An optimal home energy management and power trading in grid-connected microgrids

This section describes the results of problem 2 which is presented in section 2.2.2. To evaluate and demonstrate the versatility of our proposed scheme, simulations are carried out. Then, simulation results are shown to uncover an optimal scheduling and power trading for the household. We perform simulations multiple times and then we present the results’ average of 20 runs. Two algorithms (CSA and SA) are implemented to critically analyze and validate our proposed scheme. We consider a smart home consisting of 12 different smart appliances and each have different living habits (i.e., power rating and LOT) explained in Table 3.2. Furthermore, these appliances are categorized into three different categories (see Section 3.2.4). All of the appliances’ parameters that are used in our simulations are presented in Table 3.2. Base-load appliances may not contribute to minimizing electricity costs or PAR because these appliances cannot be shifted and must be ON according to user preferences. In our simulation setting, the operation time is considered 24 slots, 1-h each, beginning from 8 a.m. to 8 a.m. on the next day. We consider RTP signals for electricity cost calculation and RTP signals are presented in Figure 3.6. Experiments/simulations of our proposed model were executed on a computer system with an Intel Core i7 CPU 2.8 GHz processor, 8 GB RAM, and Windows 10 Operating system. Furthermore, MATLAB is used as a simulator in this work.

4.2.1

Case 1: home without energy management and microgrid

In this case, we have studied the operation of a conventional home without a microgrid and ESS integration. This conventional home is not able to manage its electricity consumption and does not have any excess electricity to sell back to the electric grid. In addition, the home cannot make any decisions about electricity usage. It blindly purchases and utilizes electricity while ignoring the electricity tariff or any other parameters. Figure 4.14 depicts the electricity bought by conventional homes from electric grid and pricing signals. The results clearly demonstrate that the conventional home ignores the pricing signals and blindly utilizes the electricity. The conventional 45

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS home purchases electricity in time slots 9 and 10 when the price is at a maximum and also creates peaks due to maximum electricity consumption. Therefore, the conventional home would pay maximum electricity costs against blind utilization of electricity. The hourly and total electricity cost against unscheduled consumption are presented in Figures 4.15 and 4.16, respectively. However, the results presented in this section consider a baseline for our later comparisons.

40

10

20

5

0 0

5

10

15

20

Electricity load (kWh)

Electricity price (kWh/cents)

RTP signals Unscheduled load

0 25

Time (hours)

Figure 4.14: Pricing signals and electricity consumption.

4.2.2

Case 2: home with energy management but without microgrid

Energy management of a home is considered in this case and the smart home is able to manage its electricity consumption. The shiftable appliances may have shifted from ON-peak to OFF-peak hours. EMC is installed in this case and EMC shifts the load according to price and load information. Figure 4.17 represents the hourly electricity consumption without energy management and with energy management using SA and CSA. The result demonstrates that electricity consumption is high without energy management in ON-peak hours; however, electricity consumption is low in ON-peak hours using SA and CSA. Our proposed algorithms efficiently shift the load while minimizing the PAR, which is presented in Figure 4.18. CSA shows high performance for PAR reduction as compared to SA and 46

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS 200

Unscheduled SA CSA

180 160

Cost (cents/kWh)

140 120 100 80 60 40 20 0 0

5

10

15

20

25

Time (hours)

Figure 4.15: Hourly electricity cost.

800 700

Total cost (cents)

600 500 400 300 200 100 0 Unschedule

SA

CSA

Figure 4.16: Total cost.

an unscheduled case. The PAR reduction is 15% and 45% using SA and CSA, respectively. We minimize the hourly electricity cost by energy management, and, eventually, per day total electricity cost is minimized. Figure 4.15 depicts the hourly electricity cost, which clearly shows that electricity cost is at a minimum in ON-peak hours using our proposed scheme, as compared to unscheduled energy consumption patterns. The total electricity consumption cost against one day is 47

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS 8

Unscheduled SA CSA

7

Load (kWh)

6 5 4 3 2 1 0 0

5

10

15

20

25

Time (hours)

Figure 4.17: Hourly electricity consumption.

presented in Figure 4.16. It may be observed from the results that the electricity cost is at a minimum using CSA when we compare with SA and unscheduled consumption of electricity. However, the electricity cost paid using SA is lower than the unscheduled electricity consumption. In case 2, the total electricity cost reduction is 26% and 36% using SA and CSA, respectively. 4 3.5 3

PAR

2.5 2 1.5 1 0.5 0 Unscheduled

SA

CSA

Figure 4.18: PAR.

48

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS

4.2.3

Case 3: home with energy management and microgrid

In this case, the smart home is similar to case 2; however, a microgrid with ESS is considered here. The smart home is able to make decisions at every hour to shift the load, purchase, sell or store electricity. In this case, a smart home imports electricity when rates are low and in ON-peak hours the load requirement is met by the microgrid, and the excess electricity is sold back to the commercial grid against high prices. The smart home earns maximum profit with this activity. Figure 4.19 shows the electricity generation from a wind turbine and solar panel. The electricity generation from the microgrid is at a maximum in ON-peak hours because, in the daytime, the wind speed and solar irradiation are at a maximum. However, the electricity generation is low at nighttime or in the morning when solar irradiation and wind speed are minimum or 0. Figures 4.20 and 4.21 represent the relationship of electricity generation from a wind turbine and wind speed, and electricity generation from solar panels and temperature, respectively. When wind speed is at a maximum, electricity generation is at a maximum and vice versa. 2.5

Electricity Generation (kWh/h)

Wind Turbine Solar Panal

2

1.5

1

0.5

0 4

8

12

16

20

24

Time/Hours

Figure 4.19: Electricity generation from wind turbines and solar panels.

The total imported and sold electricity by both algorithms SA and CSA are presented in Figure 4.22. The results represent both algorithms showing high performance. Firstly, load is shifted in OFF-peak hours and then the generated and stored electricity in ON-peak hours is sold. If a home performs this act efficiently, 49

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS 4

20

2

10

0 0

5

10

15

Wind Spead (m/s)

WT Generation (kWh)

WT Generation Wind Spead

0 25

20

Time (hours)

Figure 4.20: Relationship between electricity generation from wind turbines and wind speed. 1

30

0.5

20

0 0

5

10

15

20

Temprature of the Day

PV Generation (kWh)

PV Generation Temprature

10 25

Time (hours)

Figure 4.21: Relationship between electricity generation from solar panels and temperature.

it earns a maximum profit through electricity trading. Furthermore, our proposed CSA shows high performance as compared to SA in terms of load shifting and power selling in high price hours. Figure 4.23 depicts the total electricity cost against imported electricity and total earnings against sold electricity. Our proposed algorithm CSA shows supremacy in terms of electricity cost reduction and earnings maximization as compared to SA. The basic reason behind efficacy of CSA is that CSA has lesser parameters to be fine-tuned. 50

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS 30

5 Pricing signals Sold electricity using SA Sold electricity using CSA Imported electricity using SA Imported electricity using CSA

4

20

3

15

2

10

1

5 0

5

10

15

20

Electricity load (kWh)

Electricity price (cents/kWh)

25

0 25

Hours in a day

Figure 4.22: Sold and imported electricity with pricing signals.

800 700

Total cost (cents)

600 500 400 300 200 100 0 Unschedule

SA cost

SA earning

CSA cost

CSA earning

Figure 4.23: Cost and earnings against imported and sold electricity.

4.2.4

Performance comparison

In this section, we provide the comparison of the three case studies previously presented and our proposed scheme using SA with CSA. According to Figure 4.16, the proposed scheme using SA and CSA minimized the total electricity cost as compared to case 1. Furthermore, when we compare case 2 with case 3, the 51

Thesis by: Sheraz Aslam

4.2. AN OPTIMAL HOME ENERGY MANAGEMENT AND POWER CHAPTER 4. TRADING IN GRID-CONNECTED MICROGRIDS electricity cost is reduced more in case 3 and presented in Figure 4.23. The total imported electricity from the external grid is also minimized in case 3 when we compare with case 1 and case 2, which is shown in Figure 4.22. Figure 4.18 shows the PAR against case 1 and case 2, and results clearly demonstrate that case 2 has minimum PAR as compared to case 1. In case 3, ESS is also taken into account for reliable and stable grid operation. Nevertheless, power trading is only possible in case 3 and the total revenue generated from power trading is depicted in Figure 4.23. The overall comparison is presented in Table 4.1. It is clearly seen from Table 4.1 that our proposed scheme using CSA outperforms as compared to SA in all case studies. Table 4.1: Performance comparison.

Parameters Technique Cost (cents) PAR Cost savings Earnings (cents)

Case 1 766 3.99 0 0

Case 2 SA 562.02 3.63 26.63% 0

52

CSA 487.43 2.29 36.42% 0

Case 3 SA 335.74 3.12 56.26% 173.39

CSA 284.70 1.98 62.83% 249.39

Thesis by: Sheraz Aslam

Chapter 5 Conclusion and future work

53

CHAPTER 5.

5.1

5.1. CONCLUSION

Conclusion

With the advent of smart grid technologies, DR has become the key enabling technology to balance the electricity demand and supply. In this work, a DR scheme is proposed for electricity cost and PAR reduction based on RTP signals in the residential area. A smart home has multiple appliances, EV and own microgrid for electricity generation which is empowered by RESs. A historical data based ANN model is also implemented for accurate day-ahead weather (wind speed and temperature) prediction. Furthermore, the microgrid considers EV as a mobile storage with both charging and discharging capabilities. The problem is formulated as a MILP problem and solved optimally. The simulation results describe that our proposed MILP scheme is able to schedule smart appliances and EV according to microgrid electricity generation pattern. As a result, imported electricity from the external grid, PAR and the total cost are reduced. By implementing our proposed scheme, electricity cost is reduced by 45% and 80% without and with microgrid integration, respectively. Furthermore, comparison of EVs with and without discharging capabilities is provided. Furthermore, an electricity load management scheme is developed using SA and CSA along with an RTP scheme for power trading between consumers and commercial grid. We have considered the load scheduling and power trading problem simultaneously in a smart home that has a grid-connected microgrid. An ESS is also installed to enhance the microgrid performance and reliable grid operation. The smart home makes autonomous decisions against selling, purchasing or storing electricity according to electricity generation and pricing signals. Furthermore, a comparison of different case studies has been provided to investigate the effectiveness of our proposed scheme. Simulation results demonstrate that our proposed scheme outperforms in terms of electricity cost and PAR reduction with maximizing the earnings. It has been observed from simulation results that the proposed scheme using SA and CSA minimized the electricity cost by 26.63% and 36.42%, respectively, in case 2, and by 56.26% and 62.83%, respectively, in case 3. In addition, our proposed scheme using SA and CSA earns 173.39 and 249.39 (cents), respectively. The overall performance of CSA is superior to SA because the CSA spends a maximum amount of time on global search instead of local search.

54

Thesis by: Sheraz Aslam

CHAPTER 5.

5.2

5.2. FUTURE WORK

Future work

In future, we will investigate the performance of our proposed scheme in other electricity consuming sectors. Furthermore, case studies of real-time DR programs will extremely desirable to test the performance of same technique.

55

Thesis by: Sheraz Aslam

Chapter 6 References

56

References

[1] Gungor, Vehbi C., Dilan Sahin, Taskin Kocak, Salih Ergut, Concettina Buccella, Carlo Cecati, and Gerhard P. Hancke. ”Smart grid and smart homes: Key players and pilot projects.” IEEE Industrial Electronics Magazine 6, no. 4 (2012): 18-34. [2] SANTHOSHKUMAR, R., PG SCHOLAR, and P. KRISHNA GANDHI. ”Optimal Scheduling For Distribution System Using Advanced Metering Infrastructure with Smart Micro Grid.” (2014). [3] Benzi, Francesco, Norma Anglani, Ezio Bassi, and Lucia Frosini. ”Electricity smart meters interfacing the households.” IEEE Transactions on Industrial Electronics 58, no. 10 (2011): 4487-4494. [4] Hafeez, Ghulam, Nadeem Javaid, Sohail Iqbal, and Farman Ali Khan. ”Optimal Residential Load Scheduling Under Utility and Rooftop Photovoltaic Units.” Energies 11, no. 3 (2018): 611. [5] Asif Khan, Nadeem Javaid, Adnan Ahmad, Mariam Akbar, Zahoor Ali Khan, and Manzoor Ilahi, ”A priority-induced demand side management system to mitigate rebound peaks using multiple knapsack”, Journal of Ambient Intelligence and Humanized Computing 2018, ISSN: 1868-5137. doi: 10.1007/s12652018-0761-z. [6] Evangelisti, S.; Lettieri, P.; Clift, R.; Borello, D. Distributed generation by energy from waste technology: A life cycle perspective. Process Saf. Environ. Prot. 2015, 93, 161–172. [7] Samuel, Omaji, Nadeem Javaid, Mahmood Ashraf, Farruh Ishmanov, Muhammad Khalil Afzal, and Zahoor Ali Khan. ”Jaya based Optimization Method with High Dispatchable Distributed Generation for Residential Microgrid.” Energies 11, no. 6 (2018): 1-29. [8] Mondal, Ayan, Sudip Misra, and Mohammad S. Obaidat. ”Distributed home energy management system with storage in smart grid using game theory.” IEEE Systems Journal 11, no. 3 (2017): 1857-1866. [9] Aktas, Ahmet, Koray Erhan, Sule Ozdemir, and Engin Ozdemir. ”Experimental investigation of a new smart energy management algorithm for a hybrid energy storage system in smart grid applications.” Electric Power Systems Research 144 (2017): 185-196. 57

REFERENCES

REFERENCES

[10] Tascikaraoglu, A.; Boynuegri, A.R.; Uzunoglu, M. A demand side management strategy based on forecasting of residential renewable sources: A smart home system in Turkey. Energy Build. 2014, 80, 309–320. [11] Demand Side Response in the Domestic Sector—A Literature Review of Major Trial ; Department of Energy and Climate Change: London, UK, 2012. [12] Kim, Byung-Gook, Shaolei Ren, Mihaela van der Schaar, and Jang-Won Lee. ”Bidirectional energy trading and residential load scheduling with electric vehicles in the smart grid.” IEEE Journal on Selected Areas in Communications 31, no. 7 (2013): 1219-1234. [13] Kim, Byung-Gook, Shaolei Ren, Mihaela van der Schaar, and Jang-Won Lee. “Bidirectional energy trading and residential load scheduling with electric vehicles in the smart grid.” IEEE Journal on Selected Areas in Communications 31, no. 7 (2013): 1219-1234. [14] Cai, Lin, Jianping Pan, Lian Zhao, and Xuemin Shen. ”Networked electric vehicles for green intelligent transportation.” IEEE Communications Standards Magazine 1, no. 2 (2017): 77-83. [15] Aslam, Sheraz, Zafar Iqbal, Nadeem Javaid, Zahoor Ali Khan, Khursheed Aurangzeb, and Syed Itaza Haider. ”Towards Efficient Energy Management of Smart Buildings Exploiting Heuristic Optimization with Real Time and Critical Peak Pricing Schemes.” Energies 10, no. 12 (2017): 2065. [16] Kim, Byung-Gook, Yu Zhang, Mihaela van der Schaar, and Jang-Won Lee. ”Dynamic pricing and energy consumption scheduling with reinforcement learning.” IEEE Transactions on Smart Grid 7, no. 5 (2016): 2187-2198. [17] Tushar, Mosaddek Hossain Kamal, Chadi Assi, Martin Maier, and Mohammad Faisal Uddin. ”Smart microgrids: Optimal joint scheduling for electric vehicles and home appliances.” IEEE Transactions on Smart Grid 5, no. 1 (2014): 239-250. [18] Rahim, Sahar, Nadeem Javaid, Ashfaq Ahmad, Shahid Ahmed Khan, Zahoor Ali Khan, Nabil Alrajeh, and Umar Qasim. ”Exploiting heuristic algorithms to efficiently utilize energy management controllers with renewable energy sources.” Energy and Buildings 129 (2016): 452-470. [19] Javaid, Nadeem, Adnan Ahmed, Sohail Iqbal, and Mahmood Ashraf. ”Day Ahead Real Time Pricing and Critical Peak Pricing Based Power Scheduling for Smart Homes with Different Duty Cycles.” Energies 11, no. 6 (2018): 1464. [20] Parvez, Komal, Sheraz Aslam, Arje Saba, Syeda Aimal, Zunaira Amjad, Sikandar Asif, and Nadeem Javaid. ”Scheduling of Appliances in HEMS Using Elephant Herding Optimization and Harmony Search Algorithm.” In International Conference on Broadband and Wireless Computing, Communication and Applications, pp. 62-72. Springer, Cham, 2017.

58

Thesis by: Sheraz Aslam

REFERENCES

REFERENCES

[21] Liu, Ren-Shiou, and Yu-Feng Hsu. ”A scalable and robust approach to demand side management for smart grids with uncertain renewable power generation and bi-directional energy trading.” International Journal of Electrical Power & Energy Systems 97 (2018): 396-407. [22] Pal, Shalini, Sanjay Thakur, Rajesh Kumar, and B. K. Panigrahi. ”A strategical game theoretic based demand response model for residential consumers in a fair environment.” International Journal of Electrical Power & Energy Systems 97 (2018): 201-210. [23] Huang, Yantai, Hongjun Tian, and Lei Wang. ”Demand response for home energy management system.” International Journal of Electrical Power & Energy Systems 73 (2015): 448-455. [24] Castro, Pedro M., Iiro Harjunkoski, and Ignacio E. Grossmann. ”New continuous-time scheduling formulation for continuous plants under variable electricity cost.” Industrial & engineering chemistry research 48, no. 14 (2009): 6701-6714. [25] Luna, Adriana C., Nelson L. Diaz, Moises Graells, Juan C. Vasquez, and Josep M. Guerrero. ”Mixed-integer-linear-programming-based energy management system for hybrid PV-wind-battery microgrids: Modeling, design, and experimental verification.” IEEE Transactions on Power Electronics 32, no. 4 (2017): 2769-2783. [26] Chen, Zhi, Lei Wu, and Yong Fu. ”Real-time price-based demand response management for residential appliances via stochastic optimization and robust optimization.” IEEE Transactions on Smart Grid 3, no. 4 (2012): 1822-1831. [27] Moon, Seokjae, and Jang-Won Lee. ”Multi-residential demand response scheduling with multi-class appliances in smart grid.” IEEE Transactions on Smart Grid (2016). [28] Lu, Yuehong, Shengwei Wang, Yongjun Sun, and Chengchu Yan. ”Optimal scheduling of buildings with energy generation and thermal energy storage under dynamic electricity pricing using mixed-integer nonlinear programming.” Applied Energy 147 (2015): 49-58. [29] Shakeri, Mohammad, Mohsen Shayestegan, Hamza Abunima, SM Salim Reza, M. Akhtaruzzaman, A. R. M. Alamoud, Kamaruzzaman Sopian, and Nowshad Amin. ”An intelligent system architecture in home energy management systems (HEMS) for efficient demand response in smart grid.” Energy and Buildings 138 (2017): 154-164. [30] Hussain, Bilal, Qadeer Ul Hasan, Nadeem Javaid, Mohsen Guizani, Ahmad Almogren, and Atif Alamri. ”An Innovative Heuristic Algorithm for IoTEnabled Smart Homes for Developing Countries.” IEEE Access 6 (2018): 1555015575.

59

Thesis by: Sheraz Aslam

REFERENCES

REFERENCES

[31] Nemati, Mohsen, Martin Braun, and Stefan Tenbohlen. ”Optimization of unit commitment and economic dispatch in microgrids based on genetic algorithm and mixed integer linear programming.” Applied Energy 210 (2018): 944-963. [32] Meiqin, Mao, Sun Shujuan, and Liuchen Chang. ”Economic analysis of the microgrid with multi-energy and electric vehicles.” In Power Electronics and ECCE Asia (ICPE & ECCE), 2011 IEEE 8th International Conference on, pp. 2067-2072. IEEE, 2011. [33] Samadi, P.; Wong, V.W.; Schober, R. Load scheduling and power trading in systems with high penetration of renewable energy resources. IEEE Trans. Smart Grid 2016, 7, 1802–1812. [34] Khalid, Muhammad Usman, and Nadeem Javaid. ”An optimal scheduling of smart home appliances using heuristic techniques with real-time coordination.” In 2018 1st International Conference on Power, Energy and Smart Grid (ICPESG), pp. 1-6. IEEE, 2018. [35] Khalid, Adia, Nadeem Javaid, Mohsen Guizani, Musaed Alhussein, Khursheed Aurangzeb, and Manzoor Ilahi. ”Towards dynamic coordination among home appliances using multi-objective energy optimization for demand side management in smart buildings.” IEEE Access 6 (2018): 19509-19529. [36] Qayyum, F.A.; Naeem, M.; Khwaja, A.S.; Anpalagan, A.; Guan, L.; Venkatesh, B. Appliance scheduling optimization in smart home networks. IEEE Access 2015, 3, 2176–2190. [37] Agnetis, A.; de Pascale, G.; Detti, P.; Vicino, A. Load scheduling for household energy consumption optimization. IEEE Trans. Smart Grid 2013, 4, 2364–2373. [38] Hussain, Hafiz Majid, Nadeem Javaid, Sohail Iqbal, Qadeer Ul Hasan, Khursheed Aurangzeb, and Musaed Alhussein. ”An Efficient Demand Side Management System with a New Optimized Home Energy Management Controller in Smart Grid.” Energies 11, no. 1 (2018): 190. [39] Erdinc, O. Economic impacts of small-scale own generating and storage units, and electric vehicles under different demand response strategies for smart households. Appl. Energy 2014, 126, 142–150. [40] Mary, G.A.; Rajarajeswari, R. Smart grid cost optimization using genetic algorithm. Int. J. Res. Eng. Technol. 2014, 3, 282–287. [41] Javaid, N.; Ullah, I.; Akbar, M.; Iqbal, Z.; Khan, F.A.; Alrajeh, N.; Alabed, M.S. An intelligent load management system with renewable energy integration for smart homes. IEEE Access 2017, 5, 13587–13600. [42] Van der Stelt, S.; AlSkaif, T.; van Sark, W. Techno-economic analysis of household and community energy storage for residential prosumers with smart appliances. Appl. Energy 2018, 209, 266–276.

60

Thesis by: Sheraz Aslam

REFERENCES

REFERENCES

[43] Liu, R.S.; Hsu, Y.F. A scalable and robust approach to demand side management for smart grids with uncertain renewable power generation and bidirectional energy trading. Int. J. Electr. Power Energy Syst. 2018, 97, 396–407. [44] Bradac, Z.; Kaczmarczyk, V.; Fiedler, P. Optimal scheduling of domestic appliances via milp. Energies 2014, 8, 217–232. [45] Wang, Yunpeng, Walid Saad, Zhu Han, H. Vincent Poor, and Tamer Ba¸sar. ”A game-theoretic approach to energy trading in the smart grid.” IEEE Transactions on Smart Grid 5, no. 3 (2014): 1439-1450. [46] Shirazi, Elham, and Shahram Jadid. ”Cost reduction and peak shaving through domestic load shifting and DERs.” Energy124 (2017): 146-159. [47] Silvente, Javier, and Lazaros G. Papageorgiou. ”An MILP formulation for the optimal management of microgrids with task interruptions.” Applied Energy 206 (2017): 1131-1146. [48] Umetani, Shunji, Yuta Fukushima, and Hiroshi Morita. ”A linear programming based heuristic algorithm for charge and discharge scheduling of electric vehicles in a building energy management system.” Omega 67 (2017): 115-122. [49] Wang, Xiaonan, Ahmet Palazoglu, and Nael H. El-Farra. ”Operational optimization and demand response of hybrid renewable energy systems.” Applied Energy 143 (2015): 324-335. [50] Sheraz Aslam, Nadeem Javaid, Muhammad Asif, Umar Iqbal, Zafar Iqbal, and Mian Ahmer Sarwar, ”A mixed integer linear programming based optimal home energy management scheme considering grid-connected microgrids”, in 14th IEEE International Wireless Communications and Mobile Computing Conference (IWCMC-2018). [51] Zhang, Di, Sara Evangelisti, Paola Lettieri, and Lazaros G. Papageorgiou. ”Economic and environmental scheduling of smart homes with microgrid: DER operation and electrical tasks.” Energy Conversion and Management 110 (2016): 113-124. [52] P´erez-Vilarelle, Laura, Jos´e L. Risco-Mart´ın, and Jos´e L. Ayala. ”Modeling and simulation of wind energy production in the smart-grid scenario.” In Proceedings of the Symposium on Modeling and Simulation of Complexity in Intelligent, Adaptive and Autonomous Systems, p. 2. Society for Computer Simulation International, 2018. [53] Javaid, Nadeem, Sardar Mehboob Hussain, Ibrar Ullah, Muhammad Asim Noor, Wadood Abdul, Ahmad Almogren, and Atif Alamri. ”Demand side management in nearly zero energy buildings using heuristic optimizations.” Energies 10, no. 8 (2017): 1131. [54] Mahmood, Danish, Nadeem Javaid, Imran Ahmed, Nabil Alrajeh, Iftikhar Azim Niaz, and Zahoor Ali Khan. ”Multi-agent-based sharing power economy

61

Thesis by: Sheraz Aslam

REFERENCES

REFERENCES

for a smart community.” International Journal of Energy Research 41, no. 14 (2017): 2074-2090. [55] The WindPower Program and the UK NOABL Wind Speed Database. Available online: http://www.wind-power-program.com/index.htm (accessed on 29 March 2018). [56] Ahmad, Adnan, Asif Khan, Nadeem Javaid, Hafiz Majid Hussain, Wadood Abdul, Ahmad Almogren, Atif Alamri, and Iftikhar Azim Niaz. ”An optimized home energy management system with integrated renewable energy and storage resources.” Energies 10, no. 4 (2017): 549. [57] Javaid, Nadeem, Fahim Ahmed, Ibrar Ullah, Samia Abid, Wadood Abdul, Atif Alamri, and Ahmad S. Almogren. ”Towards cost and comfort based hybrid optimization for residential load scheduling in a smart grid.” Energies 10, no. 10 (2017): 1546. [58] Shirazi, Elham, and Shahram Jadid. Optimal residential appliance scheduling under dynamic pricing scheme via HEMDAS.” Energy and Buildings 93 (2015): 4049. [59] Do Nascimento, Marco Antonio Rosa, Lucilene de Oliveira Rodrigues, Eraldo Cruz dos Santos, Eli Eber Batista Gomes, Fagner Luis Goulart Dias, Elkin Iv´an Guti´errez Vel´asques, and Rub´en Alexis Miranda Carrillo. ”Micro gas turbine engine: a review.” In Progress in Gas Turbine Performance. InTech, (2013). [60] Song, Z.; Geng, X.; Kusiak, A.; Xu, C. Mining Markov chain transition matrix from wind speed time series data. Expert Syst. Appl. 2011, 38, 10229–10239. [61] Zubair, L. Diurnal and seasonal variation in surface wind at Sita Eliya, Sri Lanka. Theor. Appl. Climatol. 2002, 71, 119–127. [62] Aslam, Sheraz, Rasool Bukhsh, Adia Khalid, Nadeem Javaid, Ibrar Ullah, Itrat Fatima, and Qadeer Ul Hasan. ”An Efficient Home Energy Management Scheme Using Cuckoo Search.” In International Conference on P2P, Parallel, Grid, Cloud and Internet Computing, pp. 167-178. Springer, Cham, 2017. [63] Aslam, Sheraz, Sakeena Javaid, Nadeem Javaid, Syed Muhammad Mohsin, Saad Sulman Khan, and Mariam Akbar. ”An efficient home energy management and power trading in smart grid.” In International Conference on Innovative Mobile and Internet Services in Ubiquitous Computing, pp. 231-241. Springer, Cham, 2018. [64] Ding, Y.M.; Hong, S.H.; Li, X.H. A demand response energy management scheme for industrial facilities in smart grid. IEEE Trans. Ind. Inform. 2014, 10, 2257-2269. [65] Yang, X.S.; Deb, S. Cuckoo search via L´evy flights. In Proceedings of the World Congress on Nature & Biologically Inspired Computing, NaBIC 2009, Coimbatore, India, 9–11 December 2009; pp. 210–214.

62

Thesis by: Sheraz Aslam

REFERENCES

REFERENCES

[66] Merrikh-Bayat, F. A Numerical Optimization Algorithm Inspired by the Strawberry Plant. arXiv 2014, arXiv:1407.7399.

63

Thesis by: Sheraz Aslam

Appendices

64

.A. DETAIL OF APPENDICES

.A

Detail of Appendices

This section presents the code of the thesis entitled ”An optimal home energy management scheme considering grid connected microgrids with day-ahead weather forecasting using artificial neural network”. This code is developed by Sheraz Aslam under the supervision of Dr. Nadeem Javaid and Dr. Zahoor Ali Khan for the fulfilment of MS thesis presented to the Department of Computer Science, COMSATS University Islamabad (CUI) in Spring 2018. The present work is completed using the resources of ComSens (Communication over Sensors) Research Lab. In this section, we also provide the guidelines how to run the code in the readme.txt file. Furthermore, if you have any query, please contact: Email address: [email protected], [email protected] Mobile: +92-300-5792728, +92-300-8003105 The Appendix A contains the details for the implementation of MATLAB code given in the upcoming Appendix B and Appendix C. • Appendix B provides the MATLAB code for problem 1 presented 2.2.1. • Appendix C provides the MATLAB code for problem 2 indicated in 2.2.2. Readme: Before implementing the source code in MATLAB, please read the notes given below. 1. As an initial step, must read the original algorithms before going for code implementation. 2. Understand the code step by step with the help of the mentioned comments. 3. Copy the code provided in the following appendices and paste in the MATLAB file. 4. Save the MATLAB file with an appropriate file name with .m extension and excute.

65

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1:

.B

Implementation of proposed solution for problem 1:

This code is developed by Sheraz Aslam under the supervision of Dr. Nadeem Javaid. Appendix B contains the details for the implementation of MATLAB code for the problem 1 (see section 2.2.1) and save this main file name as ”milp res ev ess scheduling ma Step by step guidelines are provided in readme.txt file. Furthermore, if you want to .m file, please mail on this ID ”[email protected]”. 1 2 3 4 5 6

% This Code is written by Sheraz Aslam ( MS student ) against the research paper % " An optimal home energy management scheme considering grid connected microgrids with % dayahead weather forecsting " % This paper is submitted in Renewable Energy ( IF : 4.90)

7 8 9

% %

10 11

%

12 13 14

% %

15

Linear programming Linear Programming ( LP ) is an attempt to find a maximum or minimum solution to a function ,... given certain constraints . These constraints have to be linear . You cannot have parametric ... of hyperbolic constraints . We can solve these in polynomial time . For help - - - - - - - ______ " https :// www . mathworks . com / help / optim / ug / linprog . html "

16 17 18 19

% %

20 21 22

% %

Integer Programming Integer Programming is a subset of Linear Programming . It has all the c ha ra ct e ri st ic s of ... an LP except for one caveat : the solution to the LP must be restricted to integers . We can ’ t solve these in polynomial time .

23 24 25 26 27

% %

28 29

%

30 31

%

32 33

%

MILP An LP ( linear program ) involves minimizing ( or maximizing ) a linear function subject to linear ... constraints on the variables . Any solution that satisfies the constraints is feasible . A MILP ... is an LP with the addition of integrality restrictions on some or all of the variables . simply mean ’ s some variables are linear ( contineous ) and some are discrete

34 35 36 37 38 39 40 41

% % % % %

options = optimoptions ( ’ linprog ’ , ’ Algorithm ’ , ’ interior - point ’) ; option is used to solve linear problem by specfic linear algo / technique i . e . , simplex method , interior point method . usually linprog or intlinprog solve our problem by simpplex method when we use options as a empty [];.

42 43 44 45

clc ; clear

66

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 46 47 48 49 50 51 52 53

close all filename = ’ app . xlsx ’; % calling the excell file from folder appl ianceTab le = readtable ( filename ) %% reading the table from excell file price = xlsread ( filename ,2) ; % Second sheet / hourly prices % price =[1 1 2 3 6 6 7 8 9 8 8 8 7 6 6 5 5 4 4 3 2 2 2 2]; disp ( ’ Pricing scheme ( hourly from 0:00 - 24:00) : ’) ; disp ( mat2str ( price (2 ,:) ) ) ; % mat2str use for convertimg the matrix in to string

54 55 56 57

% this function is used to making milp problem ( creating require values % for intlinprog function

58 59 60 61 62 63

[f ,A ,b , Aeq , beq , applianceNumberVector , re_wind_new , rg_new_pv , temp_pv , wind_spead , current1 , current2 , current3 , voltage1 ,... voltage2 , voltage3 ] = MILP_fun ( applianceTable , price ) ;

64 65 66 67 68 69 70 71

nVars = numel ( f ) ; % Number of variables in the problem ... numel used for find number of data elements lb = zeros ( nVars ,1) ; % The upper and lower bounds are 0 and 1 ub = ones ( nVars ,1) ; intcon = nVars ; % MILP Area

72 73 74

%

crating a structre for problem / problem formulation

75 76 77 78 79

a p p l i a n c e _ s c h e d u l i n g _ p r o b = struct ( ’f ’ ,f , ’ intcon ’ , intcon ,... ’ Aineq ’ ,A , ’ bineq ’ ,b , ’ Aeq ’ , Aeq , ’ beq ’ , beq ,... ’lb ’ , lb , ’ ub ’ , ub , ’ options ’ ,[] ,... ’ solver ’ , ’ intlinprog ’) ;

80 81 82 83 84 85 86 87

% % % % %

options = optimoptions ( ’ linprog ’ , ’ Algorithm ’ , ’ interior - point ’) ; option is used to solve linear problem by specfic linear algo / technique i . e . , simplex method , interior point method . usually linprog or intlinprog solve our problem by simpplex method when we use options as a empty [];.

88 89 90

%%% calling the mixed integer linear programming function ( builtin of MATLAB )

91 92

[x , cost ] = intlinprog ( a p p l i a n c e _ s c h e d u l i n g _ p r o b ) ;

93 94 95

%[ x , cost ] = intlinprog (f ,1: nVars ,A ,b , Aeq , beq , lb , ub ) ; % x = intlinprog (f ,1: nVars ,A , b )

96 97 98

t ot al _a p pl ia nc e = size ( applianceTable ,1) ; % Total number of appliances

99 100

% Convert from indices in x to employee and shift information

101 102

selected = find ( x ) ; % find function is used for finding non_zero values

103

67

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 104

hoursMatrix = zeros ( total_appliance ,24) ; % initialize by 0 appliances x hours

105 106 107 108 109 110 111 112 113

% creating the matrix of appliance nd hour with minimum cost for n = 1: numel ( selected ) ; thisEntry = selected ( n ) ; thisappliance = a p p l i a n c e N u m b e r V e c t o r ( thisEntry ) ; e xe cu ti n g_ ho ur s = -A (1:24 , thisEntry ) ; hoursMatrix ( thisappliance ,:) = ex ec ut i ng _h ou r s ; end

114 115

%

finalizing the MILP results

116 117 118 119

ap =[0.2;0.8]; % power rating of freg and light which are must run appliances p =[ applia nceTable . power ; ap ]; % power rating

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

EP = price (2 ,:) ; %% electricity price refreg =[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] ’; % refreg is must run load light =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1] ’; % refreg is must run load Applian = hoursMatrix ’; % appliance matrix Applian =[ Applian light ]; Applian =[ Applian refreg ]; for hour =1:24 milp_load ( hour ) = Applian ( hour ,:) * p ; load = Applian ( hour ,:) * p ; milp_cost ( hour ) = milp_load ( hour ) * EP ( hour ) ; t o t a l _ m i l p _ c o s t _ w o u t _ R E S = sum ( milp_cost ) ; %%%% Total cost t ot al _m i lp _l oa d = sum ( milp_load ) ; %% Total load end total_milp_cost_wout_RES PAR_milp = max ( milp_load ) /(( to ta l _m il p_ l oa d ) /24) ;

138 139

%

Storage system initilization

140 141 142 143

EV =3; % Assumed initially charged 3 kw ( Electrical vehicle ) for more working go on MILP_2nf_fun . m ESS =3; % Assumed initialy charged 3 kw ( Energy storage system )

144 145 146 147 148

%

2 nd MILP function for supply side managment

%

149 150 151 152 153 154 155 156 157

[ generator_ut , RES_ut , ESS_ut , EV_ut , grid_ut , grid_ut_2 , total_hourly_RES , EV_charging ] = MILP_2nd_fun ( re_wind_new , rg_new_pv , milp_load , EP , EV , ESS ) ; for hourr =1:24 milp_cost_res ( hourr ) = grid_ut ( hourr ) * EP ( hourr ) ; t o t a l _ c o s t _ m i l p _ r e s = sum ( milp_cost_res ) ; par_with_res = max ( grid_ut ) /( sum ( grid_ut ) ) /24; end

158 159 160 161

% PAR after milp with microgrid PAR_milp2 = max ( grid_ut ) /(( t ot a l_ mi lp _ lo ad ) /24) ; % Unschedule case

68

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

%% Elastic base Appliances oven = [0 0 0 0 0 five_bulbs = [0 0 0 0 0 tv = [1 0 0 0 0 heatingSystem = [0 0 1 1 0 laptop = [0 0 0 0 0 dishWasher = [0 0 0 0 0 heter = [0 0 0 0 0 shero = [0 0 0 0 0 light = [0 0 0 0 0 must run load refreg = [1 1 1 1 1 must run load

0 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0

0 1 1 1 1 1 1 1 0

1 1 1 1 1 1 1 1 0

0 0 0 1 1 1 1 1 0

1 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0

0 1 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 0 0

0 1 0 1 0 0 0 0 0

0 0 0 0 0 0 0 0 1

0 0 0 0 0 0 0 0 1

0 0 0 0 0 0 0 0 1

0 0 0 0 1 0 0 0 1

0 0 0 0 0 0 0 0 1

0]; 0]; 0]; 0]; 1]; 0]; 0]; 0]; 1]; % light is

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]; % refreg is

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

I n t r u p t _ a p p l i a n c e s =[ oven ’ five_bulbs ’ tv ’ heatingSystem ’ laptop ’ dishWasher ’ heter ’ shero ’ light ’ refreg ’]; applancess =[ I n t r u p t _ a p p l i a n c e s ]; for hour =1:24 E l e c t r i c i t y _ c o st =[ EP ( hour ) * p (1) EP ( hour ) * p (2) EP ( hour ) * p (3) EP ( hour ) * p (4) EP ( hour ) * p (5) EP ( hour ) * p (6) ... EP ( hour ) * p (7) EP ( hour ) * p (8) EP ( hour ) * p (9) EP ( hour ) * p (10) ];% coefficients of objective function % e l e c tr i c i t y _ c o s t = E l e c t r i c i t y _ c o s t % e l e c tr i c i t y _ c o s t n = length ( E l e c t r i c i ty _ c o s t ) ; u ns ch ed u le dl oa d ( hour ) = applancess ( hour ,:) * p ; unsc heduleco st ( hour ) = applancess ( hour ,:) * Electricity_cost ’; s u m _ u n s c h e d u l e d l o a d = sum ( un s ch ed ul e dl oa d ) ; s u m _ u n s c h e d u l e d _ c o s t = sum ( u nschedul ecost ) ; thourr ( hour ) = hour ; P AR _u ns c he du le d = max ( u ns c he du le d lo ad ) /( s u m _ u n s c h e d u l e d l o a d /24) ; thourr ( hour ) = hour ; end % EV area

198 199 200 201 202 203 204 205 206 207

% to combine the charging and discharging of ev for a =1:24 if EV_charging ( a ) ==0 && EV_ut ( a ) >0 EV_charging ( a ) = - EV_ut ( a ) ; else EV_charging ( a ) = EV_charging ( a ) ; end end % end

208 209

%

Figures Area

210 211 212 213

%%

&&&&&&&&&& - - - - - - - - per hour cost - - - - - -

214 215 216 217 218 219

figure stairs (1:24 , unschedulecost , ’ Rs - ’ , ’ LineWidth ’ ,1.4) ; hold on stairs (1:24 , milp_cost ,’G * - ’ , ’ LineWidth ’ ,1.4) ; hold on

69

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 220 221 222 223 224 225 226

xlabel ( ’ Time ( hours ) ’) ; ylabel ( ’ Cost ( cents / kWh ) ’) ; legend ( ’ Unscheduled cost ’ , ’ MILP cost w / o microgrid ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; % title ( ’ Load per Hour ’) ; grid on %% &&&&&&& - - - - - - - - per hour load - - - - - - - -&&&&&&&&&&&&

227 228 229 230 231 232 233 234 235 236 237 238

figure ax = plotyy (1:24 , EP ,1:24 , unscheduledload , @plot , @stairs ) ; hold on stairs (1:24 , milp_load , ’ G * - ’ , ’ LineWidth ’ ,1.4) ; hold on % set ( ax (1) ,’ color ’ , ’b ’) ; ylabel ( ax (2) ,’ Electricity load ( kWh ) ’) ; xlabel ( ’ Time ( hours ) ’) ; ylabel ( ’ cents / kWh ’) ; % set ( gca , ’ XTick ’ ,1:24 , ’ XTickLabel ’ ,{ ’1 ’ ’2 ’ ’3 ’ ’4 ’ ’5 ’ ’6 ’ ’7 ’ ’8 ’ ’9 ’ ’10 ’ ’11 ’ ’12 ’ ’13 ’ ’14 ’ ’15 ’ ’16 ’ ’17 ’ ’18 ’ ’19 ’ ’20 ’ ’21 ’ ’22 ’ ’23 ’ ’24 ’})

239 240 241 242

legend ( ’ RTP signals ’ , ’ MILP w / o microgrid load ’ , ’ Unscheduled load ’ ) ; legend ( ’ Location ’ , ’ NorthEast ’) ; hold on

243 244 245 246 247 248 249 250

%%%%%%%%%%% TOTAL COST %%%%%%%%%%%% figure bar (1 , sum_unscheduled_cost ,0.3 , ’ red ’) hold on bar (2 , total_milp_cost_wout_RES ,0.3 , ’ green ’) hold on set ( gca , ’ XTick ’ ,1:1:2 , ’ XTickLabel ’ ,{ ’ Unschedule cost ’ , ’ MILP w / o RES cost ’})

251 252 253

ylabel ( ’ Total cost ( cents ) ’) ; grid on

254 255 256 257 258 259 260 261

%%%%%%%%%%%%%%%%% TOTAL load %%%%%%%%%%%% figure bar (1 , sum_unscheduledload ,0.3 , ’ red ’) hold on bar (2 , total_milp_load ,0.3 , ’ green ’) hold on set ( gca , ’ XTick ’ ,1:1:2 , ’ XTickLabel ’ ,{ ’ Unschedule load ’ , ’ MILP w / o RES load ’})

262 263 264

ylabel ( ’ Total load ( kWh ) ’) ; grid on

265 266 267 268 269 270 271 272 273 274 275 276 277

%%%%%%%%%%%%%%%%% PAR %%%%%%%%%%%%% figure bar (1 , PAR_unscheduled ,0.3 , ’ red ’) hold on bar (2 , PAR_milp ,0.3 , ’ green ’) hold on bar (3 , PAR_milp2 ,0.3 , ’ yellow ’) hold on set ( gca , ’ XTick ’ ,1:1:3 , ’ XTickLabel ’ ,{ ’ Unscheduled ’ , ’ MILP w / o microgrid ’ , ’ MILP with microgrid ’}) ylabel ( ’ PAR ’) ; grid on

70

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 278 279 280 281 282 283 284 285 286 287 288 289 290 291

% % % % % % % % % % % %

%%%%%%%%%%%%%%%% RES %%%%%%%%%%% Create the area plot using the area function for Wind and solar for a day figure area ( re_wind_new , ’ FaceColor ’ ,[0 1 1]) ; hold on area ( rg_new_pv , ’ FaceColor ’ , [1 1 0]) ; colormap winter legend ( ’ Wind turbine ’ , ’ Solar panal ’) xlim ([1 24]) ; set ( gca , ’ XTick ’ ,0:4:24 , ’ XTickLabel ’ ,{ ’1 ’ ’4 ’ ’8 ’ ’12 ’ ’16 ’ ’20 ’ ’24 ’}) xlabel ( ’ Time / hours ’) ylabel ( ’ Electricity generation ( kWh / h ) ’) grid on

292 293 294 295 296

%%%%% Electricity generation figure stem ( re_wind_new , ’ filled ’ , ’ LineStyle ’ , ’ -. ’ , ’ MarkerFaceColor ’ , ’ red ’ ,... ’ MarkerEdgeColor ’ , ’ green ’) % style 2

297 298 299 300 301 302 303 304 305 306 307

hold on stem ( rg_new_pv , ’ filled ’ , ’ LineStyle ’ , ’ -. ’ , ’ MarkerFaceColor ’ , ’ yellow ’ ,... ’ MarkerEdgeColor ’ , ’ blue ’) % style 2 xlabel ( ’ Time ( hours ) ’) ; ylabel ( ’ Electricity generation ( kWh ) ’) ; % set ( gca , ’ YTick ’ ,0:0.5:2 , ’ YTickLabel ’ ,{ ’0 ’ ’0.5 ’ ’1 ’ ’1.5 ’ ’2 ’}) legend ( ’ Wind generation ’ , ’ PV generation ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; grid on %%%%%%%%%%%%% wind generation and Wind spead

308 309 310 311 312 313 314 315 316 317 318 319 320 321

figure [ ax h1 h2 ]= plotyy (1:24 , re_wind_new ,1:24 , wind_spead , @plot , @plot ) ; set ( h1 , ’ Marker ’ , ’o ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’ - - ’ , ’ color ’ , ’ blue ’) set ( h2 , ’ Marker ’ , ’* ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’ - - ’ , ’ color ’ , ’ red ’) hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ax (2) ,’ Wind speed ( m / s ) ’) ; ylabel ( ’ WT generation ( kW ) ’) ; % set ( gca , ’ YTick ’ ,0:0.5:2 , ’ YTickLabel ’ ,{ ’0 ’ ’0.5 ’ ’1 ’ ’1.5 ’ ’2 ’}) legend ( ’ WT generation ’ , ’ Wind speed ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; grid on

322 323

% %% %% %% % %% %% %% % temp and PV generation

324 325 326 327 328 329 330 331 332 333 334 335

figure [ ax h1 h2 ]= plotyy (1:24 , rg_new_pv ,1:24 , temp_pv , @plot , @plot ) ; set ( h1 , ’ Marker ’ , ’o ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’: ’ , ’ color ’ , ’ blue ’) set ( h2 , ’ Marker ’ , ’* ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’: ’ , ’ color ’ , ’ red ’) % set ( h2 , ’ color ’ , ’ red ’) hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ax (2) ,’ Temperature of the day ’) ; ylabel ( ’ PV generation ( kW ) ’) ; set ( gca , ’ YTick ’ ,0:0.5:2 , ’ YTickLabel ’ ,{ ’0 ’ ’0.5 ’ ’1 ’ ’1.5 ’ ’2 ’}) legend ( ’ PV generation ’ , ’ Temperature ’) ;

71

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 336 337

legend ( ’ Location ’ , ’ NorthEast ’) ; grid on

338 339 340 341

%

MILP results with RES , EV , ESS and Generator

342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362

%%%%%% power gneration and load graph with diesel generaaor figure stairs ( milp_load , ’ -. or ’ , ’ LineWidth ’ ,1.4) hold on stairs ( generator_ut , ’ -b ’ , ’ LineWidth ’ ,1.4) hold on plot ( re_wind_new , ’k ’ , ’ LineWidth ’ ,1.4) hold on plot ( rg_new_pv , ’m ’ , ’ LineWidth ’ ,1.4) hold on legend ( ’ Demand ’ , ’ Generator ’ , ’ Wind ’ , ’ PV panel ’ , ’ Location ’ , ’ northwest ’ , ’ Orientation ’ , ’ horizontal ’) ; xlabel ( ’ Time ( hour ) ’) ; ylabel ( ’ Electicity generation / demand ( kW ) ’) ; xlim ([1 25]) ; % set ( gca , ’ XTick ’ ,0:4:24 , ’ XTickLabel ’ ,{ ’1 ’ ’4 ’ ’8 ’ ’12 ’ ’16 ’ ’20 ’ ’24 ’}) ylim ([0 6.5]) ; % set ( gca , ’ YTick ’ ,0:0.5:6.5 , ’ YTickLabel ’ ,{ ’0 ’ ’0.5 ’ ’1 ’ ’1.5 ’ ’2 ’ ’2.5 ’... % ’3 ’ ’3.5 ’ ’4 ’ ’4.5 ’ ’5 ’ ’5.5 ’ ’6 ’ ’6.5 ’}) grid on

363 364 365 366 367 368 369 370 371 372

% Load and imported electricity graph figure bpcombined = [ milp_load (:) , grid_ut (:) ]; hb = bar ( bpcombined , ’ grouped ’) ; legend ( ’ Optimal demand ’ , ’ Imported electricity ’ , ’ Location ’ , ’ northwest ’) ; xlabel ( ’ Hours in a day ’) ; ylabel ( ’ Electricity / load ( kWh ) ’) ; % title ( ’ Comparison of load with EV with discharging ’) ; hold on

373 374 375 376 377 378 379 380 381 382 383 384 385 386 387

% Load and imported electricity with and without dischargable EV graph figure bpcombined = [ milp_load (:) , grid_ut_2 (:) , grid_ut (:) ]; hb = bar ( bpcombined , ’ grouped ’) ; hold on plot ( re_wind_new , ’g ’ , ’ LineWidth ’ ,1.4) hold on legend ( ’ Load ’ , ’ Imported electricity w / o EV discharging ’ ,... ’ Imported electricity with EV discharging ’ , ’ Wind generation ’ , ’ Location ’ , ’ northwest ’) ; xlabel ( ’ Hours in a day ’) ; ylabel ( ’ Electricity / load ( kWh ) ’) ; % title ( ’ Comparison of load with EV with discharging ’) ; hold on

388 389 390 391 392 393

% Load , Ev and ESS contribution graph figure bpcombined = [ milp_load (:) , EV_ut (:) , ESS_ut (:) ]; hb = bar ( bpcombined , ’ grouped ’) ; legend ( ’ Load ’ , ’ EV contribution ’ , ’ ESS contribution ’ , ’ Location ’ , ’ northwest ’) ;

72

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 394 395 396 397

xlabel ( ’ Hours in a day ’) ; ylabel ( ’ Electricity / load ( kWh ) ’) ; % title ( ’ Comparison of load with EV with discharging ’) ; hold on

398 399 400 401 402 403 404 405 406 407 408 409 410

% Load , Ev and ESS contribution graph figure bpcombined = [ milp_load (:) ]; hb = bar ( bpcombined , ’ grouped ’) ; hold on stairs ( generator_ut , ’ -y ’ , ’ LineWidth ’ ,1.6) hold on legend ( ’ Total demand ’ , ’ Generater contribution ’ , ’ Location ’ , ’ northwest ’) ; xlabel ( ’ Hours in a day ’) ; ylabel ( ’ Electricity / load ( kWh ) ’) ; % title ( ’ Comparison of load with EV with discharging ’) ; hold on

411 412

%%%%%%%%%% figure for I - V curve of solar panel

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436

figure plot ( voltage1 , current1 , ’r ’ , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) hold on plot ( voltage2 , current2 , ’b ’ , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) hold on plot ( voltage3 , current3 , ’g ’ , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) legend ( ’10:00 ’ , ’13:00 ’ , ’16:00 ’ , ’ Location ’ , ’ southwest ’) ; % title ( ’ price signal ’) ; xlabel ( ’ Voltage ’) ; ylabel ( ’ Current ’) ; dim = [ 0 . 7 9 2 6 4 7 0 5 8 8 2 3 5 2 9 0 . 82 6 5 8 2 2 8 0 0 6 5 4 4 0 . 0 8 6 7 6 4 7 0 3 7 3 4 8 3 2 7 0 . 0 7 8 4 8 1 0 1 1 0 7 3 8 0 0 6 ] ; str = ’MPP ’; annotation ( ’ textbox ’ , dim , ’ String ’ , str , ’ FitBoxToText ’ , ’ on ’ , ’ FontSize ’ ,12 , ’ Color ’ ,[1 0 0]) ; x = [0.776470588235294 0.786764705882353]; y = [0.544303797468354 0.853164556962025]; a = annotation ( ’ textarrow ’ ,x ,y , ’ String ’ , ’ ’) ; % set ( gca , ’ XTick ’ ,0:50) % , ’ XTickLabel ’ ,{ ’8 ’ ’9 ’ ’10 ’ ’11 ’ ’12 ’ ’13 ’ ’14 ’ ’15 ’ ’16 ’ ’17 ’ ’18 ’ ’19 ’ ’20 ’ ’21 ’ ’22 ’ ’23 ’ ’24 ’ ’1 ’ ’2 ’ ’3 ’ ’4 ’ ’5 ’ ’6 ’ ’7 ’ ’8 ’}) % set ( gca , ’ YTick ’ ,2:2:30 , ’ YTickLabel ’ ,{ ’2 ’ ’4 ’ ’6 ’ ’8 ’ ’10 ’ ’12 ’ ’14 ’ ’16 ’ ’18 ’ ’20 ’ ’22 ’ ’24 ’ ’26 ’ ’28 ’ ’30 ’}) grid on

437 438 439 440 441 442 443 444 445

% % % % % % % % % % % % % %% % TOTAL COST %%% %%%%%%%% %%% figure bar (1 , sum_unscheduled_cost ,0.3 , ’ red ’) hold on bar (2 , total_milp_cost_wout_RES ,0.3 , ’ green ’) hold on bar (3 , total_cost_milp_res ,0.3 , ’ yellow ’) hold on

446 447 448 449 450

set ( gca , ’ XTick ’ ,1:1:3 , ’ XTickLabel ’ ,{ ’ Unscheduled cost ’ , ’ MILP w / o RES cost ’ , ’ MILP with RES cost ’}) ylabel ( ’ Total cost ( cents ) ’) ; grid on

451

73

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 452 453 454 455 456 457 458 459 460 461 462

% Ev charging and discharging figure stem ( EV_charging , ’: diamondr ’) % style 1 hold on plot ( total_hourly_RES , ’M ’) hold on ylabel ( ’ Electricity ( kWh ) ’) ; xlabel ( ’ Time ( hours ) ’) ; legend ( ’ Charging and discharging ’ , ’ Electricity generation from RES ’) ; hold off

463 464 465 466 467 468 469 470 471 472 473 474

%%% % a =[4 5 6 4 3 2 3 4 5 -1 -4 -2 -3 4 5 6 7 -2]; % stem ( re_wind_new , ’: diamondr ’) % style 1 % % stem ( re_wind_new , ’ filled ’ , ’ LineStyle ’ , ’ -. ’ , ’ MarkerFaceColor ’ , ’ red ’ ,... % ’ MarkerEdgeColor ’ , ’ green ’) % style 2 % % X = 0:25; % Y = [ rg_new_pv ; re_wind_new ] ’; % h = stem (X , Y ) ;

74

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1:

.B.1

MILP function

Appendix B.1 contains the details for the implementation of MATLAB function named ”MILP fun.m” which is called in main file. Please save this file in the same folder as main file. Step by step guidelines are provided in readme.txt file. 476 475

477 478 479 480 481 482 483

MILP code function [f ,A ,b , Aeq , beq , appNumberVector , re_wind_new , rg_new_pv ,... temp_pv , wind_spead , current1 , current2 , current3 , voltage1 , voltage2 , voltage3 ] = MILP_fun ( appTable , price ) % Convert the appliances information and requirements into the necessary % matrices for input to INTLINPROG

484 485 486 487 488 489

% _Copyright 2015 The MathWorks , Inc . _ [ re_wind_new , rg_new_pv , temp_pv , wind_spead , current1 , current2 , current3 , voltage1 , voltage2 , voltage3 ]= res_gen () ; % Calling the function named res_gen for elec generation numapp = size ( appTable ,1) ; % Total number of appliances

490 491 492 493 494 495 496 497 498 499 500 501 502

% Initialize various variables t ot al Ho u rM at ri x = []; load_total =[]; a pp Nu mb e rV ec to r = []; a p p N u m b e r E n t r y C o u n t = []; f = []; % Cost vector for linear programming a =1; price = price (2 ,:) ; for n = 1: numapp % For every appliancesv ... minHours = appTable . lot ( n ) ; maxHours = appTable . lot ( n ) ; hourMatrix = [];

503

for hours = minHours : maxHours % ... generate all possible solutions hourVector = zeros (1 ,24) ; hourVector (1: hours ) = 1; %%% in first row and hours coloumns is = 1

504 505 506 507 508 509 510 511

% GALLERY is a quick way to make a circulant matrix % If an employee starts a shift late at night , % A backwards ( -1) shift , the result is a symmetric matrix . % circulant ([2 3 5 7 11 13] , -1)

512 513 514 515 516 517 518 519 520 521 522 523 524

% % % % % % %

ans = 2 3 5 7 11 13 3 5 7 11 13 2 5 7 11 13 2 3 7 11 13 2 3 5 11 13 2 3 5 7 13 2 3 5 7 11 % the hours will " loop back over " into the morning . % newHourMatrix = ( gallery ( ’ circul ’ , hourVector ) ’) ; nn = 24; m = appTable . lot ( n ) ; i0 = nchoosek (1: nn , m ) ;

75

Thesis by: Sheraz Aslam

.B. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 1: 525 526 527 528

s = size ( i0 ,1) ; out = zeros (s , nn ) ; ii = bsxfun ( @plus ,( i0 - 1) *s ,(1: s ) ’) ; out ( ii ) = 1;

529

newHourMatrix = out ’; hourMatrix = [ hourMatrix newHourMatrix ];

530 531

end

532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549

% % % % % % % % % % % % % % %

% If needed , filter out the entries that are out of availability avail ableTime s = appTable . Availability ( n ) ; if iscell ( av ailableT imes ) avail ableTime s = ava ilableTi mes {1}; end if ~ isnan ( av ailableT imes ) available = false (24 ,1) ; % Convert from text ( ex : "6 -12") ... avail ableTime s = regexp ( availableTimes , ’\ d + -\ d + ’ , ’ match ’) ; for k = 1: numel ( av ailableT imes ) % ... to MATLAB numerical values ( ex : [6 12]) start StopTim es = sscanf ( availab leTimes { k } , ’%d -% d ’) ; available ( sta rtStopTi mes (1) +1: s tartStop Times (2) ) = true ; end hourMatrix = hourMatrix (: ,~ any ( bsxfun ( @and ,~ available , hourMatrix ) ) ) ; end

550 551

t ot al Ho u rM at ri x = [ to ta l Ho ur Ma t ri x hourMatrix ];

552 553 554 555 556

load_total = [ load_total hourMatrix * appTable . power ( n ) ]; % Keep track of which columns are for which employee a p p N u m b e r E n t r y C o u n t ( n ) = size ( hourMatrix ,2) ; a pp Nu mb e rV ec to r = [ ap pN u mb er Ve c to r repmat (n ,1 , a p p N u m b e r E n t r y C o u n t ( n ) ) ];

557 558 559 560

% Wages are total hours worked * hourly wage cost = appTable . power ( n ) * price ; f = [ f ; ( hourMatrix ) ’* cost ’];

561 562 563 564 565 566 567 568 569

end f =f ’; % Constraint : The total hours must be >= the minimum required A_hours = t ot a lH ou r Ma tr ix ; % b_hours = [4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4] ’; for a =1:24 b_hours ( a ) =5.1; end

570 571 572 573 574 575

% % Constraint : You can only go to work once a day A_oneTime = arrayfun ( @ ( n ) ones (1 , n ) , appNumberEntryCount , ’ Uniform ’ , false ) ; A_oneTime = blkdiag ( A_oneTime {:}) ; %%% Block - diagonal concatenation of models b_oneTime = appTable . lot ;% ones ( numapp ,1) ;

576 577 578 579 580 581 582

%% 3. Combine both of the constraints into one A and b matrix % We apply a ( -) to the Hours constraint because Ax >= b means - Ax 4 lb (1) =1; end

655 656

ub = [1 RES_hourly ESS1 EV1 inf ]; %

limit for every electricity source

657 658 659 660 661 662 663 664 665

if houur >6 && houur Ped % std ( u ns c he du le d lo ad ) % rand (1) means 1*1 matrix pop (j , i ) =1; else pop (j , i ) =0; end

986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026

end end ind = popsize ; tbits =12; insite =2; % pc =0.9; % Probability of crossover pm =1 - pc ; % Probability of mutation count =0; ss = zeros () ; %% %% Average Calculation best = inf ; gbest = inf ; Fbest = inf ; app_Sch_G = zeros (24 ,12) ; s u m _ s c h e d u l e d _ l o a d _ G =0; G_time_slots =[ t i m e _ s l o t s _ I n t r u p t t i m e _ s l o t s _ n o n I n t r time_s lotFixe d ]; E_Cost_SS_G = zeros (1 ,24) ; s um _E _C o st _S S _G =0; s ch ed ul e _l oa d _G = zeros (1 ,24) ; errorG = inf ; pop =( rand ( popsize , D ) ) ;% - theta ) *60; % x lies in [ -30 30] for j =1: popsize for i =1: D if pop (j , i ) >0.5% std ( u ns c he du le d lo ad ) % rand (1) means 1*1 matrix pop (j , i ) =1; else pop (j , i ) =0; end end end popnew = pop ; for hour =1:24 % gen =24 e l e c t r i c i t y _ c os t =[ EP ( hour ) * p (1) EP ( hour ) * p (2) EP ( hour ) * p (3) EP ( hour ) * p (4) EP ( hour ) * p (5) EP ( hour ) * p (6) EP ( hour ) * p (7) EP ( hour ) * p (8) EP ( hour ) * p (9) EP ( hour ) * p (10) EP ( hour ) * p (11) EP ( hour ) * p (12) ];% coefficients of objective function

1027 1028

%%

%%%% Evalution of population %%%%

1029 1030 1031

lhour =25 - hour ;

1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043

%% %%%%% condition for the appliance number 4 must run between 18 n 24 a4 =11; b4 =16; if hour < a4 || hour > b4 for a =1: popsize popnew (a ,4) =0; end else for a =1: popsize if popnew (a ,4) ==0

87

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: popnew (a ,4) =1;

1044 1045 1046 1047 1048

end end end %%%%%%%%%% End condition for appliance number 4

1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060

%%%%%%%%%%% for appliance number 1 a1 =2; b1 =9; if hour < a1 || hour > b1 for a =1: popsize popnew (a ,1) =0; end elseif G_time_slots (1 ,1) >=0 && ( hour >=( b1 - dw ) ) for a =1: popsize popnew (a ,1) =1; end

1061 1062 1063

end %%%%%%%%%%%% end of 1 st appliance condition

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075

%%%%%%%%%%% for appliance number 2 a2 =2; b2 =4; if hour < a2 || hour > b2 for a =1: popsize popnew (a ,2) =0; end elseif G_time_slots (1 ,2) >=0 && ( hour >=( b2 - wm ) ) popnew (a ,2) =1; end %%%%%%%%% end of 2 nd appliance condition

1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087

%%%%%%%%%%% for appliance number 3 a3 =6; b3 =10; if hour < a3 || hour > b3 for a =1: popsize popnew (a ,3) =0; end elseif G_time_slots (1 ,3) >=0 && ( hour >=( b3 - sd ) ) popnew (a ,3) =1; end %%%%%%%%% end of 3 rd appliance condition

1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099

%%%%%%%%%%% for appliance number 6 a6 =1; b6 =2; if hour < a6 || hour > b6 for a =1: popsize popnew (a ,6) =0; end elseif G_time_slots (1 ,6) >=0 && ( hour >=( b6 ) ) popnew (a ,6) =1; end %%%%%%%%% end of 6 th appliance condition

1100 1101

%%%%%%%%%%% for appliance number 7

88

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115

a7 =11; b7 =12; if hour < a7 || hour > b7 for a =1: popsize popnew (a ,7) =0; end elseif G_time_slots (1 ,7) >=0 && ( hour >=( b7 ) ) for a =1: popsize if popnew (a ,7) ==0 popnew (a ,7) =1; end end end %%%%%%%%% end of 7 th appliance condition

1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131

%%%%%%%%%%% for appliance number 8 a8 =1; b8 =2; if hour < a8 || hour > b8 for a =1: popsize popnew (a ,8) =0; end elseif G_time_slots (1 ,8) >=0 && ( hour >=( b8 ) ) for a =1: popsize if popnew (a ,8) ==0 popnew (a ,8) =1; end end end %%%%%%%%% end of 8 th appliance condition

1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147

%%%%%%%%%%% for appliance number 9 a9 =11; b9 =16; if hour < a9 || hour > b9 for a =1: popsize popnew (a ,9) =0; end elseif G_time_slots (1 ,9) >=0 && ( hour >=( b9 - l ) ) for a =1: popsize if popnew (a ,9) ==0 popnew (a ,9) =1; end end end %%%%%%%%% end of 9 th appliance condition

1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

%%%%%%%%%%% for appliance number 10 a10 =11; b10 =16; if hour < a10 || hour > b10 for a =1: popsize popnew (a ,10) =0; end elseif G_time_slots (1 ,10) >=0 for a =1: popsize if popnew (a ,10) ==0 popnew (a ,10) =1;

&& ( hour >= b10 - dd )

89

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1160 1161 1162 1163

end end end %%%%%%%%% end of 10 th appliance condition

1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179

%%%%%%%%%%% for appliance number 11 a11 =2; b11 =9; if hour < a11 || hour > b11 for a =1: popsize popnew (a ,11) =0; end elseif G_time_slots (1 ,11) >=0 && ( hour >=( b11 - vc ) ) for a =1: popsize if popnew (a ,11) ==0 popnew (a ,11) =1; end end end %%%%%%%%%%%% end of 11 th appliance condition

1180 1181 1182 1183 1184 1185 1186

% % % % % % % % % % % % % % % % start the appliance 12 condition a12 =11; if hour < a12 for a =1: popsize popnew (a ,12) =0; end

1187 1188 1189

end % %% %% %% % %% %% %% % end of 12 th condition

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199

for a =1: popsize for b =1: D if G_time_slots (1 , b ) ( std ( u n sc he du l ed lo ad ) + min ( u ns ch ed u le dl oa d ) ) ) &&( Load (1 , i ) < mean ( u ns c he du le d lo ad ) - min ( un s ch ed ul e dl oa d ) ) && Load (1 , i ) < mean ( u ns ch ed u le dl oa d ) % clc && Load (1 , i ) ( mean ( un sc h ed ul ed l oa d ) - min ( u ns c he du le d lo ad ) ) % && Load (1 , i ) = min ( EP ) ) % Compare fitness value with D11 . D11 = F1 (1 , i ) ; Lbest = popnew (i ,:) ; % gbest position achieved here . Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end end if EP ( hour ) min ( un sc h ed ul e dl oa d ) ) D11 = F1 (1 , i ) ; % mean ( u ns c he du le d lo ad ) Lbest = popnew (i ,:) ; % gbest position achieved here . Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end if i ==2 if ( F1 (1 , i ) > D11 && Load (1 , i ) > min ( un s ch ed ul e dl oa d ) ) D11 = F1 (1 , i ) ; % mean ( u ns c he du le d lo ad ) Lbest = popnew (i ,:) ; % gbest position achieved here . Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end

1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275

end end if D11 == inf for i = 1: popsize if ( F1 (1 , i ) < D11 && Load (1 , i ) > min ( un sc h ed ul ed l oa d ) ) D11 = F1 (1 , i ) ; Lbest = popnew (i ,:) ; % gbest position achieved here . Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end

91

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300

end if D11 == inf for i = 1: popsize if ( F1 (1 , i ) < D11 ) % && Load (1 , i ) > min ( u ns ch e du le dl o ad ) ) D11 = F1 (1 , i ) ; Lbest = popnew (i ,:) ; % gbest position achieved here . Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end end gbest = Lbest (1 ,:) ; popnew ( ij ,:) =0; for b =1: D if ( gbest (1 , b ) ==1) G_time_slots (1 , b ) = G_time_slots (1 , b ) -1; elseif ( gbest (1 , b ) ==0) G_time_slots (1 , b ) = G_time_slots (1 , b ) ; end end G_time_slots ; hour ; %%%%%%% check %% Next Generation

1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331

% ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘~~~~~~~~~~~~~~~~~~~~~~~~~ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘ ‘~~~~~~~~~~~~~~~~~% % - - - - - - - - - - - - - - - - Genereate new population - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% for j =1: maxgen % - - - - - - - Select Crossover pair - - - - - - - - - - - - -% ii = floor ( ind * rand ) ; jj = floor ( ind * rand ) ; if ii ==0 ii = randi ( ind ,1 ,1) ; end if jj ==0 jj = randi ( ind ,1 ,1) ; end % - - - - - - - Crossover pair selected - - - - - - - - - - -% % - - - - - - Crossover - - - - - - - - - - -% if pc > rand [ popnew ( ii ,:) , popnew ( jj ,:) ]= crossover ( pop ( ii ,:) , pop ( jj ,:) ) ; count = count +2; end % - - - - - - - - Crossover done - - - - -% % - - - - - - - - - - - - - - - - - - - - - - - - - Do Mutation at n sites - - - - - - - - - - - -% if pm > rand kk = floor ( ind * rand ) ; if kk ==0 kk = randi ( ind ,1 ,1) ; end count = count +1; popnew ( kk ,:) = mutate ( popnew ( kk ,:) , insite ) ; end % - - - - - - - - - - - - - - - - - - - - - - - - - Mutation done - - - - - - - - - - - - - - - - - - - - - -%

1332

92

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1333 1334

% - - - - - - - - - - - - - - - - - - - - - - - - - - New population generated - - - - - - - - - - - - - - - - - - - - -%

1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% popnew ; end EP_x _AppStat us = gbest ; size ( EP _x_AppSt atus ) ; app_Sch_G ( hour ,:) = gbest (: ,:) ; s ch ed ul e _l oa d_ G ( hour ) = p * gbest ’; E_Cost_SS_G ( hour ) = ds ; s u m _ s c h e d u l e d _ l o a d _ G = s ch ed ul e _l oa d_ G ( hour ) + s u m _ s c h e d u l e d _ l o a d _ G ; s um _E _C o st _S S_ G = E_Cost_SS_G ( hour ) + s um _ E_ Co st _ SS _G ; P AR _s ch e du le d_ G = max ( s ch e du le _l o ad _G ) /(( s u m _ s c h e d u l e d _ l o a d _ G ) /24) ; PAR_G =(( PA R_ s ch ed ul e d_ G ) /( PA R_ un s ch ed ul e d ) ) *100; P AR _r ed u ct io n_ G =100 - PAR_G ; hour ;

1350 1351 1352 1353 1354 1355 1356

% % % % % %

trading for each hour I think here the trading condition may implement check hourly load check battery CHECK cost / price then take descion about sale or purchase or store

1357 1358 1359 1360 1361

status = app_Sch_G ( hour ,:) ; % hourly On OFF status hourlyLoad = s c he du le _ lo ad _G ( hour ) ; % hourly load ep_hour = EP ( hour ) ; % hourly price hourly_res = t o t a l _ r es _ h o u r l y ( hour ) ; % hourly generation

1362 1363

avg_ep = mean ( EP ) ;

1364 1365 1366 1367 1368

%%%%%%%%%%%%%%%%%%%%%% start trading if ep_hour < avg_ep && hour 0.2 % ess must greater 2 kw for sale sale ( hour ) = ESS *0.9;

93

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401

ESS = ESS *0.10; elseif ep_hour 22 ESS = ESS - grid_load ( hour ) ; grid_load ( hour ) =0; sale ( hour ) = ESS *0.9; ESS = ESS *0.10; else sale ( hour ) =0; end %%%%%%%% % end trading area

1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429

%% Appliances Scheduled hours dish_washer_G (: , hour ) = app_Sch_G ( hour ,1) ; w a s h i n g _ m a c h i n e _ G (: , hour ) = app_Sch_G ( hour ,2) ; spin_dryer_G (: , hour ) = app_Sch_G ( hour ,3) ; i n t e r i o r _ l i g h t i n g _ G (: , hour ) = app_Sch_G ( hour ,4) ; refr iegrator _G (: , hour ) = app_Sch_G ( hour ,5) ; cooker_hob_G (: , hour ) = app_Sch_G ( hour ,6) ; cooker_oven_G (: , hour ) = app_Sch_G ( hour ,7) ; microvave_G (: , hour ) = app_Sch_G ( hour ,8) ; laptop_G (: , hour ) = app_Sch_G ( hour ,9) ; desktop_G (: , hour ) = app_Sch_G ( hour ,10) ; v a c u u m _ c l e a n e r _G (: , hour ) = app_Sch_G ( hour ,11) ; e l e c t r i c a l _ c a r _G (: , hour ) = app_Sch_G ( hour ,12) ; end old_fxCG ( er2 ) = s um _ E_ Co st _ SS _G ; old_fxPG ( er2 ) = P AR _ sc he du l ed _G ; if er2 >1 errorG = abs ( old_fxCG ( er2 -1) - old_fxCG ( er2 ) ) ; errorGP = abs ( old_fxPG ( er2 -1) - old_fxPG ( er2 ) ) ; errorG1 ( count2 ) = errorG ; errorG2 ( count2 ) = errorGP ; end count2 = count2 +1; % popsize = popsize +50; % maxgen = maxgen +20; PoPulationG ( count2 ) = popsize ; er2 = er2 +1;

1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448

tdw2_G = strfind ( dish_washer_G ,1) ; twm2_G = strfind ( washing_machine_G ,1) ; tsd2_G = strfind ( spin_dryer_G ,1) ; tch2_G = strfind ( cooker_hob_G ,1) ; tco2_G = strfind ( cooker_oven_G ,1) ; tm2_G = strfind ( microvave_G ,1) ; tl2_G = strfind ( laptop_G ,1) ; td2_G = strfind ( desktop_G ,1) ; tvc2_G = strfind ( vacuum_cleaner_G ,1) ; tec2_G = strfind ( electrical_car_G ,1) ; til2_G = strfind ( interior_lighting_G ,1) ; tr2_G = strfind ( refriegrator_G ,1) ; % - - - - - - - - - Base / fixed Comfort - - - - - - - - - - -% D1_G =( sum ( abs ( tch1 - tch2_G ) ) ) / sum ( cooker_hob_G ) ; D2_G =( sum ( abs ( tco1 - tco2_G ) ) ) / sum ( cooker_oven_G ) ; D3_G =( sum ( abs ( tm1 - tm2_G ) ) ) / sum ( microvave_G ) ; D4_G =( sum ( abs ( tl1 - tl2_G ) ) ) / sum ( laptop_G ) ; D5_G =( sum ( abs ( td1 - td2_G ) ) ) / sum ( desktop_G ) ;

94

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1449 1450 1451 1452 1453 1454

D6_G =( sum ( abs ( tvc1 - tvc2_G ) ) ) / sum ( v a c u u m _ c l e a n e r _ G ) ; D7_G =( sum ( abs ( tec1 - tec2_G ) ) ) / sum ( e l e c t r i c a l _ c a r _ G ) ; U s e r _ C o m f o r t _ B a s e _ G =[ D1_G D2_G D3_G D4_G D5_G D6_G D7_G ]; Base _waiting _G = sum ( U s e r _ C o m f o r t _ B a s e _ G ) ; % A v g _ U s e r _ C o m f o r t _ G a s e = Base_waiting /3; % - - - - - - - - - Brust load Intruptable - - - - - - - - - - - -%

1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476

D8_G =( sum ( abs ( tdw1 - tdw2_G ) ) ) / sum ( dish_washer_G ) ; D9_G =( sum ( abs ( twm1 - twm2_G ) ) ) / sum ( w a s h i n g _ m a c h i n e _ G ) ; D10_G =( sum ( abs ( tsd1 - tsd2_G ) ) ) / sum ( spin_dryer_G ) ; U s e r _ C o m f o r t _ G B r u s t _ G =[ D8_G D9_G D10_G ]; B ru st _ wa it in g _G = sum ( U s e r _ C o m f o r t _ G B r u s t _ G ) ; % A v g _ U s e r _ C o m f o r t _ G r u s t = Brust_waiting /4; % - - - - - - - - - Brust load unIntruptable - - - - - - - - - - - -% D11_G =( sum ( abs ( til1 - til2_G ) ) ) / sum ( i n t e r i o r _ l i g h t i n g _ G ) ; D12_G =( sum ( abs ( tr1 - tr2_G ) ) ) / sum ( refriegr ator_G ) ; U s e r _ C o m f o r t _ U n i t r p _ G =[ D11_G D12_G ]; NonIntrupt_G = sum ( U s e r _ C o m f o r t _ U n i t r p _ G ) ; % A v g _ U s e r _ C o m f o r t _ n o n = NonIntrupt /2; %% Average Calculation app_SchAvg_G = app_Sch_G + app_SchAvg_G ; schedule_load_Avg_G = s c h e d u l e _ l o a d _ A v g _ G + sc h ed ul e_ l oa d_ G ; E _C os t_ S S_ Av g_ G = E _C os t_ S S_ Av g_ G + E_Cost_SS_G ; sum_scheduled_load_Avg_G = sum_scheduled_load_G + sum_scheduled_load_Avg_G ; sum_E_Cost_SS_Avg_G = s u m _ E _ C o s t _ S S _ A v g _ G + su m _E _C os t _S S_ G ; PAR_scheduled_Avg_G = P A R _ s c h e d u l e d _ A v g _ G + PA R _s ch ed u le d_ G ; PAR_Avg_G = PAR_G + PAR_Avg_G ; PAR_reduction_Avg_G = PA R_ re d uc ti on _ G + P A R _ r e d u c t i o n _ A v g _ G ;

1477 1478 1479 1480

%% Average of Waiting Time and Maximum time B as e_ lo a d_ G_ Av g =( sum ( U s e r _ C o m f o r t _ B a s e _ G ) ) /7; B as e_ lo a d_ G_ Ma x = max ( U s e r _ C o m f o r t _ B a s e _ G ) ;

1481 1482 1483

B r u s t _ l o a d _ G _ Av g B r u s t _ l o a d _ G _ Ma x

=( sum ( U s e r _ C o m f o r t _ G B r u s t _ G ) ) /3; = max ( U s e r _ C o m f o r t _ G B r u s t _ G ) ;

NonIntp_load_G_Avg NonIntp_load_G_Max %%

=( sum ( NonIntrupt_G ) ) /2; = max ( NonIntrupt_G ) ;

1484 1485 1486 1487 1488 1489 1490

G A _ B a s e _ l o a d _ G _ A v g ( avg2 ,:) G A _ B a s e _ l o a d _ G _ M a x ( avg2 ,:)

= Ba s e_ lo ad _ G_ Av g ; = Ba s e_ lo ad _ G_ Ma x ;

G A _ B r u s t _ l o a d _ G _ A v g ( avg2 ,:) G A _ B r u s t _ l o a d _ G _ M a x ( avg2 ,:)

= B r u s t_ l o a d _ G _ A v g ; = Brust_load_G_Max ;

G A _ N o n I n t p _ l o a d _ G _ A v g ( avg2 ,:) G A _ N o n I n t p _ l o a d _ G _ M a x ( avg2 ,:)

= NonIntp_load_G_Avg ; = NonIntp_load_G_Max ;

1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506

%% Average Parameters GA_PAR ( avg2 ,:) = PA R_ s ch ed ul e d_ G ; GA_E_Cost_SS ( avg2 ,:) = E_Cost_SS_G ; G A _ s c h e d u l e _ l o a d _ ( avg2 ,:) = sc h ed ul e_ l oa d_ G ; G A _ s u m _ E _ C o s t _S S ( avg2 ,:) = s um _E _C o st _S S_ G ; GA_app_Sch (: ,: , avg2 ) = app_Sch_G ; G A _ S u m _ S c h e d u l e d _ l o a d ( avg2 ,:) = s u m _ s c h e d u l e d _ l o a d _ G ; % avg2 = avg2 +1;

95

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1507 1508 1509

% % %

if avg2 >1 MSEtst ( avg2 -1 ,:) = mse ( GA_PAR ( avg2 -1 ,:) - GA_PAR ( avg2 ,:) ) ; end app_Sch_G ; p;

1510 1511

end

1512 1513 1514 1515

GA_Base_load_Avg_Avg = mean ( G A _ B a s e _ l o a d _ G _ A v g ) ; GA_Base_load_Max_Avg = mean ( G A _ B a s e _ l o a d _ G _ M a x ) ; GA_Brust_load_Avg_Avg = mean ( G A _ B r u s t _ l o a d _ G _ A v g ) ; GA_Brust_load_Max_Avg = mean ( G A _ B r u s t _ l o a d _ G _ M a x ) ; GA_NonIntp_load_Avg_Avg = mean ( G A _ N o n I n t p _ l o a d _ G _ A v g ) ; GA_NonIntp_load_Max_Avg = mean ( G A _ N o n I n t p _ l o a d _ G _ M a x ) ; GA_PAR_Avg = mean ( GA_PAR ) ; GA_E_Cost_SS_Avg = mean ( GA_E_Cost_SS ) ; GA_scheduled_Avg = mean ( G A _ s c h e d u l e _ l o a d _ ) ; GA_sum_E_Cost_SS_Avg = mean ( G A _ s u m _ E _ C o s t _ S S ) ; U se r_ Co m fo rt _ GA =[ G A _ B a s e _ l o a d _ A v g _ A v g G A _ B r u s t _ l o a d _ A v g _ A v g G A _ N o n I n t p _ l o a d _ A v g _ A v g ]; %%%%%%%

1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529

1530

SA algorithm

1531 1532 1533

% % % % % % % % % % % % % % % % % % % strbery algoooo

1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546

%% %% Average Calculation Strawberry Algorithm app_SchAvg_sb = zeros (24 ,12) ; s c h e d u l e _ l o a d _ A v g _ s b = zeros (1 ,24) ; E _ C o s t _ S S _ A v g _ sb = zeros (1 ,24) ; s u m _ s c h e d u l e d _ l o a d _ A v g _ s b =0; s u m _ E _ C o s t _ S S _ A v g _ s b =0; P A R _ s c h e d u l e d _ A v g _ s b =0; PAR_Avg_sb =0; P A R _ r e d u c t i o n _ A v g _ s b =0; s u m _ E _ C o s t _ S S _ s b =0; s u m _ s c h e d u l e d _ l o a d _ s b =0;

1547 1548 1549

ul = -600; uh = 600;

% lower bound of variables

1550 1551 1552 1553

%%

1554 1555

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

1556 1557

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

1558 1559

% % % % % % % % % % % % % % % % % % % % % % % Strawberry Algorithm Im plement ation

1560 1561 1562

sb_time_slots =[ t i m e _ s l o t s _ I n t r u p t t i m e _ s l o t s _ n o n I n t r time_ slotFixe d ]; p =[ pIntr pNonTntr pFixed ];

96

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1563 1564 1565 1566

c _ e l e c t r i c i t y _ c o s t = -[ p (1) p (2) p (3) p (4) p (5) p (6) p (7) p (8) p (9) p (10) p (11) p (12) ]; a =0; for avg3 =1:10

1567 1568 1569 1570 1571

%% %% Average Calculation

1572 1573 1574 1575 1576 1577 1578

best = inf ; gbest = inf ; Fbest = inf ; app_Sch_PP = zeros (24 ,12) ; s u m _ s c h e d u l e d _ l o a d _ s b =0; sb_time_slots =[ t i m e _ s l o t s _ I n t r u p t t i m e _ s l o t s _ n o n I n t r t ime_slot Fixed ];

1579 1580 1581 1582 1583

E_Cost_SS_PP = zeros (1 ,24) ; s u m _ E _ C o s t _ S S _ s b =0; s c h e d u l e _ l o a d _ P P = zeros (1 ,24) ; errorPP = inf ;

1584 1585 1586 1587 1588 1589 1590

for hour =1:24 e l e c t r i c i t y _ c o s t =[ EP ( hour ) * p (1) EP ( hour ) * p (2) EP ( hour ) * p (3) EP ( hour ) * p (4) EP ( hour ) * p (5) EP ( hour ) * p (6) EP ( hour ) * p (7) EP ( hour ) * p (8) EP ( hour ) * p (9) EP ( hour ) * p (10) EP ( hour ) * p (11) EP ( hour ) * p (12) ];% coefficients of objective function

1591 1592

%%%% Evalution of population %%%%

1593 1594 1595 1596

N = 30;% popsize m = 12; % number of appliances

1597 1598 1599 1600

ul = -1; uh =1;

1601 1602 1603

drunner = 400; droot = 10;

% length of runners % length of roots

1604 1605 1606 1607

a = 0; % used in the definition of fitness function count =1; kmax = 10; % maximum number of iterations at each run

1608 1609

% function sb = ppa [

1610 1611 1612 1613

% for test_no = 1:10 % the simulation is performed 100 times and then the % if count uh r2 (i , j ) = uh ;

1640 1641

elseif r2 (i , j ) < ul r2 (i , j ) = ul ; end

1642 1643 1644

end

1645 1646

% if a solution ( runner or root ) lies % outside the legal region , we put it on % the border

end

1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661

% the following lines evaluate the m - variable Griewank ( and Rastrigin ) % function . In order to study other functions , comment the lines %62 -71 and uncomment appropriate lines among 73 -97 f = zeros (1 ,2* N ) ; temp2 = 1; for j =1: m % f = f + r2 (j ,:) .^2 -10* cos (2* pi * r2 (j ,:) ) ; % f = f + r2 (j ,:) .^2/4000; % temp2 = temp2 .* cos ( r2 (j ,:) / sqrt ( j ) ) ; f = f - tan ( r2 (j ,:) ) .*( tan ( j * r2 (j ,:) .^2/ pi ) ) .^20; temp2 = temp2 .* cos ( r2 (j ,:) / sqrt ( j ) ) ; end f = f - temp2 ;

1662 1663 1664 1665 1666 1667 1668 1669

% the following lines select N /2 of the best columns of r2 % as mother plants of the next iteration ( elite selection ) f_sorted = sort (f , ’ ascend ’) ; for j =1: N /2 r1 (: , j ) = r2 (: , find ( f == f_sorted ( j ) ,1) ) ; end

1670 1671 1672 1673 1674 1675 1676 1677 1678

% fitness evaluation for j =1: N if f ( j ) >0 weights ( j ) = 1/( a + f ( j ) ) ; else weights ( j ) = a + abs ( f ( j ) ) ; end end

98

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1679

% the following lines select N /2 columns of r2 by chance % ( i . e . , by means of roulette wheel ) as mother plants of the next % iteration . The fortune_wheel function is used for this purpose . for j = N /2+1: N chosen_index = fortune_wheel ( weights ) ; % chosen_index = R o u l e t t e W h e e l S e l e c t i o n ( weights ) ; r1 (: , j ) = r2 (: , chosen_index ) ; end rr = r1 ’; % saving the best results if min ( f ) < f_best f_best = min ( f ) ;

1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692

end

1693 1694

%

1695

%

1696

best_so_far ( k ) = f_best ; X ( test_no , k ) = f_best ;

1697 1698

%

end

1699

% test_no

1700 1701 1702

end

1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715

X = rr ; for i =1: N % converting all values into binary for switching appliances for k =1: m if X (i , k ) >( -0.1) ; X (i , k ) =1; else X (i , k ) =0; end end end %%%%%%%%%%%% scheduling appliancesS lhour =25 - hour ;

1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728

for a =1: N for b =1: m if sb_time_slots (1 , b ) max ( u ns ch ed u le dl oa d ) ) % min ( u ns ch e du le dl o ad ) && Load (1 , i ) ( mean ( un s ch ed ul e dl oa d ) + min ( u ns ch ed u le dl oa d ) ) && Load (1 , i ) = t_load - std ( un sc he d ul ed lo a d ) D11 = F1 (1 , i ) ; % mean ( u ns c he du le d lo ad ) Lbest = X (i ,:) ; % gbest position achieved here . Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end end if EP ( hour ) > D_EP for i = 1: N % if ( F1 (1 , i ) < D11 && Load (1 , i ) >( std ( unscheduledload - min ( u ns ch ed u le dl o ad ) ) ) &&( Load (1 , i ) < mean ( u ns c he du le d lo ad ) - min ( un s ch ed ul e dl oa d ) ) && ( Load (1 , i ) < mean ( u ns ch e du le dl o ad ) ) ) % clc && Load (1 , i ) ( mean ( un sc h ed ul ed l oa d ) - min ( u ns c he du le d lo ad ) ) % && Load (1 , i ) = min ( EP ) ) % Compare fitness value with D11 . if ( F1 (1 , i ) < D11 && Load (1 , i ) > ( std ( u n sc he du l ed lo a d ) +2*( min ( u ns ch ed u le dl o ad ) ) ) ) &&( Load (1 , i ) < mean ( un sc he d ul ed lo a d ) - min ( u ns ch ed u le dl oa d ) )

1769

D11 = F1 (1 , i ) ; Lbest = X (i ,:) ; % gbest position achieved here .

1770 1771 1772

Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ;

1773 1774 1775

end

1776

end

1777 1778 1779

end if EP ( hour ) D11 && Load (1 , i ) < min ( un s ch ed ul e dl oa d ) )

1784 1785 1786

D11 = F1 (1 , i ) ; % mean ( u ns c he du l ed lo ad ) Lbest = X (i ,:) ; % gbest position achieved here .

1787 1788 1789 1790 1791 1792 1793

Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end if i ==2

100

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1794

if ( F1 (1 , i ) > D11 && Load (1 , i ) > min ( un s ch ed ul e dl oa d ) )

1795 1796 1797

D11 = F1 (1 , i ) ; % mean ( u ns c he du le d lo ad ) Lbest = X (i ,:) ; % gbest position achieved here .

1798 1799 1800 1801 1802 1803

Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end

1804 1805 1806 1807 1808 1809

end end if D11 == inf for i = 1: N if ( F1 (1 , i ) < D11 && Load (1 , i ) > min ( un s ch ed ul e dl oa d ) )

1810 1811 1812

D11 = F1 (1 , i ) ; Lbest = X (i ,:) ; % gbest position achieved here .

1813 1814 1815 1816 1817 1818 1819 1820 1821 1822

Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end end if D11 == inf for i = 1: N if ( F1 (1 , i ) < D11 ) %&& ( Load (1 , i ) < min ( u n sc he du l ed lo ad ) )

1823 1824 1825

D11 = F1 (1 , i ) ; Lbest = X (i ,:) ; % gbest position achieved here .

1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843

Fbest = D11 ; ds = E_Cost (1 , i ) ; ij = i ; end end end gbest = Lbest (1 ,:) ; X ( ij ,:) =0; for b =1: D if ( gbest (1 , b ) ==1) sb_time_slots (1 , b ) = sb_time_slots (1 , b ) -1; elseif ( gbest (1 , b ) ==0) sb_time_slots (1 , b ) = sb_time_slots (1 , b ) ; end end sb_time_slots ; hour ;

1844 1845 1846 1847 1848 1849 1850 1851

EP_x_ AppStat us = gbest ; size ( EP_ x_AppSt atus ) ; app_Sch_PP ( hour ,:) = gbest (: ,:) ; s c h e d u l e _ l o a d _ P P ( hour ) = p * gbest ’; E_Cost_SS_PP ( hour ) = ds ; s u m _ s c h e d u l e d _ l o a d _ s b = s c h e d u l e _ l o a d _ P P ( hour ) + s u m _ s c h e d u l e d _ l o a d _ s b ; s u m _ E _ C o s t _ S S _ s b = E_Cost_SS_PP ( hour ) + s u m _ E _ C os t _ S S _ s b ;

101

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1852 1853 1854 1855

P A R _ s c h e d u l e d _ PP = max ( sc h e d u l e _ l o a d _ P P ) /(( s u m _ s c h e d u l e d _ l o a d _ s b ) /24) ; PAR_PP =(( P A R _ s c h e d ul e d _ P P ) /( PA R_ un s ch ed ul e d ) ) *100; P A R _ r e d u c t i o n _ PP =100 - PAR_PP ; hour ;

1856 1857 1858 1859 1860 1861

%% Appliances Scheduled hours

1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874

dish _washer_ PP (: , hour ) = app_Sch_PP ( hour ,1) ; w a s h i n g _ m a c h i n e _ P P (: , hour ) = app_Sch_PP ( hour ,2) ; spin_dryer_PP (: , hour ) = app_Sch_PP ( hour ,3) ; i n t e r i o r _ l i g h t i n g _ P P (: , hour ) = app_Sch_PP ( hour ,4) ; r ef ri eg r at or _P P (: , hour ) = app_Sch_PP ( hour ,5) ; cooker_hob_PP (: , hour ) = app_Sch_PP ( hour ,6) ; cook er_oven_ PP (: , hour ) = app_Sch_PP ( hour ,7) ; microwave_PP (: , hour ) = app_Sch_PP ( hour ,8) ; laptop_PP (: , hour ) = app_Sch_PP ( hour ,9) ; desktop_PP (: , hour ) = app_Sch_PP ( hour ,10) ; v a c u u m _ c l e a n e r _ P P (: , hour ) = app_Sch_PP ( hour ,11) ; e l e c t r i c a l _ c a r _ P P (: , hour ) = app_Sch_PP ( hour ,12) ;

1875 1876

end

1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890

% % % % % % % % % % % % % % %% return the location of string % % % % % % % % % % % % % % % % % tec3_PP = strfind ( electrical_car_PP ,[1]) ; tsd3_PP = strfind ( spin_dryer_PP ,[1]) ; tm3_PP = strfind ( microwave_PP ,[1]) ; tco3_PP = strfind ( cooker_oven_PP ,[1]) ; tch3_PP = strfind ( cooker_hob_PP ,[1]) ; til3_PP = strfind ( interior_lighting_PP ,[1]) ; tr3_PP = strfind ( refriegrator_PP ,[1]) ; twm3_PP = strfind ( washing_machine_PP ,[1]) ; tvc3_PP = strfind ( vacuum_cleaner_PP ,[1]) ; tl3_PP = strfind ( laptop_PP ,[1]) ; tdw3_PP = strfind ( dish_washer_PP ,[1]) ; td3_PP = strfind ( desktop_PP ,[1]) ;

1891 1892 1893 1894 1895 1896 1897 1898 1899

% - - - - - - - - - Intruptable Appliances - - - - - - - - - - - -% D1_PP =( sum ( abs ( tdw1 - tdw3_PP ) ) ) / sum ( dis h_washer _PP ) ; D2_PP =( sum ( abs ( twm1 - twm3_PP ) ) ) / sum ( w a s h i n g _ m a c h i n e _ P P ) ; D3_PP =( sum ( abs ( tsd1 - tsd3_PP ) ) ) / sum ( spin_dryer_PP ) ; D4_PP =( sum ( abs ( til1 - til3_PP ) ) ) / sum ( i n t e r i o r _ l i g h t i n g _ P P ) ; U s e r _ C o m f o r t _ I n t r u p t _ a p p l i a n c e s _ P P =[ D1_PP D2_PP D3_PP D4_PP ]; I n t r u p t _ a p p l i a n c e s _ P P = sum ( U s e r _ C o m f o r t _ I n t r u p t _ a p p l i a n c e s _ P P ) ;

1900 1901 1902 1903 1904 1905

% - - - - - - - - - Non intruptable Appliances - - - - - - - - - - - -% D5_PP =( sum ( abs ( tr1 - tr3_PP ) ) ) / sum ( r ef ri e gr at or _ PP ) ; D6_PP =( sum ( abs ( tch1 - tch3_PP ) ) ) / sum ( cooker_hob_PP ) ; D7_PP =( sum ( abs ( tco1 - tco3_PP ) ) ) / sum ( coo ker_oven _PP ) ; D8_PP =( sum ( abs ( tm1 - tm3_PP ) ) ) / sum ( microwave_PP ) ;

1906 1907 1908

U s e r _ C o m f o r t _ N o n _ i n t r u p t a b l e _ a p p l i a n c e s _ P P =[ D5_PP D6_PP D7_PP D8_PP ]; N o n _ i n t r u p t a b l e _ P P = sum ( U s e r _ C o m f o r t _ N o n _ i n t r u p t a b l e _ a p p l i a n c e s _ P P ) ;

1909

102

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1910 1911 1912 1913 1914

% - - - - - - - - - Base Appliances - - - - - - - - - - - -% D9_PP =( sum ( abs ( tl1 - tl3_PP ) ) ) / sum ( laptop_PP ) ; D10_PP =( sum ( abs ( td1 - td3_PP ) ) ) / sum ( desktop_PP ) ; D11_PP =( sum ( abs ( tvc1 - tvc3_PP ) ) ) / sum ( v a c u u m _ c l e a n e r _ P P ) ; D12_PP =( sum ( abs ( tec1 - tec3_PP ) ) ) / sum ( e l e c t r i c a l _ c a r _ P P ) ;

1915 1916 1917 1918

U s e r _ C o m f o r t _ B a s e _ A p p l i a n c e s _ P P =[ D9_PP D10_PP D11_PP D12_PP ]; B a s e _ A p p l i a n c e s _ P P = sum ( U s e r _ C o m f o r t _ B a s e _ A p p l i a n c e s _ P P ) ;

1919 1920 1921 1922 1923 1924

%% Average Calculation app_SchAvg_sb schedule_load_Avg_sb E_Cost_SS_Avg_sb sum_scheduled_load_Avg_sb

= app_Sch_PP + app_SchAvg_sb ; = schedule_load_Avg_sb + schedule_load_PP ; = E _ C o s t _ S S _ A v g _ s b + E_Cost_SS_PP ; = sum_scheduled_load_sb + sum_scheduled_load_Avg_sb ;

sum_E_Cost_SS_Avg_sb PAR_scheduled_Avg_sb PAR_Avg_sb PAR_reduction_Avg_sb

= sum_E_Cost_SS_Avg_sb + sum_E_Cost_SS_sb ; = PAR_scheduled_Avg_sb + PAR_scheduled_PP ; = PAR_PP + PAR_Avg_sb ; = P A R _ r e d u c t io n _ P P + P A R _ r e d u c t i o n _ A v g _ s b ;

1925 1926 1927 1928 1929 1930 1931

%% Average of Waiting Time and Maximum time

1932 1933 1934

Intp_load_PP_Avg Intp_load_PP_Max

=( sum ( I n t r u p t _ a p p l i a n c e s _ P P ) ) /4; = max ( I n t r u p t _ a p p l i a n c e s _ P P ) ;

1935 1936 1937

NonIntp_load_PP_Avg NonIntp_load_PP_Max

=( sum ( N o n _ i n t r u p t a b l e _ P P ) ) /4; = max ( N o n _ i n t r u p t a b l e _ P P ) ;

1938 1939 1940

Base_load_PP_Avg Base_load_PP_Max

=( sum ( B a se _ A p p l i a n c e s _ P P ) ) /4; = max ( B a s e _ A p p l i a n c e s _ P P ) ;

1941 1942 1943 1944

Intp_Load =[ I n t p _ l o a d_ P P _ A v g ]; NonIntp_Load =[ N o n I n t p _ l o a d _ P P _ A v g ]; Base_Load =[ B a s e _ l o a d_ P P _ A v g ];

1945 1946 1947 1948 1949

%%%%%%% LOAD =[ NonIntp_Load , Intp_Load ]; %% P P _ I n t p _ l o a d _ P P _ A v g ( avg3 ,:) = I n tp _ l o a d _ P P _ A v g ; P P _ I n t p _ l o a d _ P P _ M a x ( avg3 ,:) = Intp_load_PP_Max ;

1950 1951 1952

P P _ N o n I n t p _ l o a d _ P P _ A v g ( avg3 ,:) P P _ N o n I n t p _ l o a d _ P P _ M a x ( avg3 ,:)

= NonIntp_load_PP_Avg ; = NonIntp_load_PP_Max ;

P P _ B a s e _ l o a d _ P P _ A v g ( avg3 ,:) P P _ B a s e _ l o a d _ P P _ M a x ( avg3 ,:)

= B a se _ l o a d _ P P _ A v g ; = B a se _ l o a d _ P P _ M a x ;

1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967

%% Cofidence Interval Parameters PP_PAR ( avg3 ,:) = P A R _ s c h e d u l e d _ P P ; PP_E_Cost_SS ( avg3 ,:) = E_Cost_SS_PP ; P P _ s c h e d u l e _ l o a d _ ( avg3 ,:) = s c h e d u l e _ l o a d _ P P ; P P _ s u m _ E _ C o s t _ S S ( avg3 ,:) = s u m _ E _ C o s t _ S S _ s b ; PP_app_Sch (: ,: , avg3 ) = app_Sch_PP ; P P _ S u m _ S c h e d u l e d _ l o a d ( avg3 ,:) = s u m _ s c h e d u l e d _ l o a d _ s b ; % avg2 = avg2 +1; % if avg3 >1 % MSEtst ( avg3 -1 ,:) = mse ( PP_PAR ( avg3 -1 ,:) - PP_PAR ( avg3 ,:) ) ;

103

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 1968

% end

1969 1970

end

1971 1972 1973

%% Rsults for Plants Propagation %^^^^^^^^^^^^^^^^^^^^^&&&&&&&&&&&&&&&&&&&&^^^^^^^^^^^^^^^^^^^^^^^

1974 1975 1976 1977 1978 1979 1980

PP_Intp_load_Avg_Avg PP_Intp_load_Max_Avg PP_NonIntp_load_Avg_Avg PP_NonIntp_load_Max_Avg PP_Base_load_Avg_Avg PP_Base_load_Max_Avg

= = = = = =

mean ( P P _ I n t p _ l o a d _ P P _ A v g ) ; mean ( P P _ I n t p _ l o a d _ P P _ M a x ) ; mean ( P P _ N o n I n t p _ l o a d _ P P _ A v g ) ; mean ( P P _ N o n I n t p _ l o a d _ P P _ M a x ) ; mean ( P P _ B a s e _ l o a d _ P P _ A v g ) ; mean ( P P _ B a s e _ l o a d _ P P _ M a x ) ;

PP_PAR_Avg PP_E_Cost_SS_Avg PP_scheduled_Avg PP_sum_E_Cost_SS_Avg

= =

mean ( PP_PAR ) ; mean ( PP_E_Cost_SS ) ; mean ( P P _ s c h e d u l e _ l o a d _ ) ; mean ( P P _ s u m _ E _ C o s t _ SS ) ;

1981 1982 1983 1984 1985

= =

1986 1987 1988

U se r_ Co m fo rt _P P =[ P P _ I n t p _ l o a d _ A v g _ A v g P P _ N o n I n t p _ l o a d _ A v g _ A v g P P _ B a s e _ l o a d _ A v g _ A v g ];

1989 1990 1991 1992 1993 1994 1995

%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%

cuckoooo serch start

1996 1997

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

1998 1999 2000

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

2001 2002

2003

CSA main code

2004 2005 2006 2007 2008

%% before going for the code must read the orignal algorithms of Cuckoo and GA close all ;

2009 2010 2011 2012

%% Smart Grid Parameters intialization time_slots ; maxAvg =3;

2013 2014 2015 2016 2017 2018 2019

% Appliances = [ I n t r u p t _ a p p l i a n c e s N on _ in tr up t ab le F i x e d _ A p p l i a n c e s ]; D_EP = round ( mean ( EP ) ) ; %% Normalized load for fitness function load_ (1: length ( u ns c he du le d lo ad ) ) =( u n sc he du l ed lo ad (1: length ( un sc h ed ul ed l oa d ) ) min ( un sc h ed ul ed l oa d ) ) /( max ( un sc h ed ul ed l oa d ) - min ( u ns ch e du le dl o ad ) ) ; t_load = sum ( load_ ) ;

2020 2021 2022 2023 2024

%% Objective Load Curve for hour =1:24 if EP ( hour ) D_EP obj_Load ( hour ) = ( std ( un sc he d ul ed lo a d ) +( mean ( u n sc he d ul ed lo a d ) - min ( u ns ch ed u le dl oa d ) ) ) /2; end end %% %% %%%%%%%%%% - - - - - - - - - - - - - - - - - - - - - - - - Scheduling - - - - - - - - - - - - - - - - - - - - - - - -%%%%%%%%%%%% %% Scheduling For the Appliances just to minimize the cost and PAR ... %% - - - - - - - - - - - - - - - - - - - - - - - - - - - - Parameters Initi alizati on - - - - - - - - - - - - - - - - - - - - - - %% Nn =50; % The number of population steps D =12; % Dimension of a search space number of appliances to schedule s um _E _C o st _S S_ C =0; s u m _ s c h e d u l e d _ l o a d _ C =0; er1 =1; count1 =0; %% %% Variable used for Average Calculation %% for Cuckoo without coordination

2046 2047 2048 2049 2050 2051 2052 2053 2054

app_SchAvg_C = zeros (24 ,12) ; s c h e d u l e _ l o a d _ A v g _ C = zeros (1 ,24) ; E _C os t_ S S_ Av g _C = zeros (1 ,24) ; s u m _ s c h e d u l e d _ l o a d _ A v g _ C =0; s u m _ E _ C o s t _ S S _ A v g _ C =0; P A R _ s c h e d u l e d _ A v g _ C =0; PAR_Avg_C =0; P A R _ r e d u c t i o n _ A v g _ C =0;

2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068

%% %% average calculation for avg1 = 1:2 app_Sch_C = zeros (24 ,12) ; B_app_Sch_C = zeros (24 ,12) ; s u m _ s c h e d u l e d _ l o a d _ C =0; C_time_slots =[ t i m e _ s l o t s _ I n t r u p t t i m e _ s l o t s _ n o n I n t r time_ slotFixe d ]; E_Cost_SS_C = zeros (1 ,24) ; s um _E _C o st _S S_ C =0; P AR _s ch e du le d_ C =0; P A R _ s c h e d u l e d _ A v g =0; s ch ed ul e _l oa d_ C = zeros (1 ,24) ; ESS_c =3; % initialy consider 3 kw for hour =1:24 % for 24 hour schedule

2069 2070 2071 2072

%% %%%%%%%%%%%% Working %%%%%%%%%%%% %% %% START Cuckooo %% %% Call Cuckooo search Algorithm VIA Function %%

2073 2074 2075

[ lbest , fmin , nest , D , pa ]= c u c k o o _ s e a r c h _ w i t h o u t s h e r i (p , EP , hour , C_time_slots , unscheduledload , app_Sch_C ) ;

2076 2077 2078 2079 2080 2081 2082

%% Coordination among appliances gbest = lbest ; gb =0; gbb =0; gbest1 = gbest ; e l e c t r i c i t y _ c o st = EP ( hour ) * p ; % Price for each appliance

105

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099

time ( hour ,:) = C_time_slots ; EP_x _AppStat us = gbest ; size ( EP _x_AppSt atus ) ; s ch ed ul e _l oa d_ C ( hour ) = p * gbest ’; E_Cost_SS_C ( hour ) = e l e c t r i c i t y _ c o s t * gbest ’; s u m _ s c h e d u l e d _ l o a d _ C = s ch ed ul e _l oa d_ C ( hour ) + s u m _ s c h e d u l e d _ l o a d _ C ; s um _E _C o st _S S_ C = E_Cost_SS_C ( hour ) + s um _ E_ Co st _ SS _C ; app_Sch_C ( hour ,:) = gbest (1 ,:) ; for LL =1: length ( gbest ) if gbest (1 , LL ) >0 gbest (1 , LL ) = 1; end if gbest (1 , LL ) == 0 gbest (1 , LL ) = 0; end end

2100 2101 2102 2103 2104 2105 2106 2107

% for b =1: D % % % % end

if C_time_slots (1 , b ) ==0 gbest (1 , b ) =0; end

2108 2109 2110 2111 2112 2113 2114 2115 2116

for b =1: D if ( gbest (1 , b ) >0) C_time_slots (1 , b ) = C_time_slots (1 , b ) -1; elseif ( gbest (1 , b ) ==0) C_time_slots (1 , b ) = C_time_slots (1 , b ) ; end end

2117 2118 2119

C_app_Sch_C ( hour ,:) = gbest (1 ,:) ;

% for scheduling waiting time

2120 2121 2122 2123 2124 2125 2126 2127 2128

% % % % %

trading for each hour check hourly load check battery CHECK cost / price then take descion about sale or purchase or store

2129 2130 2131 2132 2133

status_c = C_app_Sch_C ( hour ,:) ; % hourly On OFF status hourlyLoad_c = s ch e du le _l o ad _C ( hour ) ; % hourly load ep_hour_c = EP ( hour ) ; % hourly price hourly_res_c = t o t a l_ r e s _ h o u r l y ( hour ) ; % hourly generation

2134 2135

avg_ep = mean ( EP ) ;

2136 2137 2138 2139

%%%%%%%%%%%%%%%%%%%%%%

start trading

2140

106

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2141 2142 2143 2144

if ep_hour_c < avg_ep && hour 0.2 % ess must greater 2 kw for sale sale_c ( hour ) = ESS_c *0.9; ESS_c = ESS_c *0.10; elseif ep_hour_c 22 && ESS_c >0.2 ESS_c = ESS_c - grid_load_c ( hour ) ; grid_load_c ( hour ) =0; sale_c ( hour ) = ESS_c *0.9; ESS_c = ESS_c *0.10; else sale_c ( hour ) =0; end %%%%%%%%

2182 2183 2184

%

end trading area

2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198

%% Appliances Scheduled hours dish_washer_C (: , hour ) = C_app_Sch_C ( hour ,1) ; w a s h i n g _ m a c h i n e _ C (: , hour ) = C_app_Sch_C ( hour ,2) ; spin_dryer_C (: , hour ) = C_app_Sch_C ( hour ,3) ; i n t e r i o r _ l i g h t i n g _ C (: , hour ) = C_app_Sch_C ( hour ,4) ; refr iegrator _C (: , hour ) = C_app_Sch_C ( hour ,5) ; cooker_hob_C (: , hour ) = C_app_Sch_C ( hour ,6) ; cooker_oven_C (: , hour ) = C_app_Sch_C ( hour ,7) ; microvave_C (: , hour ) = C_app_Sch_C ( hour ,8) ; laptop_C (: , hour ) = C_app_Sch_C ( hour ,9) ; desktop_C (: , hour ) = C_app_Sch_C ( hour ,10) ;

107

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2199 2200 2201 2202

v a c u u m _ c l e a n e r_ C (: , hour ) = C_app_Sch_C ( hour ,11) ; e l e c t r i c a l _ c a r_ C (: , hour ) = C_app_Sch_C ( hour ,12) ; end %%%%%%%%%% end of schedule

%%%%%%%%%%%%%%%%%%%%%

2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216

old_fxCC ( er1 ) = s um _E _ Co st _ SS _C ; old_fxPC ( er1 ) = P AR _s c he du l ed _C ; if er1 >1 errorC = abs ( old_fxCC ( er1 -1) - old_fxCC ( er1 ) ) ; errorCP = abs ( old_fxPC ( er1 -1) - old_fxPC ( er1 ) ) ; errorC1 ( count1 ) = errorC ; errorC2 ( count1 ) = errorCP ; end count1 = count1 +1; % popsize = popsize +50; % maxgen = maxgen +20; PoPulationC ( count1 ) = Nn ; er1 = er1 +1;

2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229

tdw2_C = strfind ( dish_washer_C ,1) ; twm2_C = strfind ( washing_machine_C ,1) ; tsd2_C = strfind ( spin_dryer_C ,1) ; tch2_C = strfind ( cooker_hob_C ,1) ; tco2_C = strfind ( cooker_oven_C ,1) ; tm2_C = strfind ( microvave_C ,1) ; tl2_C = strfind ( laptop_C ,1) ; td2_C = strfind ( desktop_C ,1) ; tvc2_C = strfind ( vacuum_cleaner_C ,1) ; tec2_C = strfind ( electrical_car_C ,1) ; til2_C = strfind ( interior_lighting_C ,1) ; tr2_C = strfind ( refriegrator_C ,1) ;

2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242

% - - - - - - - - - Base / fixed Comfort - - - - - - - - - - -% D1_C =( sum ( abs ( tch1 - tch2_C ) ) ) / sum ( cooker_hob_C ) ; D2_C =( sum ( abs ( tco1 - tco2_C ) ) ) / sum ( cooker_oven_C ) ; D3_C =( sum ( abs ( tm1 - tm2_C ) ) ) / sum ( microvave_C ) ; D4_C =( sum ( abs ( tl1 - tl2_C ) ) ) / sum ( laptop_C ) ; D5_C =( sum ( abs ( td1 - td2_C ) ) ) / sum ( desktop_C ) ; D6_C =( sum ( abs ( tvc1 - tvc2_C ) ) ) / sum ( v a c u u m _ c l e a n e r _ C ) ; D7_C =( sum ( abs ( tec1 - tec2_C ) ) ) / sum ( e l e c t r i c a l _ c a r _ C ) ; U s e r _ C o m f o r t _ B a s e _ C =[ D1_C D2_C D3_C D4_C D5_C D6_C D7_C ]; Base _waiting _C = sum ( U s e r _ C o m f o r t _ B a s e _ C ) ; % A v g _ U s e r _ C o m f o r t _ G a s e = Base_waiting /3; % - - - - - - - - - Brust load Intruptable - - - - - - - - - - - -%

2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255

D8_C =( sum ( abs ( tdw1 - tdw2_C ) ) ) / sum ( dish_washer_C ) ; D9_C =( sum ( abs ( twm1 - twm2_C ) ) ) / sum ( w a s h i n g _ m a c h i n e _ C ) ; D10_C =( sum ( abs ( tsd1 - tsd2_C ) ) ) / sum ( spin_dryer_C ) ; U s e r _ C o m f o r t _ C B r u s t _ C =[ D8_C D9_C D10_C ]; B ru st _w a it in g_ C = sum ( U s e r _ C o m f o r t _ C B r u s t _ C ) ; % A v g _ U s e r _ C o m f o r t _ G r u s t = Brust_waiting /4; % - - - - - - - - - Brust load unIntruptable - - - - - - - - - - - -% D11_C =( sum ( abs ( til1 - til2_C ) ) ) / sum ( i n t e r i o r _ l i g h t i n g _ C ) ; D12_C =( sum ( abs ( tr1 - tr2_C ) ) ) / sum ( refriegr ator_C ) ; U s e r _ C o m f o r t _ U n i t r p _ C =[ D11_C D12_C ]; NonIntrupt_C = sum ( U s e r _ C o m f o r t _ U n i t r p _ C ) ; % A v g _ U s e r _ C o m f o r t _ n o n = NonIntrupt /2;

2256

108

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: P AR _s ch e du le d _C = max ( s ch e du le _ lo ad _C ) /(( s u m _ s c h e d u l e d _ l o a d _ C ) /24) ; PAR_C =(( PA R _s ch ed u le d_ C ) /( PA R_ u ns ch ed u le d ) ) *100; P AR _r ed u ct io n _B =100 - PAR_C ; count1 = count1 +1;

2257 2258 2259 2260 2261

% Np = Np +10;

2262 2263

%% Average Calculation app_SchAvg_C schedule_load_Avg_C E _C os t_ S S_ Av g _C sum_scheduled_load_Avg_C sum_E_Cost_SS_Avg_C PAR_scheduled_Avg_C PAR_Avg_C PAR_reduction_Avg_C

2264 2265 2266 2267 2268 2269 2270 2271 2272

= app_Sch_C + app_SchAvg_C ; = s c h e d u l e _ l o a d _ A v g _ C + sc h ed ul e_ l oa d_ C ; = E _C os t _S S_ Av g _C + E_Cost_SS_C ; = sum_scheduled_load_C + sum_scheduled_load_Avg_C ; = s u m _ E _ C o s t _ S S _ A v g _ C + su m _E _C os t _S S_ C ; = PA R_ sc h ed ul ed _ C ; = PAR_C + PAR_Avg_C ; = PA R_ re d uc ti on _ B + P A R _ r e d u c t i o n _ A v g _ C ;

2273 2274

%% Average of Waiting Time and Maximum time B as e_ lo a d_ C_ A vg =( sum ( U s e r _ C o m f o r t _ B a s e _ C ) ) /7; B as e_ lo a d_ C_ M ax = max ( U s e r _ C o m f o r t _ B a s e _ C ) ;

2275 2276 2277 2278 2279 2280

B r u s t _ l o a d _ C _A v g B r u s t _ l o a d _ C _ Ma x

=( sum ( U s e r _ C o m f o r t _ C B r u s t _ C ) ) /3; = max ( U s e r _ C o m f o r t _ C B r u s t _ C ) ;

NonIntp_load_C_Avg NonIntp_load_C_Max %%

=( sum ( NonIntrupt_C ) ) /2; = max ( NonIntrupt_C ) ;

2281 2282 2283 2284 2285 2286 2287

c u c k o o _ B a s e _ l o a d _ C _ A v g ( avg1 ,:) c u c k o o _ B a s e _ l o a d _ C _ M a x ( avg1 ,:)

= Ba se _ lo ad _C _ Av g ; = Ba se _ lo ad _C _ Ma x ;

c u c k o o _ B r u s t _ l o a d _ C _ A v g ( avg1 ,:) c u c k o o _ B r u s t _ l o a d _ C _ M a x ( avg1 ,:)

= B r u st _ l o a d _ C _ A v g ; = Brust_load_C_Max ;

2288 2289 2290 2291

c u c k o o _ N o n I n t p _ l o a d _ C _ A v g ( avg1 ,:) c u c k o o _ N o n I n t p _ l o a d _ C _ M a x ( avg1 ,:)

2292 2293

= NonIntp_load_C_Avg ; = NonIntp_load_C_Max ;

2294 2295

%% Cofidence Interval Parameters Cuckoo_PAR ( avg1 ,:) = PAR_scheduled_Avg_C ; C u c k o o _ E _ C o s t _S S ( avg1 ,:) = E_Cost_SS_C ; C u c k o o _ s c h e d u l e _ l o a d _ ( avg1 ,:) = sc he d ul e_ lo a d_ C ; C u c k o o _ s u m _ E _ C o s t _ S S ( avg1 ,:) = s um _ E_ Co st _ SS _C ; Cuck oo_app_S ch (: ,: , avg1 ) = C_app_Sch_C ; C u c k o o _ S u m _ S c h e d u l e d _ l o a d ( avg1 ,:) = s u m _ s c h e d u l e d _ l o a d _ C ; C u c k o o _ a p p _ S c h _ C u c k o o (: ,: , avg1 ) = app_Sch_C ; app_Sch_C1 = app_Sch_C ; app_Sch_C11 = app_Sch_C ; w_time = time_slots ;

2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314

% % % %

if avg1 >1 MSEtst ( avg1 -1 ,:) = mse ( Cuckoo_PAR ( avg1 -1 ,:) - Cuckoo_PAR ( avg1 ,:) ) ; end app_Sch_C ; end %% Rsults for cuckoo search %^^^^^^^^^^^^^^^^^^^^^&&&&&&&&&&&&&&&&&&&&^^^^^^^^^^^^^^^^^^^^^^^

109

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329

cuckoo_Base_load_Avg_Avg = mean ( c u c k o o _ B a s e _ l o a d _ C _ A v g ) ; cuckoo_Base_load_Max_Avg = mean ( c u c k o o _ B a s e _ l o a d _ C _ M a x ) ; cuckoo_Brust_load_Avg_Avg = mean ( c u c k o o _ B r u s t _ l o a d _ C _ A v g ) ; cuckoo_Brust_load_Max_Avg = mean ( c u c k o o _ B r u s t _ l o a d _ C _ M a x ) ; cuckoo_NonIntp_load_Avg_Avg = mean ( c u c k o o _ N o n I n t p _ l o a d _ C _ A v g ) ; cuckoo_NonIntp_load_Max_Avg = mean ( c u c k o o _ N o n I n t p _ l o a d _ C _ M a x ) ; cucko o_PAR_A vg = ( sum ( Cuckoo_PAR ) ) /3; cuckoo_E_Cost_SS_Avg = mean ( C u c k o o _ E _ C o s t _ S S ) ; cuckoo_scheduled_Avg = mean ( C u c k o o _ s c h e d u l e _ l o a d _ ) ; cuckoo_sum_E_Cost_SS_Avg = mean ( C u c k o o _ s u m _ E _ C o s t _ S S ) ; U s e r _ C o m f o r t _ c u c k o o =[ c u c k o o _ B a s e _ l o a d _ A v g _ A v g c u c k o o _ B r u s t _ l o a d _ A v g _ A v g c u c k o o _ N o n I n t p _ l o a d _ A v g _ A v g ]; %%%%%%%

2330 2331 2332 2333 2334 2335 2336

%%%

profit for ea =1:24 % cuckoo profit_c ( ea ) = sale_c ( ea ) * EPS_sale ( ea ) ; % tota l_profit _c = sum ( profit_c ) ; %

hourly profit total profit

2337 2338 2339

cost_c ( ea ) = grid_load_c ( ea ) * EP ( ea ) ; % total_cost_c = sum ( cost_c ) ; % total cost

HOURLY COST

2340 2341 2342 2343

% SA profit_s ( ea ) = sale ( ea ) * EPS_sale ( ea ) ; % tota l_profit _s = sum ( profit_s ) ; %

hourly profit total profit

2344 2345 2346

cost_s ( ea ) = grid_load ( ea ) * EP ( ea ) ; % HOURLY COST total_cost_s = sum ( cost_s ) ; % total cost

2347 2348

end

2349 2350 2351 2352 2353 2354 2355

%% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %% %%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTS %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTS %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTS %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTS %%%%%%%%%%%%

2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOTAL COST single home %%%%% %%%%%%% %% figure fH = gcf ; colormap ( jet (4) ) ; bar (1 , sum_unscheduled_cost ,0.3 , ’ red ’) hold on bar (2 , PP_sum_E_Cost_SS_Avg ,0.3 , ’ y ’) hold on bar (3 , cuckoo_sum_E_Cost_SS_Avg ,0.3 , ’ M ’) hold on % bar (4 , PP_sum_E_Cost_SS_Avg ,0.3 , ’ black ’) % hold on set ( gca , ’ XTick ’ ,1:1:3 , ’ XTickLabel ’ ,{ ’ Unschedule ’ , ’SA ’ , ’ CSA ’}) ylabel ( ’ Total cost ( cents ) ’) ; % title ( ’ Over All Cost ’) ;

110

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2373 2374 2375 2376 2377 2378 2379

% saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ total_cost ’ , ’ eps ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ total_cost ’ , ’ fig ’) ; % a p p l y h a t c h _ p l u s c o l o r ( fH , ’\ - x . ’ , 0 , [1 0 1 0] , jet (4) ) ; % a p p l yh a t c h _ p l u s C ( fH , ’\ - x . ’ , ’ rkbk ’) ; grid on

2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PAR figure bar (1 , PAR_unscheduled ,0.3 , ’ red ’) hold on bar (2 , PP_PAR_Avg ,0.3 , ’ yellow ’) hold on bar (3 , cuckoo_PAR_Avg ,0.3 , ’ M ’) hold on % bar (4 , PP_PAR_Avg ,0.3 , ’ black ’) % hold on

% %%%%%%% %%%%%%

2398 2399 2400 2401 2402 2403 2404 2405 2406

ylabel ( ’ PAR ’) ; set ( gca , ’ XTick ’ ,1:1:3 , ’ XTickLabel ’ ,{ ’ Unscheduled ’ , ’ SA ’ , ’ CSA ’}) % title ( ’ Peak To Average Ratio ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ par ’ , ’ eps ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ par ’ , ’ fig ’) ; grid on

2407 2408 2409

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

LOAD PER HOUR single home

%%%%% %%%%%%% %%

2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430

figure stairs (1:24 , unscheduledload , ’ Rs - ’ , ’ LineWidth ’ ,1.4) ; hold on stairs (1:24 , PP _ s c h e d u l e d _ A v g ,’ yellow ’ , ’ LineWidth ’ ,1.4) ; hold on stairs (1:24 , c u c k o o _ s c h e d u l e d _ A v g ,’M + - ’ , ’ LineWidth ’ ,1.4) ; hold on % stairs (1:24 , PP_scheduled_Avg , ’ black + - ’ , ’ LineWidth ’ ,1.4) ; % hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ’ Load ( kWh ) ’) ; % xlim ([0 24]) ; % set ( gca , ’ XTick ’ ,0:24 , ’ XTickLabel ’ ,{ ’8 ’ , ’9 ’ ’10 ’ ’11 ’ ’12 ’ ’13 ’ ’14 ’ ’15 ’ ’16 ’ ’17 ’ ’18 ’ ’19 ’ ’20 ’ ’21 ’ ’22 ’ ’23 ’ ’24 ’ ’1 ’ ’2 ’ ’3 ’ ’4 ’ ’5 ’ ’6 ’ ’7 ’ ’8 ’}) legend ( ’ Unscheduled ’ , ’ SA ’ , ’ CSA ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; % title ( ’ Load per Hour ’) ; set ( legend , ’ FontSize ’ ,11) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ hourly_load ’ , ’ eps ’) ;

111

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2431 2432 2433

% saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ hourly_load ’ , ’ fig ’) ; grid on

2434 2435 2436

%%%%%%%%%%%%%%%%%%%%%%%

RTP

2437 2438 2439 2440 2441 2442 2443 2444 2445

figure stairs ( EP , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) ; hold on stairs ( EPS_sale , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) ; hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ’ Electricity price ( cents ) ’) ; % xlim ([1 24]) ;

2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456

set ( gca , ’ XTick ’ ,0:4:24 , ’ XTickLabel ’ ,{ ’0 ’ ’4 ’ ’8 ’ ’12 ’ ’16 ’ ’20 ’ ’24 ’}) % ylim ([0.1 .3]) ; % set ( gca , ’ YTick ’ ,0.1:0.05:0.3 , ’ YTickLabel ’ ,{ ’0.1 ’ ’0.15 ’ ’0.2 ’ ’0.25 ’ ’0.3 ’}) legend ( ’ Buy from utility ’ , ’ Sell to utility ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ sale_purchase_price ’ , ’ eps ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ sale_purchase_price ’ , ’ fig ’) ; grid on

2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480

% % %% %% % %% %% %% % %% Waiting Time for single home % % % % % % % % % % % % % % % % % % % % base_load =[ G A _ B a s e _ l o a d _ A v g _ A v g c u c k o o _ B a s e _ l o a d _ A v g _ A v g P P _ B a s e _ l o a d _ A v g _ A v g ]; Brust_Load =[ G A _ B r u s t _ l o a d _ A v g _ A v g c u c k o o _ B r u s t _ l o a d _ A v g _ A v g P P _ I n t p _ l o a d _ A v g _ A v g ]; Intrup_Load =[ G A _ N o n I n t p _ l o a d _ A v g _ A v g c u c k o o _ N o n I n t p _ l o a d _ A v g _ A v g P P _ N o n I n t p _ l o a d _ A v g _ A v g ]; LOAD =[ base_load ; Brust_Load ; Intrup_Load ]; figure bar_Grapg = bar ( LOAD ) ; set ( bar_Grapg (1) ,’ FaceColor ’ ,[0.3 0.6 0.8]) ; bar_Grapg = bar ( LOAD ) ; set ( bar_Grapg (2) ,’ FaceColor ’ ,[0.3 0.6 0.8]) ; set ( bar_Grapg (3) ,’ FaceColor ’ ,[0.1 0.5 0]) ; ylabel ( ’ Waiting time ( hours ) ’) ; set ( gca , ’ XTick ’ ,1:1:6 , ’ XTickLabel ’ ,{ ’ Base load ’ , ’ Intruptable load ’ , ’ Unintruptable load ’}) legend ({ ’ Average GA ’ , ’ Average Cuckoo ’ , ’ Strawberry ’}) set ( legend , ’ FontSize ’ ,11) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ waiting_time ’ , ’ eps ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ waiting_time ’ , ’ fig ’) ; grid on

2481 2482

%

&&&&&&&&&&&&&&&&&&&&&& - - - - - - - - per hour cost - - - - - - - -&&&&&&&&&&&&&&&&&&&&&&&&

2483 2484 2485 2486 2487 2488

figure stairs (1:24 , unschedulecost , ’ Rs - ’ , ’ LineWidth ’ ,1.4) ; hold on stairs (1:24 , PP _ E _ C o s t _ S S _ A v g ,’ yellow ’ , ’ LineWidth ’ ,1.4) ; hold on

112

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506

stairs (1:24 , cuckoo_E_Cost_SS_Avg , ’ M + - ’ , ’ LineWidth ’ ,1.4) hold on % stairs (1:24 , PP_E_Cost_SS_Avg , ’ black + - ’ , ’ LineWidth ’ ,1.4) % hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ’ Cost ( cents / kWh ) ’) ; % xlim ([0 24]) ; % set ( gca , ’ XTick ’ ,0:24 , ’ XTickLabel ’ ,{ ’8 ’ , ’9 ’ ’10 ’ ’11 ’ ’12 ’ ’13 ’ ’14 ’ ’15 ’ ’16 ’ ’17 ’ ’18 ’ ’19 ’ ’20 ’ ’21 ’ ’22 ’ ’23 ’ ’24 ’ ’1 ’ ’2 ’ ’3 ’ ’4 ’ ’5 ’ ’6 ’ ’7 ’ ’8 ’}) legend ( ’ Unscheduled ’ , ’ SA ’ , ’ CSA ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; % title ( ’ Load per Hour ’) ; set ( legend , ’ FontSize ’ ,11) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ hourly_cost ’ , ’ eps ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ hourly_cost ’ , ’ fig ’) ; grid on

2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Create the area plot using the area function for Wind and solar for a day figure area ( re_wind_new , ’ FaceColor ’ ,[0 1 0]) ; hold on area ( rg_new_pv , ’ FaceColor ’ , [1 0 0]) ; colormap winter % Add a legend legend ( ’ Wind turbine ’ , ’ Solar panal ’) % xlim ([1 24]) ; set ( gca , ’ XTick ’ ,0:4:24 , ’ XTickLabel ’ ,{ ’1 ’ ’4 ’ ’8 ’ ’12 ’ ’16 ’ ’20 ’ ’24 ’}) % Add title and axis labels % title ( ’ Electricty Generation ’) xlabel ( ’ Time ( hours ) ’) ylabel ( ’ Electricity generation ( kW ) ’) % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ gen_wind_pv ’ , ’ eps ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ gen_wind_pv ’ , ’ fig ’) ; grid on

2529 2530 2531 2532

% % % % % % % % % % % % % % % % % % % % wind generation and Wind spead

2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546

figure [ ax h1 h2 ]= plotyy (1:24 , re_wind_new ,1:24 , wind_spead , @plot , @plot ) ; set ( h1 , ’ Marker ’ , ’o ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’ - - ’) set ( h2 , ’ Marker ’ , ’* ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’ - - ’) hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ax (2) ,’ Wind spead ( m / s ) ’) ; ylabel ( ’ WT generation ( kW ) ’) ; % set ( gca , ’ YTick ’ ,0:0.5:2 , ’ YTickLabel ’ ,{ ’0 ’ ’0.5 ’ ’1 ’ ’1.5 ’ ’2 ’}) % set ( gca , ’ YYTick ’ ,0:5:20 , ’ YYTickLabel ’ ,{ ’0 ’ ’5 ’ ’10 ’ ’15 ’ ’20 ’}) legend ( ’ WT generation ’ , ’ Wind spead ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ;

113

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2547 2548 2549 2550 2551

% saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ wind_gen_wind_spead ’ , ’ jpg ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ wind_gen_wind_spead ’ , ’ fig ’) ; grid on

2552 2553

% %% %% %% % %% %% %% % temp and PV generation

2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571

figure [ ax h1 h2 ]= plotyy (1:24 , rg_new_pv ,1:24 , temp_pv , @plot , @plot ) ; set ( h1 , ’ Marker ’ , ’o ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’: ’) set ( h2 , ’ Marker ’ , ’* ’ , ’ MarkerSize ’ ,8 , ’ LineStyle ’ , ’: ’) hold on xlabel ( ’ Time ( hours ) ’) ; ylabel ( ax (2) ,’ Temperature of the day ’) ; ylabel ( ’ PV generation ( kW ) ’) ; % set ( gca , ’ YTick ’ ,0:0.5:2 , ’ YTickLabel ’ ,{ ’0 ’ ’0.5 ’ ’1 ’ ’1.5 ’ ’2 ’}) % set ( gca , ’ YYTick ’ ,0:5:20 , ’ YYTickLabel ’ ,{ ’0 ’ ’5 ’ ’10 ’ ’15 ’ ’20 ’}) legend ( ’ PV generation ’ , ’ Temprature ’) ; legend ( ’ Location ’ , ’ NorthEast ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ temp_pv_gn ’ , ’ jpg ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ temp_pv_gn ’ , ’ fig ’) ; grid on

2572 2573 2574

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% figure for I - V curve of solar panel

2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597

figure plot ( voltage1 , current1 , ’r ’ , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) hold on plot ( voltage2 , current2 , ’b ’ , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) hold on plot ( voltage3 , current3 , ’g ’ , ’ markersize ’ ,8 , ’ LineWidth ’ ,1.5) legend ( ’09:00 ’ , ’12:00 ’ , ’15:00 ’ , ’ Location ’ , ’ southwest ’) ; % title ( ’ price signal ’) ; xlabel ( ’ Voltage ’) ; ylabel ( ’ Current ’) ; dim = [ 0 . 7 9 2 6 4 7 0 5 8 8 2 3 5 2 9 0 . 8 26 5 8 2 2 8 0 0 6 5 4 4 0 . 0 8 6 7 6 4 7 0 3 7 3 4 8 3 2 7 0 . 0 7 8 4 8 1 0 1 1 0 7 3 8 0 0 6 ] ; str = ’MPP ’; annotation ( ’ textbox ’ , dim , ’ String ’ , str , ’ FitBoxToText ’ , ’ on ’ , ’ FontSize ’ ,12 , ’ Color ’ ,[1 0 0]) ; x = [0.776470588235294 0.786764705882353]; y = [0.544303797468354 0.853164556962025]; a = annotation ( ’ textarrow ’ ,x ,y , ’ String ’ , ’ ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ i_v_curve ’ , ’ jpg ’) ; % saveas ( gca , ’ f :\ all_data \ Research_work \ processing work \3 r d _ w o r k _ c o d e _ l a t e x \ figures \ i_v_curve ’ , ’ fig ’) ; grid on

2598 2599 2600 2601 2602 2603

% Load and imported electricity graph figure bpcombined = [ sale (:) ]; [ ax h1 h2 ]= plotyy (1:24 , EP ,1:24 , bpcombined , @plot , @bar ) ;

2604

114

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2605 2606 2607 2608 2609 2610 2611 2612 2613

% hb = bar ( bpcombined , ’ grouped ’) ; hold on % plot ( EP , ’m ’ , ’ LineWidth ’ ,1.4) % hold on legend ( ’ RTP signals ’ , ’ Sold electricity ’ , ’ Location ’ , ’ northwest ’) ; xlabel ( ’ Hours in a day ’) ; ylabel ( ’ Electricity / load ( kWh ) ’) ; % title ( ’ Comparison of load with EV with discharging ’) ; hold on

2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629

% Load and imported electricity graph figure bpcombined = [ sale (:) , sale_c (:) , grid_load (:) , grid_load_c (:) ]; [ ax h1 h2 ]= plotyy (1:24 , EP ,1:24 , bpcombined , @plot , @bar ) ; hold on legend ( ’ Pricing signals ’ , ’ Sold electricity using SA ’ , ’ Sold electricity using CSA ’ ,... ’ Imported electricity using SA ’ , ’ Imported electricity using CSA ’ , ’ Location ’ , ’ northeast ’) ; xlabel ( ’ Hours in a day ’) ; ylabel ( ’ Electricity price ( cents / kWh ) ’) ; ylabel ( ax (2) ,’ Electricity load ( kW ) ’) ; % title ( ’ Comparison of load with EV with discharging ’) ; hold on

2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650

% earning and cost figure bar (1 , sum_unscheduled_cost ,0.3 , ’ red ’) hold on bar (2 , total_cost_s ,0.3 , ’ yellow ’) hold on bar (3 , total_profit_s ,0.3 , ’ yellow ’) hold on bar (4 , total_cost_c ,0.3 , ’ M ’) hold on bar (5 , total_profit_c ,0.3 , ’ M ’) hold on % bar (4 , PP_sum_E_Cost_SS_Avg ,0.3 , ’ black ’) % hold on set ( gca , ’ XTick ’ ,1:1:5 , ’ XTickLabel ’ ,{ ’ Unschedule ’ , ’ SA cost ’ , ’ SA earning ’ , ’ CSA cost ’ , ’ CSA earning ’}) ylabel ( ’ Total cost ( cents ) ’) ; grid on hold off

115

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2:

.C.1

RES generation function

Appendix C.1 contains the details for the implementation of MATLAB function named ”res gen.m” which is called in main file. Please save this file in the same folder as main file. Step by step guidelines are provided in readme.txt file. Please find the electricity generation function from section .B.2.

116

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2:

.C.2

IV curve function

Appendix C.2 contains the details for the implementation of MATLAB function named ”IV curve.m” which is called in main file. Please save this file in the same folder as main file. Step by step guidelines are provided in readme.txt file. Please find the electricity generation function from section .B.4.

117

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2:

.C.3

Cuckoo search algorithm function

Appendix C.3 contains the details for the implementation of MATLAB function named ”cuckoo search.m” which is called in main file. Please save this file in the same folder as main file. Step by step guidelines are provided in readme.txt file. 2651 2652 2653

% % % % % % % % % % % % % % % % % % % % % % % % % % % %

----------------------------------------------------------------Cuckoo Search ( CS ) algorithm by Xin - She Yang and Suash Deb % Programmed by Xin - She Yang at Cambridge University % Programming dates : Nov 2008 to June 2009 % Last revised : Dec 2009 ( simplified version for demo only ) % ----------------------------------------------------------------Papers -- Citation Details : 1) X . - S . Yang , S . Deb , Cuckoo search via Levy flights , in : Proc . of World Congress on Nature & Biologically Inspired Computing ( NaBIC 2009) , December 2009 , India , IEEE Publications , USA , pp . 210 -214 (2009) . http :// arxiv . org / PS_cache / arxiv / pdf /1 00 3 /1 00 3 .1 59 4 v1 . pdf 2) X . - S . Yang , S . Deb , Engineering optimization by cuckoo search , Int . J . Mathematical Modelling and Numerical Optimisation , Vol . 1 , No . 4 , 330 -343 (2010) . http :// arxiv . org / PS_cache / arxiv / pdf /1 00 5 /1 00 5 .2 90 8 v2 . pdf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -% This demo program only implements a standard version of % Cuckoo Search ( CS ) , as the Levy flights and generation of % new solutions may use slightly different methods . % The pseudo code was given sequentially ( select a cuckoo etc ) , % but the imp lementat ion here uses Matlab ’ s vector capability , % which results in neater / better codes and shorter running time . % This imp lementa tion is different and more efficient than the % the demo code provided in the book by " Yang X . S . , Nature - Inspired Metaheuristic Algoirthms , % 2 nd Edition , Luniver Press , (2010) . " % --------------------------------------------------------------- %

2688 2689

% % % % % %

=============================================================== % Notes : % Different im pl e me nt at i on s may lead to slightly different % behavour and / or results , but there is nothing wrong with it , % as this is the nature of random walks and all metaheu ristics . % -----------------------------------------------------------------

2690

CSA algorithm

2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687

2691 2692 2693 2694 2695 2696 2697 2698 2699 2700

function [ bestnest , fmin , nest , D , pa ]= cuckoo_search (p , EP , hour , C_time_slots , unscheduledload , app_Sch_C , sheri ) % Number of nests ( or different solutions ) n =50; % Nn =50; D =12; % %% %% %% % %% %% %% % % Discovery rate of alien eggs / solutions

118

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2701

pa =0.25;

2702 2703 2704 2705 2706 2707 2708 2709 2710 2711

%% Change this if you want to get better results % Tolerance Tol =40; %% Simple bounds of the search domain % Lower bounds nd = D ; Lb = -5* ones (1 , nd ) ; % Upper bounds Ub =5* ones (1 , nd ) ;

2712 2713 2714 2715 2716

% Random initial solutions for i =1: n , nest (i ,:) = Lb +( Ub - Lb ) .* rand ( size ( Lb ) ) ; end

2717 2718 2719 2720 2721

% Get the current best fitness =10^10* ones (n ,1) ; % intialize a vector to save the fitness value of nests [ fmin , bestnest , nest , fitness ]= get_best_nest ( nest , nest , fitness , p ,D , EP , hour , C_time_slots , unscheduledload , app_Sch_C , sheri ) ;

2722 2723 2724 2725 2726

N_iter =0; %% Starting iterations count =1; while ( count 0.5 % You can change this accordingly

120

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: newnest (j , i ) =1;

2817

else

2818

newnest (j , i ) =0;

2819

end

2820

end

2821 2822

end

2823 2824 2825

e l e c t r i c i t y _ c o st = EP ( hour ) * p ; % Possible pirce for each appliance %% %%%% Non intruptible appliance : working in series %%%%

2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864

lhour =25 - hour ; Nn =50; % if lhour 1 % if app_Sch_C ( hour -1 ,5) ==1 % nest (: ,5) =1; % end % if C_time_slots (1 ,5) >0 % nest (: ,6) =0; % end % if C_time_slots (1 ,5) 0 % nest (: ,6) =0; % end %% condition for the appliance number 4 must run between 18 n 24 a4 =11; b4 =16; if hour < a4 || hour > b4 for a =1: Nn newnest (a ,4) =0; end else for a =1: Nn if newnest (a ,4) ==0 newnest (a ,4) =1; end end end %%%%%%%%%% End condition for appliance number 4

2865 2866 2867 2868 2869 2870 2871 2872 2873 2874

%%%%%%%%%%% for appliance number 1 a1 =2; b1 =12; if hour < a1 || hour > b1 for a =1: Nn newnest (a ,1) =0; end elseif C_time_slots (1 ,1) >=0 && ( hour >=( b1 - sheri (: ,1) ) ) for a =1: Nn

121

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: newnest (a ,1) =1;

2875 2876

end

2877 2878 2879

end %%%%%%%%%%%% end of 1 st appliance condition

2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893

%%%%%%%%%%% for appliance number 2 washing machine a2 =2; b2 =7; if hour < a2 || hour > b2 for a =1: Nn newnest (a ,2) =0; end elseif C_time_slots (1 ,2) >=0 && ( hour >=( b2 - sheri (: ,2) ) ) for a =1: Nn newnest (a ,2) =1; end end %%%%%%%%% end of 2 nd appliance condition

2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905

%%%%%%%%%%% for appliance number 3 a3 =6; b3 =13; if hour < a3 || hour > b3 for a =1: Nn newnest (a ,3) =0; end elseif C_time_slots (1 ,3) >=0 && ( hour >=( b3 - sheri (: ,3) ) ) newnest (a ,3) =1; end %%%%%%%%% end of 3 rd appliance condition

2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917

%%%%%%%%%%% for appliance number 6 a6 =1; b6 =6; if hour < a6 || hour > b6 for a =1: Nn newnest (a ,6) =0; end elseif C_time_slots (1 ,6) >=0 && ( hour >=( b6 - sheri (: ,6) ) ) newnest (a ,6) =1; end %%%%%%%%% end of 6 th appliance condition

2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932

%%%%%%%%%%% for appliance number 7 a7 =11; b7 =16; if hour < a7 || hour > b7 for a =1: Nn newnest (a ,7) =0; end elseif C_time_slots (1 ,7) >=0 for a =1: Nn if newnest (a ,7) ==0 newnest (a ,7) =1; end end end

&& ( hour >=( b7 - sheri (: ,7) ) )

122

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2933

%%%%%%%%% end of 7 th appliance condition

2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949

%%%%%%%%%%% for appliance number 8 a8 =1; b8 =7; if hour < a8 || hour > b8 for a =1: Nn newnest (a ,8) =0; end elseif C_time_slots (1 ,8) >=0 && ( hour >=( b8 - sheri (: ,8) ) ) for a =1: Nn if newnest (a ,8) ==0 newnest (a ,8) =1; end end end %%%%%%%%% end of 8 th appliance condition

2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965

%%%%%%%%%%% for appliance number 9 a9 =9; b9 =16; if hour < a9 || hour > b9 for a =1: Nn newnest (a ,9) =0; end elseif C_time_slots (1 ,9) >=0 && ( hour >=( b9 - sheri (: ,9) ) ) for a =1: Nn if newnest (a ,9) ==0 newnest (a ,9) =1; end end end %%%%%%%%% end of 9 th appliance condition

2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981

%%%%%%%%%%% for appliance number 10 a10 =7; b10 =16; if hour < a10 || hour > b10 for a =1: Nn newnest (a ,10) =0; end elseif C_time_slots (1 ,10) >=0 && ( hour >= b10 - sheri (: ,10) ) for a =1: Nn if newnest (a ,10) ==0 newnest (a ,10) =1; end end end %%%%%%%%% end of 10 th appliance condition

2982 2983 2984 2985 2986 2987 2988 2989 2990

%%%%%%%%%%% for appliance number 11 a11 =2; b11 =11; if hour < a11 || hour > b11 for a =1: Nn newnest (a ,11) =0; end elseif C_time_slots (1 ,11) >=0

&& ( hour >=( b11 - sheri (: ,11) ) )

123

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 2991 2992 2993 2994 2995 2996 2997

for a =1: Nn if newnest (a ,11) ==0 newnest (a ,11) =1; end end end %%%%%%%%%%%% end of 11 th appliance condition

2998 2999 3000 3001 3002 3003 3004

% % % % % % % % % % % % % % %% start the appliance 12 condition a12 =11; if hour < a12 for a =1: Nn newnest (a ,12) =0; end

3005 3006 3007

end % %% %% %% % %% %% %% % end of 12 th condition

3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018

for b =1: D if C_time_slots (1 , b ) D11 && Load (1 , i ) > min ( un s ch ed ul e dl oa d ) )

3076 3077

D11 = F1 (1 , i ) ; % mean ( u ns c he du le d lo ad ) Lbest = nest (i ,:) ; % gbest position achieved here . end

3078 3079 3080 3081 3082 3083 3084 3085

end end if D11 == inf for i = 1: size ( nest ,1) if ( F1 (1 , i ) < D11 && Load (1 , i ) > min ( un s ch ed ul e dl oa d ) )

3086

D11 = F1 (1 , i ) ; Lbest = nest (i ,:) ; % gbest position achieved here .

3087 3088 3089

end

3090 3091 3092 3093 3094 3095

end end if D11 == inf for i = 1: size ( nest ,1) if ( F1 (1 , i ) < D11 ) % && Load (1 , i ) > min ( u ns c he du le d lo ad ) )

3096

D11 = F1 (1 , i ) ; Lbest = nest (i ,:) ; % gbest position achieved here .

3097 3098 3099

end

3100 3101

end

3102

end % Find the current best fmin = D11 ; best = Lbest ;

3103 3104 3105

125

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2: 3106 3107 3108 3109 3110 3111 3112

%% Replace some nests by constructing new solutions / nests function new_nest = empty_nests ( nest , Lb , Ub , pa ) % A fraction of worse nests are discovered with a probability pa n = size ( nest ,1) ; % Discovered or not -- a status vector K = rand ( size ( nest ) ) > pa ;

3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124

% In the real world , if a cuckoo ’ s egg is very similar to a host ’ s eggs , then % this cuckoo ’ s egg is less likely to be discovered , thus the fitness should % be related to the difference in solutions . Therefore , it is a good idea % to do a random walk in a biased way with some random step sizes . %% New solution by biased / selective random walks stepsize = rand *( nest ( randperm ( n ) ,:) - nest ( randperm ( n ) ,:) ) ; new_nest = nest + stepsize .* K ; for j =1: size ( new_nest ,1) s = new_nest (j ,:) ; new_nest (j ,:) = simplebounds (s , Lb , Ub ) ; end

3125 3126 3127 3128 3129 3130 3131

% Application of simple constraints function s = simplebounds (s , Lb , Ub ) % Apply the lower bound ns_tmp = s ; I = ns_tmp < Lb ; ns_tmp ( I ) = Lb ( I ) ;

3132 3133 3134 3135 3136 3137

% Apply the upper bounds J = ns_tmp > Ub ; ns_tmp ( J ) = Ub ( J ) ; % Update this new move s = ns_tmp ;

3138 3139 3140 3141 3142 3143 3144 3145

%% You can replace the following by your own functions % A d - dimensional objective function function z = fobj ( u ) %% d - dimensional sphere function sum_j =1^ d ( u_j -1) ^2. % with a minimum at (1 ,1 , .... , 1) ; z = sum (( u -1) .^2) ;

126

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2:

.C.4

Crossover function

Appendix C.4 contains the details for the implementation of MATLAB function named ”crossover.m” which is called in main file. Please save this file in the same folder as main file. Step by step guidelines are provided in readme.txt file. 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159

% - - - - - - - - - - - Crossover operator - - - - - - - - - - - - - - -% function [c , d ]= crossover (a , b ) nn = length ( a ) ; % generating random crossover point cpoint = floor ( nn * rand ) ; if cpoint ==0 cpoint = randi (6 ,1 ,1) ; end c =[ a (1: cpoint ) b ( cpoint +1: end ) ]; d =[ b (1: cpoint ) a ( cpoint +1: end ) ]; % - - - - - - - - - - - - Crossover ends - - - - - - - - - - - - - - - - - -%

127

Thesis by: Sheraz Aslam

.C. IMPLEMENTATION OF PROPOSED SOLUTION FOR PROBLEM 2:

.C.5

Mutate function

Appendix C.5 contains the details for the implementation of MATLAB function named ”mutate.m” which is called in main file. Please save this file in the same folder as main file. Step by step guidelines are provided in readme.txt file. 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182

% - - - - - Mutatation operator - - - - - -% function anew = mutate (a , insite ) nn = length ( a ) ; for i =1: insite j = floor ( rand * nn ) ; if j ==0 j = randi ( nn ,1 ,1) ; end k=a(j); if k ==1 a ( j ) =0; else if k ==0 a ( j ) =1; end end anew = a ; end % - - - - - - -**************** - - - - - - -%

128

Thesis by: Sheraz Aslam