Sie sind auf Seite 1von 59

LIFETIME IMPROVEMENT USING TYPE-2 FUZZY

SETS IN WIRELESS SENSO NETWORKS

A PROJECT REPORT

Submitted by

ARCHANA . S (Reg. No. 201406007)


MAHESWAR . J (Reg. No. 201406253)
SEYEDALI FATHIMA .J (Reg.No.201406255)

in partial fulfillment for the award of the degree


of

BACHELOR OF ENGINEERING
in

INFORMATION TECHNOLOGY

DEPARTMENT OF INFORMATION TECHNOLOGY


MEPCO SCHLENK ENGINEERING COLLEGE, SIVAKASI
(An Autonomous Institution affiliated to Anna University Chennai)

April 2018
BONAFIDE CERTIFICATE

Certified that this project report titled “Lifetime Improvement Using

Type-2 Fuzzy Sets in Wireless Sensor Network” is the bonafide work of

S.ARCHANA(201406007),J.MAHESWARI(201406253),J.SEYEDALI

FATHIMAI(201406055) who carried out the research under my supervision. Certified

further, that to the best of my knowledge the work reported herein does not form part of

any other project report or dissertation on the basis of which a degree or award was

conferred on an earlier occasion on this or any other candidate.

Dr.T.Revathi,M.E.,Ph.D., MR.G.Yogarajan M.E.,(Ph.D).,

Head of the Department Supervisor


Senior Professor, Assistant Professor(Senior Grade),
Department of Information Technology, Department of Information Technology,
Mepco Schlenk Engineering College, Mepco Schlenk Engineering College,
Sivakasi. Sivakasi.

Submitted for viva-Voce Examination held at MEPCO SCHLENK ENGINEERING

COLLEGE, SIVAKASI (AUTONOMOUS) on ……………..............

Internal Examiner External Examiner


ABSTRACT

In remote places the wireless sensor networks is not practically feasible.To increase the
network lifetime ,scalability and to reduce the energy consumption we use clustering
approach. The current researchers proposed numerous clustering
algorithms.Clusterhead overburden is the problem in most of the algorithms,By using
fuzzy logic these problem can be overcome. Many researches use type-1 fuzzy logic to
increase the efficiency of the CH.We propose a clustering algorithm on the basis of
Type-2 fuzzy logic to improve the lifetime of the network.
ACKNOWLEDGEMENT

First of all, we thank our parents and almighty for showering grace and

blessings for making this work a great success.

To begin, we sincerely thank the college management and the Head of the

Institution Dr.S.Arivazhagan, M.E., Ph.D., for providing sufficient working

environment such as systems and library facilities which enable to complete our

project.

We are especially indebted to Dr.T.Revathi, M.E., Ph.D., Professor and Head of

Information Technology, for having allowed us to make use of the laboratory facilities

liberally, which had greatly helped us in carrying out this project.

Our special thanks to our final year Project coordinator, Mrs.J.Angela Jennifa

Sujana, M.E., (Ph.D.), whose help, stimulating suggestions and encouragement,

helped us to coordinate our project especially in writing this project.

We extend our thanks to Mrs.R.Venitta Raj,M.E.,Assistant Professor(Senior

Grade) of Information Technology, our internal guide, for her prompt guidance,

precious support and knowledge that she shared with us in the cooperative work.

Last but not the least, a very special thanks to all out friends with whom we have

been with us through all our ups and downs in our life.
TABLE OF CONTENTS

CHAPTER TITLE PAGE NUMBER

LIST OF TABLES
LIST OF FIGURES
LIST OF ABBREVIATIONS
1. INTRODUCTION
1.1 Wireless sensor networks-an overview
1.2 Wireless sensor networks
1.2.1 Characteristics of WSNs
1.2.2 Issues related to WSNs
1.2.3 Challenges in WSNs
1.2.4 Applications of WSNs
1.3 Network Simulator(NS)
1.3.1 NS Installation
1.3.2 NS2 Programming Languages
1.3.3 NS2 Architecture
1.3.4 Tcl Basics
1.3.5 Trace File Format
1.3.6 Basic TCL command

2. LITERATURE SURVEY
2.1 An Application-Specific Protocol Architecture for
Wireless Microsensor Networks
2.2 A fuzzy logic-based clustering algorithm for
wsn to extend the network lifetime
2.3 F-MCHEL: Fuzzy based master cluster head election
leach protocol in wireless sensor network
2.4 Cluster-head election using fuzzy logic for wireless sensor
networks
2.5 Objective
2.6 Scope of the proposed system
2.7 Problem statement

3. SYSTEM DESIGN
3.1 Overview of the proposed system
3.2 Proposed Algorithm
3.3 Fuzzy Approach
3.3.1 Fuzzification
3.3.2 If-Then-Rules
3.3.3 Type Reducer
3.3.4 Defuzzification

4. IMPLEMENTATION METHODOLOGY
4.1 Overview
4.2 Modules
4.3 Module description
4.4 Code
5. SNAPSHOTS
6. CONCLUSION AND FUTURE ENHANCEMENT
6.1 Conclusion
6.2 Future Enhancement
7. REFERENCES
LIST OF TABLES

TABLE TABLE NAME PAGE NO:


NUMBER:
I IF-THEN Rules

II Comparison between Type-1 and Type-II

i
LIST OF FIGURES

FIGURE FIGURE NAME PAGE NO:


NUMBER:
1 Sensor Node Architecture

2 Wireless Sensor Network

3 Wireless Sensor Network Architecture

4 Block Diagram For Type-2 Fuzzy Logic

5 Linguistic Variables

6 Initial Layout of the Network

7 Clustering Node

8 Type-1 Fuzzy Logic Result

9 Type-2 Fuzzy Logic Result

10 Comparison of both Result

ii
LIST OF ABBREVIATIONS

ABBREVIATION EXPANSION

 WSNs Wireless Sensor Networks


 NS 2.34 Network Simulator 2.34
 Tcl Tool Command Language
 Octl Object Oriented extension of Tcl
 NAM Network Animator
 COG Center of Gravity
 LEACH Low-Energy Adaptive Clustering Hierarchy
 CH Cluster Head
 CSMA/CA Carrier Sense Multiple Access with Collision
Avoidance
 SB-CH Stand By Cluster Head

iii
I. INTRODUCTION

1.1 WIRELESS SENSOR NETWORKS-AN OVERVIEW

A wireless sensor network consists of a large number of tiny, low-power sensor


nodes. The node has sensing, data processing and wireless communication
components. Sensor nodes are deployed randomly in the deployment region under
examination and collect sensor data. Wireless sensor network have attracted much
attention because of their wide range of application, such as military, environmental
monitoring, and health care industry. Unlike wired and mobile Ad hoc network,
wireless sensor network are infrastructure-less and can operate in any environment as
compared to the traditional network. When sensor network are deployed in hostile
environments security becomes more important as they are prone to different types of
malicious attacks. In order to provide security for sensor network, key management is
applied. Although many protocols and algorithms have been proposed for traditional
wireless ad-hoc network, they are not well suited for the unique features and
application requirements of wireless sensor network. To illustrate this point, the
differences between wireless sensor network and ad-hoc network are outlined below:
The number of sensor nodes in a sensor network can be several orders of magnitude
higher than the nodes in an ad-hoc network . Sensor nodes are densely deployed.
Sensor nodes are prone to failures. Sensors facilitate the instrumenting and controlling
of factories, offices, homes, vehicles, cities and the ambiance, especially as
commercial off-the-shelf technology becomes available. With sensor network
technology ships, aircraft and buildings can “self-detect” structural faults. Places of
public assembly can be instrumented to detect airborne agents such as toxins and to
trace the contamination which is present. Earthquake-oriented sensors in buildings
can locate potential survivors and can help assess structural damage; tsunami-alerting
sensors are useful for nations with extensive coastlines. Sensors also find extensive
applicability on the battlefield for reconnaissance and surveillance.
Improving the lifetime in wireless sensor network is important because the sensor
nodes in wireless sensor network are constrained by limited energy. The way to
improve a WSN lifetime is to develop energy efficient protocols for reducing energy

