ArticlePDF Available

Energy Management With a World-Wide Adaptive Thermostat Using Fuzzy Inference System_ With Source _Code

Authors:

Abstract and Figures

Energy management of residential buildings plays an important role in a smart grid. Region specific fuzzy logic strategies are proposed recently. However, no such approach exists that covers all regions of the world. A fuzzy logic-based strategy for the construction of fuzzy controller covering the entire globe would be cost effective due to the increasing power of micro-controllers. Results show that our proposed approach achieves a minimum energy savings of 6.5%, irrespective of where it is used around the world. This research will provide a model for extending the region specific solutions for a worldwide adaption. INDEX TERMS Energy management, thermostat, smart grid, fuzzy logic, fuzzy inference systems.
Content may be subject to copyright.
SPECIAL SECTION ON ENERGY MANAGEMENT IN BUILDINGS
Received March 4, 2018, accepted April 3, 2018, date of publication April 17, 2018, date of current version July 6, 2018.
Digital Object Identifier 10.1109/ACCESS.2018.2828040
Energy Management With a World-Wide
Adaptive Thermostat Using Fuzzy
Inference System
SAKEENA JAVAID1, NADEEM JAVAID 1, (Senior Member, IEEE), SOHAIL IQBAL 2,
MOHSEN GUIZANI 3, (Fellow, IEEE), AHMAD AL-MOGREN 4,
AND ATIF ALAMRI 4, (Member, IEEE)
1COMSATS Institute of Information Technology, Islamabad 44000, Pakistan
2School of Electrical Engineering and Computer Science, National University of Science and Technology, Islamabad 44000, Pakistan
3University of Idaho, Moscow, ID 83844, USA
4Research Chair of Pervasive and Mobile Computing College of Computer and Information Sciences, King Saud University, Riyadh 11633, Saudi Arabia
Corresponding author: Nadeem Javaid (nadeemjavaidqau@gmail.com)
This work was supported by the King Saud University through the Vice Deanship of Research Chairs.
ABSTRACT Energy management of residential buildings plays an important role in a smart grid. Region
specific fuzzy logic strategies are proposed recently. However, no such approach exists that covers all regions
of the world. A fuzzy logic-based strategy for the construction of fuzzy controller covering the entire globe
would be cost effective due to the increasing power of micro-controllers. Results show that our proposed
approach achieves a minimum energy savings of 6.5%, irrespective of where it is used around the world.
This research will provide a model for extending the region specific solutions for a worldwide adaption.
INDEX TERMS Energy management, thermostat, smart grid, fuzzy logic, fuzzy inference systems.
I. INTRODUCTION
Demand response (DR) based programs always play a vital
role in smart grid’s (SG) energy management field. Currently,
heating ventilation and air conditioning (HVAC) systems
entail 64% and 57% of total residential energy consumption
in Canada and the U.S. respectively [1] and [2]. One of
the most significant factors for peak load management are
residential HVAC systems during peak demand periods. For
instance, these devices are mostly comprised of 50% of the
additional critical peak electricity consumption during hot
summer days in California [3]. SG incentives are targeted to
improve power blackouts in order to lower network voltages
and to enable consumers’ engagement in the operation of the
power system, especially via smart meters (SMs) [4], smart
energy management systems (EMSs) and smart homes [5].
In addition, decentralized EMS based on distributed intelli-
gence are proposed for enhancing microgrid performance [6].
Energy management is categorized as: direct load control
and indirect load control methods [7]–[9]. Direct load control
describes the use of technological measurements which also
explains total energy demands by shuffling various equip-
ment ON or OFF during high demands (like load shifting),
whereas, indirect load control is a method where consumers
manage the electricity load reduction using a price signal.
Multiple electricity tariffs or pricing mechanisms: fixed price,
dynamic price, time of use (TOU), etc. are utilized to encour-
age consumers while participating in load reduction during
high price rate hours. Utilities speculate the electricity cost
for various intervals of the day according to the pricing tariffs,
such as, the TOU rates: off peak (OP), mid peak (MP) and
high peak (HP). Merging the indirect load with the direct load
control for load shedding or shifting in HVAC systems is very
succinct. The control of these systems is also shown in the
Fig. 1 with the help of some commonly used parameters from
the recent literature [6] and [7].
The incentive based power management approach [10],
is proposed for minimizing the electricity bill and peak
formation by defining the energy consumption patterns of
individual appliances. Linear programming and decentralized
game theoretic schemes are used for centralized optimization
in their work. Furthermore, authors also elaborate the mea-
surements about peak to average ratio (PAR) that how high
electricity deteriorates the systems performance in terms of
efficiency and reliability. Similarly, on the generation side,
systems performance can be improved by reduction in peak
demand [11]. Moreover, the assumption relevant to the over-
all constant energy consumption leads to minimization of the
PAR as well as minimization of the peak energy demand.
This reduction also increases the reliability of the system via
increasing the auxiliary capacity in case of supply limitations,
VOLUME 6, 2018 This work is licensed under a Creative Commons Attribution 3.0 License. For more information, see http://creativecommons.org/licenses/by/3.0/ 33489
_ With Source _Code
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
FIGURE 1. HVAC control system using the Prate,Tempoutdoor , indoor temperature and HO parameters.
which also contributes well in the significant factors of elec-
tricity shortages [12].
In some scenarios, users do not automate their smart ther-
mostats, by mistake, particularly when Tempoutdoor is sud-
denly rising or dropping. In addition, day-ahead pricing and
environmental conditions strongly depend on the consumers’
participation because even advanced thermostats such as
NEST [13], may often compromise on saving energy and
users’ thermal comfort without any consumer response [14].
On the other hand, occupancy and user negligence (i.e., while
considering the users’ behaviors) are important parame-
ters which may impact the fundamental functionality of
thermostats resulting in reduced power consumption and
cost savings. Researchers model the occupants’ activities
and evaluate the most influential parameters in occupant’s
behavior for energy saving in [15] and [16]. The influence
of user behaviors on thermostats has effects in many cases
where residential customers forget or neglect to participate in
DR during peak prices [17].
In this paper, a world-wide adaptive thermostat model is
presented which manages the energy in the hottest and coldest
countries of the world. This model is initialized using: ini-
tialized setpoints (I_SPs); outdoor temperature (Tempoutdoor );
home occupancy (HO) and utility price (Prate) for residential
buildings. The proposed system has been developed for the
effective management of energy consumption in residential
buildings and it has been evaluated with fuzzy logic tech-
niques and wireless sensor capabilities. While comparing to
other types of controllers, the progressive achievements of
fuzzy logic controllers (FLCs) reside in the fact that they need
very little mathematical modeling for their implementation.
Systems control variables: input and output of FLCs are real
variables which are based on the collection of IF-THEN rules
for achieving the desired outcomes. Mamdani and Sugeno
fuzzy inference systems (FISs) are used for inferring the
defined fuzzy rules (Frules). All rules are defined on the
basis of a human intuition method which is efficient and
cost effective. The proposed system takes into account differ-
ent parameters and information which correspond to power
management along with users’ comfort levels in residential
sectors; i.e., residential buildings. Furthermore, fundamental
targets of this study are to preserve energy and cost without
sacrificing more consumers’ thermal comfort. In this way,
fuzzy logic gives a very feasible and implementable solution
for achieving these objectives.
The remainder of this paper is organized as follows.
In Section II, the literature review is discussed along with
the existing limitations and list of contributions. Section III
explains the problem statement and Section IV describes the
problem formulation. The proposed solution is presented in
Section V and implementation with results and analyses are
discussed in Section VI. Finally, the paper is concluded in
Section VII.
II. LITERATURE REVIEW
Yan et al. [18] develop a HVAC system by specifying two
DR methodologies namely: 1) demand side bedding; and
2) frequency controlled reserve. These strategies provide help
33490 VOLUME 6, 2018
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
TABLE 1. Nomenclature.
to bring up the role of both DR programs and SMs in sav-
ing energy and enhancing the grid efficiency. Beside these
schemes, day-ahead electricity prices, TOU rates, real time
pricing (RTP), and combination of all these pricing tariffs
provide opportunities for residential users to reduce the con-
sumption and the electricity bill by shifting the operations of
their home appliances from HP rates to OP rates [19] and [20].
Another energy management technique investigates the per-
formance of residential HVAC systems by load shedding in
response to different parameters: 1) time varying prices [17];
2) variations of ambient temperature [21]; and 3) in home user
activity (occupancy) [22].
Recently, consumers use: 1) programmable communicat-
ing thermostats (PCTs); 2) price-responsive thermostats [13];
and 3) occupancy-responsive thermostats [14] to control res-
idential HVAC systems by initializing their schedules and
setpoints for different temperature ranges. Bidirectional com-
munication capabilities (i.e., using ZigBee protocols (IEEE
802.15.4)) of these thermostats optimize them to communi-
cate with utilities for participating in the DR programs [23].
These thermostats receive price signals from SG while auto-
matically decreasing or increasing the ISPs to a level pre-
defined by the user. Occupancy responsive thermostats track
occupancy level and then immediately modify setpoints when
a building or room is not occupied. In addition, there are
some disadvantages to the aforementioned thermostats. Users
often lose their thermal comfort particularly in cold winter
days or hot summer days when they participate in DR pro-
grams during high electricity prices [24] and [25].
All of the aforementioned challenges are restricted to
indoor temperature and also having communication gaps
with advanced technologies, like SMs, which are the limi-
tations of previous PTs. PTs are extended into PCTs [25],
with the incorporation of communication and wireless sensor
nodes. In addition, a PCT comprises of the controller and
sensors, which further utilizes: 1) LCD user interface; and
2) wireless interface; in order to provide communication
and network capability for sensors. A set of programs and
incentives: RTP, TOU rates and DR may apply by utility com-
panies and SGs for encouraging consumers to reduce their
energy usage during peak demand periods, where studies
of [8], [17], [26] are helpful. Utilities supply energy with
various Prates for the specified intervals: OP, MP and HP
based on the defined electricity tariffs. Whereas, some cities
of the Ontario, Canada, users are informed about the pricing
tariffs for various intervals during the 24 hours in a day [27].
An efficient energy management technique is presented for
optimizing the daily (24-hour) load profiles of the number of
chillers known as daily optimal chiller loading (DOCL) [28].
Optimizing the daily power consumption patterns of the
chillers, their aggregated consumption is evaluated. Authors
use the enhanced differential bat algorithm (DBA) for the
optimization of 24 hours energy consumption. Henceforth,
the households engage themselves in DR events and TOU
rates via predefining or managing their dwellings’ devices.
The prime motivation of utilizing SG incentives for system
reliability in order to tackle critical conditions and avoiding
power losses are increasing rapidly [29]–[31]. The specialty
of advanced PCTs is their communication with SMs for
capturing the energy pricing signals in order to respond to
the variations in pricing signals [27], and also help users to
contribute in DR events and TOU pricing signals.
PCTs are also helpful in managing dwellings’ appliances
for saving electricity bills on peak prices [27] and contribute
in DR events utilizing TOU rates defined for consumers.
In addition, consumers define some threshold for their bills
VOLUME 6, 2018 33491
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
FIGURE 2. Thermostats and their features.
by manually entering specific offset values, which correspond
to different TOU rates [27]. They apply the offset values
for the I_SPs for decreasing them during a heating pro-
cess or increasing them during a cooling process which result
in minimizing the energy consumption. The ISPs values
depend on the user’s priorities according to their standards
of comforts. Furthermore, consumers’ dissatisfaction repre-
sent that they have to maintain constant interaction with the
traditional PCTs especially during cold winter times or hot
summer times for participating in the DR events [25] and [31].
This constant interaction disturbs consumers by leading them
to interact with PCTs like a single PT. Some important fea-
tures of the thermostats are also mentioned in Fig. 2.
A. LIMITATIONS IN THE EXISTING LITERATURE
Keshtkar et al. [32] discuss EMS in buildings using the FLC.
They consider four input parameters: Prate,HO,Tempoutdoor
and I_SPs. However, this system lacks adaptation in the
thermostat. The system considered in [33] is an extension
of [32]. Authors tried to make it adaptive using the same
fuzzy logic approach. This approach introduces the training
of I_SPs of the thermostat by considering three consecutive
changes of the same setpoint in the same day of the week; it
automates this setpoint to the optimized setpoint. However,
these techniques pose the following limitations.
All of these approaches control the energy consumption
patterns for cold cities or hot cities separately. None of
these approaches provide the setpoint control for both
hot and cold cities simultaneously.
These studies are country oriented research, specifically
working with systems in Canada, UK , and others as
mentioned in [32] and [33].
These two limitations led us to extend this study for fur-
ther enhancement in the thermostat setpoints’ optimization.
Table 2 describes the comparative analysis of some existing
techniques.
B. CONTRIBUTIONS
We have following contributions in the proposed model:
Develop a world-wide adaptive thermostat model to
manage the energy consumption and cost of residential
buildings using I_SPs.
All prior models are based on management of the heat-
ing system control or cooling system control; however,
the proposed system manages both heating and cooling
systems’ temperature control simultaneously using a
fuzzy logic approach.
The proposed system uses different I_SPs in each case:
1) for heating; and 2) for cooling; to avoid the peak
formation during the PHs.
Two FISs are used for inferring the rules: 1) Mamdani;
and 2) Sugeno for the evaluation of the aforementioned
system’s parameters because both of the FISs use simple
antecedent and consequent information for rules’ com-
putation.
III. PROBLEM STATEMENT
In residential sectors, HVAC systems utilize a large amount
of the aggregated energy consumption throughout the world.
33492 VOLUME 6, 2018
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
TABLE 2. Recent trends: state of the art work on thermostats in consideration of the respective parameters: occupancy, price and adaptiveness.
These systems entail approximately a 64% and about
57% from the aggregated power utilization in Canada and
U.S. [33]. They are all comprised on usage of the essen-
tial loads which can create peaks or they can contribute
to power outages or blackouts due to huge consumption in
any particular area (city). Moreover, variations from flat-
rates to dynamic pricing tariffs largely impact the increase
of the electricity bills which play a significant role in HVAC
systems. Providing an automatic control of HVAC systems,
PTs are used for preserving power inconsideration to users’
thermal preferences. Users maintain setpoints for using PTs
as an EMS in their dwellings and optimize the temperature
during various time periods of a day for depicting their daily
consumption patterns and comfort standards.
The PTs employ sensors for temperature measurement
with an adjusted setpoint using a control logic [32]. Using the
described thermostat model, they maintain the indoor tem-
perature for heating or cooling by increasing or decreasing
the I_SP values. Although, various studies show that there
are no significant reductions in electricity cost using the PTs
as compared to the non-PTs. Because non-PTs are manually
controlled devices and often users forget to operate them
and this feature lead to the maximum energy consumption.
In addition, there is one more obstacle of using PTs that users
mostly do not remember to reprogram PTs in order to respond
to the varying electricity prices which lead to users’ discom-
fort. In some studies, thermostats are designed for automating
their setpoints, like in [32] and [33], by considering the
outdoor climate conditions. All of these studies are relevant to
a specific country and can control heating or cooling setpoints
separately. However, there is no such technique which can be
applied to a world-wide adaptive scale for controlling HVAC
systems simultaneously. There is a need to design a model
that can control HVAC systems to fulfill the requirements of
residential users.
IV. PROBLEM FORMULATION
This section will discuss the details of the formulation of
energy consumption, cost, PAR and user comfort (UC) for
residential consumers. The proposed model is evaluated with
the help of fuzzy logic and trapezoidal membership functions
which are also used for the assignments of fuzzy intervals
of all model’s parameters (including HO,Tempoutdoor ,I_SPs
and Prate). Energy consumption is evaluated with the help of
Frules, some of the sample Frules are specified in Table 3.
A. MAMDANI AND SUGENO FIS
Mamdani fuzzy system uses inputs in a crisp format, fuzzifies
it, maps it using a FIS, generates its fuzzy output and defuzzi-
fies it to get a crisp output [34]. Mamdani method has several
t-norms for utilizing the connectives of the antecedents and
several defuzzification methods, however, we have used the
centroid method. It uses linguistic variables for the rules
(as described next) and its antecedents and consequents are
both linguistic variables. All input membership functions
are generated using the linguistic variables: Tempoutdoor
{L,M,H},HO ∈ {A,P},I_SP ∈ {L,M,H}and Prate
∈ {OP,MP,HP}
Frules are described in the following formate. For example;
IF Tempoutdoor is “Normal” AND Prate is “Mid Peak” AND
HO is “Present” AND I_SP is “Medium”, THEN
energyconsumption is “Medium”.
Sugeno fuzzy system uses the systematic approach to
define the Frules for the given inputs and outputs of the
system. It takes the antecedents as a linguistic variables,
however, it’s consequent parts are functions, which are either
VOLUME 6, 2018 33493
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
TABLE 3. Sample fuzzy rules for hot and cold cities.
zero order, linear piecewise or the first order. In this model,
each rule has a crisp output obtained by the weighted average
defuzzification method. It is also computationally efficient.
For example, by considering the above example;
IF Tempoutdoor is “Normal” AND Prate is “Mid Peak” AND
HO is “Present” AND I_SP is “Medium”, THEN
energyconsumption =energyconsumption(Tempoutdoor ,Prate,
O,I_SP).
The defuzzification methods are centroid and weighted
average, which are described earlier. Centroid is computed
using the formula [35];
z=RµC(z)·zdz
RµC(z)dz (1)
µC(z) is the membership function of fuzzy set C.
Weighted average defuzzification method for the Sugeno is
calculated as;
z=C¯z· ¯z
C¯z(2)
In short, Mamdani is intuitive method and has wider applica-
tions. It is more appropriate to human input whereas Sugeno
performs efficiently with the optimization and adaptive tech-
niques [35]. Sugeno is considered feasible for mathematical
analysis. Due to its optimal nature, Sugeno FIS is expected
to outperform Mamdani FIS in energy consumption as well.
Cost is computed using this formula [36];
Cost_Econs(hour)=Econs(hour )TOUrates(hour ) (3)
Here, Cost_Econs(hour) is the hourly cost whereas Econs is the
electricity consumed at any specific hour and TOUrates(hour)
are the hourly pricing tariffs defined by the utilities.
PAR is calculated as;
PAR =max_Load
Average_Load (4)
UC is computed with the help of following equation;
Uc1
Tempoutdoor I_SP (5)
such that:
Uc=
0;if 40 Tempoutdoor <0
1abs(Tempoutdoor I_SPs)1.4;
if 0Tempoutdoor <50
0;if 50 Tempoutdoor <
(5a)
In case of hot cities; 0 <Tempoutdoor <50C and
I_SP ranges from 20-25C; however, in cold cities case;
I_SP − −40 <Tempoutdoor <0C and I_SP 18-21C
taken from [37] and [38].
The energy efficiency gain (Egain) is computed with the help
of the equation;
Egain =Eapre Eapro
Eapre
(6)
Where, Eapre is the efficiency of the previous approach and
Eapro is the efficiency of the proposed approach.
V. SYSTEM MODEL
In this study, a world-wide adaptive thermostat model is
developed to enhance the functionality of existing ther-
mostats for residential buildings. Existing thermostats [32]
and [37] are based on controlling the heating system and
they are also designed to be used in specific country
(i.e., Canada (Fuzzy logic based adaptive thermostat [33])
and UK (NEST [13] thermostat)). In this paper, a new strat-
egy is developed to control HVAC systems throughout the
world. It’s control parameters are: Tempoutdoor ,HO and Prate
schemes (i.e., TOU, RTP, flate rate (FLR) and critical peak
pricing (CPP)). The TOU pricing scheme is used in this
scenario. This system is an extension of [39] and it’s system
model is depicted in Fig. 3.
In Fig. 3, two separate units are used for the heating and
cooling control of HVAC systems. The first unit deals with
the cold temperature control optimization and the second
unit deals with the hot temperature control optimization.
These two units are combined to form one new system called
world-wide adaptive thermostat model which controls both
heating and cooling setpoints simultaneously. Because earlier
systems like [32] have been designed for one country only.
33494 VOLUME 6, 2018
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
FIGURE 3. System model of the world-wide adaptive thermostat for the optimal energy consumption.
Sensor nodes are deployed to get the surrounding informa-
tion (i.e., Tempoutdoor ) and user HO information for optimiz-
ing the indoor temperature (I_SPs), whereas, the electricity
price is communicated via SMs and real time systems to the
buildings.
The reason behind designing two separate units is to con-
trol the hot and cold cities temperature. Because both cities
(hot and cold) indicate the different temperature ranges like
25-50C for hot cities [37] and -40-19C for cold cities [40].
So, thermostat for cold cities does not provide the optimal
control for the hot cities due to the variation in temperatures
range. On the other side, thermostat for cold cities cannot
cover the defined temperature range for the hot cities in worst
cases. Due to these reasons, a new world-wide adaptive ther-
mostat is proposed which controls these both simultaneously.
The proposed work covers the heat and cool setpoint opti-
mization units using the fuzzy logic. It has two control units
which are designed for controlling the heat setpoints and
cooling setpoints. It is also designed for controlling the world-
wide energy consumption instead of the existing country ori-
ented systems (which were designed for controlling the heat
setpoints only). Proposed system considers the Tempoutdoor ,
HO,Prate and I_SPs as the input values, whereas, it consid-
ers the energy consumption, cost and peak to average ratio
as the output parameters. Here, two countries are taken to
model the heating and cooling power consumption around
the globe. The thermostat is used to optimize the setpoints
for monitoring the total power consumption in any building.
The countries considered for analyzing the power consump-
tion are Libya and Russia. Libya is hottest country and Russia
is the coldest country chosen in the world. Then, we have
chosen the hottest and coldest city of the Libya and Russia
for formalizing the solution to our modeled problem. Tripoli
is chosen as the hottest city and its temperature data is taken
from weather forecasting website [37]. Yakutsk is considered
as the coldest city from Russia and it’s temperature informa-
tion is also taken from the weather forecasting site [40]. The
I_SPs are used for controlling the indoor temperature of the
residential buildings.
This scenario is evaluated with the help of fuzzy
logic. Fuzzy logic comprises of the following processes/
components: a) fuzzification; b) rule base; c) FIS and
d) defuzzification. In fuzzification, inputs of the system are
mapped to fuzzy values using membership functions. Rule
base is used for maintaining the proposed system’s rules for
evaluating the energy consumption. FISs are used to infer
the Frules, which are defined in the rule base and defuzzifi-
cation maps the fuzzy values to concrete values for the final
output [32].
The inputs and outputs of the system are I_SPs,
Tempoutdoor , user HO and Prate . The output of this sys-
tem is energy consumption. The membership functions con-
sidered for the inputs such as Tempoutdoor are: 1) Very
Cold (VC); 2) Cold (C); and 3) Normal (N) for the
cold cities whereas for hot cities; the membership func-
tions are: 1) N; 2) Hot (H); and 3) Very Hot (VH).
VOLUME 6, 2018 33495
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
FIGURE 4. Input membership functions for outdoor temperature, occupancy, price and initialized setpoints. (a) Outdoor
temperature range for cold cities. (b) Outdoor temperature range for hot cities. (c) User occupancy in buildings. (d) Utility price
rates. (e) Initialized setpoints for cold cities. (f) Initialized setpoints for hot cities. (g) Energy consumption for hot and cold cities.
The HO has two membership functions: 1) Absent (A);
and 2) Present (P). Prate has three membership functions:
1) L; 2) M; and 3) H . The output membership functions of the
energy consumption are: 1) Very Low (VL); 2) L; 3) M; 4) H;
and 5) Very High (VH). These input and output membership
functions are also described in Fig. 4 (a-g) along with their
specified ranges. The Tempoutdoor data is taken from [37]
and [40] and price information from [32].
Trapezoidal membership functions are used to maintain
the state of the information (i.e., TOU price signal val-
ues), although, triangular membership functions are efficient,
however, they lack the ability to collect information about
the data set points. In our work, the maintenance of state
information is a necessary component that is the reason,
trapezoidal membership function is preferred over triangular
function. The input and output membership functions are
chosen as trapezoidal because their shapes have a flat top and
they maintain the status information for the chosen members
instead of the triangular membership functions; since the
considered membership functions: Prate,Tempoutdoor,HO and
I_SP maintain the same data values for multiple hours (for
using the TOU price signal) and then vary after those specific
hours. So, these flat top level membership functions have the
advantage of simplicity [38] and [35]. Triangular membership
functions are only used to obtain the setpoint information and
they do not maintain any state information.
33496 VOLUME 6, 2018
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
Algorithm 1 Minimize Energy Consumption
(Min_Econs(A))
1Initialization: A (Tempoutdoor ,I_SPs,Prate and HO)
2Fuzzification
3Tempoutdoor {L, M, H}
4I_SPs {L, M, H}
5Prate {OP, MP, HP}
6HO {A, P}
7Rule Base by incorporating the fuzzy rules using
Table III
8FIS evaluation using Mamdani or Sugeno
9for thr =1to Thr do
10 I_SPs =I_SPshr
11 if Normal_scenario then
12 if I _SPs(thr )==HP(thr )then
13 A[I_SPs ]I_SPs RedH
14 else if I_SPs(thr )==MP(thr )then
15 A[I_SPs ]=I_SPs RedM
16 else
17 A[I_SPs ]=I_SPs RedL
18 end
19 end
20 end
21 end
22 else
23 def_Setpoint_CS(tCRD,RedL,RedM,RedH)
24 end
25 Defuzzification
26 Using the aggregated Frules
27 Calculate Econs using Frules
28 Calculate Ecost and PAR
29 end
The system is evaluated with the help of Frules for deter-
mining the system output. There are 3 variables with 3 values
and a fourth variable with 2 values, so, we have a total of fifty
four rules (332=54) defined in the rule base for evaluating
the energy consumption with the help of two FISs named
as Mamdani and Sugeno. The list of rules defined for this
model including both hot and cold cities are defined using the
IF-THEN format described in Section IV. The defuzzification
method used in Mamdani FIS is centroid and in Sugeno, it is
used as weighted average [35]. The list of sample rules are
presented in Table 3.
The temperature information for both cities are used in
terms of two scenarios: Normal case and critical case (CS)
scenarios. In a normal case, the hourly temperature vari-
ations are considered in comfortable temperature range
(i.e., below 35C in summers and above 0C in winter). In CS:
when the temperature exceeds the comfort zone (i.e., above
35C in summers and below 0C in winters). The work
flow of both scenarios is described in Algorithm 1 and
Algorithm 2. The major steps of the FLC are described as
follows:
Algorithm 2 Adjust Setpoints for Minimum Energy Con-
sumption (Min_Econs_Setpoints(A))
1def_Setpoint_CS(tCRD,RedL,RedM,RedH)
2if I _SPs(thr )==HP(thr )then
3tCRD=kRedH;
4else if I_SPs(thr )==MP(thr )then
5tCRD=2kRedM;
6else
7tCRD=3kRedL;
8A[I_SPs ]tCRD
9end
10 end
11 end
1) The first step deals with the initialization of the system
parameters: Tempoutdoor ,I_SP,Prate and HO.
2) At the second step, the system deals with the
fuzzification of parameters (building the membership
functions).
3) The third step is based on defining the rules in a rule
base, as the sensor nodes are already deployed in the
system so evaluation of the energy consumption is
based on the Frules.
4) The fourth step contains the FIS system (Mamdani and
Sugeno), which are used for the rule evaluation.
5) In the fifth step, defuzzification is performed and the
final value is returned to the Econs. The Ecost is calcu-
lated after the energy consumption using Eq. 3.
6) When the consumers’ DR option is active, their active
participation is monitored and repeated until changes
are in process.
VI. IMPLEMENTATION AND RESULTS
In this Section, we discuss the energy management in res-
idential buildings using our designed FLC. This controller
automates the thermostat setpoints for the hot and cold cities
throughout the world using four inputs: 1) HO; 2) Prate;
3) I_SPs and 4) Tempoutdoor as mentioned in Section V.
Tempoutdoor has been sensed by the sensor nodes deployed
by the users. Sugeno and Mamdani FIS are used. In addi-
tion, the membership functions are specified as trapezoidal;
also mentioned in Section V (the System Model). We have
simulated the effect of these parameters for two scenarios:
a) energy efficiency in cold countries and b) energy efficiency
in hot countries. Furthermore, both scenarios are evaluated
for the following performance metrics: energy consumption,
cost, PAR and comfort. Prate are listed in Table 4.
A. ENERGY CONSUMPTION IN HOT CITIES
Fig. 5 shows the energy consumption of our designed con-
troller using the Mamdani and Sugeno FIS and two pre-
vious controllers. The behavior of energy consumption is
maintained at a desired comfort level using the I_SPs. The
Tempoutdoor is minimum during the initial 6 hours of the day
VOLUME 6, 2018 33497
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
TABLE 4. Schedules of price rates and occupancy level during the full day.
FIGURE 5. Energy consumption in hot cities over a complete day.
and the setpoint maintained by the controller is feasible. The
setpoint is maintained at an increasing level during the OPHs
because there are no huge electricity bills. The Tempoutdoor
for the hot cities is catalogued on hourly basis [37].
After that, the setpoint is reduced because of the PHs where
the comfort level is little compromised. In residential build-
ings, users mostly leave at 9am, so the electricity demand
changes after every hour and the setpoint is also modified by
the controller accordingly. At the 11th hour, the MPs arrive
and users are expected outside the building. The setpoint is
again increased to stabilize the PAR till the 16th hour. From
the 17th to the 19th hour, the setpoint is again decreased due to
the PHs and then after the 20th hour, it is set to the optimum
range. Although the energy consumption has been reduced,
the UC has also been compromised. The maximum energy
consumption in hot cities is 8.5 kWh, 8.04 kWh, 6.5 kWh and
6.4 kWh using the Fixed Setpoint, Programmable, Mamdani
and Sugeno approach, respectively. Sugeno is consuming less
energy than all the previous approaches.
We have also run this simulation for evaluating the power
consumption of one month and results are shown in Fig. 6.
The energy consumption of this approach using these two
FISs is relatively less than the previous two approaches which
shows the efficiency of this scheme to earlier schemes. The
energy consumption by the Mamdani FIS is 3600 kWh,
Sugeno is 3400 kWh, Fixed setpoint approach is 3900 kWh
and Programmable shows 3800 kWh. Sugeno FIS outper-
forms all schemes in this case too, which is more energy
efficient. Mamdani and Sugeno FISs are more energy effi-
cient than the previous schemes because they formulate
the rules on the basis of human inductive method and
they also use efficient defuzzification functions, i.e., cen-
troid and weighted average. Due to these reasons, they are
FIGURE 6. One month simulation of energy consumption in hot cities.
computationally efficient. Especially, Sugeno uses more
effective defuzzification function (i.e., weighted average),
that is why, it outperforms the Mamdani FIS.
FIGURE 7. Cost of the total energy used in a complete day for hot cities.
B. COST OBTAINED IN HOT CITIES
The cost is computed by Eq. 3, which is also used in the
previous Section (cost for hot cities) as shown in Fig. 7.
The fixed setpoint approach costs 13.39 dollars (i.e., equiv-
alent 18.21 Libyan dinars), Programmable approach costs
13.06 dollars (17.76 dinars), Mamdani FIS costs 10.70 dol-
lars (14.56 dinars) and Sugeno FIS costs 9.77 dollars
(13.29 dinars). In addition, Sugeno costs less to the Pro-
grammable approach and more cost effective than the
previous approaches.
Although, the proposed approach is improvised with the
reduction of energy consumption, cost and PAR to the pre-
vious schemes; however, it sacrifices a little bit UC at PHs
inconsideration to the difference in outdoor and indoor tem-
peratures. As the comfortable room temperature is varying
between 18-21Cduring the winter and 23-25Cduring the
summer seasons. The peak formation is a major problem
throughout the literature, however, it is resolved in this tech-
nique at the cost of comfort compromise as shown in Fig. 8.
During peak demand periods, load is curtailed and consumers
demand less from the utilities. Consumers’ demand does not
contribute in overburdening the utilities and PAR remains
stable. Comfort is increased when we have an ideal building
indoor and outdoor temperatures. Although, this model is a
world-wide adaptive; however, it has a limitation relevant to
comfort compromise.
33498 VOLUME 6, 2018
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
FIGURE 8. PAR in hot cities.
C. ENERGY CONSUMPTION IN COLD CITIES
To be more comprehensive, we have taken the coldest city
İYakutsk, Russiaİ of the world and calculated its energy
consumption based on outdoor temperature variations during
a 24 hour period. The reason behind the selection of Yakutsk,
is to evaluate our proposed work in worst scenario. Because,
minimum energy consumption in this country will depict
that less cold countries can easily utilize this proposal to
efficiently manage the available electricity. Fig. 9 shows the
energy consumption of the proposed designed FLC with both
FISs and its comparison with the two previous controllers.
Its energy consumption is computed by analyzing the Frules.
In our scheme, the energy consumption is increased by setting
the I_SPs high in the initial 6 hours of the day because
Tempoutdoor is very low as shown in Fig. 9 and it is taken
from [38] for the 24 hour period. The Sugeno FIS performs
better in this case as compared to Mamdani due to its efficient
consequent part which is kept constant in our case.
FIGURE 9. Energy consumption in cold cities over a complete day.
Tempoutdoor for cold cities lies in the range of 40 to
19. However, we are considering the temperature data of
one day in this study, which lies in the specified range.
The setpoint is reduced in the PHs by keeping the energy
consumption below the peak formation. The demand of the
load changes during every hour in a residential building and
then it is modified by the controller automatically using the
sensors’ information. At the 11th hour, when the MP hours
arrive, the setpoint is again increased to maintain the UC
level till the 16th hour. During the 17th to the 19th hour,
the setpoint is again decreased due to the PHs and then after
the 20th hour, it is increased to achieve the desired comfort
due to OPHs. During PHs, the UC is a little bit compromised
even though the PAR is minimized by reducing the energy
consumption. The maximum hourly consumption by Fixed
setpoint, Programmable, Mamdani and Sugeno approach is
9.05 kWh, 9.0 kWh, 7.5 kWh and 6.5 kWh, respectively. The
proposed FLC improves the energy consumption compared to
the previous two controllers by effectively managing the set-
points. Since our FLC is utilizing the trapezoidal membership
functions, that is why, the trend of its lines follow its original
trapezoidal shapes.
FIGURE 10. One month simulation of energy consumption for cold cities.
We have simulated one month of power consumption and
the results are shown in Fig. 10. The energy consumption
of the FLC using Mamdani FIS is upto 4000 kWh, Sugeno
consumes 3200 kWh, the Fixed setpoint thermostat shows
5500 kWh and the Programmable shows 5000 kWh. Sugeno
and Mamdani consume less than the other two controllers and
also beat the previous schemes.
D. COST
The cost is computed using Eq. 3 and the proposed system
performs the best among all approaches. Using the Fixed
setpoint approach, the cost is nearly 18.5 dollars (i.e., equiva-
lent to 1071.9 Russian roubles), the Programmable approach
costs 16.39 dollars (949.6 roubles), the Mamdani FIS costs
12.75 dollars (738.8 roubles), whereas Sugeno FIS costs
10.02 dollars (580.7 roubles) per day as shown in Fig. 11.
Mamdani and Sugeno cost less because they use efficient
computation methods. Sugeno uses even more effective meth-
ods (i.e., weighted average) that is why it outperforms the
Mamdani method.
E. PAR
Although, the parameters included in this approach are not
directly interlinked with the PAR, however, the PAR obtained
is sufficiently good in this scheme which is shown in Fig. 12.
The DR option is enabled in this approach and the peak for-
mation is avoided by the load curtailment at PHs. The Mam-
dani FIS obtained 1.08, whereas the Sugeno obtained 1.02.
PAR is minimized at the cost of load curtailment and
users do not participate in the high demands from the
utility.
VOLUME 6, 2018 33499
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
FIGURE 11. Cost of the total energy used in a complete day for cold cities.
FIGURE 12. PAR in cold cities.
FIGURE 13. Energy efficiency achieved in hot and cold cities by Mamdani
and Sugeno FIS.
F. ENERGY EFFICIENCY
By considering all the above parameters including the energy
consumption, we can conclude that our proposed scheme is
more energy efficient than the previous schemes. It is shown
in Fig. 13 that the Mamdani and Sugeno FISs are 18.29% and
34.51% more energy efficient than the previous controllers in
cold cities whereas in hot cities both are 6.48% and 15.99%
performing efficiently. In cold cities, devices consume more
energy as compared to hot cities that is why those are more
energy efficient [43].
G. TRADE-OFF OF THE PROPOSED SCHEME
The trade-off is a compromise in this scheme, the UC is com-
promised at the cost of curtailment in energy consumption
and cost savings. The UC is compromised during PHs. More-
over, the load is curtailed during PHs which minimizes cost,
however, it also compromises the UC. When the temperature
increases or decreases in the CS, it effects the comfort level a
little bit. In normal scenarios, the comfort level is maintained
upto the customers’ requirements.
H. ANALYSIS OF THE RESULTS AND DISCUSSION
Mamdani and Sugeno, both FISs give reasonable results,
however, Mamdani FIS does not evaluate all the rules to its
full capacity whereas Sugeno evaluates them to full capac-
ity [35]. This is because it uses efficient defuzzification meth-
ods (i.e., weighted average). In addition, Sugeno is also more
accurate in terms of energy efficiency which is verified by the
simulation results as shown in Fig. 13. The major distinctive
points deduced after the comparison of both FIS in the fuzzy
logic for both the hottest and coldest cities of the world are:
Sugeno FIS computes the output to its full capacity
because it uses the consequent part either linear or con-
stant and the defuzzification method used in this case is
weighted average which is computationally efficient.
Mamdani is not much efficient when compared to the
Sugeno FIS because its consequent part is also a fuzzy
interval and its defuzzification method is centroid, which
is not efficient in computation.
Trapezoidal membership function is efficient and effec-
tive in this case because it maintains state, if its state
is not varying for certain time intervals. For example,
the temperature and cost considered here are not varying
for multiple hours that is why, this is used here and found
efficient in determining the proper output.
For maintaining the effective load schedule, cold cities
require twice more energy to the hot cities because
appliances used for the heating requires more energy as
compared to appliances used for cooling.
Due to the increase and decrease in Tempoutdoor ,
the comfort varies in each case; however, the comfort
is compromised in the proposed scheme due to load
curtailment in PHs. User comfort compromised by the
Mamdani and Sugeno FISs is 18% and 35% in cold
cities. Whereas, in hot cities, user comfort is compro-
mised by both FISs: 6% and 16%.
PAR is minimized at the consumer level after the peak
load curtailment. Consumers do not participate in the
high demand from utility during the peak hours.
VII. CONCLUSION
In this paper, a world-wide adaptive thermostat model using
fuzzy logic is presented. The designed thermostat has effec-
tively reduced the energy consumption of HVAC systems
while considering the consumers preferences in residential
buildings. Mamdani and Sugeno FISs are used for the analy-
sis of power consumption, cost and PAR. Simulation results
showed that the energy consumption, cost and PAR were sig-
nificantly reduced, especially using the Sugeno FIS method.
Mamdani and Sugeno FISs are 18% and 35% more energy
efficient than the previous controllers in cold cities. In hot
cities, both FISs performed 6% and 16% more efficient.
However, due to effective reduction in cost, energy consump-
tion and avoiding the peak formation, the proposed system
33500 VOLUME 6, 2018
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
suffered from comfort level maintenance during peak hours
when outdoor environmental temperature is very high or very
low. In the future, this system can be extended to improve
the comfort level during the high price rate hours by utilizing
pricing schemes for checking the effect of dynamic pricing
tariffs. Later, the humidity and real feedback will be included
for the improvement in users’ preferences.
REFERENCES
[1] Energy Efficiency Trends in Canada, Natural Res. Canada’s Office Energy
Efficiency, Washington, DC, USA, 2011.
[2] Household Energy Consumption and Expenditures, Consumption by End
Use, Energy Inf. Admin., Washington, DC, USA, 2010.
[3] P. McAuliffe and A. Rosenfeld, ‘‘Response of residential customers to
critical peak pricing and time-of-use rates during the summer of 2010,’
California Energy Commission, Sacramento, CA, USA, Tech. Rep., 2010.
[4] Smart Grid System Report, U.S. Dept. Energy, Washington, DC, USA,
Jul. 2009.
[5] A. Vojdani, ‘‘Smart integration,’IEEE Power Energy Mag., vol. 6, no. 6,
pp. 71–79, Nov./Dec. 2008.
[6] C.-S. Karavas, G. Kyriakarakos, K. G. Arvanitis, and G. Papadakis,
‘‘A multi-agent decentralized energy management system based on dis-
tributed intelligence for the design and control of autonomous polygen-
eration microgrids,’Energy Convers. Manage., vol. 103, pp. 166–179,
Oct. 2015.
[7] S. R. Gubba et al., ‘‘Energy management by controlling air conditioning
systems in residential settings,’’ in Proc. IEEE Workshop Environ., Energy,
Structural Monitor. Syst. (EESMS), Jun. 2016, pp. 1–5.
[8] M. H. Albadi and E. F. El-Saadany, ‘‘A summary of demand response
in electricity markets,’Electr. Power Syst. Res., vol. 78, no. 11,
pp. 1989–1996, 2008.
[9] M. A. Piette, O. Sezgen, D. S. Watson, N. Motegi, C. Shockman, and
L. ten Hope, ‘‘Development and evaluation of fully automated demand
response in large facilities,’’ California Energy Commission, Sacramento,
CA, USA, Tech. Rep. 500-01-034, 2005.
[10] A.-H. Mohsenian-Rad, V. W. S. Wong, J. Jatskevich, R. Schober, and
A. Leon-Garcia, ‘‘Autonomous demand-side management based on game-
theoretic energy consumption scheduling for the future smart grid,’IEEE
Trans. Smart Grid, vol. 1, no. 3, pp. 320–331, Dec. 2010.
[11] S. Huang, J. Xiao, J. F. Pekny, G. V. Reklaitis, and A. L. Liu, ‘‘Quantifying
system-level benefits from distributed solar and energy storage,’’ J. Energy
Eng., vol. 138, no. 2, pp. 33–42, 2011.
[12] F. A. Wolak, ‘‘Diagnosing the California electricity crisis,’Electr. J.,
vol. 16, no. 7, pp. 11–37, 2003.
[13] S. Chanana and M. Arora, ‘‘Demand response from residential air con-
ditioning load using a programmable communication thermostat,’Int.
J. Electr., Electron. Sci. Eng., vol. 7, no. 12, pp. 1–7, 2013.
[14] D. Geelen, A. Reinders, and D. Keyson, ‘‘Empowering the end-user in
smart grids: Recommendations for the design of products and services,’
Energy Policy, vol. 61, pp. 151–161, Oct. 2013.
[15] A. Mirakhorli and B. Dong, ‘‘Occupancy behavior based model predictive
control for building indoor climate—A critical review,’’ Energy Buildings,
vol. 129, pp. 499–513, Oct. 2016.
[16] I. Gaetani, P.-J. Hoes, and J. L. Hensen, ‘‘Occupant behavior in building
energy simulation: Towards a fit-for-purpose modeling strategy,’Energy
Buildings, vol. 121, pp. 188–204, Jun. 2016.
[17] A. Faruqui and S. Sergici, ‘‘Household response to dynamic pricing of
electricity: A survey of 15 experiments,’’ J. Regulatory Econ., vol. 38,
no. 2, pp. 193–225, 2010.
[18] C. Yan, X. Xue, S. Wang, and B. Cui, ‘‘A novel air-conditioning system
for proactive power demand response to smart grid,’’ Energy Convers.
Manage., vol. 102, pp. 239–246, Sep. 2015.
[19] N. D. Hatziargyriou, A. Dimeas, A. G. Tsikalakis, J. A. P. Lopes,
G. Karniotakis, and J. Oyarzabal, ‘‘Management of microgrids in market
environment,’’ in Proc. IEEE Int. Conf. Future Power Syst., Nov. 2005,
pp. 1–7.
[20] F. Gangale, A. Mengolini, and I. Onyeji, ‘‘Consumer engagement:
An insight from smart grid projects in Europe,’Energy Policy, vol. 60,
pp. 621–628, Sep. 2013.
[21] S. Karjalainen, ‘‘Thermal comfort and use of thermostats in Finnish homes
and offices,’Building Environ., vol. 44, no. 6, pp. 1237–1245, 2009.
[22] B. J. Johnson, M. R. Starke, O. A. Abdelaziz, R. K. Jackson, and
L. M. Tolbert, ‘‘A method for modeling household occupant behavior to
simulate residential energy consumption,’’ in Proc. IEEE PES Innov. Smart
Grid Technol. Conf. (ISGT), Feb. 2014, pp. 1–5.
[23] J. Woolley, M. Pritoni, and M. Modera, ‘‘Why occupancy-responsive adap-
tive thermostats do not always save-and the limits for when theyshould,’’ in
Proc. ACEEE Summer Study Energy Efficiency Buildings, Asilomar, CA,
USA, 2014, pp. 337–350
[24] N. Saputro, K. Akkaya, and S. Uludag, ‘‘A survey of routing proto-
cols for smart grid communications,’Comput. Netw., vol. 56, no. 11,
pp. 2742–2771, 2012.
[25] I. S. Walker and A. K. Meier, ‘‘Residential thermostats: Comfort controls
in California homes,’’ Lawrence Berkeley Nat. Lab., Berkeley, CA, USA,
Tech. Rep. LBNL-938E, 2008.
[26] C. King and D. Delurey, ‘‘Efficiency and demand response twins, sib-
lings, or cousins? Analyzing the conservation effects of demand response
programs,’’ Public Utilities, Fortnightly Mag., 2005, pp. 54–61.
[27] (2014). Electricity Pricing and Costs, Time of Use Rates, Hydro One.
Accessed: Jun. 20, 2016. [Online]. Available: http://www.hydroone.com/
TOU/Pages/Default.aspx
[28] L. dos Santos Coelho and A. Askarzadeh, ‘‘An enhanced bat algorithm
approach for reducing electrical power consumption of air conditioning
systems based on differential operator,’’ Appl. Thermal Eng., vol. 99,
pp. 834–840, Apr. 2016.
[29] S. P. Holland and E. T. Mansur, ‘‘The distributional and environmen-
tal effects of time-varying prices in competitive electricity markets,’
Center Study Energy Markets, Univ. California, Berkeley, CA, USA,
Tech. Rep. 143, 2006.
[30] A. Pina, C. Silva, P. Ferrão, ‘‘The impact of demand side management
strategies in the penetration of renewable electricity,’Energy, vol. 4, no. 1,
pp. 128–137, 2012.
[31] I. S. Walker and A. K. Meier, ‘‘Demand responsive control of air con-
ditioning via programmable communicating thermostats (PCTs), codes
and standards enhancement (CASE),’’ California Energy Commission,
Berkeley, CA, USA, Tech. Rep. LBNL-938E, 2006.
[32] A. Keshtkar, S. Arzanpour, F. Keshtkar, and P. Ahmadi, ‘‘Smart residential
load reduction via fuzzy logic, wireless sensors, and smart grid incentives,’’
Energy Buildings, vol. 104, pp. 165–180, Oct. 2015.
[33] A. Keshtkar and S. Arzanpour, ‘‘An adaptive fuzzy logic system for res-
idential energy management in smart grid environments,’’ Appl. Energy,
vol. 186, pp. 68–81, Jan. 2017.
[34] S. B. Bacha and B. Bede, ‘‘On Takagi Sugeno approximations of Mamdani
fuzzy systems,’’ in Proc. IEEE Annu. Conf. North Amer.Fuzzy Inf. Process.
Soc. (NAFIPS), Oct./Nov. 2016, pp. 1–7.
[35] T. J. Ross, Fuzzy Logic With Engineering Applications. New York, NY,
USA: Wiley, 2009.
[36] Sugeno and Mamdani Fuzzy Inference Systems. Accessed: Jun. 22, 2017.
[Online]. Available: https://www.mathworks.com/help/fuzzy/comparison-
of-sugeno-and-mamdani-systems.html
[37] (Oct. 2016). Weather Forecast Data, Past Weather in Yakutsk, Russia.
Accessed: Jun. 20, 2017. [Online]. Available: https://www.timeanddate.
com/weather/russia/yakutsk/historic
[38] Fuzzy Logic Tutorial Membership Functions. Accessed: Jun. 20, 2017.
[Online]. Available: http://www-rohan.sdsu.edu/doc/matlab/toolbox/
fuzzy/fuzzytu3.html
[39] S. Javaid, N. Javaid, S. Iqbal, and M. J. Mughal, ‘‘Controlling energy
consumption with the world-wide adaptive thermostat using fuzzy infer-
ence system in smart grid,’’ in Proc. 8th Int. Conf. ICT Converg., Jeju,
South Korea, Oct. 2017, pp. 66–71.
[40] (Jun. 2016). Weather Forecast Data, Past Weather in Tripoli, Libya.
Accessed: Jun. 20, 2017. [Online]. Available: https://www.timeanddate.
com/weather/libya/tripoli/historic
[41] Y. Liu, C. Yuen, S. Huang, N. U. Hassan, X. Wang, and S. Xie, ‘‘Peak-
to-average ratio constrained demand-side management with consumer’s
preference in residential smart grid,’IEEE J. Sel. Topics Signal Process.,
vol. 8, no. 6, pp. 1084–1097, Dec. 2014.
[42] A. Meier, ‘‘Thermostat interface and usability: A survey,’’ Lawrence
Berkeley Nat. Lab., Berkeley, CA, USA, Tech. Rep. LBNL-5043E, 2011.
[43] (2013). Michael Sivak. Hot Cities More Sustainable Than Cold Ones, Study
Says. Accessed: Jun. 25, 2017. [Online]. Available: http://science.nbcnews.
com/news/2013/03/27/17490775-hot-cities-more-sustainable-than-cold-
ones-study-says?lite
VOLUME 6, 2018 33501
S. Javaid et al.: Energy Management With a Worldwide Adaptive Thermostat Using FIS
SAKEENA JAVAID is currently pursuing the Ph.D. degree under the super-
vision of Dr. N. Javaid. She is currently a Research Associate with the Com-
munications over Sensors Laboratory, Department of Computer Science,
COMSATS Institute of Information Technology, Islamabad, Pakistan.
NADEEM JAVAID (S’08–M’11–SM’16) received
the bachelor’s degree in computer science from
Gomal University, Dera Ismail Khan, Pakistan,
in 1995, the master’s degree in electronics from
Quid-i-Azam University, Islamabad, Pakistan, in
1999, and the Ph.D. degree in computer science
from the University of Paris-Est, France, in 2010.
He has supervised seven Ph.D. and 85 master’s the-
ses. He is currently an Associate Professor and the
Founding Director of the Communications over
Sensors Research Laboratory, Department of Computer Science, COMSATS
Institute of Information Technology, Islamabad. He has authored over 650
articles in technical journals and international conferences. His research
interests include energy optimization in smart/micro grids, cloud computing
for smart grids, IoT-enabled wireless sensor networks, and big data analytics
in smart grids. He was a recipient of the Best University Teacher Award from
the Higher Education Commission of Pakistan in 2016 and the Research
Productivity Award from the Pakistan Council for Science and Technology
in 2017. He is an Associate Editor of the IEEE ACCESS journal and an Editor
of the International Journal of Space Based and Situated Computing.
SOHAIL IQBAL received the M.Sc. and M.Phil.
degrees in mathematics from Quaid-i-Azam Uni-
versity, Pakistan, in 2002 and 2004, respectively,
and the Ph.D. degree in surgical robotics from the
University of Paris-Est, France, in 2010. He was
a Scientific Advisor under the French Ministry
of Higher Education from 2008 to 2010. He is
currently an Assistant Professor with the National
University of Sciences and Technology, Islam-
abad. His main research interests include apply
mathematical techniques to different areas of computer science and engineer-
ing with special focus on robot modeling, energy management, and fuzzy
controllers.
MOHSEN GUIZANI (S’85–M’89–SM’99–F’09)
received the B.S. (Hons.) and M.S. degrees in elec-
trical engineering, and the M.S. and Ph.D. degrees
in computer engineering from Syracuse Univer-
sity, Syracuse, NY, USA, in 1984, 1986, 1987, and
1990, respectively. He served as an Associate Vice
President of Graduate Studies with Qatar Univer-
sity, the Chair of the Computer Science Depart-
ment, Western Michigan University, and the Chair
of the Computer Science Department, University
of West Florida. He also served in academic positions at the University
of Missouri–Kansas City, the University of Colorado–Boulder, Syracuse
University, and Kuwait University. He is currently a Professor and the ECE
Department Chair with the University of Idaho, USA. He is an author of nine
books and over 500 publications in refereed journals and conferences. His
research interests include wireless communications and mobile computing,
computer networks, mobile cloud computing, security, and smart grid. He is
a Senior Member of ACM. He received the Teaching Award multiple times,
the Best Research Award three times, and the Wireless Technical Committees
Recognition Award in 2017. He was the Chair of the IEEE Communications
Society Wireless Technical Committee and the Chair of the TAOS Technical
Committee. He served as a member, the chair,and a general chair of a number
of international conferences. He served as the IEEE Computer Society
Distinguished Speaker from 2003 to 2005. He has guest edited a number of
special issues in IEEE journals and magazines. He was the Founder and the
Editor-in-Chief of Wireless Communications and Mobile Computing journal
from 2000 to 2016. He is currently the Editor-in-Chief of IEEE Network and
serves on the editorial boards of several international technical journals.
AHMAD AL-MOGREN received the Ph.D. degree
in computer sciences from Southern Methodist
University, Dallas, TX, USA, in 2002. He was
an Assistant Professor of computer science and a
member of the Scientific Council, Riyadh College
of Technology. He also served as the Dean of the
College of Computer and Information Sciences
and the Head of the Council of Academic Accredi-
tation, Al Yamamah University. He is currently an
Associate Professor and the Vice Dean of devel-
opment and quality with the College of Computer and Information Sciences,
King Saud University, Saudi Arabia. His research areas of interest include
mobile and pervasive computing, computer security, sensor and cognitive
network, and data consistency. He has served as a guest editor for several
computer journals.
ATIF ALAMRI (M12) received the B.Sc. and
M.Sc. degrees in information systems from the
College of Computer and Information Sciences
(CCIS), King Saud University (KSU), Riyadh,
Saudi Arabia, in 2000 and 2004, respectively, and
the Ph.D. degree in computer science from the
School of Information Technology and Engineer-
ing, University of Ottawa, Canada, in 2010. He is
currently an Associate Professor with the Informa-
tion Systems Department, CCIS, KSU. He is one
of the founding members of the Chair of Pervasive and Mobile Comput-
ing, CCIS, KSU, and successfully managing its research program, which
transformed the chair as one of the best chairs of research excellence in the
college. He is also acting as an Assistant Vice-Rector of Technical, Vice
Presidents Office for Quality and Development, KSU. His research areas
of interest are multimedia-assisted health systems, ambient intelligence,
service-oriented architecture, multimedia cloud, sensor cloud, Internet of
Things, big data, mobile cloud, social network, and recommender system.
33502 VOLUME 6, 2018
MATLAB Source Code for paper
Energy Management With a World-Wide Adaptive Thermostat Using Fuzzy Inference
System
Authors: Sakeena Javaid, Nadeem Javaid, Sohail Iqbal, Mohsin Guizani,
Ahmad Al-Mogren and Atif Alamri
For further queries, readers can contact on following email IDs: sakeenajavaid@gmail.com,
nadeemjavaidqau@gmail.com
Note: This code is provided in one .m file. This code is developed for the energy management
of the hottest and the coldest regions of the world by introducing the new concept of world-
wide adaptive thermostat. The complete source code is also provided in Researchgate
https://www.researchgate.net/publication/342283294_Fuzzy_Cold_Hot_Regionzip”.
Link of the paper: https://ieeexplore.ieee.org/document/8339511/
Citation: S. Javaid, N. Javaid, S. Iqbal, M. Guizani, A. Al-Mogren and A. Alamri, "Energy
Management With a World-Wide Adaptive Thermostat Using Fuzzy Inference System," in
IEEE Access, vol. 6, pp. 33489-33502, 2018, doi: 10.1109/ACCESS.2018.2828040.
%% Code written in Matlab 2018a
%% Copyright (C) 2016 Sakeena Javaid; PhD Candidate
%% This code is developed by Sakeena Javaid under the suervision of Dr. Nadeem Javaid. Initially, we have implemented
the previous paper
%% "A. Keshtkar, S. Arzanpour, F. Keshtkar, and P. Ahmadi, ``Smart residential load reduction via fuzzy logic, wireless
sensors,
%% and smart grid incentives", Energy Buildings, vol. 104, pp. 165_180, Oct. 2015."
%% and extended it. Our contribution in the revious work is the develpment of new thermostat, i.e., worldwide adaptive
thermostate.
%% For the clear understanding of the code, please read the paper in depth first.
%% The Implementation of the Fixed setpoint thermostat and programmable thermostat are provided first because these are
the earlier works
%% for our work.
%% Our proposed system's code has two parts: code for the cold cities and code for the hot cities.
%%
close all;
clear;
tic
%% Cold Cities code for exisiting approaches
%% Fixed thermostate energy consumption
%% Initialization
TOU_Rates=[0.072 0.072 0.072 0.072 0.072 0.072 0.129 0.129 0.129 0.129 0.109 0.109 0.109 0.109 0.109 0.109 0.129
0.129 0.129 0.072 0.072 0.072 0.072 0.072]; % TOU price rates
TOU_Outdoor_Temp=[-1 -1 -1 -1 -1 -3 -4 -3 -1 1 3 4 5 6 5 4 2 2 2 2 2 1 1 -1]; %Oct 1, 2016//
https://www.timeanddate.com/weather/russia/yakutsk/historic?month=10&year=2016
%%
Setpoint=5; %% initialized setpoints for different hours of the day defined by the above-mentioned paper
Setpoint1=21;
Setpoint2=18;
Setpoint3=19;
Setpoint4=22;
Setpoint5=23;
%% Setpoints decrement values (offset values) for off-peak, peak and mid-peak hours as defined in the above-mentioned
paper
a=1; %% for off-peak hours
b=3; %% for peak hours
d=2; %% for mid-peak hours
%%
c=1.005; % Velocity of air particles
Mf_air=[0.05 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4]; % mass of air for 24
hours of the day
%% Fixed thermostate Code
for hr=1:24 % hr is used for depicting hours, %%
if hr==1 %% Cacluation started from the first hour of the day
init_Setpoints(hr)=Setpoint1; %Setpoints are taken from the paper on hourly basis
indoor_Temp(hr)=Setpoint; % Indoor temperature
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr)); % Eqaution for computing the energy
consumption using the indoor tmeperature
hourly_consumption(hr)=abs(DQ_h(hr)); %% Absolute of the obtained energy consumption value, so that negative
vlauses could be ignored.
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr); %% Cost on hourly basis
elseif hr>1 && hr<=8 %% Please follow the comments for hr==1 for the rest of the code. These are similar comments.
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=8 && hr<=12
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=12 && hr<=17
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=17 && hr<=20
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=20 && hr<=24
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
end
end
Fixed_T_hourly_consumption= hourly_consumption; %% array of hourly energy consumption records for the full day
Fixed_Thermostate_Consumption=sum(hourly_consumption); %% sum of the full day energy consumption
Fixed_T_Cost=sum(Cost5); %% sum of the cost obtained during the 24 hours of the day.
PAR_unscheduled_U=max(hourly_consumption)/(sum(hourly_consumption)/24); %% PAR computed
avg_con=(sum(hourly_consumption)/24); %% average energy consumption for unscheduled load
%% Prgrammable Thermostate code
for hour=1:24
Mf_air_PT=[0.02 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.2 0.4 0.4 0.4 0.4 0.3 0.3 0.3 0.3 0.3]; % mass of air
particles
if hour==1 %% cacluation started from the first hour of the day
PT_init_Setpoints(hour)=Setpoint1; % setpoint taken from the above-mentioned paper
PT_indoor_Temp(hour)=Setpoint; %% indoor temperature according to the defined setpoints
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour)); %% hourly energy
consumption calculated using the above-mentioned paper
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour)); %% absolute of the hourly energy consumption
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour); %% hourly cost computed
elseif hour>1 && hour<=8 %% please follow the comments for rest of the hours same as the hour==1
PT_newSetpoint1=Setpoint1;
PT_init_Setpoints(hour)=PT_newSetpoint1;
PT_indoor_Temp(hour)=Setpoint1;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=8 && hour<=12
PT_newSetpoint2=Setpoint2;
PT_init_Setpoints(hour)=PT_newSetpoint2;
PT_indoor_Temp(hour)=Setpoint2;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=12 && hour<=17
PT_newSetpoint3=Setpoint3;
PT_init_Setpoints(hour)=PT_newSetpoint3;
PT_indoor_Temp(hour)=Setpoint3;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=17 && hour<=20
PT_newSetpoint4=Setpoint4;
PT_init_Setpoints(hour)=PT_newSetpoint4;
PT_indoor_Temp(hour)=Setpoint4;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=20 && hour<=24
PT_newSetpoint5=Setpoint5;
PT_init_Setpoints(hour)=PT_newSetpoint5;
PT_indoor_Temp(hour)=Setpoint5;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
end
end
PT_TOU_hourly_consumption= PT_hourly_consumption; %% array maintaining the energy consumption for the 24 hours
of the day
PT_Consumption=sum(PT_hourly_consumption); %% aggregated energy consumption for the whole day
PAR_unscheduled_P=max(PT_hourly_consumption)/avg_con; %% PAR is comuted using this equation after optimizing the
load
BAR(1,1)=sum(PT_Consumption); %% bar plot for the aggregated energy consumption
PT_Cost=sum(Cost3); %% sum of the cost for full day
%% coding of our proposed scheme "World-wide adaptive thermostat"
%% creation of a new fis file %%%%%%%%%%%%%%%
%% Initialization
% on-peak: 7am-11am and 5pm-7pm; Mid-peak:11am-5pm; Off-peak: 8pm-6am
TOU_Outdoor_Temp=[-1 -1 -1 -1 -1 -3 -4 -3 -1 1 3 4 5 6 5 4 2 2 2 2 2 1 1 -1]; %Oct 1, 2016//
https://www.timeanddate.com/weather/russia/yakutsk/historic?month=10&year=2016
TOU_Rates=[0.072 0.072 0.072 0.072 0.072 0.072 0.129 0.129 0.129 0.129 0.109 0.109 0.109 0.109 0.109 0.109 0.129
0.129 0.129 0.072 0.072 0.072 0.072 0.072];
offPeak=[1 2 3 4 5 6 20 21 22 23 24]; %off peak duration: 11 hours in total
OnPeak=[7 8 9 10 17 18 19]; % On peak duration: 7 hours in total
MidPeak=[11 12 13 14 15 16]; % Mid peak duration: 6 hours in total
Sum_Cost=1;
One_C=[offPeak OnPeak MidPeak];
cold_Mamdani = newfis('Cold City Data.fis');
%%%%%%%%%%%%%%%Step1: Fuzzification of the input and output variables%%%%%%
%% Input variables
%% First input variable
cold_Mamdani.input(1).name = 'Outdoor Temperature (Degree-Celcius)'; %% outdoor temperature
cold_Mamdani.input(1).range = [-40 19]; % range of out door temperature
cold_Mamdani.input(1).mf(1).name = 'Very Cold'; %% first membership function for outdoor temperature
cold_Mamdani.input(1).mf(1).type = 'trapmf'; %% membership function type for outdoor temperature
cold_Mamdani.input(1).mf(1).params = [-40 -40 -30 -19]; %% range of the membership function
cold_Mamdani.input(1).mf(2).name = 'Cold'; %% second membership function for the outdoor temperature
cold_Mamdani.input(1).mf(2).type = 'trapmf'; %% membership function type for outdoor temperature
cold_Mamdani.input(1).mf(2).params = [-30 -20 0 10]; %% range of the membership function
cold_Mamdani.input(1).mf(3).name = 'Normal'; %% third membership function for the outdoor temperature
cold_Mamdani.input(1).mf(3).type = 'trapmf'; %% membership function type for outdoor temperature
cold_Mamdani.input(1).mf(3).params = [0 10 19 19]; %% range of the membership function
%% second input variable
cold_Mamdani.input(2).name = 'Price (Cents)'; %% Price
cold_Mamdani.input(2).range = [4 16]; %% Range of the price
cold_Mamdani.input(2).mf(1).name = 'Off Peak'; %% First membership function for the price
cold_Mamdani.input(2).mf(1).type = 'trapmf'; %% membership function type for price
cold_Mamdani.input(2).mf(1).params = [4 4 7 10]; %% range of the membership function
cold_Mamdani.input(2).mf(2).name = 'Mid Peak'; %% Second membership function for the price
cold_Mamdani.input(2).mf(2).type = 'trapmf'; %% membership function type for price
cold_Mamdani.input(2).mf(2).params = [7 9 11.5 13]; %% range of the membership function
cold_Mamdani.input(2).mf(3).name = 'High Peak'; %% Third membership function for the price
cold_Mamdani.input(2).mf(3).type = 'trapmf'; %% membership function type for price
cold_Mamdani.input(2).mf(3).params = [10 13 16 16]; %% range of the membership function
%% Third input variable
cold_Mamdani.input(3).name = 'Occupancy'; %% Occupancy
cold_Mamdani.input(3).range = [0 250]; %% range
cold_Mamdani.input(3).mf(1).name = 'Present'; %% First membership function of occupancy
cold_Mamdani.input(3).mf(1).type = 'trapmf'; %% membership function type for occupancy
cold_Mamdani.input(3).mf(1).params = [0 0 126 126]; %% range of the membership function
cold_Mamdani.input(3).mf(2).name = 'Absent'; %% Second membership function of occupancy
cold_Mamdani.input(3).mf(2).type = 'trapmf'; %% membership function type for occupancy
cold_Mamdani.input(3).mf(2).params = [125 125 250 250]; %% range of the membership function
%% Fourth input variable
cold_Mamdani.input(4).name = 'Initialized Setpoints (Degree-Celcius)'; %% initialized setpoints
cold_Mamdani.input(4).range = [14 19]; %% range
cold_Mamdani.input(4).mf(1).name = 'Low'; %% First membership function of initialized setpoints
cold_Mamdani.input(4).mf(1).type = 'trapmf'; %% membership function type for initialized setpoints
cold_Mamdani.input(4).mf(1).params = [14 14 16 17]; %% range of the membership function
cold_Mamdani.input(4).mf(2).name = 'Medium'; %% Second membership function of initialized setpoints
cold_Mamdani.input(4).mf(2).type = 'trapmf'; %% membership function type for initialized setpoints
cold_Mamdani.input(4).mf(2).params = [16 16.5 17.5 18]; %% range of the membership function
cold_Mamdani.input(4).mf(3).name = 'High'; %% Third membership function of initialized setpoints
cold_Mamdani.input(4).mf(3).type = 'trapmf'; %% membership function type for initialized setpoints
cold_Mamdani.input(4).mf(3).params = [17 18 19 19]; %% range of the membership function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%% Output Variable: energy consumption
cold_Mamdani.output(1).name = 'Energy Consumption (kWh)'; %% Energy consumption
cold_Mamdani.output(1).range = [0 9]; %% Range
cold_Mamdani.output(1).mf(1).name = 'Very Low'; %% First membership function of the energy consumption
cold_Mamdani.output(1).mf(1).type = 'trapmf'; %% Membership function type
cold_Mamdani.output(1).mf(1).params = [0 0 1 2]; %% Range of membership function
cold_Mamdani.output(1).mf(2).name = 'Low'; %% Second membership function of the energy consumption
cold_Mamdani.output(1).mf(2).type = 'trapmf'; %% Membership function type
cold_Mamdani.output(1).mf(2).params = [1 2 3 4]; %% Range of membership function
cold_Mamdani.output(1).mf(3).name = 'Medium'; %% Third membership function of the energy consumption
cold_Mamdani.output(1).mf(3).type = 'trapmf'; %% Membership function type
cold_Mamdani.output(1).mf(3).params = [3 4 5 6]; %% Range of membership function
cold_Mamdani.output(1).mf(4).name = 'High'; %% Fourth membership function of the energy consumption
cold_Mamdani.output(1).mf(4).type = 'trapmf'; %% Membership function type
cold_Mamdani.output(1).mf(4).params = [5 6 7 8]; %% Range of membership function
cold_Mamdani.output(1).mf(5).name = 'Very High'; %% Fifth membership function of the energy consumption
cold_Mamdani.output(1).mf(5).type = 'trapmf'; %% Membership function type
cold_Mamdani.output(1).mf(5).params = [7 8 10 10]; %% Range of membership function
%%%%%%%%%%%%% Step2: Formation of the Rules Base System %%%%%%%%%%%%%%%%%%%%%%%%%
%% Fuzzy Rule base system
cold_Mamdani.rule(1).antecedent = [1 1 1 1]; %% Possible input combinations of the memberships functions
cold_Mamdani.rule(1).consequent = 1; %% Output part of the rule
cold_Mamdani.rule(1).weight = 1; %% weight means operator rither 1 -> AND or 2 -> OR
cold_Mamdani.rule(1).connection = 1; %% connection represents either AND or OR operator is used.
cold_Mamdani.rule(2).antecedent = [1 1 1 2]; %% comments of rule 1 are the same for all.
cold_Mamdani.rule(2).consequent = 2;
cold_Mamdani.rule(2).weight = 1;
cold_Mamdani.rule(2).connection = 1;
cold_Mamdani.rule(3).antecedent = [1 1 1 3];
cold_Mamdani.rule(3).consequent = 3;
cold_Mamdani.rule(3).weight = 1;
cold_Mamdani.rule(3).connection = 1;
cold_Mamdani.rule(4).antecedent = [1 1 2 1];
cold_Mamdani.rule(4).consequent = 2;
cold_Mamdani.rule(4).weight = 1;
cold_Mamdani.rule(4).connection = 1;
cold_Mamdani.rule(5).antecedent = [1 1 2 2];
cold_Mamdani.rule(5).consequent = 4;
cold_Mamdani.rule(5).weight = 1;
cold_Mamdani.rule(5).connection = 1;
cold_Mamdani.rule(6).antecedent = [1 1 2 3];
cold_Mamdani.rule(6).consequent = 5;
cold_Mamdani.rule(6).weight = 1;
cold_Mamdani.rule(6).connection = 1;
cold_Mamdani.rule(7).antecedent = [1 2 1 1];
cold_Mamdani.rule(7).consequent = 1;
cold_Mamdani.rule(7).weight = 1;
cold_Mamdani.rule(7).connection = 1;
cold_Mamdani.rule(8).antecedent = [1 2 1 2];
cold_Mamdani.rule(8).consequent = 2;
cold_Mamdani.rule(8).weight = 1;
cold_Mamdani.rule(8).connection = 1;
cold_Mamdani.rule(9).antecedent = [1 2 1 3];
cold_Mamdani.rule(9).consequent = 3;
cold_Mamdani.rule(9).weight = 1;
cold_Mamdani.rule(9).connection = 1;
cold_Mamdani.rule(10).antecedent = [1 2 2 1];
cold_Mamdani.rule(10).consequent = 2;
cold_Mamdani.rule(10).weight = 1;
cold_Mamdani.rule(10).connection = 1;
cold_Mamdani.rule(11).antecedent = [1 2 2 2];
cold_Mamdani.rule(11).consequent = 3;
cold_Mamdani.rule(11).weight = 1;
cold_Mamdani.rule(11).connection = 1;
cold_Mamdani.rule(12).antecedent = [1 2 2 3];
cold_Mamdani.rule(12).consequent = 4;
cold_Mamdani.rule(12).weight = 1;
cold_Mamdani.rule(12).connection = 1;
cold_Mamdani.rule(13).antecedent = [1 3 1 1];
cold_Mamdani.rule(13).consequent = 1;
cold_Mamdani.rule(13).weight = 1;
cold_Mamdani.rule(13).connection = 1;
cold_Mamdani.rule(14).antecedent = [1 3 1 2];
cold_Mamdani.rule(14).consequent = 2;
cold_Mamdani.rule(14).weight = 1;
cold_Mamdani.rule(14).connection = 1;
cold_Mamdani.rule(15).antecedent = [1 3 1 3];
cold_Mamdani.rule(15).consequent = 3;
cold_Mamdani.rule(15).weight = 1;
cold_Mamdani.rule(15).connection = 1;
cold_Mamdani.rule(16).antecedent = [1 3 2 1];
cold_Mamdani.rule(16).consequent = 2;
cold_Mamdani.rule(16).weight = 1;
cold_Mamdani.rule(16).connection = 1;
cold_Mamdani.rule(17).antecedent = [1 3 2 2];
cold_Mamdani.rule(17).consequent = 3;
cold_Mamdani.rule(17).weight = 1;
cold_Mamdani.rule(17).connection = 1;
cold_Mamdani.rule(18).antecedent = [1 3 2 3];
cold_Mamdani.rule(18).consequent = 4;
cold_Mamdani.rule(18).weight = 1;
cold_Mamdani.rule(18).connection = 1;
cold_Mamdani.rule(19).antecedent = [2 1 1 1];
cold_Mamdani.rule(19).consequent = 1;
cold_Mamdani.rule(19).weight = 1;
cold_Mamdani.rule(19).connection = 1;
cold_Mamdani.rule(20).antecedent = [2 1 1 2];
cold_Mamdani.rule(20).consequent = 2;
cold_Mamdani.rule(20).weight = 1;
cold_Mamdani.rule(20).connection = 1;
cold_Mamdani.rule(21).antecedent = [2 1 1 3];
cold_Mamdani.rule(21).consequent = 3;
cold_Mamdani.rule(21).weight = 1;
cold_Mamdani.rule(21).connection = 1;
cold_Mamdani.rule(22).antecedent = [2 1 2 1];
cold_Mamdani.rule(22).consequent = 2;
cold_Mamdani.rule(22).weight = 1;
cold_Mamdani.rule(22).connection = 1;
cold_Mamdani.rule(23).antecedent = [2 1 2 2];
cold_Mamdani.rule(23).consequent = 3;
cold_Mamdani.rule(23).weight = 1;
cold_Mamdani.rule(23).connection = 1;
cold_Mamdani.rule(24).antecedent = [2 1 2 3];
cold_Mamdani.rule(24).consequent = 4;
cold_Mamdani.rule(24).weight = 1;
cold_Mamdani.rule(24).connection = 1;
cold_Mamdani.rule(25).antecedent = [2 2 1 1];
cold_Mamdani.rule(25).consequent = 1;
cold_Mamdani.rule(25).weight = 1;
cold_Mamdani.rule(25).connection = 1;
cold_Mamdani.rule(26).antecedent = [2 2 1 2];
cold_Mamdani.rule(26).consequent = 5;
cold_Mamdani.rule(26).weight = 1;
cold_Mamdani.rule(26).connection = 1;
cold_Mamdani.rule(27).antecedent = [2 2 1 3];
cold_Mamdani.rule(27).consequent = 4;
cold_Mamdani.rule(27).weight = 1;
cold_Mamdani.rule(27).connection = 1;
cold_Mamdani.rule(28).antecedent = [2 2 2 1];
cold_Mamdani.rule(28).consequent = 2;
cold_Mamdani.rule(28).weight = 1;
cold_Mamdani.rule(28).connection = 1;
cold_Mamdani.rule(29).antecedent = [2 2 2 2];
cold_Mamdani.rule(29).consequent = 3;
cold_Mamdani.rule(29).weight = 1;
cold_Mamdani.rule(29).connection = 1;
cold_Mamdani.rule(30).antecedent = [2 2 2 3];
cold_Mamdani.rule(30).consequent = 3;
cold_Mamdani.rule(30).weight = 1;
cold_Mamdani.rule(30).connection = 1;
cold_Mamdani.rule(31).antecedent = [2 3 1 1];
cold_Mamdani.rule(31).consequent = 1;
cold_Mamdani.rule(31).weight = 1;
cold_Mamdani.rule(31).connection = 1;
cold_Mamdani.rule(32).antecedent = [2 3 1 2];
cold_Mamdani.rule(32).consequent = 2;
cold_Mamdani.rule(32).weight = 1;
cold_Mamdani.rule(32).connection = 1;
cold_Mamdani.rule(33).antecedent = [2 3 1 3];
cold_Mamdani.rule(33).consequent = 3;
cold_Mamdani.rule(33).weight = 1;
cold_Mamdani.rule(33).connection = 1;
cold_Mamdani.rule(34).antecedent = [2 3 2 1];
cold_Mamdani.rule(34).consequent = 2;
cold_Mamdani.rule(34).weight = 1;
cold_Mamdani.rule(34).connection = 1;
cold_Mamdani.rule(35).antecedent = [2 3 2 2];
cold_Mamdani.rule(35).consequent = 3;
cold_Mamdani.rule(35).weight = 1;
cold_Mamdani.rule(35).connection = 1;
cold_Mamdani.rule(36).antecedent = [2 3 2 3];
cold_Mamdani.rule(36).consequent = 3;
cold_Mamdani.rule(36).weight = 1;
cold_Mamdani.rule(36).connection = 1;
cold_Mamdani.rule(37).antecedent = [3 1 1 1];
cold_Mamdani.rule(37).consequent = 1;
cold_Mamdani.rule(37).weight = 1;
cold_Mamdani.rule(37).connection = 1;
cold_Mamdani.rule(38).antecedent = [3 1 1 2];
cold_Mamdani.rule(38).consequent = 1;
cold_Mamdani.rule(38).weight = 1;
cold_Mamdani.rule(38).connection = 1;
cold_Mamdani.rule(39).antecedent = [3 1 1 3];
cold_Mamdani.rule(39).consequent = 2;
cold_Mamdani.rule(39).weight = 1;
cold_Mamdani.rule(39).connection = 1;
cold_Mamdani.rule(40).antecedent = [3 1 2 1];
cold_Mamdani.rule(40).consequent = 1;
cold_Mamdani.rule(40).weight = 1;
cold_Mamdani.rule(40).connection = 1;
cold_Mamdani.rule(41).antecedent = [3 1 2 2];
cold_Mamdani.rule(41).consequent = 2;
cold_Mamdani.rule(41).weight = 1;
cold_Mamdani.rule(41).connection = 1;
cold_Mamdani.rule(42).antecedent = [3 1 2 3];
cold_Mamdani.rule(42).consequent = 2;
cold_Mamdani.rule(42).weight = 1;
cold_Mamdani.rule(42).connection = 1;
cold_Mamdani.rule(43).antecedent = [3 2 1 1];
cold_Mamdani.rule(43).consequent = 1;
cold_Mamdani.rule(43).weight = 1;
cold_Mamdani.rule(43).connection = 1;
cold_Mamdani.rule(44).antecedent = [3 2 1 2];
cold_Mamdani.rule(44).consequent = 1;
cold_Mamdani.rule(44).weight = 1;
cold_Mamdani.rule(44).connection = 1;
cold_Mamdani.rule(45).antecedent = [3 2 1 3];
cold_Mamdani.rule(45).consequent = 2;
cold_Mamdani.rule(45).weight = 1;
cold_Mamdani.rule(45).connection = 1;
cold_Mamdani.rule(46).antecedent = [3 2 2 1];
cold_Mamdani.rule(46).consequent = 1;
cold_Mamdani.rule(46).weight = 1;
cold_Mamdani.rule(46).connection = 1;
cold_Mamdani.rule(47).antecedent = [3 2 2 2];
cold_Mamdani.rule(47).consequent = 2;
cold_Mamdani.rule(47).weight = 1;
cold_Mamdani.rule(47).connection = 1;
cold_Mamdani.rule(48).antecedent = [3 2 2 3];
cold_Mamdani.rule(48).consequent = 3;
cold_Mamdani.rule(48).weight = 1;
cold_Mamdani.rule(48).connection = 1;
cold_Mamdani.rule(49).antecedent = [3 3 1 1];
cold_Mamdani.rule(49).consequent = 1;
cold_Mamdani.rule(49).weight = 1;
cold_Mamdani.rule(49).connection = 1;
cold_Mamdani.rule(50).antecedent = [3 3 1 2];
cold_Mamdani.rule(50).consequent = 1;
cold_Mamdani.rule(50).weight = 1;
cold_Mamdani.rule(50).connection = 1;
cold_Mamdani.rule(51).antecedent = [3 3 1 3];
cold_Mamdani.rule(51).consequent = 2;
cold_Mamdani.rule(51).weight = 1;
cold_Mamdani.rule(51).connection = 1;
cold_Mamdani.rule(52).antecedent = [3 3 2 1];
cold_Mamdani.rule(52).consequent = 1;
cold_Mamdani.rule(52).weight = 1;
cold_Mamdani.rule(52).connection = 1;
cold_Mamdani.rule(53).antecedent = [3 3 2 2];
cold_Mamdani.rule(53).consequent = 2;
cold_Mamdani.rule(53).weight = 1;
cold_Mamdani.rule(53).connection = 1;
cold_Mamdani.rule(54).antecedent = [3 3 2 3];
cold_Mamdani.rule(54).consequent = 3;
cold_Mamdani.rule(54).weight = 1;
cold_Mamdani.rule(54).connection = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Inference Engine: Rules
Evaluation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% on-peak: 7am-11am and 5pm-7pm; Mid-peak:11am-5pm; Off-peak: 8pm-6am
for j=1:24
if j==1 %% counter used for counting hours in a day
rule1=cold_Mamdani.rule(1).consequent; %% rules are used for the computation of energy consumption and cost on
hourly basis
EC(j)=rule1; % energy consumption
cost2(j)=TOU_Rates(j)*EC(j); %% cost
end
if(j==2) %% Please follow the comments written for hour 1 for the rest for 23 hours, as these are all same
rule3=cold_Mamdani.rule(1).antecedent;
Nrule1=evalfis(rule3, cold_Mamdani);
rule2=cold_Mamdani.rule(2).antecedent;
Nrule2=evalfis(rule2, cold_Mamdani);
Np_Sum=plus(Nrule1, Nrule2);
EC(j)=Np_Sum;
cost2(j)=TOU_Rates(j)*EC(j);
end
if(j==3)
rule4=cold_Mamdani.rule(4).antecedent;
Nrule4=evalfis(rule4, cold_Mamdani);
rule5=cold_Mamdani.rule(5).antecedent;
Nrule5=evalfis(rule5, cold_Mamdani);
Np_Sum1=plus(Nrule4, Nrule5);
EC(j)=Np_Sum1;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==4
rule7=cold_Mamdani.rule(7).antecedent;
Nrule7=evalfis( rule7, cold_Mamdani);
Np_Sum2=Nrule7;
EC(j)=Np_Sum2;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==5
rule10=cold_Mamdani.rule(10).antecedent;
Nrule10=evalfis( rule10, cold_Mamdani);
rule11=cold_Mamdani.rule(11).antecedent;
Nrule11=evalfis( rule11, cold_Mamdani);
Np_Sum3=plus(Nrule10, Nrule11);
EC(j)=Np_Sum3;
cost2(j)=TOU_Rates(j)*EC(j);
end
if(j==6)
rule13=cold_Mamdani.rule(13).antecedent;
Nrule13=evalfis( rule13, cold_Mamdani);
rule14=cold_Mamdani.rule(14).antecedent;
Nrule14=evalfis( rule14, cold_Mamdani);
Np_Sum4=plus(Nrule13, Nrule14);
EC(j)=Np_Sum4;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==7
rule16=cold_Mamdani.rule(16).antecedent;
Nrule16=evalfis(rule16, cold_Mamdani);
EC(j)=Nrule16;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==8
rule17=cold_Mamdani.rule(17).antecedent;
Nrule17=evalfis(rule17, cold_Mamdani);
EC(j)=Nrule17;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==9
rule18=cold_Mamdani.rule(18).antecedent;
Nrule18=evalfis(rule18, cold_Mamdani);
EC(j)=Nrule18;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==10
rule19=cold_Mamdani.rule(19).antecedent;
Nrule19=evalfis(rule19, cold_Mamdani);
EC(j)=Nrule19;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==11
rule20=cold_Mamdani.rule(20).antecedent;
Nrule20=evalfis(rule20, cold_Mamdani);
EC(j)=Nrule20;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==12
rule22=cold_Mamdani.rule(22).antecedent;
Nrule22=evalfis(rule22, cold_Mamdani);
EC(j)=Nrule22;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==13
rule24=cold_Mamdani.rule(24).antecedent;
Nrule24=evalfis(rule24, cold_Mamdani);
EC(j)=Nrule24;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==14
rule26=cold_Mamdani.rule(26).antecedent;
Nrule26=evalfis(rule26, cold_Mamdani);
EC(j)=Nrule26;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==15
rule28=cold_Mamdani.rule(28).antecedent;
Nrule28=evalfis(rule28, cold_Mamdani);
rule29=cold_Mamdani.rule(29).antecedent;
Nrule29=evalfis(rule29, cold_Mamdani);
EC(j)=plus(Nrule28, Nrule29);
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==16
rule30=cold_Mamdani.rule(30).antecedent;
Nrule30=evalfis(rule30, cold_Mamdani);
EC(j)=Nrule30;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==17
rule32=cold_Mamdani.rule(32).antecedent;
Nrule32=evalfis(rule32, cold_Mamdani);
EC(j)= Nrule32;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==18
rule33=cold_Mamdani.rule(33).antecedent;
Nrule33=evalfis(rule33, cold_Mamdani);
EC(j)=Nrule33;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==19
rule34=cold_Mamdani.rule(34).antecedent;
Nrule34=evalfis(rule34, cold_Mamdani);
EC(j)=Nrule34;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==20
rule35=cold_Mamdani.rule(35).antecedent;
Nrule35=evalfis(rule35, cold_Mamdani);
rule36=cold_Mamdani.rule(36).antecedent;
Nrule36=evalfis(rule36, cold_Mamdani);
Np_Sum5=plus(Nrule35, Nrule36);
EC(j)=Np_Sum5;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==21
rule38=cold_Mamdani.rule(38).antecedent;
Nrule38=evalfis(rule38, cold_Mamdani);
rule39=cold_Mamdani.rule(39).antecedent;
Nrule39=evalfis(rule39, cold_Mamdani);
EC(j)=plus(Nrule38, Nrule39);
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==22
rule41=cold_Mamdani.rule(41).antecedent;
Nrule41=evalfis(rule41, cold_Mamdani);
EC(j)=Nrule41;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==23
rule44=cold_Mamdani.rule(44).antecedent;
Nrule44=evalfis(rule44, cold_Mamdani);
EC(j)=Nrule44;
cost2(j)=TOU_Rates(j)*EC(j);
end
if j==24
rule47=cold_Mamdani.rule(47).antecedent;
Nrule47=evalfis(rule47, cold_Mamdani);
rule48=cold_Mamdani.rule(48).antecedent;
Nrule48=evalfis(rule48, cold_Mamdani);
EC(j)=Nrule47;
cost2(j)=TOU_Rates(j)*EC(j);
end
end
Total_Cost_Mamdani=sum(cost2); %% total cost of the day for the mamdani FIS
PAR_Fuzzy_Th=(max(EC))/avg_con; %% PAR obtained for the whole day
%% Energy efficiency gain
E_prg=PT_Consumption; %energy consumption computed by programmable approach
E_mam=sum(EC); %energy consumption otained by Mamdani
cold_Gain_In_Eff_mam=abs((E_prg-E_mam)/E_prg); %% Energy efficiency gain by Mamdani
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Step 4: Defuzzification
%%%%%%%%%%%%%%%%%%
%% Centroid method is used here
w_rules=1;
Sum_rules=sum([rule4, rule5, rule7, rule10, rule11, rule13, rule14, rule16, rule17, rule18, rule19, rule20, rule22, rule24,
rule26, rule28, rule29, rule30, rule32, rule44, rule47, rule48]);
Defuzz_Rule=(Sum_rules*w_rules)/w_rules;
%% FIS genrations step for Mamdani based system
figure;
plotfis(cold_Mamdani); %% Initializing the FIS architechture
figure;
plotmf(cold_Mamdani, 'input',1); %% adding input 1 to the system
set(gca,'FontSize',20);
figure;
plotmf(cold_Mamdani, 'input',2); %% adding input 2 to the system
set(gca,'FontSize',20);
figure;
plotmf(cold_Mamdani, 'input',3); %% adding input 3 to the system
set(gca,'FontSize',20);
figure;
plotmf(cold_Mamdani, 'input',4); %% adding input 4 to the system
figure;
plotmf(cold_Mamdani, 'output',1); %% output of the system
set(gca,'FontSize',20);
%% Coding of the sugeno FIS
%% Input variables
TOU_Rates=[0.072 0.072 0.072 0.072 0.072 0.072 0.129 0.129 0.129 0.129 0.109 0.109 0.109 0.109 0.109 0.109 0.129
0.129 0.129 0.072 0.072 0.072 0.072 0.072];
sug_fismat = mam2sug(cold_Mamdani); %%sugeno to mamdani conversion
%% Outdoor temperature
sug_fismat.input(1).name = 'Outdoor Temperature (Degree-Celcius)'; %% Outdoor temperature
sug_fismat.input(1).range = [-40 19];
sug_fismat.input(1).mf(1).name = 'Very Cold'; %All comments are same as the comments in the mamdani FIS system,
sug_fismat.input(1).mf(1).type = 'trapmf'; %% Please follow the above-mentioned comments
sug_fismat.input(1).mf(1).params = [-40 -40 -30 -19];
sug_fismat.input(1).mf(2).name = 'Cold';
sug_fismat.input(1).mf(2).type = 'trapmf';
sug_fismat.input(1).mf(2).params = [-30 -20 0 10];
sug_fismat.input(1).mf(3).name = 'Normal';
sug_fismat.input(1).mf(3).type = 'trapmf';
sug_fismat.input(1).mf(3).params = [0 10 19 19];
%% price
sug_fismat.input(2).name = 'Price (Cents)';
sug_fismat.input(2).range = [4 16];
sug_fismat.input(2).mf(1).name = 'Off Peak';
sug_fismat.input(2).mf(1).type = 'trapmf';
sug_fismat.input(2).mf(1).params = [4 4 7 10];
sug_fismat.input(2).mf(2).name = 'Mid Peak';
sug_fismat.input(2).mf(2).type = 'trapmf';
sug_fismat.input(2).mf(2).params = [7 9 11.5 13];
sug_fismat.input(2).mf(3).name = 'High Peak';
sug_fismat.input(2).mf(3).type = 'trapmf';
sug_fismat.input(2).mf(3).params = [10 13 16 16];
%% Occupancy
sug_fismat.input(3).name = 'Occupancy';
sug_fismat.input(3).range = [0 250];
sug_fismat.input(3).mf(1).name = 'Present';
sug_fismat.input(3).mf(1).type = 'trapmf';
sug_fismat.input(3).mf(1).params = [0 0 126 126];
sug_fismat.input(3).mf(2).name = 'Absent';
sug_fismat.input(3).mf(2).type = 'trapmf';
sug_fismat.input(3).mf(2).params = [125 125 250 250];
%% Initialized Setpoints
sug_fismat.input(4).name = 'Initialized Setpoints (Degree-Celcius)';
sug_fismat.input(4).range = [14 19];
sug_fismat.input(4).mf(1).name = 'Low';
sug_fismat.input(4).mf(1).type = 'trapmf';
sug_fismat.input(4).mf(1).params = [14 14 16 17];
sug_fismat.input(4).mf(2).name = 'Medium';
sug_fismat.input(4).mf(2).type = 'trapmf';
sug_fismat.input(4).mf(2).params = [16 16.5 17.5 18];
sug_fismat.input(4).mf(3).name = 'High';
sug_fismat.input(4).mf(3).type = 'trapmf';
sug_fismat.input(4).mf(3).params = [17 18 19 19];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%% Output Variable
sug_fismat.output(1).name = 'Energy Consumption (kWh)';
sug_fismat.output(1).range = [0 1];
sug_fismat.output(1).mf(1).name = 'Very Low';
sug_fismat.output(1).mf(1).params = [0];
sug_fismat.output(1).mf(1).name = 'Low';
sug_fismat.output(1).mf(1).params = [0.3];
sug_fismat.output(1).mf(2).name = 'Medium';
sug_fismat.output(1).mf(2).params = [0.6];
sug_fismat.output(1).mf(2).name = 'High';
sug_fismat.output(1).mf(2).params = [0.9];
sug_fismat.output(1).mf(3).name = 'Very High';
sug_fismat.output(1).mf(3).params = [1];
%%%%%%%%%%%%% Step2: Formation of the Rules Base System %%%%%%%%%%%%%%%%%%%%%%%%%
%% Fuzzy Rule base SYSTEM
sug_fismat.rule(1).antecedent = [1 1 1 1]; % Possible input combinations of the memberships functions
sug_fismat.rule(1).consequent = 2; % Output part of the rule
sug_fismat.rule(1).weight = 1; % weight means operator rither 1 -> AND or 2 -> OR
sug_fismat.rule(1).connection = 1; % connection represents either AND or OR operator is used.
sug_fismat.rule(2).antecedent = [1 1 1 2];
sug_fismat.rule(2).consequent = 1;
sug_fismat.rule(2).weight = 1;
sug_fismat.rule(2).connection = 1;
sug_fismat.rule(3).antecedent = [1 1 1 3];
sug_fismat.rule(3).consequent = 3;
sug_fismat.rule(3).weight = 1;
sug_fismat.rule(3).connection = 1;
sug_fismat.rule(4).antecedent = [1 1 2 1];
sug_fismat.rule(4).consequent = 2;
sug_fismat.rule(4).weight = 1;
sug_fismat.rule(4).connection = 1;
sug_fismat.rule(5).antecedent = [1 1 2 2];
sug_fismat.rule(5).consequent = 3;
sug_fismat.rule(5).weight = 1;
sug_fismat.rule(5).connection = 1;
sug_fismat.rule(6).antecedent = [1 1 2 3];
sug_fismat.rule(6).consequent = 4;
sug_fismat.rule(6).weight = 1;
sug_fismat.rule(6).connection = 1;
sug_fismat.rule(7).antecedent = [1 2 1 1];
sug_fismat.rule(7).consequent = 2;
sug_fismat.rule(7).weight = 1;
sug_fismat.rule(7).connection = 1;
sug_fismat.rule(8).antecedent = [1 2 1 2];
sug_fismat.rule(8).consequent = 3;
sug_fismat.rule(8).weight = 1;
sug_fismat.rule(8).connection = 1;
sug_fismat.rule(9).antecedent = [1 2 1 3];
sug_fismat.rule(9).consequent = 3;
sug_fismat.rule(9).weight = 1;
sug_fismat.rule(9).connection = 1;
sug_fismat.rule(10).antecedent = [1 2 2 1];
sug_fismat.rule(10).consequent = 2;
sug_fismat.rule(10).weight = 1;
sug_fismat.rule(10).connection = 1;
sug_fismat.rule(11).antecedent = [1 2 2 2];
sug_fismat.rule(11).consequent = 5;
sug_fismat.rule(11).weight = 1;
sug_fismat.rule(11).connection = 1;
sug_fismat.rule(12).antecedent = [1 2 2 3];
sug_fismat.rule(12).consequent = 4;
sug_fismat.rule(12).weight = 1;
sug_fismat.rule(12).connection = 1;
sug_fismat.rule(13).antecedent = [1 3 1 1];
sug_fismat.rule(13).consequent = 1;
sug_fismat.rule(13).weight = 1;
sug_fismat.rule(13).connection = 1;
sug_fismat.rule(14).antecedent = [1 3 1 2];
sug_fismat.rule(14).consequent = 3;
sug_fismat.rule(14).weight = 1;
sug_fismat.rule(14).connection = 1;
sug_fismat.rule(15).antecedent = [1 3 1 3];
sug_fismat.rule(15).consequent = 3;
sug_fismat.rule(15).weight = 1;
sug_fismat.rule(15).connection = 1;
sug_fismat.rule(16).antecedent = [1 3 2 1];
sug_fismat.rule(16).consequent = 3;
sug_fismat.rule(16).weight = 1;
sug_fismat.rule(16).connection = 1;
sug_fismat.rule(17).antecedent = [1 3 2 2];
sug_fismat.rule(17).consequent = 5;
sug_fismat.rule(17).weight = 1;
sug_fismat.rule(17).connection = 1;
sug_fismat.rule(18).antecedent = [1 3 2 3];
sug_fismat.rule(18).consequent = 4;
sug_fismat.rule(18).weight = 1;
sug_fismat.rule(18).connection = 1;
sug_fismat.rule(19).antecedent = [2 1 1 1];
sug_fismat.rule(19).consequent = 1;
sug_fismat.rule(19).weight = 1;
sug_fismat.rule(19).connection = 1;
sug_fismat.rule(20).antecedent = [2 1 1 2];
sug_fismat.rule(20).consequent = 2;
sug_fismat.rule(20).weight = 1;
sug_fismat.rule(20).connection = 1;
sug_fismat.rule(21).antecedent = [2 1 1 3];
sug_fismat.rule(21).consequent = 3;
sug_fismat.rule(21).weight = 1;
sug_fismat.rule(21).connection = 1;
sug_fismat.rule(22).antecedent = [2 1 2 1];
sug_fismat.rule(22).consequent = 2;
sug_fismat.rule(22).weight = 1;
sug_fismat.rule(22).connection = 1;
sug_fismat.rule(23).antecedent = [2 1 2 2];
sug_fismat.rule(23).consequent = 5;
sug_fismat.rule(23).weight = 1;
sug_fismat.rule(23).connection = 1;
sug_fismat.rule(24).antecedent = [2 1 2 3];
sug_fismat.rule(24).consequent = 4;
sug_fismat.rule(24).weight = 1;
sug_fismat.rule(24).connection = 1;
sug_fismat.rule(25).antecedent = [2 2 1 1];
sug_fismat.rule(25).consequent = 1;
sug_fismat.rule(25).weight = 1;
sug_fismat.rule(25).connection = 1;
sug_fismat.rule(26).antecedent = [2 2 1 2];
sug_fismat.rule(26).consequent = 5;
sug_fismat.rule(26).weight = 1;
sug_fismat.rule(26).connection = 1;
sug_fismat.rule(27).antecedent = [2 2 1 3];
sug_fismat.rule(27).consequent = 4;
sug_fismat.rule(27).weight = 1;
sug_fismat.rule(27).connection = 1;
sug_fismat.rule(28).antecedent = [2 2 2 1];
sug_fismat.rule(28).consequent = 2;
sug_fismat.rule(28).weight = 1;
sug_fismat.rule(28).connection = 1;
sug_fismat.rule(29).antecedent = [2 2 2 2];
sug_fismat.rule(29).consequent = 3;
sug_fismat.rule(29).weight = 1;
sug_fismat.rule(29).connection = 1;
sug_fismat.rule(30).antecedent = [2 2 2 3];
sug_fismat.rule(30).consequent = 3;
sug_fismat.rule(30).weight = 1;
sug_fismat.rule(30).connection = 1;
sug_fismat.rule(31).antecedent = [2 3 1 1];
sug_fismat.rule(31).consequent = 1;
sug_fismat.rule(31).weight = 1;
sug_fismat.rule(31).connection = 1;
sug_fismat.rule(32).antecedent = [2 3 1 2];
sug_fismat.rule(32).consequent = 2;
sug_fismat.rule(32).weight = 1;
sug_fismat.rule(32).connection = 1;
sug_fismat.rule(33).antecedent = [2 3 1 3];
sug_fismat.rule(33).consequent = 3;
sug_fismat.rule(33).weight = 1;
sug_fismat.rule(33).connection = 1;
sug_fismat.rule(34).antecedent = [2 3 2 1];
sug_fismat.rule(34).consequent = 2;
sug_fismat.rule(34).weight = 1;
sug_fismat.rule(34).connection = 1;
sug_fismat.rule(35).antecedent = [2 3 2 2];
sug_fismat.rule(35).consequent = 3;
sug_fismat.rule(35).weight = 1;
sug_fismat.rule(35).connection = 1;
sug_fismat.rule(36).antecedent = [2 3 2 3];
sug_fismat.rule(36).consequent = 3;
sug_fismat.rule(36).weight = 1;
sug_fismat.rule(36).connection = 1;
sug_fismat.rule(37).antecedent = [3 1 1 1];
sug_fismat.rule(37).consequent = 1;
sug_fismat.rule(37).weight = 1;
sug_fismat.rule(37).connection = 1;
sug_fismat.rule(38).antecedent = [3 1 1 2];
sug_fismat.rule(38).consequent = 2;
sug_fismat.rule(38).weight = 1;
sug_fismat.rule(38).connection = 1;
sug_fismat.rule(39).antecedent = [3 1 1 3];
sug_fismat.rule(39).consequent = 3;
sug_fismat.rule(39).weight = 1;
sug_fismat.rule(39).connection = 1;
sug_fismat.rule(40).antecedent = [3 1 2 1];
sug_fismat.rule(40).consequent = 2;
sug_fismat.rule(40).weight = 1;
sug_fismat.rule(40).connection = 1;
sug_fismat.rule(41).antecedent = [3 1 2 2];
sug_fismat.rule(41).consequent = 3;
sug_fismat.rule(41).weight = 1;
sug_fismat.rule(41).connection = 1;
sug_fismat.rule(42).antecedent = [3 1 2 3];
sug_fismat.rule(42).consequent = 3;
sug_fismat.rule(42).weight = 1;
sug_fismat.rule(42).connection = 1;
sug_fismat.rule(43).antecedent = [3 2 1 1];
sug_fismat.rule(43).consequent = 1;
sug_fismat.rule(43).weight = 1;
sug_fismat.rule(43).connection = 1;
sug_fismat.rule(44).antecedent = [3 2 1 2];
sug_fismat.rule(44).consequent = 2;
sug_fismat.rule(44).weight = 1;
sug_fismat.rule(44).connection = 1;
sug_fismat.rule(45).antecedent = [3 2 1 3];
sug_fismat.rule(45).consequent = 3;
sug_fismat.rule(45).weight = 1;
sug_fismat.rule(45).connection = 1;
sug_fismat.rule(46).antecedent = [3 2 2 1];
sug_fismat.rule(46).consequent = 2;
sug_fismat.rule(46).weight = 1;
sug_fismat.rule(46).connection = 1;
sug_fismat.rule(47).antecedent = [3 2 2 2];
sug_fismat.rule(47).consequent = 3;
sug_fismat.rule(47).weight = 1;
sug_fismat.rule(47).connection = 1;
sug_fismat.rule(48).antecedent = [3 2 2 3];
sug_fismat.rule(48).consequent = 3;
sug_fismat.rule(48).weight = 1;
sug_fismat.rule(48).connection = 1;
sug_fismat.rule(49).antecedent = [3 3 1 1];
sug_fismat.rule(49).consequent = 1;
sug_fismat.rule(49).weight = 1;
sug_fismat.rule(49).connection = 1;
sug_fismat.rule(50).antecedent = [3 3 1 2];
sug_fismat.rule(50).consequent = 1;
sug_fismat.rule(50).weight = 1;
sug_fismat.rule(50).connection = 1;
sug_fismat.rule(51).antecedent = [3 3 1 3];
sug_fismat.rule(51).consequent = 3;
sug_fismat.rule(51).weight = 1;
sug_fismat.rule(51).connection = 1;
sug_fismat.rule(52).antecedent = [3 3 2 1];
sug_fismat.rule(52).consequent = 2;
sug_fismat.rule(52).weight = 1;
sug_fismat.rule(52).connection = 1;
sug_fismat.rule(53).antecedent = [3 3 2 2];
sug_fismat.rule(53).consequent = 3;
sug_fismat.rule(53).weight = 1;
sug_fismat.rule(53).connection = 1;
sug_fismat.rule(54).antecedent = [3 3 2 3];
sug_fismat.rule(54).consequent = 4;
sug_fismat.rule(54).weight = 1;
sug_fismat.rule(54).connection = 1;
%% on-peak: 7am-11am and 5pm-7pm; Mid-peak:11am-5pm; Off-peak: 8pm-6am
for i=1:24
if i==1 %% counter for the hours, please follow the above-mentioned comments (described for mamdani) for the rest of
the system
EC1(i)=zeros(1,1);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if(i==2)
rule3=sug_fismat.rule(3).consequent;
rule4=sug_fismat.rule(4).consequent;
rule5=sug_fismat.rule(5).consequent;
Np_Sum=plus(rule3, rule4);
EC1(i)=plus(Np_Sum, rule5);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if(i==3)
rule6=sug_fismat.rule(6).consequent;
rule7=sug_fismat.rule(7).consequent;
Np_Sum1=plus(rule6, rule7);
EC1(i)=Np_Sum1;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==4
rule9=sug_fismat.rule(9).consequent;
rule10=sug_fismat.rule(10).consequent;
Np_Sum2=plus(rule9, rule10);
EC1(i)=Np_Sum2;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==5 && i==One_C(i)
rule12=sug_fismat.rule(12).consequent;
rule13=sug_fismat.rule(13).consequent;
rule14=sug_fismat.rule(14).consequent;
Np_Sum3=plus(rule12, rule13);
EC1(i)=plus(Np_Sum3, rule14);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if(i==6) && i==One_C(i)
rule15=sug_fismat.rule(15).consequent;
rule16=sug_fismat.rule(16).consequent;
Np_Sum4=plus(rule15, rule16);
EC1(i)=Np_Sum4;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==7
rule18=sug_fismat.rule(18).consequent;
EC1(i)=rule18;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==8
rule19=sug_fismat.rule(19).consequent;
EC1(i)=rule19;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==9
rule20=sug_fismat.rule(20).consequent;
EC1(i)=rule20;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==10
rule21=sug_fismat.rule(21).consequent;
EC1(i)=rule21;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==11
rule22=sug_fismat.rule(22).consequent;
rule23=sug_fismat.rule(23).consequent;
EC1(i)=plus(rule22, rule23);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==12
rule24=sug_fismat.rule(24).consequent;
rule25=sug_fismat.rule(25).consequent;
EC1(i)=plus(rule24, rule25);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==13
rule26=sug_fismat.rule(26).consequent;
EC1(i)=rule26;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==14
rule28=sug_fismat.rule(28).consequent;
rule29=sug_fismat.rule(29).consequent;
EC1(i)=plus(rule28, rule29);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==15
rule30=sug_fismat.rule(30).consequent;
rule31=sug_fismat.rule(31).consequent;
EC1(i)=plus(rule30, rule31);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==16
rule32=sug_fismat.rule(32).consequent;
rule33=sug_fismat.rule(33).consequent;
EC1(i)=plus(rule32, rule33);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==17
rule34=sug_fismat.rule(34).consequent;
EC1(i)= rule34;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==18
rule35=sug_fismat.rule(35).consequent;
EC1(i)=rule35;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==19
rule36=sug_fismat.rule(36).consequent;
EC1(i)=rule36;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==20
rule37=sug_fismat.rule(37).consequent;
rule38=sug_fismat.rule(38).consequent;
rule39=sug_fismat.rule(39).consequent;
Np_Sum5=plus(rule37, rule38);
EC1(i)=plus(Np_Sum5, rule39);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==21
rule40=sug_fismat.rule(40).consequent;
rule41=sug_fismat.rule(41).consequent;
rule42=sug_fismat.rule(42).consequent;
Np_Sum6=plus(rule40, rule41);
EC1(i)=plus(Np_Sum6, rule42);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==22
rule43=sug_fismat.rule(43).consequent;
rule44=sug_fismat.rule(44).consequent;
rule45=sug_fismat.rule(45).consequent;
Np_Sum7=plus(rule43, rule44);
EC1(i)=plus(Np_Sum7, rule45);
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==23
rule46=sug_fismat.rule(46).consequent;
rule47=sug_fismat.rule(47).consequent;
Np_Sum8=rule46;
EC1(i)=Np_Sum8;
cost4(i)=TOU_Rates(i)*EC1(i);
end
if i==24
rule49=sug_fismat.rule(49).consequent;
rule50=sug_fismat.rule(50).consequent;
rule51=sug_fismat.rule(51).consequent;
Np_Sum9=plus(rule49, rule50);
Np_Sum10=plus(Np_Sum9, rule51);
EC1(i)=Np_Sum10;
cost4(i)=TOU_Rates(i)*EC1(i);
end
end
Sugeno_PAR=max(EC1)/avg_con; %% PAR obtained by the Sugeno FIS
avg_con;
Total_Cost_Sugeno=sum(cost4); %% Total cost of the day
%% Defuzzification
mem_val=54;
Sug_Defuzz1=sum(EC1)*mem_val/sum(EC1);
%% Energy Efficiency gain by the sugeno FIS
E_prg=PT_Consumption; % energy consumption by programmable approach
E_sug=sum(EC1); % energy consumption by Mamdani
cold_Gain_In_Eff_sug=(E_prg-E_sug)/E_prg; %% total energy efficieny gain
%% Results for the cold cities by the exisitng and proposed schemes
%% Energy consumption per day plot
figure
stairs(1:24, smooth(Fixed_T_hourly_consumption), 'r-o', 'LineWidth',1.5); %% Energy Consumption by Fixed setpoint
thermostat
hold on;
stairs(1:24, smooth(PT_TOU_hourly_consumption), 'b-*', 'LineWidth',1.5); %% Energy Consumption by Fixed
programmable thermostat
hold on;
stairs(1:24, smooth(EC), 'y-^','LineWidth',1.5); %% Energy Consumption by Mamdani FIS
hold on;
stairs(1:24, smooth(EC1), 'g-+','LineWidth',1.5); %% Energy Consumption by Sugeno FIS
xlabel('Time (hours)'); %% x label
ylabel('Energy Consumption (kWh)'); %% y label
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno'); %% legends of the plot
ylim([0 15]); %% y limit
set(gca,'FontSize',14); %% font size
grid on; %% For enabling grid in the plot
%% Energy consumption per munth %% This plot is used for the aggregated consumption of the energy per month
figure;
bar(1, 30*Fixed_Thermostate_Consumption, 0.2, 'r'); %% the same sequence of the techniques is followed as described in
the
hold on; %% earlier plot, please follow it for thr rest of the plots
bar(2, 30*BAR(1,1), 0.2, 'b');
hold on;
bar(3, 30*sum(EC), 0.2, 'y');
hold on;
bar(4, 30*sum(EC1), 0.2, 'g');
set(gca, 'XTick',1:1:4, 'XTickLabel',{'1','2','3','4'});
ylabel('Energy Consumption (kWh)');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
set(gca,'FontSize',14);
grid on;
%% PAR plot for the proposed and exisitng techniques
figure;
bar(1, PAR_unscheduled_U, 0.2, 'r');
hold on;
bar(2, PAR_unscheduled_P, 0.2, 'b');
hold on;
bar(3, PAR_Fuzzy_Th, 0.2, 'y');
hold on;
bar(4, Sugeno_PAR, 0.2, 'g');
set(gca,'XTick',1:1:4, 'XTickLabel',{'1','2','3','4'});
ylabel('PAR');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
set(gca,'FontSize',14);
grid on;
%% cost per day of all techniques
figure;
bar(1, Fixed_T_Cost, 0.2, 'r');
hold on;
bar(2, PT_Cost, 0.2, 'b');
hold on;
bar(3, Total_Cost_Mamdani, 0.2, 'y');
hold on;
bar(4, Total_Cost_Sugeno, 0.2, 'g');
set(gca, 'XTick',1:1:4, 'XTickLabel',{'1','2','3','4'});
ylabel('Cost (Dollars)');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
set(gca,'FontSize',14);
grid on;
%% efficiency gain of the proposed techniques
% figure;
% bar(1, cold_Gain_In_Eff_mam, 0.2, 'y');
% hold on;
% bar(2, cold_Gain_In_Eff_sug, 0.2, 'g');
% set(gca, 'XTick',1:1:2, 'XTickLabel',{'Cold cities'});
% ylabel('Efficiency Gain');
% legend('Mamdani','Sugeno');
% set(gca,'FontSize',14);
% grid on;
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%End of the Cold Cities
Code%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CODE FOR HOT CITIES (with the same sequence as described in the code for cold sequence)
%% Fixed Thermostate Energy consumption
%% Initialization of the variables
TOU_Rates=[0.072 0.072 0.072 0.072 0.072 0.072 0.129 0.129 0.129 0.129 0.109 0.109 0.109 0.109 0.109 0.109 0.129
0.129 0.129 0.072 0.072 0.072 0.072 0.072]; %% time of use tariff rates, reference is mentioned in the paper
TOU_Outdoor_Temp=[28 27 26 26 26 25 26 29 30 33 32 34 34 35 36 37 38 40 39 37 35 33 33 28]; %first june 2016//
%https://www.timeanddate.com/weather/libya/tripoli/historic?month=6&year=2016
%% setpoints described for various intervals of the day
Setpoint=5;
Setpoint2=18;
Setpoint3=19;
Setpoint1=21;
Setpoint4=22;
Setpoint5=23;
%% off-set values for on-peak, mid-peak and off-peak hours
a=1; %% for off-peak hours
d=2; %% for mid-peak hours
b=3; %% for high-peak hours
%%
c=1.005; % Velocity of air particles
Mf_air=[0.05 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5]; %% mass of air
particles
%% Fixed thermostate Code
for hr=1:24
if hr==1 %% Counter for the hour
init_Setpoints(hr)=Setpoint1; %% please follow the same comments as described in the mamdani FIS for the cold cities
indoor_Temp(hr)=Setpoint;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>1 && hr<=8
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=8 && hr<=12
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=12 && hr<=17
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=17 && hr<=20
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
elseif hr>=20 && hr<=24
init_Setpoints(hr)=Setpoint1;
indoor_Temp(hr)=Setpoint1;
DQ_h(hr)=Mf_air(hr)*c*(TOU_Outdoor_Temp(hr)-indoor_Temp(hr));
hourly_consumption(hr)=abs(DQ_h(hr));
Cost5(hr)=hourly_consumption(hr)*TOU_Rates(hr);
end
end
Fixed_T_hourly_consumption= hourly_consumption;
Fixed_Thermostate_Consumption=sum(hourly_consumption);
Fixed_T_Cost=sum(Cost5);
PAR_Unscheduled=max(hourly_consumption)/(sum(hourly_consumption)/24);
avg_con=(sum(hourly_consumption)/24);
%% Programmable Thermostate
Mf_air_PT=[0.05 0.5 0.5 0.5 0.5 0.5 0.4 0.4 0.4 0.4 0.4 0.5 0.5 0.5 0.5 0.5 0.4 0.4 0.5 0.5 0.5 0.5 0.5 0.5]; %% please follow
the same comments as described in the mamdani FIS for the cold cities
TOU_Rates=[0.072 0.072 0.072 0.072 0.072 0.072 0.129 0.129 0.129 0.129 0.109 0.109 0.109 0.109 0.109 0.109 0.129
0.129 0.129 0.072 0.072 0.072 0.072 0.072]; %% please follow the same comments as described in the mamdani FIS for the
cold cities
for hour=1:24
if hour==1
PT_init_Setpoints(hour)=Setpoint1; %% please follow the same comments as described in the mamdani FIS for the
cold cities
PT_indoor_Temp(hour)=Setpoint;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>1 && hour<=8
PT_newSetpoint1=Setpoint1;
PT_init_Setpoints(hour)=PT_newSetpoint1;
PT_indoor_Temp(hour)=Setpoint1;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=8 && hour<=12
PT_newSetpoint2=Setpoint2;
PT_init_Setpoints(hour)=PT_newSetpoint2;
PT_indoor_Temp(hour)=Setpoint2;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=12 && hour<=17
PT_newSetpoint3=Setpoint3;
PT_init_Setpoints(hour)=PT_newSetpoint3;
PT_indoor_Temp(hour)=Setpoint3;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=17 && hour<=20
PT_newSetpoint4=Setpoint4;
PT_init_Setpoints(hour)=PT_newSetpoint4;
PT_indoor_Temp(hour)=Setpoint4;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
elseif hour>=20 && hour<=24
PT_newSetpoint5=Setpoint5;
PT_init_Setpoints(hour)=PT_newSetpoint5;
PT_indoor_Temp(hour)=Setpoint5;
PT_DQ_h(hour)=Mf_air_PT(hour)*c*(TOU_Outdoor_Temp(hour)-PT_indoor_Temp(hour));
PT_hourly_consumption(hour)=abs(PT_DQ_h(hour));
Cost3(hour)=PT_hourly_consumption(hour)*TOU_Rates(hour);
end
end
PT_TOU_hourly_consumption= PT_hourly_consumption; %% hourly energy consumption
PT_Consumption=sum(PT_TOU_hourly_consumption); %% aggregated energy consumption
BAR(1,1)=sum(PT_Consumption); %% data used for plot
avg_con;
PAR_PT=max(PT_hourly_consumption)/avg_con; %% PAR for the whole day
avg_con1=(sum(PT_hourly_consumption)/24); %% Average energy consumption
PT_Cost=sum(Cost3); %% total cost of the Mamani system
%%%% Fuzzy Logic Code %%%%%%%%%%%%%%%
%% % on-peak: 7am-11am and 5pm-7pm; Mid-peak:11am-5pm; Off-peak: 8pm-6am
TOU_Outdoor_Temp=[28 27 26 26 26 25 26 29 30 33 32 34 34 35 36 37 38 40 39 37 35 33 33 28]; %first june 2016//
%https://www.timeanddate.com/weather/libya/tripoli/historic?month=6&year=2016
TOU_Rates=[0.072 0.072 0.072 0.072 0.072 0.072 0.072 0.129 0.129 0.129 0.109 0.109 0.109 0.109 0.109 0.109 0.129
0.129 0.129 0.072 0.072 0.072 0.072 0.072];
%%
%% Mamdani hot cities
hot_Mamdani = newfis('Hot City Data.fis');
%%%%%%%%%%%%%%%Step1: Fuzzification of the input and output variables%%%%%%
%% Input variables
%% outdoor temperature
hot_Mamdani.input(1).name = 'Ourdoor Temperature (Degree-Celcius)'; %% please follow the same comments as described
in the mamdani FIS for the cold cities
hot_Mamdani.input(1).range = [25 50];
hot_Mamdani.input(1).mf(1).name = 'Normal';
hot_Mamdani.input(1).mf(1).type = 'trapmf';
hot_Mamdani.input(1).mf(1).params = [25 25 30 35]; %% range id only different as compared to the cold cities, rest of the
inputs are same only the variations in values
hot_Mamdani.input(1).mf(2).name = 'Hot'; %% Please follow above-mentioned comments
hot_Mamdani.input(1).mf(2).type = 'trapmf';
hot_Mamdani.input(1).mf(2).params = [30 35 40 45];
hot_Mamdani.input(1).mf(3).name = 'Very Hot';
hot_Mamdani.input(1).mf(3).type = 'trapmf';
hot_Mamdani.input(1).mf(3).params = [40 45 58 58];
%% price
hot_Mamdani.input(2).name = 'Price (Cents)';
hot_Mamdani.input(2).range = [4 16];
hot_Mamdani.input(2).mf(1).name = 'Off Peak';
hot_Mamdani.input(2).mf(1).type = 'trapmf';
hot_Mamdani.input(2).mf(1).params = [4 4 7 10];
hot_Mamdani.input(2).mf(2).name = 'Mid Peak';
hot_Mamdani.input(2).mf(2).type = 'trapmf';
hot_Mamdani.input(2).mf(2).params = [7 10 11.5 13];
hot_Mamdani.input(2).mf(3).name = 'High Peak';
hot_Mamdani.input(2).mf(3).type = 'trapmf';
hot_Mamdani.input(2).mf(3).params = [10 13 16 16];
%% Occupancy
hot_Mamdani.input(3).name = 'Occupancy';
hot_Mamdani.input(3).range = [0 250];
hot_Mamdani.input(3).mf(1).name = 'Present';
hot_Mamdani.input(3).mf(1).type = 'trapmf';
hot_Mamdani.input(3).mf(1).params = [0 0 126 126];
hot_Mamdani.input(3).mf(2).name = 'Absent';
hot_Mamdani.input(3).mf(2).type = 'trapmf';
hot_Mamdani.input(3).mf(2).params = [125 125 250 250];
%% Initialized Setpoints
hot_Mamdani.input(4).name = 'Initialized Setpoints (Degree-Celcius)';
hot_Mamdani.input(4).range = [20 25];
hot_Mamdani.input(4).mf(1).name = 'Low';
hot_Mamdani.input(4).mf(1).type = 'trapmf';
hot_Mamdani.input(4).mf(1).params = [20 20 21 22];
hot_Mamdani.input(4).mf(2).name = 'Medium';
hot_Mamdani.input(4).mf(2).type = 'trapmf';
hot_Mamdani.input(4).mf(2).params = [21 22 23 24];
hot_Mamdani.input(4).mf(3).name = 'High';
hot_Mamdani.input(4).mf(3).type = 'trapmf';
hot_Mamdani.input(4).mf(3).params = [23 24 25 25];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%% Output Variable
%% energy cosnumption
hot_Mamdani.output(1).name = 'Energy Consumption (kWh)';
hot_Mamdani.output(1).range = [0 9];
hot_Mamdani.output(1).mf(1).name = 'Very Low';
hot_Mamdani.output(1).mf(1).type = 'trapmf';
hot_Mamdani.output(1).mf(1).params = [0 0 1 2];
hot_Mamdani.output(1).mf(2).name = 'Low';
hot_Mamdani.output(1).mf(2).type = 'trapmf';
hot_Mamdani.output(1).mf(2).params = [1 2 3 4];
hot_Mamdani.output(1).mf(3).name = 'Medium';
hot_Mamdani.output(1).mf(3).type = 'trapmf';
hot_Mamdani.output(1).mf(3).params = [3 4 5 6];
hot_Mamdani.output(1).mf(4).name = 'High';
hot_Mamdani.output(1).mf(4).type = 'trapmf';
hot_Mamdani.output(1).mf(4).params = [5 6 7 8];
hot_Mamdani.output(1).mf(5).name = 'Very High';
hot_Mamdani.output(1).mf(5).type = 'trapmf';
hot_Mamdani.output(1).mf(5).params = [7 8 9 9];
%%%%%%%%%%%%% Step2: Formation of the Rules Base System %%%%%%%%%%%%%%%%%%%%%%%%%
%% Fuzzy Rule base SYSTEM
%% Fuzzy Rule base SYSTEM
hot_Mamdani.rule(1).antecedent = [1 1 1 1]; % Possible input combinations of the memberships functions
hot_Mamdani.rule(1).consequent = 1; % Output part of the rule
hot_Mamdani.rule(1).weight = 1; % weight means operator rither 1 -> AND or 2 -> OR
hot_Mamdani.rule(1).connection = 1; % connection represents either AND or OR operator is used.
hot_Mamdani.rule(2).antecedent = [1 1 1 2]; %% please follow the same comments as described in the mamdani FIS for the
cold cities
hot_Mamdani.rule(2).consequent = 2;
hot_Mamdani.rule(2).weight = 1;
hot_Mamdani.rule(2).connection = 1;
hot_Mamdani.rule(3).antecedent = [1 1 1 3];
hot_Mamdani.rule(3).consequent = 3;
hot_Mamdani.rule(3).weight = 2;
hot_Mamdani.rule(3).connection = 1;
hot_Mamdani.rule(4).antecedent = [1 1 2 1];
hot_Mamdani.rule(4).consequent = 2;
hot_Mamdani.rule(4).weight = 1;
hot_Mamdani.rule(4).connection = 1;
hot_Mamdani.rule(5).antecedent = [1 1 2 2];
hot_Mamdani.rule(5).consequent = 3;
hot_Mamdani.rule(5).weight = 1;
hot_Mamdani.rule(5).connection = 1;
hot_Mamdani.rule(6).antecedent = [1 1 2 3];
hot_Mamdani.rule(6).consequent = 4;
hot_Mamdani.rule(6).weight = 1;
hot_Mamdani.rule(6).connection = 1;
hot_Mamdani.rule(7).antecedent = [1 2 1 1];
hot_Mamdani.rule(7).consequent = 1;
hot_Mamdani.rule(7).weight = 1;
hot_Mamdani.rule(7).connection = 1;
hot_Mamdani.rule(8).antecedent = [1 2 1 2];
hot_Mamdani.rule(8).consequent = 2;
hot_Mamdani.rule(8).weight = 1;
hot_Mamdani.rule(8).connection = 1;
hot_Mamdani.rule(9).antecedent = [1 2 1 3];
hot_Mamdani.rule(9).consequent = 3;
hot_Mamdani.rule(9).weight = 1;
hot_Mamdani.rule(9).connection = 1;
hot_Mamdani.rule(10).antecedent = [1 2 2 1];
hot_Mamdani.rule(10).consequent = 2;
hot_Mamdani.rule(10).weight = 1;
hot_Mamdani.rule(10).connection = 1;
hot_Mamdani.rule(11).antecedent = [1 2 2 2];
hot_Mamdani.rule(11).consequent = 3;
hot_Mamdani.rule(11).weight = 1;
hot_Mamdani.rule(11).connection = 1;
hot_Mamdani.rule(12).antecedent = [1 2 2 3];
hot_Mamdani.rule(12).consequent = 4;
hot_Mamdani.rule(12).weight = 1;
hot_Mamdani.rule(12).connection = 1;
hot_Mamdani.rule(13).antecedent = [1 3 1 1];
hot_Mamdani.rule(13).consequent = 1;
hot_Mamdani.rule(13).weight = 1;
hot_Mamdani.rule(13).connection = 1;
hot_Mamdani.rule(14).antecedent = [1 3 1 2];
hot_Mamdani.rule(14).consequent = 2;
hot_Mamdani.rule(14).weight = 1;
hot_Mamdani.rule(14).connection = 1;
hot_Mamdani.rule(15).antecedent = [1 3 1 3];
hot_Mamdani.rule(15).consequent = 3;
hot_Mamdani.rule(15).weight = 1;
hot_Mamdani.rule(15).connection = 1;
hot_Mamdani.rule(16).antecedent = [1 3 2 1];
hot_Mamdani.rule(16).consequent = 2;
hot_Mamdani.rule(16).weight = 1;
hot_Mamdani.rule(16).connection = 1;
hot_Mamdani.rule(17).antecedent = [1 3 2 2];
hot_Mamdani.rule(17).consequent = 3;
hot_Mamdani.rule(17).weight = 1;
hot_Mamdani.rule(17).connection = 1;
hot_Mamdani.rule(18).antecedent = [1 3 2 3];
hot_Mamdani.rule(18).consequent = 4;
hot_Mamdani.rule(18).weight = 1;
hot_Mamdani.rule(18).connection = 1;
hot_Mamdani.rule(19).antecedent = [2 1 1 1];
hot_Mamdani.rule(19).consequent = 2;
hot_Mamdani.rule(19).weight = 1;
hot_Mamdani.rule(19).connection = 1;
hot_Mamdani.rule(20).antecedent = [2 1 1 2];
hot_Mamdani.rule(20).consequent = 3;
hot_Mamdani.rule(20).weight = 1;
hot_Mamdani.rule(20).connection = 1;
hot_Mamdani.rule(21).antecedent = [2 1 1 3];
hot_Mamdani.rule(21).consequent = 4;
hot_Mamdani.rule(21).weight = 1;
hot_Mamdani.rule(21).connection = 1;
hot_Mamdani.rule(22).antecedent = [2 1 2 1];
hot_Mamdani.rule(22).consequent = 3;
hot_Mamdani.rule(22).weight = 1;
hot_Mamdani.rule(22).connection = 1;
hot_Mamdani.rule(23).antecedent = [2 1 2 2];
hot_Mamdani.rule(23).consequent = 4;
hot_Mamdani.rule(23).weight = 1;
hot_Mamdani.rule(23).connection = 1;
hot_Mamdani.rule(24).antecedent = [2 1 2 3];
hot_Mamdani.rule(24).consequent = 5;
hot_Mamdani.rule(24).weight = 1;
hot_Mamdani.rule(24).connection = 1;
hot_Mamdani.rule(25).antecedent = [2 2 1 1];
hot_Mamdani.rule(25).consequent = 1;
hot_Mamdani.rule(25).weight = 1;
hot_Mamdani.rule(25).connection = 1;
hot_Mamdani.rule(26).antecedent = [2 2 1 2];
hot_Mamdani.rule(26).consequent = 2;
hot_Mamdani.rule(26).weight = 1;
hot_Mamdani.rule(26).connection = 1;
hot_Mamdani.rule(27).antecedent = [2 2 1 3];
hot_Mamdani.rule(27).consequent = 3;
hot_Mamdani.rule(27).weight = 1;
hot_Mamdani.rule(27).connection = 1;
hot_Mamdani.rule(28).antecedent = [2 2 2 1];
hot_Mamdani.rule(28).consequent = 2;
hot_Mamdani.rule(28).weight = 1;
hot_Mamdani.rule(28).connection = 1;
hot_Mamdani.rule(29).antecedent = [2 2 2 2];
hot_Mamdani.rule(29).consequent = 3;
hot_Mamdani.rule(29).weight = 1;
hot_Mamdani.rule(29).connection = 1;
hot_Mamdani.rule(30).antecedent = [2 2 2 3];
hot_Mamdani.rule(30).consequent = 3;
hot_Mamdani.rule(30).weight = 1;
hot_Mamdani.rule(30).connection = 1;
hot_Mamdani.rule(31).antecedent = [2 3 1 1];
hot_Mamdani.rule(31).consequent = 2;
hot_Mamdani.rule(31).weight = 1;
hot_Mamdani.rule(31).connection = 1;
hot_Mamdani.rule(32).antecedent = [2 3 1 2];
hot_Mamdani.rule(32).consequent = 2;
hot_Mamdani.rule(32).weight = 1;
hot_Mamdani.rule(32).connection = 1;
hot_Mamdani.rule(33).antecedent = [2 3 1 3];
hot_Mamdani.rule(33).consequent = 3;
hot_Mamdani.rule(33).weight = 1;
hot_Mamdani.rule(33).connection = 1;
hot_Mamdani.rule(34).antecedent = [2 3 2 1];
hot_Mamdani.rule(34).consequent = 2;
hot_Mamdani.rule(34).weight = 1;
hot_Mamdani.rule(34).connection = 1;
hot_Mamdani.rule(35).antecedent = [2 3 2 2];
hot_Mamdani.rule(35).consequent = 3;
hot_Mamdani.rule(35).weight = 1;
hot_Mamdani.rule(35).connection = 1;
hot_Mamdani.rule(36).antecedent = [2 3 2 3];
hot_Mamdani.rule(36).consequent = 3;
hot_Mamdani.rule(36).weight = 1;
hot_Mamdani.rule(36).connection = 1;
hot_Mamdani.rule(37).antecedent = [3 1 1 1];
hot_Mamdani.rule(37).consequent = 2;
hot_Mamdani.rule(37).weight = 1;
hot_Mamdani.rule(37).connection = 1;
hot_Mamdani.rule(38).antecedent = [3 1 1 2];
hot_Mamdani.rule(38).consequent = 3;
hot_Mamdani.rule(38).weight = 1;
hot_Mamdani.rule(38).connection = 1;
hot_Mamdani.rule(39).antecedent = [3 1 1 3];
hot_Mamdani.rule(39).consequent = 3;
hot_Mamdani.rule(39).weight = 1;
hot_Mamdani.rule(39).connection = 1;
hot_Mamdani.rule(40).antecedent = [3 1 2 1];
hot_Mamdani.rule(40).consequent = 3;
hot_Mamdani.rule(40).weight = 1;
hot_Mamdani.rule(40).connection = 1;
hot_Mamdani.rule(41).antecedent = [3 1 2 2];
hot_Mamdani.rule(41).consequent = 4;
hot_Mamdani.rule(41).weight = 1;
hot_Mamdani.rule(41).connection = 1;
hot_Mamdani.rule(42).antecedent = [3 1 2 3];
hot_Mamdani.rule(42).consequent = 5;
hot_Mamdani.rule(42).weight = 1;
hot_Mamdani.rule(42).connection = 1;
hot_Mamdani.rule(43).antecedent = [3 2 1 1];
hot_Mamdani.rule(43).consequent = 3;
hot_Mamdani.rule(43).weight = 1;
hot_Mamdani.rule(43).connection = 1;
hot_Mamdani.rule(44).antecedent = [3 2 1 2];
hot_Mamdani.rule(44).consequent = 3;
hot_Mamdani.rule(44).weight = 1;
hot_Mamdani.rule(44).connection = 1;
hot_Mamdani.rule(45).antecedent = [3 2 1 3];
hot_Mamdani.rule(45).consequent = 3;
hot_Mamdani.rule(45).weight = 1;
hot_Mamdani.rule(45).connection = 1;
hot_Mamdani.rule(46).antecedent = [3 2 2 1];
hot_Mamdani.rule(46).consequent = 4;
hot_Mamdani.rule(46).weight = 1;
hot_Mamdani.rule(46).connection = 1;
hot_Mamdani.rule(47).antecedent = [3 2 2 2];
hot_Mamdani.rule(47).consequent = 5;
hot_Mamdani.rule(47).weight = 1;
hot_Mamdani.rule(47).connection = 1;
hot_Mamdani.rule(48).antecedent = [3 2 2 3];
hot_Mamdani.rule(48).consequent = 4;
hot_Mamdani.rule(48).weight = 1;
hot_Mamdani.rule(48).connection = 1;
hot_Mamdani.rule(49).antecedent = [3 3 1 1];
hot_Mamdani.rule(49).consequent = 1;
hot_Mamdani.rule(49).weight = 1;
hot_Mamdani.rule(49).connection = 1;
hot_Mamdani.rule(50).antecedent = [3 3 1 2];
hot_Mamdani.rule(50).consequent = 2;
hot_Mamdani.rule(50).weight = 1;
hot_Mamdani.rule(50).connection = 1;
hot_Mamdani.rule(51).antecedent = [3 3 1 3];
hot_Mamdani.rule(51).consequent = 2;
hot_Mamdani.rule(51).weight = 1;
hot_Mamdani.rule(51).connection = 1;
hot_Mamdani.rule(52).antecedent = [3 3 2 1];
hot_Mamdani.rule(52).consequent = 2;
hot_Mamdani.rule(52).weight = 1;
hot_Mamdani.rule(52).connection = 1;
hot_Mamdani.rule(53).antecedent = [3 3 2 2];
hot_Mamdani.rule(53).consequent = 4;
hot_Mamdani.rule(53).weight = 1;
hot_Mamdani.rule(53).connection = 1;
hot_Mamdani.rule(54).antecedent = [3 3 2 3];
hot_Mamdani.rule(54).consequent = 4;
hot_Mamdani.rule(54).weight = 1;
hot_Mamdani.rule(54).connection = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Inference Engine: Rules
Evaluation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% on-peak: 7am-11am and 5pm-7pm; Mid-peak:11am-5pm; Off-peak: 8pm-6am
for i=1:24
if i==1
rule1=hot_Mamdani.rule(1).consequent; %% please follow the same comments as described in the mamdani FIS for the
cold cities
EC1(i)=rule1;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if(i==2)
rule2=hot_Mamdani.rule(2).consequent;
rule3=hot_Mamdani.rule(3).consequent;
EC1(i)=plus(rule2, rule3);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if(i==3)
rule4=hot_Mamdani.rule(4).consequent;
rule5=hot_Mamdani.rule(5).consequent;
rule6=hot_Mamdani.rule(6).consequent;
Np_Sum6=plus(rule4, rule5);
EC1(i)=plus(Np_Sum6,rule6);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==4
rule7=hot_Mamdani.rule(7).consequent;
rule8=hot_Mamdani.rule(8).consequent;
EC1(i)=plus(rule7, rule8);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==5
rule10=hot_Mamdani.rule(10).consequent;
rule11=hot_Mamdani.rule(11).consequent;
rule12=hot_Mamdani.rule(12).consequent;
Np_Sum12=plus(rule10, rule11);
EC1(i)=plus(Np_Sum12, rule12);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if(i==6)
rule13=hot_Mamdani.rule(13).consequent;
rule14=hot_Mamdani.rule(14).consequent;
rule15= hot_Mamdani.rule(15).consequent;
Np_Sum4=plus(rule13, rule14);
EC1(i)= plus(Np_Sum4, rule15);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==7
rule16=hot_Mamdani.rule(16).consequent;
EC1(i)=rule16;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==8
rule17=hot_Mamdani.rule(17).consequent;
EC1(i)=rule17;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==9
rule18=hot_Mamdani.rule(18).consequent;
EC1(i)=rule18;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==10
rule19=hot_Mamdani.rule(19).consequent;
EC1(i)=rule19;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==11
rule20=hot_Mamdani.rule(20).consequent;
rule21=hot_Mamdani.rule(21).consequent;
EC1(i)=plus(rule20,rule21);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==12
rule22=hot_Mamdani.rule(22).consequent;
rule23=hot_Mamdani.rule(23).consequent;
EC1(i)=plus(rule22,rule23);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==13
rule24=hot_Mamdani.rule(24).consequent;
rule25=hot_Mamdani.rule(25).consequent;
EC1(i)=plus(rule24,rule25);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==14
rule26=hot_Mamdani.rule(26).consequent;
rule27=hot_Mamdani.rule(27).consequent;
EC1(i)=plus(rule26,rule27);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==15
rule28=hot_Mamdani.rule(28).consequent;
rule29=hot_Mamdani.rule(29).consequent;
EC1(i)=plus(rule28,rule29);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==16
rule30=hot_Mamdani.rule(30).consequent;
rule31=hot_Mamdani.rule(31).consequent;
EC1(i)=plus(rule30,rule31);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==17
rule32=hot_Mamdani.rule(32).consequent;
EC1(i)= rule32;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==18
rule33=hot_Mamdani.rule(33).consequent;
EC1(i)=rule33;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==19
rule34=hot_Mamdani.rule(34).consequent;
EC1(i)=rule34;
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==20
rule35=hot_Mamdani.rule(35).consequent;
rule36=hot_Mamdani.rule(36).consequent;
EC1(i)=plus(rule35,rule36);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==21
rule38=hot_Mamdani.rule(38).consequent;
rule39=hot_Mamdani.rule(39).consequent;
EC1(i)=plus(rule38,rule39);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==22
rule41=hot_Mamdani.rule(41).consequent;
rule42=hot_Mamdani.rule(42).consequent;
EC1(i)=plus(rule41,rule42);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==23
rule44=hot_Mamdani.rule(44).consequent;
rule45=hot_Mamdani.rule(45).consequent;
EC1(i)=plus(rule44,rule45);
cost1(i)=TOU_Rates(i)*EC1(i);
end
if i==24
rule47=hot_Mamdani.rule(47).consequent;
EC1(i)=rule47;
cost1(i)=TOU_Rates(i)*EC1(i);
end
end
Total_Cost_Mamdani=sum(cost1); %%
PAR_Fuzzy_Mamdani=max(EC1)/avg_con;
max(EC1);
avg_con;
%% efficiency
E_prg=PT_Consumption; %energy consumption by programmable approach
E_mam=sum(EC1); %energy consumption by Mamdani
hot_Gain_In_Eff_mam=abs((E_prg-E_mam)/E_prg); %%efficiency gain
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Step 4: Defuzzification
%%%%%%%%%%%%%%%%%%
%% Centroid method is used here
w_rules=1;
Sum_rules=sum([rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9, rule10, rule11, rule12, rule13, rule14, rule15,
rule16, rule17, rule18, rule19, rule20, rule21, rule22, rule23, rule24, rule25, rule26, rule27, rule28, rule29, rule30, rule31,
rule32, rule33, rule34, rule35, rule36, rule38, rule39, rule41, rule42, rule44, rule45, rule47]);
Defuzz_Rule=(Sum_rules*w_rules)/w_rules;
%% FIS genration of hot cities (This is the figure for system model, if you reader want to view, they can remove the
comments and execute it again)
figure;
plotfis(hot_Mamdani); %% all comments are same as for mamdani FIS in cold cities
figure;
plotmf(hot_Mamdani, 'input',1);
set(gca,'FontSize',20);
figure;
plotmf(hot_Mamdani, 'input',2);
set(gca,'FontSize',20);
figure;
plotmf(hot_Mamdani, 'input',3);
set(gca,'FontSize',20);
figure;
plotmf(hot_Mamdani, 'input',4);
set(gca,'FontSize',20);
%% Inpmlementation of Sugeno FIS Started
hot_Mamdani = newfis('Hot City Data.fis'); %% all comments are same as for Sugeno FIS in cold cities
sug_fismat = mam2sug(hot_Mamdani);
%%%%%%%%%%%%%%%Step1: Fuzzification of the input and output variables%%%%%%
%% Input variables
%% outdoor temperature
sug_fismat.input(1).name = 'Outdoor Temperature (Degree-Celcius)';
sug_fismat.input(1).range = [25 58];
sug_fismat.input(1).mf(1).name = 'Normal';
sug_fismat.input(1).mf(1).type = 'trapmf';
sug_fismat.input(1).mf(1).params = [25 25 27.5 30];
sug_fismat.input(1).mf(2).name = 'Hot';
sug_fismat.input(1).mf(2).type = 'trimf';
sug_fismat.input(1).mf(2).params = [30 37 44];
sug_fismat.input(1).mf(3).name ='Very Hot';
sug_fismat.input(1).mf(3).type = 'trapmf';
sug_fismat.input(1).mf(3).params = [37 44 58 58];
%% Price
sug_fismat.input(2).name = 'Price (Cents)'; %% all comments are same as for sugeno FIS in cold cities except values
sug_fismat.input(2).range = [4 16];
sug_fismat.input(2).mf(1).name = 'Off Peak';
sug_fismat.input(2).mf(1).type = 'trapmf';
sug_fismat.input(2).mf(1).params = [4 4 7 10];
sug_fismat.input(2).mf(2).name = 'Mid Peak';
sug_fismat.input(2).mf(2).type = 'trimf';
sug_fismat.input(2).mf(2).params = [10 11.5 13];
sug_fismat.input(2).mf(3).name = 'High Peak';
sug_fismat.input(2).mf(3).type = 'trapmf';
sug_fismat.input(2).mf(3).params = [11.5 13 16 16];
%% Occupancy
sug_fismat.input(3).name = 'Occupancy';
sug_fismat.input(3).range = [0 250];
sug_fismat.input(3).mf(1).name = 'Present';
sug_fismat.input(3).mf(1).type = 'trapmf';
sug_fismat.input(3).mf(1).params = [0 0 126 126];
sug_fismat.input(3).mf(2).name = 'Absent';
sug_fismat.input(3).mf(2).type = 'trapmf';
sug_fismat.input(3).mf(2).params = [125 125 250 250];
%% Initialized Setpoints
sug_fismat.input(4).name = 'Initialized Setpoints (Degree-Celcius)';
sug_fismat.input(4).range = [16 26];
sug_fismat.input(4).mf(1).name = 'Low';
sug_fismat.input(4).mf(1).type = 'trapmf';
sug_fismat.input(4).mf(1).params = [16 16 23 24];
sug_fismat.input(4).mf(2).name = 'Medium';
sug_fismat.input(4).mf(2).type = 'trimf';
sug_fismat.input(4).mf(2).params = [24 24.5 25];
sug_fismat.input(4).mf(3).name = 'High';
sug_fismat.input(4).mf(3).type = 'trapmf';
sug_fismat.input(4).mf(3).params = [24.5 25 26 26];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%% Output Variable
%% Energy Consumption
sug_fismat.output(1).name = 'Energy Consumption (kWh)';
sug_fismat.output(1).range = [0 1];
sug_fismat.output(1).mf(1).name = 'Very Low';
sug_fismat.output(1).mf(1).params = [0];
sug_fismat.output(1).mf(1).name = 'Low';
sug_fismat.output(1).mf(1).params = [0.3];
sug_fismat.output(1).mf(2).name = 'Medium';
sug_fismat.output(1).mf(2).params = [0.6];
sug_fismat.output(1).mf(2).name = 'High';
sug_fismat.output(1).mf(2).params = [0.9];
sug_fismat.output(1).mf(3).name = 'Very High';
sug_fismat.output(1).mf(3).params = [1];
%%%%%%%%%%%%% Step2: Formation of the Rules Base System %%%%%%%%%%%%%%%%%%%%%%%%%
%% Fuzzy Rule base SYSTEM
%% Fuzzy Rule base SYSTEM
sug_fismat.rule(1).antecedent = [1 1 1 1]; % Possible input combinations of the memberships functions
sug_fismat.rule(1).consequent = 1; % Output part of the rule
sug_fismat.rule(1).weight = 1; % weight means operator rither 1 -> AND or 2 -> OR
sug_fismat.rule(1).connection = 1; % connection represents either AND or OR operator is used.
sug_fismat.rule(2).antecedent = [1 1 1 2];
sug_fismat.rule(2).consequent = 2;
sug_fismat.rule(2).weight = 1;
sug_fismat.rule(2).connection = 1;
sug_fismat.rule(3).antecedent = [1 1 1 3];
sug_fismat.rule(3).consequent = 3;
sug_fismat.rule(3).weight = 2;
sug_fismat.rule(3).connection = 1;
sug_fismat.rule(4).antecedent = [1 1 2 1];
sug_fismat.rule(4).consequent = 2;
sug_fismat.rule(4).weight = 1;
sug_fismat.rule(4).connection = 1;
sug_fismat.rule(5).antecedent = [1 1 2 2];
sug_fismat.rule(5).consequent = 3;
sug_fismat.rule(5).weight = 1;
sug_fismat.rule(5).connection = 1;
sug_fismat.rule(6).antecedent = [1 1 2 3];
sug_fismat.rule(6).consequent = 4;
sug_fismat.rule(6).weight = 1;
sug_fismat.rule(6).connection = 1;
sug_fismat.rule(7).antecedent = [1 2 1 1];
sug_fismat.rule(7).consequent = 1;
sug_fismat.rule(7).weight = 1;
sug_fismat.rule(7).connection = 1;
sug_fismat.rule(8).antecedent = [1 2 1 2];
sug_fismat.rule(8).consequent = 2;
sug_fismat.rule(8).weight = 1;
sug_fismat.rule(8).connection = 1;
sug_fismat.rule(9).antecedent = [1 2 1 3];
sug_fismat.rule(9).consequent = 3;
sug_fismat.rule(9).weight = 1;
sug_fismat.rule(9).connection = 1;
sug_fismat.rule(10).antecedent = [1 2 2 1];
sug_fismat.rule(10).consequent = 2;
sug_fismat.rule(10).weight = 1;
sug_fismat.rule(10).connection = 1;
sug_fismat.rule(11).antecedent = [1 2 2 2];
sug_fismat.rule(11).consequent = 3;
sug_fismat.rule(11).weight = 1;
sug_fismat.rule(11).connection = 1;
sug_fismat.rule(12).antecedent = [1 2 2 3];
sug_fismat.rule(12).consequent = 4;
sug_fismat.rule(12).weight = 1;
sug_fismat.rule(12).connection = 1;
sug_fismat.rule(13).antecedent = [1 3 1 1];
sug_fismat.rule(13).consequent = 1;
sug_fismat.rule(13).weight = 1;
sug_fismat.rule(13).connection = 1;
sug_fismat.rule(14).antecedent = [1 3 1 2];
sug_fismat.rule(14).consequent = 2;
sug_fismat.rule(14).weight = 1;
sug_fismat.rule(14).connection = 1;
sug_fismat.rule(15).antecedent = [1 3 1 3];
sug_fismat.rule(15).consequent = 3;
sug_fismat.rule(15).weight = 1;
sug_fismat.rule(15).connection = 1;
sug_fismat.rule(16).antecedent = [1 3 2 1];
sug_fismat.rule(16).consequent = 2;
sug_fismat.rule(16).weight = 1;
sug_fismat.rule(16).connection = 1;
sug_fismat.rule(17).antecedent = [1 3 2 2];
sug_fismat.rule(17).consequent = 3;
sug_fismat.rule(17).weight = 1;
sug_fismat.rule(17).connection = 1;
sug_fismat.rule(18).antecedent = [1 3 2 3];
sug_fismat.rule(18).consequent = 4;
sug_fismat.rule(18).weight = 1;
sug_fismat.rule(18).connection = 1;
sug_fismat.rule(19).antecedent = [2 1 1 1];
sug_fismat.rule(19).consequent = 2;
sug_fismat.rule(19).weight = 1;
sug_fismat.rule(19).connection = 1;
sug_fismat.rule(20).antecedent = [2 1 1 2];
sug_fismat.rule(20).consequent = 3;
sug_fismat.rule(20).weight = 1;
sug_fismat.rule(20).connection = 1;
sug_fismat.rule(21).antecedent = [2 1 1 3];
sug_fismat.rule(21).consequent = 4;
sug_fismat.rule(21).weight = 1;
sug_fismat.rule(21).connection = 1;
sug_fismat.rule(22).antecedent = [2 1 2 1];
sug_fismat.rule(22).consequent = 3;
sug_fismat.rule(22).weight = 1;
sug_fismat.rule(22).connection = 1;
sug_fismat.rule(23).antecedent = [2 1 2 2];
sug_fismat.rule(23).consequent = 4;
sug_fismat.rule(23).weight = 1;
sug_fismat.rule(23).connection = 1;
sug_fismat.rule(24).antecedent = [2 1 2 3];
sug_fismat.rule(24).consequent = 5;
sug_fismat.rule(24).weight = 1;
sug_fismat.rule(24).connection = 1;
sug_fismat.rule(25).antecedent = [2 2 1 1];
sug_fismat.rule(25).consequent = 1;
sug_fismat.rule(25).weight = 1;
sug_fismat.rule(25).connection = 1;
sug_fismat.rule(26).antecedent = [2 2 1 2];
sug_fismat.rule(26).consequent = 2;
sug_fismat.rule(26).weight = 1;
sug_fismat.rule(26).connection = 1;
sug_fismat.rule(27).antecedent = [2 2 1 3];
sug_fismat.rule(27).consequent = 3;
sug_fismat.rule(27).weight = 1;
sug_fismat.rule(27).connection = 1;
sug_fismat.rule(28).antecedent = [2 2 2 1];
sug_fismat.rule(28).consequent = 2;
sug_fismat.rule(28).weight = 1;
sug_fismat.rule(28).connection = 1;
sug_fismat.rule(29).antecedent = [2 2 2 2];
sug_fismat.rule(29).consequent = 3;
sug_fismat.rule(29).weight = 1;
sug_fismat.rule(29).connection = 1;
sug_fismat.rule(30).antecedent = [2 2 2 3];
sug_fismat.rule(30).consequent = 3;
sug_fismat.rule(30).weight = 1;
sug_fismat.rule(30).connection = 1;
sug_fismat.rule(31).antecedent = [2 3 1 1];
sug_fismat.rule(31).consequent = 2;
sug_fismat.rule(31).weight = 1;
sug_fismat.rule(31).connection = 1;
sug_fismat.rule(32).antecedent = [2 3 1 2];
sug_fismat.rule(32).consequent = 2;
sug_fismat.rule(32).weight = 1;
sug_fismat.rule(32).connection = 1;
sug_fismat.rule(33).antecedent = [2 3 1 3];
sug_fismat.rule(33).consequent = 3;
sug_fismat.rule(33).weight = 1;
sug_fismat.rule(33).connection = 1;
sug_fismat.rule(34).antecedent = [2 3 2 1];
sug_fismat.rule(34).consequent = 2;
sug_fismat.rule(34).weight = 1;
sug_fismat.rule(34).connection = 1;
sug_fismat.rule(35).antecedent = [2 3 2 2];
sug_fismat.rule(35).consequent = 3;
sug_fismat.rule(35).weight = 1;
sug_fismat.rule(35).connection = 1;
sug_fismat.rule(36).antecedent = [2 3 2 3];
sug_fismat.rule(36).consequent = 3;
sug_fismat.rule(36).weight = 1;
sug_fismat.rule(36).connection = 1;
sug_fismat.rule(37).antecedent = [3 1 1 1];
sug_fismat.rule(37).consequent = 2;
sug_fismat.rule(37).weight = 1;
sug_fismat.rule(37).connection = 1;
sug_fismat.rule(38).antecedent = [3 1 1 2];
sug_fismat.rule(38).consequent = 3;
sug_fismat.rule(38).weight = 1;
sug_fismat.rule(38).connection = 1;
sug_fismat.rule(39).antecedent = [3 1 1 3];
sug_fismat.rule(39).consequent = 3;
sug_fismat.rule(39).weight = 1;
sug_fismat.rule(39).connection = 1;
sug_fismat.rule(40).antecedent = [3 1 2 1];
sug_fismat.rule(40).consequent = 3;
sug_fismat.rule(40).weight = 1;
sug_fismat.rule(40).connection = 1;
sug_fismat.rule(41).antecedent = [3 1 2 2];
sug_fismat.rule(41).consequent = 4;
sug_fismat.rule(41).weight = 1;
sug_fismat.rule(41).connection = 1;
sug_fismat.rule(42).antecedent = [3 1 2 3];
sug_fismat.rule(42).consequent = 5;
sug_fismat.rule(42).weight = 1;
sug_fismat.rule(42).connection = 1;
sug_fismat.rule(43).antecedent = [3 2 1 1];
sug_fismat.rule(43).consequent = 3;
sug_fismat.rule(43).weight = 1;
sug_fismat.rule(43).connection = 1;
sug_fismat.rule(44).antecedent = [3 2 1 2];
sug_fismat.rule(44).consequent = 3;
sug_fismat.rule(44).weight = 1;
sug_fismat.rule(44).connection = 1;
sug_fismat.rule(45).antecedent = [3 2 1 3];
sug_fismat.rule(45).consequent = 3;
sug_fismat.rule(45).weight = 1;
sug_fismat.rule(45).connection = 1;
sug_fismat.rule(46).antecedent = [3 2 2 1];
sug_fismat.rule(46).consequent = 4;
sug_fismat.rule(46).weight = 1;
sug_fismat.rule(46).connection = 1;
sug_fismat.rule(47).antecedent = [3 2 2 2];
sug_fismat.rule(47).consequent = 5;
sug_fismat.rule(47).weight = 1;
sug_fismat.rule(47).connection = 1;
sug_fismat.rule(48).antecedent = [3 2 2 3];
sug_fismat.rule(48).consequent = 4;
sug_fismat.rule(48).weight = 1;
sug_fismat.rule(48).connection = 1;
sug_fismat.rule(49).antecedent = [3 3 1 1];
sug_fismat.rule(49).consequent = 1;
sug_fismat.rule(49).weight = 1;
sug_fismat.rule(49).connection = 1;
sug_fismat.rule(50).antecedent = [3 3 1 2];
sug_fismat.rule(50).consequent = 2;
sug_fismat.rule(50).weight = 1;
sug_fismat.rule(50).connection = 1;
sug_fismat.rule(51).antecedent = [3 3 1 3];
sug_fismat.rule(51).consequent = 2;
sug_fismat.rule(51).weight = 1;
sug_fismat.rule(51).connection = 1;
sug_fismat.rule(52).antecedent = [3 3 2 1];
sug_fismat.rule(52).consequent = 2;
sug_fismat.rule(52).weight = 1;
sug_fismat.rule(52).connection = 1;
sug_fismat.rule(53).antecedent = [3 3 2 2];
sug_fismat.rule(53).consequent = 4;
sug_fismat.rule(53).weight = 1;
sug_fismat.rule(53).connection = 1;
sug_fismat.rule(54).antecedent = [3 3 2 3];
sug_fismat.rule(54).consequent = 4;
sug_fismat.rule(54).weight = 1;
sug_fismat.rule(54).connection = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Inference Engine: Rules
Evaluation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% on-peak: 7am-11am and 5pm-7pm; Mid-peak:11am-5pm; Off-peak: 8pm-6am
for j=1:24
if j==1
EC(j)=zeros(1,1);
cost(j)=TOU_Rates(j)*EC(j);
end
if(j==2)
rule1=sug_fismat.rule(1).consequent;
rule2=sug_fismat.rule(2).consequent;
EC(j)=plus(rule3, rule2);
cost(j)=EC(j)*TOU_Rates(j);
end
if(j==3)
rule4=sug_fismat.rule(4).consequent;
rule5=sug_fismat.rule(5).consequent;
EC(j)=plus(rule4, rule5);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==4
rule7=sug_fismat.rule(7).consequent;
rule8=sug_fismat.rule(8).consequent;
rule9=sug_fismat.rule(9).consequent;
Np_Sum2=plus(rule7, rule8);
EC(j)=plus(Np_Sum2, rule9);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==5
rule10=sug_fismat.rule(10).consequent;
rule11=sug_fismat.rule(11).consequent;
Np_Sum3=plus(rule10, rule11);
EC(j)=Np_Sum3;
cost(j)=TOU_Rates(j)*EC(j);
end
if(j==6)
rule13=sug_fismat.rule(13).consequent;
rule14=sug_fismat.rule(14).consequent;
rule15= sug_fismat.rule(15).consequent;
Np_Sum4=plus(rule13, rule14);
EC(j)=plus(Np_Sum4, rule15);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==7
rule16=sug_fismat.rule(16).consequent;
EC(j)=rule16;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==8
rule17=sug_fismat.rule(17).consequent;
EC(j)=rule17;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==9
rule18=sug_fismat.rule(18).consequent;
EC(j)=rule18;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==10
rule19=sug_fismat.rule(19).consequent;
EC(j)=rule19;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==11
rule20=sug_fismat.rule(20).consequent;
EC(j)=rule20;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==12
rule22=sug_fismat.rule(22).consequent;
rule23=sug_fismat.rule(23).consequent;
EC(j)=plus(rule22, rule23);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==13
rule24=sug_fismat.rule(24).consequent;
rule25=sug_fismat.rule(25).consequent;
EC(j)=plus(rule24, rule25);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==14
rule26=sug_fismat.rule(26).consequent;
rule27=sug_fismat.rule(27).consequent;
EC(j)=plus(rule26, rule27);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==15
rule28=sug_fismat.rule(28).consequent;
rule29=sug_fismat.rule(29).consequent;
EC(j)=plus(rule28, rule29);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==16
rule31=sug_fismat.rule(31).consequent;
rule32=sug_fismat.rule(32).consequent;
EC(j)=plus(rule32, rule32);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==17
rule33=sug_fismat.rule(33).consequent;
EC(j)= rule33;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==18
rule34=sug_fismat.rule(34).consequent;
EC(j)=rule34;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==19
rule35=sug_fismat.rule(35).consequent;
EC(j)=rule35;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==20
rule36=sug_fismat.rule(36).consequent;
rule37=sug_fismat.rule(37).consequent;
New_Sum=plus(rule36, rule37);
EC(j)=New_Sum;
cost(j)=TOU_Rates(j)*EC(j);
end
if j==21
rule39=sug_fismat.rule(39).consequent;
rule40=sug_fismat.rule(40).consequent;
EC(j)=plus(rule39, rule40);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==22
rule42=sug_fismat.rule(42).consequent;
rule43=sug_fismat.rule(43).consequent;
EC(j)=plus(rule42, rule43);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==23
rule45=sug_fismat.rule(45).consequent;
rule46=sug_fismat.rule(46).consequent;
EC(j)=plus(rule45, rule46);
cost(j)=TOU_Rates(j)*EC(j);
end
if j==24
rule48=sug_fismat.rule(48).consequent;
EC(j)=rule48;
cost(j)=TOU_Rates(j)*EC(j);
end
end
Total_Cost_Sugeno=sum(cost); %%Total cost obtained by sugeno FIS
avg_con2=sum(EC)/24; %% average consumption
PAR_Sugeno=max(EC)/avg_con; %% PAR obtained by sugeno FIS
%% Defuzzification method
Sug_Defuzz=sum(EC)*54/sum(EC);
%% Efficiency gain
E_prg=PT_Consumption; %consumption by programmable approach
E_sug=sum(EC); %consumption by Mamdani
hot_Gain_In_Eff_sug=(E_prg-E_sug)/E_prg; % Energy efficiency gain
%% Results: Plots for hot cities; please follow the same comments as described in the results of cold cities.
%% consumption per day
figure %%Please follow the comments of cold cities for these results
stairs(1:24, smooth(Fixed_T_hourly_consumption), 'r-o', 'LineWidth',1.5);
hold on;
stairs(1:24, smooth(PT_TOU_hourly_consumption), 'b-*', 'LineWidth',1.5);
hold on;
stairs(1:24, smooth(EC1), 'y-^','LineWidth',1.5);
xlabel('Time (Hours)');
hold on;
stairs(1:24, smooth(EC), 'g-+','LineWidth',1.5);
ylabel('Energy Consumption (kWh)');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
ylim([0 10]);
set(gca,'FontSize',14);
grid on;
%% consumption per munth
figure;
bar(1, 30*Fixed_Thermostate_Consumption, 0.2, 'r'); %%Please follow the comments of cold cities for these results
hold on;
bar(2, 30*BAR(1,1), 0.2, 'b');
hold on;
bar(3, 30*sum(EC1), 0.2, 'y');
hold on;
bar(4, 30*sum(EC), 0.2, 'g');
set(gca, 'XTick',1:1:4, 'XTickLabel',{'1','2','3','4'});
ylabel('Energy Consumption (kWh)');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
set(gca,'FontSize',14);
ylim([0 4000]);
%% EP plot %%Please follow the comments of cold cities for these results (Readers can view it for their understanding)
% figure
% stairs(1:24, TOU_Rates,'bx-','LineWidth',2.00);
% xlabel('Time (Hours)');
% ylabel('Price (Dollars)');
% legend('TOU Rates'); %,
%% PAR
figure;
bar(1, PAR_Unscheduled, 0.2, 'r'); %%Please follow the comments of cold cities for these results
hold on;
bar(2, PAR_PT, 0.2, 'b');
hold on;
bar(3, PAR_Fuzzy_Mamdani, 0.2, 'y');
hold on;
bar(4, PAR_Sugeno, 0.2, 'g');
set(gca, 'XTick',1:1:4, 'XTickLabel',{'1','2','3','4'});
ylabel('PAR');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
set(gca,'FontSize',14);
grid on;
%% cost per day
figure;
bar(1, Fixed_T_Cost, 0.2, 'r'); %%Please follow the comments of cold cities for these results
hold on;
bar(2, PT_Cost, 0.2, 'b');
hold on;
bar(3, Total_Cost_Mamdani, 0.2, 'y');
hold on;
bar(4, Total_Cost_Sugeno, 0.2, 'g');
set(gca, 'XTick',1:1:4, 'XTickLabel',{'1','2','3','4'});
ylabel('Cost (Dollars)');
legend('Fixed Setpoint','Programmable Approach','Mamdani','Sugeno');
set(gca,'FontSize',14);
grid on;
figure
Cold=[0.1829 0.3451];
Hot=[0.0648 0.1599];
Load=[Cold; Hot];
bar_Grapg= bar(Load);
set(bar_Grapg(1),'FaceColor','blue');
set(bar_Grapg(2),'FaceColor','yellow');
ylabel('Energy Efficiency');
set(gca, 'XTick',1:1:2,'XTickLabel',{'Cold Cities', 'Hot Cities'})
legend({'Mamdani','Sugeno'});
grid on