1
Fig 1.1 Sensor Node Architecture

consumption. One of the well known energy efficient methods is the clustering based
algorithm which is designed for homogeneous wireless sensor network. The
clustering algorithms were also improved and applied to the heterogeneous wireless
sensor network. Recent advances in wireless communication technologies have
enabled the development of large-scale wireless sensor network that consist of many
low-powers, low-cost and small-size sensor nodes. Sensor network hold the promise
of facilitating large-scale and real-time data processing in complex environments.
Wireless sensors have become an excellent tool for military applications involving
intrusion detection, perimeter monitoring, and information gathering and smart
logistics support in an unknown deployed area. Other applications include sensor-based
personal health monitor, location detection with sensor networks and movement
detection.
1.2 WIRELESS SENSOR NETWORK
A Wireless Sensor Network is one kind of wireless network includes a large
number of circulating, self-directed, minute, low powered devices named sensor nodes
called motes. These networks certainly cover a huge number of spatially distributed,
little, battery-operated, embedded devices that are networked to caring collect, process,

2
and transfer data to the operators, and it has controlled the capabilities of computing &
processing. Nodes are the tiny computers, which work jointly to form the networks.

Fig1.2 Wireless Sensor Network

The sensor node is a multi-functional, energy efficient wireless device. The


applications of motes in industrial are widespread. A collection of sensor nodes collects
the data from the surroundings to achieve specific application objectives. The
communication between motes can be done with each other using transceivers. In a
wireless sensor network, the number of motes can be in the order of hundreds/ even
thousands. In contrast with sensor n/ws, Ad Hoc networks will have fewer nodes
without any structure.

Wireless Sensor Network Architecture

The most common WSN architecture follows the OSI architecture Model. The
architecture of the WSN includes five layers and three cross layers. Mostly in sensor
n/w we require five layers, namely application, transport, n/w, data link & physical
layer. The three cross planes are namely power management, mobility management,
and task management. These layers of the WSN are used to accomplish the n/w and
make the sensors work together in order to raise the complete efficiency of the

3
network.Please follow the below link for: Types of wireless sensor networks and WSN
topologies

Fig 1.3 Wireless Sensor Network Architecture

Application Layer

The application layer is liable for traffic management and offers software for
numerous applications that convert the data in a clear form to find positive information.
Sensor networks arranged in numerous applications in different fields such as
agricultural, military, environment, medical, etc.

Transport Layer

The function of the transport layer is to deliver congestion avoidance and reliability
where a lot of protocols intended to offer this function are either practical on the
upstream. These protocols use dissimilar mechanisms for loss recognition and loss
recovery. The transport layer is exactly needed when a system is planned to contact
other networks.Providing a reliable loss recovery is more energy efficient and that is
one of the main reasons why TCP is not fit for WSN. In general, Transport layers can be
separated into Packet driven, Event driven. There are some popular protocols in the
transport layer namely STCP (Sensor Transmission Control Protocol), PORT
(Price-Oriented Reliable Transport Protocol and PSFQ (pump slow fetch quick).

Network Layer

4
The main function of the network layer is routing, it has a lot of tasks based on the
application, but actually, the main tasks are in the power conserving, partial memory,
buffers, and sensor don’t have a universal ID and have to be self-organized.

The simple idea of the routing protocol is to explain a reliable lane and redundant lanes,
according to a convinced scale called metric, which varies from protocol to protocol.
There are a lot of existing protocols for this network layer, they can be separate into;
flat routing and hierarchic routing or can be separated into time driven, query-driven &
event driven.

Data Link Layer

The data link layer is liable for multiplexing data frame detection, data streams,
MAC, & error control, confirm the reliability of point–point (or) point– multipoint.

Physical Layer

The physical layer provides an edge for transferring a stream of bits above
physical medium. This layer is responsible for the selection of frequency, generation
of a carrier frequency, signal detection, Modulation & data encryption. IEEE 802.15.4
is suggested as typical for low rate particular areas & wireless sensor network with
low cost, power consumption, density, the range of communication to improve the
battery life. CSMA/CA is used to support star & peer to peer topology. There are
several versions of IEEE 802.15.4.V.

1.2.1 CHARACTERISTICS OF WSNs


The main characteristics of WSNs include:
 Power consumption constraints for nodes using batteries or energy harvesting
The nodes in WSN have only limited energy and the nodes can harvest the
energy from the environment.
 Ability to cope with node failures
Nodes in WSN can get failed at any time because of its battery shortage.
 Mobility of nodes
The nodes in WSN have the property of mobility
.
 Communication failures

5
When the nodes moves away from communication range of the
neighbor then the communication failure will happen.
 Heterogeneity of nodes
Nodes in WSN can have different properties like communication range,
energy required for reception and transmission and so on.
 Scalability to large scale of deployment
Large number of nodes can be deployed using various topology.
 Ability to withstand harsh environmental conditions
Sensor can be active under harsh environmental conditions like in
thermal power plant.
 Ease of use
WSN can be used for any application and they are easy to use.
1.2.2 ISSUES RELATED TO WSN
A. Design Issues:
Fault–tolerant Communication: Due to the deployment of sensor nodes in an
uncontrolled or harsh environment, it is not uncommon for the sensor nodes to
become faulty and unreliable
Low latency: The events which the framework deals with are urgent which should be
recognized
immediately by the operator. Therefore, the framework has to detect and notify the
events quickly as soon as possible.
Scalability: A system, whose performance improves after adding hardware,
proportionally to the capacity added, is said to be a scalable system. The number of
sensor nodes deployed in the sensing area may be in the order of hundreds or thousands,
or more.
Transmission Media: In a multi-hop sensor network, communicating nodes are
linked by a wireless medium. The traditional problems associated with a wireless
channel (e.g., fading, high error rate) may also affect the operation of the sensor
network.
Coverage Problems: One fundamental problem in wireless sensor networks is the
coverage problem, which reflects the quality of service that can be provided by a
particular sensor network. The coverage problem is defined from several points of view
due to a variety of sensor networks and a wide - range of their applications.

6
B. Topology Issues
Geographic Routing: Geographic routing is a routing principle that relies on
geographic position information. It is mainly proposed for wireless networks and based
on the idea that the source sends a message to the geographic location of the destination
instead of using the network address.
Sensor Holes: A routing hole consists of a region in the sensor network, where either
node are not available or the available nodes cannot participate in the actual routing of
the data due to various possible reasons. The task of identifying holes is especially
challenging since typical wireless sensor networks consist of lightweight, Low -
capability nodes that are unaware of their geographic location.
Coverage Topology: Coverage problem reflects how well an area is monitored or
tracked by sensors. The coverage and connectivity problems in sensor networks have
received considerable attention in the research community in recent years. This
problem can be formulated as a decision problem, whose goal is to determine whether
every point in the service area of the sensor network is covered by at least k sensors,
where k is a given parameter
C. Other Issues
The major issues that affect the design and performance of a wireless sensor network
are as follows:
Hardware and Operating System for WSN
Wireless Radio Communication Characteristics
Medium Access Schemes
Deployment
Localization
Synchronization
Calibration
Network Layer
Transport Layer
Data Aggregation and Data Dissemination
Database Centric and Querying
Architecture
Programming Models for Sensor Networks

7
Middleware
1.2.3 CHALLENGES IN WSN
A. Challenges in real time
WSN deal with real world environments. In many cases, sensor data must be
delivered within time constraints so that appropriate observations can be made or
actions taken. Very few results exist to date regarding meeting real-time requirements
in WSN. Most protocols either ignore real-time or simply attempt to process as fast as
possible and hope that this speed is sufficient to meet deadlines. Some initial results
exist for real-time routing. To date, the limited results that have appeared for WSN
regarding real-time issues has been in routing. Many other functions must also meet
real -time constraints including: data fusion, data transmission, target and event
detection and classification, query processing, and security. New results are needed to
guarantee soft real-time requirements and
that deal with the realities of WSN such as lost messages, noise and congestion. Using
feedback control to address both steady state and transient behavior seems to hold
promise. Dealing with real- time usually identifies the need for
differentiated services, e.g., routing solutions need to support different classes of
traffic; guarantees for the important traffic and less support for unimportant traffic. It is
important not only to develop real - time protocols for WSN, but associated analysis
techniques must also be developed.
B. Challenges in power managements
Low-cost deployment is one acclaimed advantage of sensor networks. Limited
processor bandwidth and small memory are two arguable constraints in sensor
networks, which will disappear with the development of fabrication techniques.
However, the energy constraint is unlikely to be solved soon due to slow progress in
developing battery capacity. Moreover, the untended nature of sensor nodes and
hazardous sensing environments preclude battery replacement as a feasible solution.
On the other hand, the surveillance nature of many sensor network applications requires
a long lifetime; therefore, it is a very important research issue to provide a form of
energy –efficient surveillance service for a geographic area. Much of the
current research focuses on how to provide full or partial sensing coverage in the
context of energy conservation.
C. Network Scale and Time- Varying Characteristics of WSN

8
Under severe energy constraints, Sensor nodes operate with limited computing,
storage and communication capabilities . Depending upon the application, the densities
of the WSNs may vary widely, ranging from very sparse to very dense. In these sensor
nodes the behavior of sensor nodes is dynamic and highly adaptive, as the need to self
organize and conserve energy forces sensor nodes to adjust the behavior constantly in
response to their current level of activity. Furthermore, the sensor nodes may be
requires adjusting the behavior in response to the erratic and unpredictable behavior of
wireless connections caused by high noise levels and radio-frequency interference, to
prevent severe performance degradation of the application supported.
D. Management at a Distance
Sensor nodes will be deployed at our door field such as a subway station. It is difficult
for managers or operators to manage the network directly. Thus the framework should
provide an indirect remote control/ management system.
1.2.4 APPLICATION OF WIRELESS SENSOR NETWORKS
WSN are collections of compact-size ,relatively inexpensive computational nodes
that measure local environments conditions or other parameters and forward such
information to a central point for appropriate processing .WSNs nodes(WSN) can sense
the environment ,can communicate with neighbor nodes ,and can ,in many cases
,perform basic computations on the data being collected .WSNs support a wide
range of useful applications. It has so many real time applications like Area monitoring,
Environmental sensing, Air pollution monitoring ,Forest fires detection, Greenhouse
monitoring, Landslide detection, Machine health monitoring, etc.
A. HOME CONTROL
Home control applications provide control, conservation, convenience, and safety, as
follows
 Sensing applications facilitate flexible management of lighting, heating, and
cooling systems from anywhere in the home.
 Sensing application automate control of multiple home systems to improve
conservation, convenience, and safety.
 Sensing application capture highly detailed electric, water, and gas utility usage
data.
B. MEDICAL APPLICATIONS

9
A number of hospitals and medical centers are exploring applications of WSN
technology to a range of medical applications, including pre-hospital and
in-hospital emergency care, disaster response, and stroke patient rehabilitation.
WSNs have the potential to affect the delivery and study of recitative care by
allowing vital signs to be collected and integrated automatically into the patient
care record and used for real-time triage, correlation with hospital records, and
long-term observation. WSNs permit home monitoring for chronic and elderly
patients, facilitating long-term care and trend analysis; this is in turn can sometimes
reduce the length of the hospital stays. WSNs also permit collection of long-term
medical information that populates database of clinical data; this enables
longitudinal studies across populations and allows physicians to study the effects of
medical intervention programs.
C. MILTARY SURVEILLANCE:
WSNs can replace single high-cost sensor assets with large arrays distributed
sensors for both security and surveillance application. The WSN node are smaller
and more capable of than sensor assets presently in the inventory; the added
feature of robust, situation. Distributed sensing has the additional advantages of
being able to provide redundant and hence highly reliable information on threats
as well as the ability to localize threats by both coherent
and incoherent processing among the distributed sensor nodes WSNs can be used in
traditional sensor network applications for large area and perimeter monitoring
and will ultimately enable every platoon, squad, and soldier to deploy WSNs to
accomplish a number of mission and self-production.

D. AIR POLLUTION MONITORING


Wireless sensor networks have been deployed in several cities(Stockholm,London
or Brisbane) to monitor the concentration of dangerous gases for citizens.These can
take advantages of the ad-hoc wireless links rather than wired installations,which also
make then more mobile for testing reading in different areas.There are various
architectures than can be used for such applications as well as different kinds of data
analysis and data mining that can be conducted.

10
E. WIRELESS INSTRUMENTATION
Collecting real time data from wildfires is important for life safety considerations
and allows predictive analysis of evolving fire behavior.One way to collect such data
is to deploy sensors in the wildlife environment.Firebus are small wireless sensor
(motes) based on TinyOS that self-organize into networks for collecting real-time data
in wildfire environment.The fireBug system combines state-of-the-art sensor hardware
running TinyOS with standard off-the-self World wild Web and database
technology,allowing rapid deployment of sensor and behavior monitoring.

F. AGRICULTURE
Using sensor networks within the agriculture industry is increasingly
common,using a wireless network frees the farmer from the maintenance of writing in a
difficult environment.Gravity feed water system can be monitored using pressure
transmitters to monitor water tank levels pumps can be controlled using wireless I/O
devices and water use can be measurement and wirelessly transmitted back to a central
control centre for billing.Irrigation automation enables more efficient water use and
reduces waste.

1.3 NETWORK SIMULATOR(NS)


NS is a discrete event scheduler and excellent network simulator targeted at the
networking research. NS provides substantial support for the design of network
component as the simulation of the transmissions using transport and application
agents,routing using several protocols and multicast protocols and multicast protocols
over wired and wireless (local and satellite) networks.NS is not a polished and finished
product,but it is the result of an on-going effort of research and development.NS began
as a variant of the REAL network simulator in 1989 and have evolved substantially
over the past few years.Moreover it is a free open source.

11
1.3.1 NS INSTALLATION
The following are the steps to install NS2 in the Linux operating system which is as
given
 The installation file for NS22 is obtained
 If the file is in .gz extension (e.., nsallinone-2.30.tar.gz) then it is extracted by using
the command
 Gunzip -xvzf nsallinone-2.30.tar.gz
 The files extracted in the nsallinone-2.30 directory
 Then the command ./install is given for installing NS2
After the successful installation,the path has been set for NS2 in profile file
1.3.2 NS2 PROGRAMMING LANGUAGES
In NS2,c++ is used as back end.This is used for per packed processing in the
simulation steps,faster to run,detailed and has the complete control of the simulation
under it.Object tool Command Language(Otcl) is used as front end.It is used for setting
the topologies,scenarios,simulations configure in the connections.Otcl allows changes
in the structure based on the application we undertake.
1.3.3 NS2 ARCHITECTURE
The NS2 architecture is typically show in fig 6.The core of NS2 architecture is
c++.The classes for controlling the packet processing are being written in C.The tcl
script use these classes and define their procedures to implement those class
member.The Otcl scripts built over Tcl employs the interfaces is used over the essence
of Otcl which acts as a C++ glue over Otcl.The network components are built based on
this TclCL with the scheduling of events over the various layers of NS2.
1.3.4 TCL BASICS
In NS2 simulation,the network may be either wired o wireless.The following fig 7
illustrating the simplified user’s view of NS of NS in which the user provides the
simulation program written using the Otcl/Tcl script to the Otcl interpreter,with the
help of the NS simulator library gives out the simulation results.The generated results
are used for further NAM output generation and for further analysis by the user like
throughput measurements,packet loss graph generation etc.
1.3.5 TRACE FILE FORMAT

12
The result generated by NS for any Otcl script will produce the trace file that
consists of all details about the event,event time the packet type,its size source and the
destination node identifier(ID),flags flow ID,source and the destination
addresses,sequence number of the packet,and the packet ID.This trace file is obtained
when the Otcl/tcl script given to the Otcl interpreter using the command,
$ns<filename.tcl>
1.3.6 BASIC TCL COMMAND
Net ns[new simulator]
This is the first line in the tcl script.This line declares new variable ns using the set
command.NS is the instance of the simulator class,so on object.The code[[new
Simulator] is the instantiation of the class simulator usin the reserved word new.Using
these new variable ns,we can use all the methods of the simulator.
set tracefile[open out.t w]
$ns trace-all $tracefile1
In order to have the output file with data on the simulation (trace file) or files used
for visualization(nam files)we need to create the files using “open command”.It creates
a data trace file called “out.tr”.The second line open the file “out.tr” to be used for
writingdeclared as “w”.The trace-all that have as parameter the name f the file where
the traces will go.
set namefile [open out.name w]
$ns namtrace-all $namfile
It creates a nam visualization tace file called “out.nam”.The second line open the
file “out.nam” to be used for writing ,declared as “w”.The last line tells the simulator to
record all simulation traces in NAM input format.
$ns color fid color
It is to set off the packets for a flow specified by the flow id.This member function
of “simulator” object is the NAM displayand has no effort on the actual effort on the
actual simulation.
proc finish{}
At the end of the ns program we should call the procedure “finish” and specify and
what time the termination should occur
Setn0[$ns node]

13
The member function node creates a node.we created a node that is pointed by
the variable n0.Once we define several nodes,we can define the links that connect
them.
Set udp[new Agent/UDP]
This command gives a pointer called “udp” to the agent,which is an object in
NS.A UDP agent accepts data in variable size chunks from an applications,and
segments the data if needed.UDP packets also contain a monotonically increasing
sequence number and an RTP Timestamp.The user can create any agent or traffic
sources are implemented in C++ and linked to OTcl.
set cbr1 [new Application/Traffic/CBR]
$ns at 0.1 “$cbr start”
$ns at 5.0 “$cbr stop”
This command is used to schedule the beginning and the end of the CBR
applications. CBR will be active from time 1.0 till 5.0
$ns run
After finishing all network configurations,scheduling and post simulation
procedure specification are done,the last thin is run the simulation

2. LITERATURE SURVEY
2.1 AN APPLICATION-SPECIFIC PROTOCOL ARCHITECTURE FOR
WIRELESS MICROSENSOR NETWORKS
Networking together hundreds or thousands of cheap microsensor nodes allows
users to accurately monitor a remote environment by intelligently combining the data
from the individual nodes. These networks require robust wireless communication
protocols that are energy efficient and provide low latency. In this paper, we develop
and analyze low-energy adaptive clustering hierarchy (LEACH), a protocol
architecture for microsensor networks that combines the ideas of energy-efficient
cluster-based routing and media access together with application-specific data
aggregation to achieve good performance in terms of system lifetime, latency, and
application-perceived quality. LEACH includes a new, distributed cluster formation
technique that enables self-organization of large numbers of nodes, algorithms for
adapting clusters and rotating cluster head positions to evenly distribute the energy load
among all the nodes, and techniques to enable distributed signal processing to save
communication resources. Our results show that LEACHcan improve system lifetime
by an order of magnitude compared with general-purpose multihop approaches.

14
2.2 A FUZZY LOGIC-BASED CLUSTERING ALGORITHM FOR
WSN TO EXTEND THE NETWORK LIFETIME
Wireless sensor network (WSN) brings a new paradigm of real-time embedded
systems with limited computation, communication, memory, and energy resources
that are being used for huge range of applications where the traditional
infrastructure-based network is mostly infeasible. The sensor nodes are densely
deployed in a hostile environment to monitor, detect, and analyze the physical
phenomenon and consume considerable amount of energy while transmitting the
information. It is impractical and sometimes impossible to replace the battery and to
maintain longer network life time. So, there is a limitation on the lifetime of the
battery power and energy conservation is a challenging issue. Appropriate cluster
head (CH) election is one such issue, which can reduce the energy consumption
dramatically. Low energy adaptive clustering hierarchy (LEACH) is the most famous
hierarchical routing protocol, where the CH is elected in rotation basis based on a
probabilistic threshold value and only CHs are allowed to send the information to the
base station (BS). But in this approach, a super-CH (SCH) is elected among the CHs
who can only send the information to the mobile BS by choosing suitable fuzzy
descriptors, such as remaining battery power, mobility of BS, and centrality of the
clusters. Fuzzy inference engine (Mamdani’s rule) is used to elect the chance to be the
SCH. The results have been derived from NS-2 simulator and show that the proposed
protocol performs better than the LEACH protocol in terms of the first node dies, half
node alive, better stability, and better lifetime.
2.3 F-MCHEL: FUZZY BASED MASTER CLUSTER HEAD ELECTION
LEACH PROTOCOL IN WIRELESS SENSOR NETWORK
Wireless Sensor Network is the network of power-limited sensing devices called
sensors deployed in a region to sense various types of physical information from the
environment when these sensors sense and transmit data to other sensors present in the
network; considerable amount of energy is dissipated. In this paper, an effort has been
done to propose F-MCHEL, a homogeneous energy protocol. In LEACH protocol the
clusters are formed randomly on the basis of threshold values; whereas, in the proposed
protocol a fuzzy logic approach is used to elect the cluster-head based on two
descriptors - energy and proximity distance .Out of these elected cluster heads one
Master cluster head has been elected .The cluster head which has the maximum residual
energy is elected as Master cluster head. In conventional Leach approach all the Cluster
heads are used to sends the aggregated information to the base station, however in the

15
proposed protocol only Master cluster head sends the aggregated information to the
base station. Simulation results on MATLAB shows that the proposed protocol
provides higher energy efficiency, better stability period and lower instability period as
compared to LEACH protocol in spite of overhead of election of Master cluster head.
Results obtained shows that an appropriate Master cluster-head election can drastically
reduce the energy consumption and enhance the lifetime of the network.
2.4 CLUSTER-HEAD ELECTION USING FUZZY LOGIC FOR WIRELESS
SENSOR NETWORKS
Wireless Sensor Networks (WSNs) present a new generation of real-time
embedded systems with limited computation, energy and memory resources that are
being used in a wide variety of applications where traditional networking
infrastructure is practically infeasible. Appropriate cluster-head node election can
drastically reduce the energy consumption and enhance the lifetime of the network. In
this paper, a fuzzy logic approach to cluster-head election is proposed based on three
descriptors - energy, concentration and centrality. Simulation shows that depending
upon network configuration, a substantial increase in network lifetime can be
accomplished as compared to probabilistically selecting the nodes as cluster-heads
using only local information.
2.5 OBJECTIVE
To design a system which selects optimal CH based on three parameters distance,
remaining energy,concentration of the node .To choose an optimal CH,we use type-2
fuzzy logic and then cluster the nodes based on the distance,the cluster is divided into
levels.
2.6 SCOPE OF THE PROPOSED SYSTEM
This work is suitable for the environment where the nodes are static and it has to
communicate to its sink in a frequent manner. Nodes in the network are having less
resource,because energy is effectively utilized to enhance the network lifetime.
2.7 PROBLEM STATEMENT
Limitations in the communications range, sensor nodes transmit their sensed data
through multiple range.Each sensor node act as routing element for other nodes for
transmitting data.Energy is therefore of utmost importance in power-constrained sensor
networks.Unbalanced is an inherent problem in WSNs characterized by the
many-to-one traffic pattern.Uneven energy dissipation can significantly reduce

16
network lifetime.So we have to design a system in such a way that,it has to find an
optimal CH and the network energy has to be utilized in an efficient way. Because
without having efficient power management scheme,we cannot prolong the network
lifetime.

3. SYSTEM DESISIGN

3.1 OVERVIEW OF THE PROPOSED SYSTEM

Due to advances in wireless sensor technology and communication


techniques,wireless sensor networks have wide variety of applications like habitat and
ecosystem monitoring,seismic monitoring,disaster monitoring, healthcare
monitoring,security and surveillance and etc.Limited resource and dynamic topology
are the important characteristics of a sensor network.In wireless sensor network the
most important problem to deal with is power scarcity,because of its battery size and
weight.Lifetime and power management are inter-related.Prolonging lifetime of a
WSN can be achieved by utilizing the power of a sensor node in an efficient
manner.Typically a sensor network has to sense and communicate the sensed data ti its
base station(may be mobile or fixed).For the purpose of communication and limitations
in sensor nodes’s communication range,each cluster has to select a optimal CH.
In the proposed model, sensor nodes are considered to be deployed uniformly to
monitor the environment continuously.
1) All the sensor nodes are considered to be static including the base station.
2) Homogeneous networks have been considered such that all the sensor nodes have
initial equal energy.
3) Distance between the base station and the sensor node is computed based on
received signal strength indicator (RSSI).
4) A stand by CH (SB-CH) is elected in the last level of the chain (nearer to the BS)
for delivering the message to BS in case of any energy drop out occurs at last CH.
5) System Model
In the proposed model, CH is elected based on the T2FL model viewing that T2FLcan
handle higher level uncertainties present in the complex real world environments.
3.2 PROPOSED SYSTEM