Supplementary resource (1)

Data
June 2020
Sakeena Javaid · Nadeem Javaid · Mohsen Guizani · Ahmad Almogren · Atif Almari
ResearchGate has not been able to resolve any citations for this publication.
Article
Full-text available
Occupant behavior is nowadays acknowledged as a main source of discrepancy between predicted and actual building performance; therefore, researchers attempt to model occupants’ presence and adaptive actions more realistically. Literature shows a proliferation of increasingly complex, data-based models that well fit the cases analyzed. However, the actual use of these models by practitioners is very limited. Moreover, simpler models might be preferable, depending on the aim of investigation. The present study proposes shifting the focus to fit-for-purpose modeling, in which the most appropriate model for a specific case is characterized by the lowest complexity, while preserving its validity with respect to the aim of the simulation. A number of steps are taken to achieve this shift in focus. The existing models are presented according to complexity. The available inter-comparison studies are critically reviewed. Subsequently, a list of parameters that affect the choice of an appropriate modeling strategy is presented as a first attempt to derive guidelines and generate a framework for investigation. To support such claims the effect of some of the listed parameters is evaluated in a case study. The main conclusion to be drawn is that determining the best complexity for occupant behavior modeling is strongly case specific.
Conference Paper
Controlling power utilization in the residential area is one of the major challenges in the smart grid (SG). Demand response (DR) has played a vital role in energy management and improved it with the involvement of residential consumers who participate in such programs from utilities for scheduling their appliances to the off peak hours. In this paper, we have proposed a worldwide adaptive thermostat model for effectively managing the power in all countries of the world. The proposed approach has been evaluated with the help of fuzzy logic and its two inference systems (FIS): 1) Mamdani and 2) Takagi Sugeno. Utilizing the membership functions; outdoor temperature, user occupancy, utility price and initialized setpoints are evaluated for maintaining the buildings temperature. Furthermore, energy consumption in buildings is analyzed by tuning the indoor initialized setpoints while considering all the aforementioned parameters. Simulations are conducted in Matlab to validate the proposed system model and results show that energy consumption in cold countries is reduced upto 45% as compared to the existing programmable approach. Index Terms—Energy management, thermostat, smart grid, fuzzy logic, takagi sugeno fuzzy inference system, mamdani fuzzy inference system
Article
Heating, Ventilation and Air Conditioning (HVAC) systems represent a significant portion of total residential energy consumption in North America. Programmable thermostats are being used broadly for automatic control of residential HVAC systems while users initialize their everyday schedules and preferences. The main aim of smart grid initiatives such as time-varying prices is to encourage consumers to reduce their consumption during high electricity demand. However, it is usually a hassle to residential customers to manually re-programme their thermostats in response to dynamic electricity prices or environmental conditions that vary over time. In addition, the lack of energy management systems such as thermostats capable of learning autonomously and adapting to users’ schedule and preference changes are major obstacles of existing thermostats in order to save energy and optimally benefit from smart grid initiatives. To address these problems, in this paper an adaptable autonomous energy management solution for residential HVAC systems is presented. Firstly, an autonomous thermostat utilizing a synergy of Supervised Fuzzy Logic Learning (SFLL), wireless sensors capabilities, and dynamic electricity pricing is developed. In the cases that the user may override the decision made by autonomous system, an Adaptive Fuzzy Logic Model (AFLM) is developed in order to detect, learn, and adapt to new user’s preferences. Moreover, to emulate a flexible residential building, a ‘house energy simulator’ equipped with HVAC system, thermostat and smart meter is developed in Matlab-GUI. The results show that the developed autonomous thermostat can adjust the set point temperatures of the day without any interaction from its user while saving energy and cost without jeopardizing user’s thermal comfort. In addition, the results demonstrate that if any change(s) occurs to user’s schedules and preferences, the developed AFLM learns and adapts to new modifications while not ignoring energy conservation aspects.
Article
This paper reviews occupancy based Model Predictive Control (MPC) for building indoor climate control. Occupancy behavior in buildings is stochastic and complex in nature. With better understanding of occupancy presence in rooms and spaces, advanced controls, such as MPC, can be designed to achieve a more energy efficient operation, compared to more traditional control methods, while comfort is maintained. This paper starts with an overview of traditional controls implemented in buildings, and importance of occupancy based controls. Various control-oriented building modeling methods including physics-based and data-driven models are reviewed. Later on, a comprehensive review of MPC in terms of control theory, objective functions, constrains, optimization methods, system characteristics and various types of MPC is presented conducted. In principle, MPC finds an optimal sequence of control commands to optimize an objective function, considering system model, disturbances, predictions and actuation constraints. Lastly, occupancy based controls including commonly used rule-based and latest model-based controls are reviewed. In addition, a few experimental studies are presented and discussed. The paper presents a holistic overview of occupancy-based MPC for building heating, ventilation, and air conditioning (HVAC) systems, and discusses current status and future challenges. The purpose of this paper is to provide a guideline forresearchers who would like to conduct similar studies to have a better understanding of established research methods.
Conference Paper
This paper demonstrates some results from an on-going experiment on energy management in a residential testbed in Singapore by controlling the air-conditioning (AC) system. The testbed is set up at the faculty housing of Singapore University of Technology and Design (SUTD) in which the ACs installed within each unit can be controlled from a remote server. The control can be conducted both in terms of switching on/off and changing the temperature set-point of the ACs. The main objectives are to reduce the consumption of energy at a residential setting by controlling the ACs' temperature set-points and investigating the feasibility of having residential ACs as interruptible loads for demand response and thus enabling residential users to participate in the energy market. The control methodology is briefly discussed and the users' inputs on the experience of such experiments are also explained. Some preliminary results from the experiments are discussed and some insights are provided into how much load can be controlled through the set-point temperature of ACs such that the users do not feel any discomfort.
Article
The incentives such as demand response (DR) programs, time-of-use (TOU) and real-time pricing (RTP) are applied by utilities to encourage customers to reduce their load during peak load hours. However, it is usually a hassle for residential customers to manually respond to prices that vary over time. In this paper, a fuzzy logic approach (FLA) utilizing wireless sensors and smart grid incentives for load reduction in residential HVAC systems is presented. Programmable communicating thermostats (PCTs) are used to control residential HVAC systems in order to manage and reduce energy use, while consumers accommodate their everyday schedules. Hence, the FLA is embedded into existing PCTs to augment more intelligence to them for load reduction, while maintaining thermal comfort. To emulate an actual thermostat, a PCT capable of handling both TOU and RTP is simulated in Matlab/GUI. It is utilized as a ‘simulator engine’ to evaluate the performance of FLA via applying several different scenarios. The results show that the FLA decreases/increases the initialized set points without jeopardizing thermal comfort by applying specific fuzzy rules through evaluating the information received from wireless sensors and smart grid incentives. Our approach results in better energy and cost saving in residential buildings versus existing PCT.
Article
The autonomous polygeneration microgrid topology has been developed in order to cover holistically needs in a remote area such as electrical energy, space heating and cooling, potable water through desalination and hydrogen as fuel for transportation. The existence of an advanced energy management system is essential for the operation of an autonomous polygeneration microgrid. So far, energy management systems based on a centralized management and control have been developed for the autonomous polygeneration microgrid topology based on computational intelligence approaches. A decentralized management and control energy management system can have important benefits, when taking into consideration the autonomous character of these microgrids. This paper presents the design and investigation of a decentralized energy management system for the autonomous polygeneration microgrid topology. The decentralized energy management system gives the possibility to control each unit of the microgrid independently. The most important advantage of using a decentralized architecture is that the managed microgrid has much higher chances of partial operation in cases when malfunctions occur at different parts of it, instead of a complete system breakdown. The designed system was based on a multi-agent system and employed Fuzzy Cognitive Maps for its implementation. It was then compared through a case study with an existing centralized energy management system. The technical performance of the decentralized solution performance is on par with the existing centralized one, presenting improvements in financial and operational terms for the implementation and operation of an autonomous polygeneration microgrid.