17
1) Let N sensor nodes distributed randomly over M×M region where k clusters are

assumed
2) N sensor nodes are divided into different levels.
3) Level should be numbered according to the distance from the base station.
4) Elect the CH at each level based on T2FL Model.
5) Apply Fuzzy if-then-else rule to elect the CH.
6) Select k-optimal CHs in each round
/∗ for k-optimal CH ∗ /
7) Transfer the data from one CH to other CH till it reaches at the base station but data
should come from the upper level.
8) One sensor node with higher energy is elected as a stand by (SB-CH) close to the
base station to resume the connectivity if any failure occurs at last CH (the reason is
that CH closer to BS consumes more energy)
/∗ end of for ∗ /
9) BS collects the aggregated data from last CH in the chain
/∗ End of rounds ∗ /
3.3 FUZZY APPROACH

A. Fuzzy logic
It is a form of many-valued logic in which the truth values of variables may be any
real number between 0 and 1. It is employed to handle the concept of partial truth,
where the truth value may range between completely true and completely false. By
contrast, in Boolean logic, the truth values of variables may only be the integer values 0
or 1.

18
Fig 1.4 Block Diagram For Type-2 Fuzzy Logic

B. Lingustic Variables
While variables in mathematics usually take numerical values, in fuzzy logic
applications non-numeric values are often used to facilitate the expression of rules and
facts.
A linguistic variable such as age may accept values such as young and its antonym
old. Because natural languages do not always contain enough value terms to express a
fuzzy value scale, it is common practice to modify linguistic values with adjectives or
adverbs. For example, we can use the hedges rather and somewhat to construct the
additional values rather old or somewhat young.

Fig 1.5 Lingustic Variables

19
3.3.1 FUZZIFICATION
Fuzzification is the process of changing a real scalar value into a fuzzy value.
This is achieved with the different types of fuzzifiers (membership functions).
The simplest membership functions are formed using straight lines. The simplest is the
triangular membership function, and it has the function name trimf.
The trapezoidal membership function, trapmf, has a flat top and really is just a
truncated triangle curve. These straight line membership functions have the advantage
of simplicity.
Two membership functions are built on the Gaussian distribution curve: a simple
Gaussian curve and a two-sided composite of two different Gaussian curves. The two
functions are gaussmf and gauss2mf. The generalized bell membership has the
function name gbellmf.
Because of their smoothness and concise notation, Gaussian and bell membership
functions are popular methods for specifying fuzzy sets. Both of these curves have the
advantage of being smooth and nonzero at all points.
Although the Gaussian membership functions and bell membership functions achieve
smoothness, they are unable to specify asymmetric membership functions, which are
important in certain applications.
the sigmoidal membership function is defined, which is either open left or right.
Asymmetric and closed (i.e. not open to the left or right) membership functions can be
synthesized using two sigmoidal functions, so in addition to the basic sigmf, you also
have the difference between two sigmoidal functions, dsigmf, and the product of two
sigmoidal functions psigmf.

20
3.3.2 IF-THEN-RULES

Table-I:IF-THEN Rules

21
3.3.3 TYPE REDUCER

The type-reducer generates a type-1 fuzzy set output, which is then converted to a
numeric output through running the defuzzifier.

3.3.4 DEFUZZIFICATION

A. COG Method

This method is valid for fuzzy sets with symmetrical output membership functions
and produces results very close to the COA method. This method is less
computationally intensive. Each membership function is weighted by its maximum
membership value. The defuzzified value is defined as :

∑ 𝒎(𝒙). 𝒙
𝑪𝑭 =
∑ 𝒎(𝒙)

Here ∑ denotes the algebraic summation and x is the element with maximum
membership function.

4. IMPLEMENTATION AND METHODOLOGY

4.1 OVERVIEW

This chapter will describe the implementation and methodologies used to


achieve the system design discussed in chapter 3.
4.2 MODULES
Modules in our work are
i. Clustering
ii. Type -1 Fuzzy logic
iii. Type-2 logic

22
4.3 MODULE DESCRIPTION
i. Clustering
Clustering is the task of dividing the population or data points into a number of
groups such that data points in the same groups are more similar to other data points
in the same group than those in other groups. In simple words, the aim is to segregate
groups with similar traits and assign them into clusters.
ii. Type-1 Fuzzy Logic
T1FL model consists of four modules: a fuzzifier, fuzzy inference engine, fuzzy rules
and a defuzzifier. There are four steps required to complete the process.T1FL is used to
handle the uncertainty level to some extent not completely because Type-1 fuzzy sets
are certain.
iii.Type-2 Fuzzy Logic
Type-2 Fuzzy Logic (T2FL) model is useful in circumstances where it is difficult to
determine an exact numeric membership function and there are measurement
uncertainties . The idea is to apply T2FL on WSN which can help to elect an efficient
CH so that it can distribute the load evenly among the sensor nodes. In [20], T2FL is
characterized by a superior membership function and an inferior membership
function. These two functions can be represented (each one) by a Type-1fuzzy set
membership function. The interval between these two functions represents the
footprint of uncertainty (FOU) which is used to characterize a T2FL set. Let the FOU
is expressed
as f. If f º [0, 1], and f →0, then Member Function is considered as T1FL. If f →0 to 1,
then T2FL have a wide range of FOU between 0 to1. But the rules formation is same
as T1FL. It can be expressed as:
T ype2FL = PrincipalMF (T ype1FL) + FOU

BatteryPower Distance to BS Concentration Type-1Fuzzy Type-2Fuzzy


0.95 0.55 0.91 0.7 0.6

Table II :Comparison between Type-1 and Type-II

23
4.4 CODE
#include <iostream>
#include <fstream>
using namespace std;
class Fuzzy2{
public:
string CF,CF1,CF2,CF3,CF4,CF5,CF6;
float t,ss1,ss2,output,ss3,ss4;
int my=0,tree=0,third=0;
float b,energy,energy1,final;
Stringcf1="vpoor",cf2="poor",cf3="bavg",cf4="avg",cf5="abavg",cf6="strong”;
string h1,h2,h3,s1,s2,s3,s4,s5,s6,cf7=”vstrong”;
float mid,g1,g2,g3;
int p2=1;
float one,two,three,four,ot,tf,min,max,max1,min1,three1,two1,one1,tf1,ot1,four1;
float one3,two3,three3,four3,ot3,tf3;
float min3,max3,max2,min2,three2,two2,one2,tf2,ot2,four2;
float c1,c2,c3,c4,c5,c6,aa1,aa2,aa3;
float one4,two4,three4,four4,ot4,tf4,min4,max4;
float power,dist,conc;
int m;
int a[10];
float ls1=0,ls2=0.5,ls3=0.4,ls4=0.7,ls5=0.6,ls6=1;
float i1,i2,i3,l1,l2,l3,i4,i5;
int nos,y1=0;
void nodepower(float power){
if((power>=ls1 && power<=ls6 )){
if((power>=ls1)&&(power<=ls3)){
cout<<"inside low slope 2 nd membership";
one=power-ls1;

24
two=ls3-ls1;
ot=one/two;
three=ls2-power;
four=ls2-ls3;
tf=three/four;
if(ot<tf)
min=ot;
else
min=tf;
if(min>0)
max=min;
else
max=0;
cout<<"low max is"<<max;
s1="low";
cout<<s1;}
else if((power>ls3)&&(power<=ls2)){
cout<<"=================";
one2=power-ls3;
two2=ls2-ls3;
ot2=one2/two2;
three2=ls4-power;
four2=ls4-ls2;
tf2=three2/four2;
if(ot2<tf2)
min2=ot2;
else
min2=tf2;
if(min2>0)
max2=min2;
else
max2=0;
cout<<"normal max is"<<max2;
s2="medium";

25
cout<<s2;
one=power-ls1;
two=ls3-ls1;
ot=one/two;
three=ls2-power;
four=ls2-ls3;
tf=three/four;
if(ot<tf)
min=ot;
else
min=tf;
if(min>0)
max=min;
else
max=0;
cout<<"low max is"<<max;
s1="low";
cout<<s1;}
else if((power>ls2)&&(power<=ls5))
{cout<<"=================";
one2=power-ls3;
two2=ls2-ls3;
ot2=one2/two2;
three2=ls4-power;
four2=ls4-ls2;
tf2=three2/four2;
if(ot2<tf2)
min2=ot2;
else
min2=tf2;
if(min2>0)
max2=min2;
else
max2=0;

26
s2="medium";
cout<<s2;
cout<<"normal max is"<<max2;}
else if((power>ls5)&&(power<=ls4)){
one3=power-ls5;
two3=ls4-ls5;
ot3=one3/two3;
three3=ls6-power;
four3=ls6-ls4;
tf3=three3/four3;
if(ot3<tf3)
min3=ot3;
else
min3=tf3;
if(min3>0)
max3=min3;
else
max3=0;
cout<<"high max is"<<max3;
s1="high";
cout<<s1;
cout<<"=================";
one2=power-ls3;
two2=ls2-ls3;
ot2=one2/two2;
three2=ls4-power;
four2=ls4-ls2;
tf2=three2/four2;
if(ot2<tf2)
min2=ot2;
else
min2=tf2;
if(min2>0)
max2=min2;

27
else
max2=0;
cout<<"normal max is"<<max2;
s2="medium";
cout<<s2;}
else if((power>ls4)&&(power<=ls6)){
one3=power-ls5;
two3=ls4-ls5;
ot3=one3/two3;
three3=ls6-power;
four3=ls6-ls4;
tf3=three3/four3;
if(ot3<tf3)
min3=ot3;
else
min3=tf3;
if(min3>0)
max3=min3;
else
max3=0;
cout<<"high max is"<<max3;
s1="high";
cout<<s1<<"\n";}
else
cout<<"error";}
else{
out<<"exit";}}
/////FUZZY RULES
void first(float p,float d,float c){
//1
if(((p>=ls1)&&(p<=ls3))&&((d>=ls1)&&(d<=ls3))&&((c>=ls1)&&(c<=ls3))){
CF=cf1;
if((max<max4)&&(max>max6))
ss1=max;

28
else if((max4<max)&&(max4>max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//2
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls1)&&(d<=ls3))&&((c>ls2)&&(c<=ls5))){
CF=cf2;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//3
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls1)&&(d<=ls3))&&((c>ls4)&&(c<=ls6))){
CF=cf3;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}//4
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls2)&&(d<=ls5))&&((c>=ls1)&&(c<=ls3))){
CF=cf2;
if((max<max4)&&(max<max6))

29
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//5
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls2)&&(d<=ls5))&&((c>ls2)&&(c<=ls5))){
CF=cf3;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//6
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls2)&&(d<=ls5))&&((c>ls4)&&(c<=ls6))){
CF=cf4;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//7
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls4)&&(d<=ls6))&&((c>=ls1)&&(c<=ls3))){

30
CF=cf3;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//8
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls4)&&(d<=ls6))&&((c>=ls2)&&(c<=ls5))){
CF=cf4;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//9
else
if(((p>=ls1)&&(p<=ls3))&&((d>ls4)&&(d<=ls6))&&((c>=ls4)&&(c<=ls6))){
CF=cf5;
if((max<max4)&&(max<max6))
ss1=max;
else if((max4<max)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//10

31
else
if(((p>ls2)&&(p<=ls5))&&((d>=ls1)&&(d<=ls3))&&((c>=ls1)&&(c<=ls3))){
CF=cf2;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//11
else if(((p>ls2)&&(p<=ls5))&&((d>ls1)&&(d<=ls3))&&((c>ls2)&&(c<=ls5))){
CF=cf3;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//12
else if(((p>ls2)&&(p<=ls5))&&((d>ls1)&&(d<=ls3))&&((c>ls4)&&(c<=ls6))){
CF=cf4;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}//13

32
else
if(((p>ls2)&&(p<=ls5))&&((d>ls2)&&(d<=ls5))&&((c>=ls1)&&(c<=ls3))){
CF=cf3;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//14
else if(((p>ls2)&&(p<=ls5))&&((d>ls2)&&(d<=ls5))&&((c>ls2)&&(c<=ls5))){
CF=cf4;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//15
else if(((p>ls2)&&(p<=ls5))&&((d>ls2)&&(d<=ls5))&&((c>ls4)&&(c<=ls6))){
CF=cf5;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//16

33
else
if(((p>ls2)&&(p<=ls5))&&((d>ls4)&&(d<=ls6))&&((c>=ls1)&&(c<=ls3))){
CF=cf4;
if((max2<max4)&&(max2<max6))
ss1=max;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//17
else
if(((p>ls2)&&(p<=ls5))&&((d>ls4)&&(d<=ls6))&&((c>=ls2)&&(c<=ls5))){
CF=cf5;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//18
else
if(((p>ls2)&&(p<=ls5))&&((d>ls4)&&(d<=ls6))&&((c>=ls4)&&(c<=ls6))){
CF=cf6;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;

34
cout<<CF;}
//19
else
if(((p>ls4)&&(p<=ls6))&&((d>=ls1)&&(d<=ls3))&&((c>=ls1)&&(c<=ls3))){
CF=cf3;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//20
else if(((p>ls4)&&(p<=ls6))&&((d>ls1)&&(d<=ls3))&&((c>ls2)&&(c<=ls5))){
CF=cf4;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//21
else if(((p>ls4)&&(p<=ls6))&&((d>ls1)&&(d<=ls3))&&((c>ls4)&&(c<=ls6))){
CF=cf5;
if((max2<max4)&&(max2<max6))
ss1=masx2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;

35
cout<<CF;}//22
else
if(((p>ls4)&&(p<=ls6))&&((d>ls2)&&(d<=ls5))&&((c>=ls1)&&(c<=ls3))){
CF=cf4;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//23
else if(((p>ls4)&&(p<=ls6))&&((d>ls2)&&(d<=ls5))&&((c>ls2)&&(c<=ls5))){
CF=cf5;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//24
else if(((p>ls4)&&(p<=ls6))&&((d>ls2)&&(d<=ls5))&&((c>ls4)&&(c<=ls6))){
CF=cf6;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}

36
//25
else
if(((p>ls4)&&(p<=ls6))&&((d>ls4)&&(d<=ls6))&&((c>=ls1)&&(c<=ls3))){
CF=cf5;
if((max2<max4)&&(max2<max6))
ss1=max;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//26
else
if(((p>ls4)&&(p<=ls6))&&((d>ls4)&&(d<=ls6))&&((c>=ls2)&&(c<=ls5))){
CF=cf6;
if((max2<max4)&&(max2<max6))
ss1=max2;
else if((max4<max2)&&(max4<max6))
ss1=max4;
else
ss1=max6;
cout<<ss1;
cout<<CF;}
//27
else
if(((p>ls4)&&(p<=ls6))&&((d>ls4)&&(d<=ls6))&&((c>=ls4)&&(c<=ls6))){
cout<<max3<<"\n";
cout<<max4<<"\n";
cout<<max6<<"\n";
CF=cf7;
if((max3<max4)&&(max3<max6))
ss1=max3;
else if((max4<max3)&&(max4<max6))

37
ss1=max4;
else
ss1=max6;
cout<<"selfee"<<ss1;
cout<<CF<<"\n"<<"hello fathima";}
////DEFUZZIFICATION
void de(){
if(ss1>=ss2){
output=ss1;
cout<<"my output is efficient energy"<<output;
if(CF==cf1){
energy=((0.04+0.02)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf2){
energy=((0.04+0.06)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf3){
energy=((0.03+0.09)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf4){
energy=((0.3+0.25)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf5){
energy=((0.2+0.5)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf6){
energy=((0.2+0.7)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf7){
energy=((0.2+0.9)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else
cout<<"not valid";
///1INSIDE OVERLAP MEMBERSHIP FUNCTION

38
if(CF==cf1&&CF1==cf1){
final=((energy*0.02)+(energy1*0.02))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//2
else if(CF==cf1&&CF1==cf2){
final=((energy*0.02)+(energy1*0.06))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//3
else if(CF==cf1&&CF1==cf3){
final=((energy*0.02)+(energy1*0.09))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//4
else if(CF==cf1&&CF1==cf4){
final=((energy*0.02)+(energy1*0.25))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//5
else if(CF==cf1&&CF1==cf5){
final=((energy*0.02)+(energy1*0.5))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//6
else if(CF==cf1&&CF1==cf6){
final=((energy*0.02)+(energy1*0.7))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//7
else if(CF==cf1&&CF1==cf7){
final=((energy*0.02)+(energy1*0.9))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}
else{output=ss2;
cout<<"my output is"<<output;
if(CF==cf1){
energy=((0.04+0.02)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf2){
energy=((0.04+0.06)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf3){
energy=((0.03+0.09)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf4){
energy=((0.3+0.25)*ss1)/2;

39
cout<<"ENERGY IS"<<energy;}
else if(CF==cf5){
energy=((0.2+0.5)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf6){
energy=((0.2+0.7)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else if(CF==cf7){
energy=((0.2+0.9)*ss1)/2;
cout<<"ENERGY IS"<<energy;}
else
cout<<"not valid";
///1DEFUZZIFICATION CENTROID METHOD
if(CF==cf1&&CF1==cf1){
final=((energy*0.02)+(energy1*0.02))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//2
else if(CF==cf1&&CF1==cf2){
final=((energy*0.02)+(energy1*0.06))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//3
else if(CF==cf1&&CF1==cf3){
final=((energy*0.02)+(energy1*0.09))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//4
else if(CF==cf1&&CF1==cf4){
final=((energy*0.02)+(energy1*0.25))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//5
else if(CF==cf1&&CF1==cf5){
final=((energy*0.02)+(energy1*0.5))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//6
else if(CF==cf1&&CF1==cf6){
final=((energy*0.02)+(energy1*0.7))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}//7
else if(CF==cf1&&CF1==cf7){
final=((energy*0.02)+(energy1*0.9))/(energy+energy1);
cout<<"\n"<<"my final output is"<<final<<"\n";}}

40
else
cout<<"not valid";}}
///////////////////DYNAMIC MEMBERSHIP FUNCTION
void sup(int s,float p,float d,float c){
ls1=ls1*s;
ls3=ls3*s;
ls4=ls4*s;
ls5=ls5*s;
ls6=ls6*s;
cout<<ls1<<" \n";
cout<<ls2<<" \n";
cout<<ls3<<" \n";
cout<<ls4<<" \n";
cout<<ls5<<" \n";
cout<<ls6<<" \n";
i1=(ls1+ls2)/2;
i2=(ls4+ls3)/2;
i3=(ls6+ls5)/2;
i4=(ls2+ls3)/2;
i5=(ls5+ls4)/2;}};
int main () {
Fuzzy2 f2;
int aa;
float E=0;
string l11,l12,l13,ans;
cout<<"enter the mmbership fuction";
cin>>f2.m;
cout<<"enter the power";
cin>>f2.power;
cout<<"enter the dist";
cin>>f2.dist;
cout<<"enter the concentration";
cin>>f2.conc;
f2.sup(f2.m,f2.power,f2.dist,f2.conc);

41
cout<<"\n";
f2.nodepower(f2.power);
f2.distance(f2.dist);
f2.concentration(f2.conc);
f2.first(f2.power,f2.dist,f2.conc);
f2.de();}

NS2 CODE:
# Define options
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
Set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna # antenna model
Set val(ifqlen) 50 ;# max packet in ifq
Set val(nn) 8 ;# number of mobilenodes
Set val(rp) AODV ;# routing protocol
Set val(xx) 500 ;# X dimension of topography
Set val(yy) 400 ;# Y dimension of topography
Set val(stop) 10 ;# time of simulation end
#Creating simulation:
set ns [new Simulator]
#Creating nam and trace file:
set tracefd [open wireless3.tr w]
set namtrace [open wireless3.nam w]
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(xx) $val(yy)
# set up topography object
set topo [new Topography]
$topo load_flatgrid $val(xx) $val(yy)
set god_ [create-god $val(nn)]
# configure the nodes

42
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
## Creating node objects..
for {set i 0} {$i < $val(nn) } { incr i } {
set node_($i) [$ns node]}
for {set i 0} {$i < $val(nn)} {incr i} {
$node_($i) color darkgreen
$ns at 0.0 "$node_($i) color darkgreen"}
set fp1 "yposition.txt"
set filename "xposition.txt"
set fp2 [open $fp1 "w"]
set fileId [open $filename "w"]
## Provide initial location of mobilenodes..
if {$val(nn) >0} {
for {set i 1} {$i < $val(nn) } { incr i } {
set xx [expr rand()*600]
set yy [expr rand()*500];
puts $fileId $xx
puts $fp2 $yy
$node_($i) set X_ $xx
$node_($i) set Y_ $yy
#puts -nonewline $fileId $xx}}

43
close $fileId
close $fp2
set fp2 [open $fp1 "r"]
set county 0
while { [gets $fp2 data] >= 0 } {
incr county
puts $data
puts $county}
set fileId [open $filename "r"]
while { [gets $fileId data1] >= 0 } {
puts $data1}
set bsx $data(5)
puts"the bs coordinate its"
puts $bsx
# Define node initial position in nam
for {set i 0} {$i < $val(nn)} { incr i } {
# 30 defines the node size for nam
$ns initial_node_pos $node_($i) 30}
# Telling nodes when the simulation ends
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "$node_($i) reset";}
# dynamic destination setting procedure..
$ns at 0.0 "destination"
proc destination {} {
global ns val node_
set time 1.0
set now [$ns now]
for {set i 0} {$i<$val(nn)} {incr i} {
set xx [expr rand()*500]
set yy [expr rand()*400]
$ns at $now "$node_($i) setdest $xx $yy 10.0"
}
$ns at [expr $now+$time] "destination"}
#stop procedure..

44
$ns at $val(stop) "stop"
proc stop {} {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam wireless3.nam &
}
$ns run

45
5. SNAPSHOTS

We have randomly deployed 20 nodes simulation area.Each node having 1 joule as


initial energy, and queue size is 10.Fig 1.6 shows initial layout

Fig1.6 Initial Layout of the network

After the nodes started clustering based on distance is given in Fig 1.7

Fig1.7 After Clustering

46
Fig1.8 Type-1 Fuzzy Logic Result

Fig1.9 Type-2 Fuzzy Logic Result

47
100
90
80
70
60
50
40
30
20
10
0
A B
A - Type-2 Fuzzy
B - Type-1 Fuzzy

Fig1.10 Comparison of both Result

48
6 . CONCLUSION AND FUTURE ENHANCEMENT

6.1 CONCLUSION

Three fuzzy descriptors such as remaining battery power, distance to base station,
and concentration have been considered. Each Cluster Head sends the data to the next
level (starting from the first level to the last level) till it reaches at the base station. The
novelty of the protocol utilizes the concept of Type 2 Fuzzy Logic justifying that fuzzy
logic model handles real time problems more accurately than any other probabilistic
model. Again, Type 2 Fuzzy Logic Model handles the measured level of uncertainties
more accurately than Type1 Fuzzy logic model.

6.2 FUTURE ENHANCEMENT


The proposed approach will be extended by considering extra parameter for detecting
the confidence factor and thereby network lifetime can be increased .

49
7. REFERENCES

[1] W. R. Heinzelman, A. Chandrakasan, and H. Balakrishnan, “Energyefficient


communication protocol for wireless microsensor networks,” in Proc. 33rd Hawaii
Int. Conf. Syst. Sci. (HICSS), Washington, DC, USA, Jan. 2000, pp. 1–10.

[2] W. B. Heinzelman, A. P. Chandrakasan, and H. Balakrishnan, “An


application-specific protocol architecture for wireless microsensor networks,” IEEE
Trans. Wireless Commun., vol. 1, no. 4, pp. 660–670, Oct. 2002.

[3] S. Lindsey and C. S. Raghabendra, “PEGASIS: Power efficient gathering in


sensor information systems,” in Proc. IEEE Aerosp. Conf., Mar. 2002,pp. 3-1125–
3-1130.

[4] J.-M. Kim, S.-H. Park, Y.-J. Han, and T. Chung, “CHEF: Cluster head election
mechanism using fuzzy logic in wireless sensor networks,” in Proc. ICACT, Feb.
2008, pp. 654–659.

[5] T. Sharma and B. Kumar, “F-MCHEL: Fuzzy based master cluster head election
leach protocol in wireless sensor network,” Int. J. Comput. Sci. Telecommun., vol. 3,
no. 10, pp. 8–13, Oct. 2012.

[6] P. Nayak and C. Praneeth, “Monitoring water quality through wireless sensor
network, raspberry pi, and Arduino,” in Proc. IEEE TENSYMP,Jul. 2017.

50

Das könnte Ihnen auch gefallen