You are on page 1of 49

A Project Report

On
Implementation ACO Algorithm in WSN

Submitted in partial fulfillment of the requirements
For the award of the degree of

Bachelor of Technology
In
Information Technology

By
Anurag Mishra, Bipin Yadav, Himanshu Chaudhary
Roll No: 1009713028, 1009713037, 1009713047

Under the Supervision of
Mr. Ranjeet Kumar

Galgotias College of Engineering & Technology
Greater Noida 201306
Affiliated to

Uttar Pradesh Technical University
Lucknow
ii
CANDIDATES DECLARATION

I hereby declare that the work presented in this dissertation entitled Implementation of ACO
algorithm in WSN, in partial fulfillment of the requirement for the award of the degree of Bachelor of
Technology in Information Technology, submitted to Uttar Pradesh Technical University, Lucknow, is an
authentic record of my own work carried out during the period from 01/02/2014 to 25/04/2014 under the
guidance of Mr. Ranjeet Kumar, A.P., GCET, Greater Noida.
The work reported in this dissertation has not been submitted by me for award of any other degree
or diploma.


Date:
Place: Greater Noida Anurag Mishra, Bipin Yadav, Himanshu Chaudhary
Roll no. 1009713028, 1009713037,1009713047
iii
CERTIFICATE

This is to certify that the Project report (ITR-752) entitled Implementation of ACO algorithm in
WSN done by Anurag Mishra, Bipin Yadav, Himanshu Chaudhary, Roll No.1009713028,1009713037,
1009713047 is an authentic work carried out by him at GCET, Greater Noida under my guidance. The
matter embodied in this project work has not been submitted earlier for the award of any degree or
diploma to the best of my knowledge and belief.

Date: __________________




Dr. Bhawna Mallick (Signature of Guide)
(Professor & Head) Mr. Ranjeet Kumar
Department of Information Technology (Assistant Professor)







iv
ACKNOWLEDGEMENT

The satisfaction that accompanies with the successful completion of any task would be
incomplete without the mention of people whose ceaseless cooperation made it possible,
whose constant guidance and encouragement crown all efforts with success.
We are grateful to our project guide Mr. RANJEET KUMAR for the guidance, inspiration
and constructive suggestions that helped us in the preparation of this project. We would like
to thank Mr. SANDEEP RAJ whose constructive suggestions were very useful in the
preparation of this project. We also grateful to department of Information Technology for the
guidance, inspiration and constructive suggestions that helped us in the preparation of this
project.


v
ABSTRACT

KEYWORDS: Ant Colony Optimization (ACO), multi-Hop technique, mobile Base
station (MBS).
In current scenario the WSN system has energy dissipation problem, as it would be
impossible to recharge the battery of nodes. And also there is possibility that a system in
which central base system is mobile. We need a system where we can minimize the power
dissipation and better connectivity in moving base station environment. We considered a
condition where a set of source nodes generate data samples that must be delivered to the
mobile Base station (MBS). Our objective is to implement Ant Colony Optimization (ACO)
Algorithm in Wireless Sensor Network to find the shortest path between the nodes.
We are also using multi-Hop technique. In multi-Hop data technique, energy dissipation is
lesser than the single-Hop technique. The total energy dissipation incurred by the network to
transmit the information from sources nodes to the LBSs should be minimized. So that if we
use ACO algorithm for data transfer in a network having mobile station, we will be able to
reduce energy consumption without any compromise on data security and transfer speed.




















vi
TABLE OF CONTENTS

Candidates Declaration ............................................................................................................... (ii)
Certificate .......................................................................................................................... (iii)
Acknowledgement ....................................................................................................................... (iv)
Abstract ........................................................................................................................... (v)
List of Figures ........................................................................................................................... (viii)
Abbreviations (ix)

1. Introduction .1-7

1.1 Modules in WSN.......................2
1.2 Characteristics of WSN..3
1.3 Types of Sensor Network.4-5
1.4 Application of WSN...5-7
1.5 Purpose......................7
1.6 Project Scope....................7

2. Literature Survey.......................8-10

3. Problem Statement...................11-12


3.1 Objective........................11
3.2 Related Work...11
3.3 Scope.............................12

4. Proposed Work Done.13-22

4.1 ACO Algorithm.13
4.2 Working Platform..14-21
4.2.1 Java............14-21
4.2.2 NetBeans21-22


5. HLD & LLD................................23-33

5.1 UML Diagrams23
5.2 Use Case Diagram...24-25
5.3 Class Diagram...25-27
5.4 Sequence Diagram....28
5.5 State Transition Diagram..29-31
5.6 Collaboration Diagram32
5.7 Activity Diagram..33

vii

6. Ant Colony Optimization34-35

6.1 The Double Bridge Experiment34
6.2 Ant System....34-35


7. Screen Shot of Working Code..36-38

8. Conclusion...39


























viii

LIST OF FIGURES



Page
No.
Figure 1 Wireless Sensor Network 1
Figure 2 Architecture of Node in WSN 3
Figure 3 Sink Node in WSN 4
Figure 4 Sink Node in WSN 5
Figure 5 Class Diagram of Topology in WSN 23
Figure 6 Class Diagram of Cluster in WSN 24
Figure 7 Sequence Diagram of WSN 26
Figure 8 State Transition Diagram of Node 29
Figure 9 State Transition Diagram of Node Routing 31
Figure 10 Collaboration Diagram of Message Transmission 33
Figure 11 Activity diagrams of Message Transmission in WSN 34
Figure 12 Screen Shot of Working Code 36-38

















ix
Abbreviations

WSN: Wireless Sensor Network
ACO: Ant Colony Optimization
LEACH: Low Energy Adaptive Clustering Hierarchy
TL-LEACH: Two level LEACH
MBS: Mobile Base Station
LBS: Local Base Station
MHRT: Multi-Hop Routing Technique
MANET: Mobile ad- hoc Network
MCU: Micro controller unit

1

Chapter 1
INTRODUCTION
Wireless Sensor Networks are heterogeneous systems containing many small devices called sensor nodes
with general-purpose computing elements. These networks will consist of hundreds or thousands of low cost,
low power and self-organizing nodes which are highly distributed either inside the system or very close to it.
These nodes consist of three main components-sensing, data processing and communication. Two other
components are also there called, aggregation and base station. Aggregation points gathers data from their
neighboring nodes integrates the collected data and then forwards it to the base station for further processing.
Various applications of WSN includes habitat monitoring, manufacturing and logistics, environmental
observation and forecast systems, military applications, health, home and office application and a variety of
intelligent and smart systems.




Fig. 1.1 Wireless Sensor Network





2

1.1 Modules in WSN:
The working of sensor network can be categorized in four modules:

A. Computing Module:
This module contains Micro controller unit (MCU), which is responsible for the control of the sensors and
execution of communication protocols.

B. Communication Module:
This module is responsible for radio communication between neighboring nodes and the outside world. In
this functioning it is better to completely shut down the radio rather than put it in the idle mode when it is not
transmitting or receiving because of the high power consumed in this mode.

C. Sensing Module:
It consists of a group of sensors and actuators and links the node to the outside world. Energy consumption
can be reduced by using low power components and saving power at the cost of performance which is not
required.

D. Power Supply Module:
It consists of a battery which supplies power to the node. It should be seen that the amount of power drawn
from a battery is checked because if high current is drawn from a battery for a long time, the battery will die
even though it could have gone on for a longer time.

All the sensor nodes are scattered and entire area, where these sensor nodes are installed is called sensor
field. Each sensor nodes has the capabilities to collect data and route data back to the sink. Sink is base
station which store data and transmit to the centralized control. The architecture of node can be understands
by following figure.


3


Fig. 1.2 Architecture of Node in WSN

Sink: Sink is the base station which is responsible to transmits data to authorize user. Data are routed back
to the sink by a multi hop infrastructure less architecture through the sink. The sink may communicate with
the task manager node via Internet or satellite. The design of the sensor network is influenced by many
factors, including fault tolerance, scalability, production costs, operating environment, sensor network
topology, hardware constraints, transmission media, and power consumption.


Fig. 1.3 Sink Node in WSN


4

1.2 Characteristics of WSN:
1. Compact size
2. Physical security
3. Power
4. Memory space
5. Bandwidth
6. Unreliable communications

1.3 Types of Sensor Networks:
1. Terrestrial WSNs
2. Underground WSNs
3. Underwater WSNs
4. Multimedia WSNs

1. Terrestrial WSNs:
In these, nodes are distributed in a given area either in an ad hoc manner (sensor nodes are randomly placed
into the target area by dropping it from plane) or in pre-planned manner (sensor nodes are placed according
to grid placement, optimal placement, 2-d and 3-d placement models). Since battery power is limited and it
cannot be recharged, terrestrial sensor nodes must be provided with an optional power source such as solar
cells.

2. Underground WSNs:
In these, sensor nodes are buried underground or in a cave or mine that monitors the underground conditions.
Sink nodes are deployed above the ground to forward the gathered information from the sensor nodes to the
base station. These are more expensive than the terrestrial sensor networks because proper nodes are to
be selected that can assure reliable communication through soil, rock, water and other mineral contents.




5

3. Underwater WSNs:
In these, sensor nodes and vehicles are located underwater. Autonomous vehicles are used for gathering
the data from the sensor nodes. Sparse deployment of nodes is done in this network. Main problems that
come under this while communicating are limited bandwidth, long propagation delay and signal fading issue.

4. Multimedia WSNs:
In these, low cost sensor nodes are equipped with cameras and microphones. These nodes are located in a
pre-planned manner to guarantee coverage. Issues in these networks are demand of high bandwidth, high
energy consumption, quality of service provisioning, data processing and compression techniques, and cross
layer design.

1.4 Application of WSN:

1.4.1. Area monitoring:
Area monitoring is a common application of WSNs. In area monitoring, the WSN is deployed over a region
where some phenomenon is to be monitored. A military example is the use of sensors detect enemy intrusion;
a civilian example is the geo-fencing of gas or oil pipelines.
1.4.2. Health care monitoring:
The medical applications can be of two types: wearable and implanted. Wearable devices are used on the
body surface of a human or just at close proximity of the user. The implantable medical devices are those
that are inserted inside human body. There are many other applications too e.g. body position measurement
and location of the person, overall monitoring of ill patients in hospitals and at homes.
1.4.3. Air pollution monitoring:
Wireless sensor networks have been deployed in several cities (Stockholm, London and Brisbane) to monitor
the concentration of dangerous gases for citizens. These can take advantage of the ad hoc wireless links
rather than wired installations, which also make them more mobile for testing readings in different areas.
1.4.4. Forest fire detection:
6

A network of Sensor Nodes can be installed in a forest to detect when a fire has started. The nodes can be
equipped with sensors to measure temperature, humidity and gases which are produced by fire in the trees
or vegetation. The early detection is crucial for a successful action of the firefighters; thanks to Wireless
Sensor Networks, the fire brigade will be able to know when a fire is started and how it is spreading.
1.4.5. Landslide detection:
A landslide detection system makes use of a wireless sensor network to detect the slight movements of soil
and changes in various parameters that may occur before or during a landslide. Through the data gathered
it may be possible to know the occurrence of landslides long before it actually happens.
1.4.6. Water quality monitoring:
Water quality monitoring involves analyzing water properties in dams, rivers, lakes & oceans, as well as
underground water reserves. The use of many wireless distributed sensors enables the creation of a more
accurate map of the water status, and allows the permanent deployment of monitoring stations in locations
of difficult access, without the need of manual data retrieval.
1.4.7. Natural disaster prevention:
Wireless sensor networks can effectively act to prevent the consequences of natural disasters, like floods.
Wireless nodes have successfully been deployed in rivers where changes of the water levels have to be
monitored in real time.
1.4.8. Industrial monitoring:
1.4.8.1 Machine health monitoring:
Wireless sensor networks have been developed for machinery condition-based maintenance (CBM) as they
offer significant cost savings and enable new functionality. In wired systems, the installation of enough
sensors is often limited by the cost of wiring. Previously inaccessible locations, rotating machinery, hazardous
or restricted areas, and mobile assets can now be reached with wireless sensors.
1.4.8.2 Data logging:
Wireless sensor networks are also used for the collection of data for monitoring of environmental information,
this can be as simple as the monitoring of the temperature in a fridge to the level of water in overflow tanks
in nuclear power plants. The statistical information can then be used to show how systems have been
working. The advantage of WSNs over conventional loggers is the "live" data feed that is possible.
7

1.4.8.3 Water/Waste water monitoring:
Monitoring the quality and level of water includes many activities such as checking the quality of underground
or surface water and ensuring a countrys water infrastructure for the benefit of both human and animal.

1.5 Purpose:
In large environmental setup sensor nodes are distributed pervasively, begin at same energy storage and
create clusters. Some of the nodes utilize more energy dissipation due to the far away from the base station
and rest of the nodes operates at less energy consumption. Therefore, after the some successful rounds
there will be a significant variation in nodes energy consumption. Finally, the network performance will be
turn down because the distribution of the live and dead nodes within the network. But a significant amount of
energy saving can be achieved in wireless sensor networks with a mobile base station that collects data from
sensor nodes via short-range communications with Multi hop routing strategy. It is vital solution to enhance
the energy transmission dissipation and network lifetime by using the structure of multi levels clustering that
reduces the number of nodes when data is transmitted from source to the base station and reducing total
energy consumption. With the help of Ant Colony Optimization algorithm we find the shortest path and that
help to achieve energy efficiency and better performance.
1.6 Project Scope:
This algorithm works efficiently in Wireless Sensor Network and improves its performance. It can be
implemented to the various areas where it could be impossible or inconvenient to recharge the battery,
because nodes may be deployed in a hostile or unpractical environment.
The multi- level clustering with dynamic local base station provide a better energy utilization and hop
connectivity with the Base Station. Through multi-level clustering and Ant Colony Optimization (ACO)
algorithm for determining the shortest path between the nodes for data transfer to a mobile base station.
In this we demonstrate the idea to save the energy in a wireless sensor network for reduction of energy
consumption. We are using LEACH protocol on both single and multiple hops (as results shows). OPNET is
a good tools to demonstrate our work in fully supported almost feature of IEEE 802.15.4. We are chosen
this idea to help in todays era to reduce global warming like issues.

8

Chapter 2
Literature Survey

Wireless Sensor networks consists of hundreds or thousands of low cost, low power and self-
organizing nodes which are highly distributed. Due to the reason that the sensor nodes are highly
distributed, there is a need of security in the network. Security is an important issue nowadays in
almost every network. There are some security issues and many attacks that need to be look around
and work upon. This paper discusses some of the issues and the denial of service attacks of security

Wireless Sensor Networks use numbers of sensors to send data from sender to base station.
Wireless Sensor Nodes are battery-powered devices. Power saving is always vital to increase the
lifetime of Wireless Sensor Networks. There are many Protocols has designed and proposed for WS
Networks to increase its performance in terms of throughput, network lifetime and security, An
efficient secured multi-hop routing technique for wireless sensor networks (ES-MHRT) was
proposed recently, which was a two contemporary hybrid Multi-Hop Routing Techniques, namely,
Flat Multi- Hop Routing Technique and Hierarchical Multi-Hop Routing Technique for providing trust
worthy and efficient routing in WS networks. It demonstrates the effective performance in terms of
Network Lifetime and superior connectivity. However, from the literature survey, it is observed that
in ES-MHRT the sender understand the status of delivery report from receiver only, which costs
more time to understand the reliable route. Thus Sender couldnt forward the data in fast manner,
which affects the Network Performance in terms of Throughput and Bandwidth Utilization. This is
the major issue. To address this issue, this project work is planned to design an efficient Distributed
Monitoring System, which will help the ES-MHRT to push more volume of Data with Secured Route.

The study of Wireless Sensor Network (WSN) is considered to be one of the most challenging issues
of recent research in the field of electronic communication as well as computer application. One of
the major problems with the wireless communication sensors reflects an issue related to the high
energy consumption against marginal performance in terms of output. In this paper, it has been
attempted to give an overview of the energy consumption related issues and suggest some
9

possibilities for improvement of the WSN in terms of optimized output. Power source in WSN often
consists of a battery with a limited energy budget. It could be impossible or inconvenient to recharge
the battery, because nodes may be deployed in a hostile or unpractical environment. Therefore,
energy conservation is a key issue in the design of systems based on wireless sensor networks.


WSN is a kind of MANET, sometimes some existing routing protocols for ad hoc network are used
directly in WSN. However, the difference between MANET and WSN leads to routing requirements
for the two are also quite different in some aspects.
Data are collected from multiple data sources to a data recipient or terminal in WSN, rather than
communication between any pair of nodes in MANET.

Because the data being collected by sensor nodes is related to common phenomena, the data
packets being communicated in WSN is likely to be redundant.

In most scenarios nodes in WSN move slowly. This is not like MANET which has highly dynamic
network topology generally.

As mentioned above, energy is more precious and limited in WSN than MANET. Because it has
been very difficult to advance battery technology recently, energy efficiency should be considered
one of the most critical issues not only on the aspect of underlying hardware architectures but also
upper communication protocols by researchers of WSN.

For these reasons many existing routing protocols proposed for MANETs are not suitable to WSNs. Recently
some routing protocols specialized for WSN have been developed. There are two categories in routing
protocols for WSN. One is data centric routing; the other is hierarchical routing.
Multi Hop Leach Routing Strategy Multi hop LEACH routing strategy is based on single hop LEACH
routing protocol, usually LEACH protocol transmits compressed data from cluster heads to base
station directly. Basically there are two approaches to transmit data from sensor node to base station:
10

Single hop or direct transmission. Multi-hop or minimum transmission Single and multi-hop are
shown in following figure.


Fig 2.1 Multi-Hop Leach Routing Strategy










11

Chapter 3
Problem statement
In our problem, a set of source nodes generate data samples that must be delivered to the Mobile Base
station (MBS). Our objective is to find a Local Base Station (LBS) in each clusters of nodes and with the help
of the Ant Colony Optimization (ACO), we find the shortest path within the cluster and then between the
clusters. The LBSs cache the data originated from various source nodes and that send information to the
Base Station via short-range transmissions when it arrives.
The total energy dissipation incurred by the network to transmit the information from sources nodes to the
LBSs should be minimized under the constraint that all information must be delivered to the MBS through the
shortest path. The network has the ability to identify any malicious node then it will have the ability to discard
that node from the network.
3.1 Objective:
To design and implement a network that Improve Energy-Efficiency & Performance of Wireless Sensor
Network having Mobile Base Station by Ant Colony Optimization algorithm. So that effective utilization of the
energy of the nodes can be done.
3.2 Related Work:
We have seen that cluster members can randomly form cluster heads within the groups. This can be
extended to forming hierarchical clusters. Here the cluster heads communicate with the super cluster heads,
i.e. the cluster heads of the above hierarchy and so on, towards the base station. Based on this many
hierarchical algorithm has introduced and these are:
LEACH : Low-Energy Adaptive Clustering Hierarchy
TL-LEACH : Two-Level Hierarchy LEAC

Basically there are two approaches to transmit data from sensor node to base station:
Single hop or direct transmission.
Multi hop or minimum transmission.
12


Multi hop transmission consumes less energy than single hop.
In current scenario the WSN system has energy dissipation problem, as it would be impossible to recharge
the battery of nodes, because nodes may be deployed in a hostile or unpractical environment. And also
there is possibility that a system in which central base system is mobile. So, we need a system where we
can minimize the power dissipation and better connectivity in moving base station environment when the
location of the Mobile Base Station changes, according to that position of the Local Base Station location
also changes to find the effective path.
3.3 Scope:
This algorithm works efficiently in Wireless Sensor Network and improves its performance. It can be
implemented to the various areas where it could be impossible or inconvenient to recharge the battery,
because nodes may be deployed in a hostile or unpractical environment.
The multi- level clustering with dynamic local base station provide a better energy utilization and hop
connectivity with the Base Station. Through multi-level clustering and Ant Colony Optimization (ACO)
algorithm for determining the shortest path between the nodes for data transfer to a mobile base station.









13

Chapter 4
Proposed Work done
In current scenario the WSN system has energy dissipation problem, as it would be impossible to recharge
the battery of nodes, because nodes may be deployed in a hostile or unpractical environment. And also
there is possibility that a system in which central base system is mobile. So, we need a system where we
can minimize the power dissipation and better connectivity in moving base station environment when the
location of the Mobile Base Station changes, according to that position of the Local Base Station location
also changes to find the effective path.
In our problem, a set of source nodes generate data samples that must be delivered to the Base
station.
Our objective is to find a Shortest Path in each clusters of nodes and with the help of the Ant
Colony Optimization (ACO), we find the shortest path within the cluster and then between the
clusters.
The total energy dissipation incurred by the network to transmit the information from sources nodes
to sink node should be minimized.
The network has the ability to create a new shortest path between source and sink node in case of
any malicious node (obstacle) occurs in old shortest path.

4.1 ACO Algorithm:
The ACO algorithm is stated below:

1- Ants originate from the nest cell and travel to neighboring cells randomly.
2- When an ant comes across a food cell, it returns to the nest, leaving a pheromone behind on
every cell through which it passes.
3- As ants discover a cell containing a pheromone trail, they are more likely to follow it and find the
food.
4- Pheromones evaporate over time. Longer paths require more traversal time, so they deteriorate
more rapidly than shorter paths.
14

4.2 Working Platform:
4.2.1 Java:-
Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now
a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java
platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer
low-level facilities. Java applications are typically compiled to byte code (class file) that can run on any Java
Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-
based, object-oriented language that is specifically designed to have as few implementation dependencies
as possible. It is intended to let application developers "write once, run anywhere". Java is currently one of
the most popular programming languages in use, and is widely used from application software to web
applications.

The original and reference implementation Java compilers, virtual machines, and class libraries were
developed by Sun from 1995.

History
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. Java
was originally designed for interactive television, but it was too advanced. The language was initially called
Oak after an oak tree that stood outside Gosling's office; it went by the name Green later, and was later
renamed Java, from a list of random words. Gosling aimed to implement a virtual machine and a language
that had a familiar C/C++ style of notation.
Sun Microsystems released the first public implementation as Java 1.0 in 1995. It promised "Write Once, Run
anywhere" (WORA), providing no-cost run-times on popular platforms. Fairly secure and featuring
configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated
the ability to run Java applets within web pages, and Java quickly became popular. With the advent of Java
2 (released initially as J2SE 1.2 in December 19981999), new versions had multiple configurations built for
different types of platforms. For example, J2EE targeted enterprise applications and the greatly stripped-
15

down version J2ME for mobile applications (Mobile Java). J2SE designated the Standard Edition. In 2006,
for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.
Sun make most of its Java implementations available without charge, despite their proprietary software
status. Sun generated revenue from Java through the selling of licenses for specialized products such as the
Java Enterprise System. Sun distinguishes between its Software Development Kit (SDK) and Runtime
Environment (JRE) (a subset of the SDK); the primary distinction involves the JRE's lack of the compiler,
utility programs, and header files.
On November 13, 2006, Sun released much of Java as open source software under the terms of the GNU
General Public License (GPL). On May 8, 2007, Sun finished the process, making all of Java's core code
available under free software/open-source distribution terms, aside from a small portion of code to which Sun
did not hold the copyright.
Following Oracle Corporation's acquisition of Sun Microsystems in 2009-2010, Oracle has described itself as
the "steward of Java technology with a relentless commitment to fostering a community of participation and
transparency".
Characteristics:-
Simple
Object oriented
Distributed
Interpreted
Robust
Secure
Architecture neutral
Portable
High performance
Multithreaded
With most programming languages, you either compile or interpret a program so that you can run it on your
computer. The Java programming language is unusual in that a program is both compiled and interpreted.
With the compiler, first you translate a program into an intermediate language called Java byte codes the
platform-independent codes interpreted by the interpreter on the Java platform. The interpreter parses and
16

runs each Java byte code instruction on the computer. Compilation happens just once; interpretation occurs
each time the program is executed. The following figure illustrates how this works.







Figure 4.1: Java programming steps



You can think of Java byte codes as the machine code instructions for the Java Virtual Machine (Java VM).
Every Java interpreter, whether it's a development tool or a Web browser that can run applets, is an
implementation of the Java VM.

Java byte codes help make "write once, run anywhere" possible. You can compile your program into byte
codes on any platform that has a Java compiler. The byte codes can then be run on any implementation of
the Java VM. That means that as long as a computer has a Java VM, the same program written in the Java
programming language can run on Windows 2000, a Solaris workstation, or on an iMac.












Figure 4.2: write once run everywhere


17

The Java Platform

A platform is the hardware or software environment in which a program runs. We've already mentioned some
of the most popular platforms like Windows 2000, Linux, Solaris, and Mac OS. Most platforms can be
described as a combination of the operating system and hardware. The Java platform differs from most other
platforms in that it's a software-only platform that runs on top of other hardware-based platforms.

The Java platform has two components:

The Java Virtual Machine (Java VM)
The Java Application Programming Interface (Java API)

Java Virtual Machine is standardized hypothetical computer, which is emulated inside our computer by a
program. It is base of Java platform and is ported onto various hardware-based platforms.
The Java API is a large collection of ready-made software components that provide many useful capabilities,
such as graphical user interface (GUI) widgets. The Java API is grouped into libraries of related classes and
interfaces; these libraries are known as packages.
The following figure depicts a program that's running on the Java platform. As the figure shows, the Java API
and the virtual machine insulate the program from the hardware.







Figure 4.3 Java API






18

What Can Java Technology Do?

The most common types of programs written in the Java programming language are applets and applications.
If you've accessed the Web, you're probably already familiar with applets. An applet is a program that adheres
to certain conventions that allow it to run within a Java-enabled browser.
However, the Java programming language is not just for writing cute, entertaining applets for the Web. The
general-purpose, high-level Java programming language is also a powerful software platform. Using the
generous API, you can write many types of programs.
An application is a standalone program that runs directly on the Java platform. A special kind of application
known as a server serves and supports clients on a network. Examples of servers are Web servers, proxy
servers, mail servers, and print servers. Another specialized program is a servlet. A servlet can almost be
thought of as an applet that runs on the server side. Java Servlets are a popular choice for building interactive
web applications, replacing the use of CGI scripts. Servlets are similar to applets in that they are runtime
extensions of applications. Instead of working in browsers, though, servlets run within Java Web servers,
configuring or tailoring the server.

AWT and Swing:
The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing, graphics, and user-
interface widget toolkit. The AWT is part of the Java Foundation Classes (JFC) the standard API for
providing a graphical user interface (GUI) for a Java program. AWT is also the GUI toolkit for a number
of Java ME profiles. For example, Connected Device Configuration profiles require Java runtimes on mobile
telephones to support AWT.
As the AWT is a bridge to the underlying native user-interface, its implementation on a new operating
system may involve a lot of work, especially if it involves any of the AWT GUI widgets, because each of them
requires that its native peers be developed from scratch.
Swing is the primary Java GUI widget toolkit. It is part of Oracle's Java Foundation Classes (JFC)
an API for providing a graphical user interface (GUI) for Java programs.
Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract
Window Toolkit (AWT). Swing provides a native look and feel that emulates the look and feel of several
platforms, and also supports a pluggable look and feel that allows applications to have a look and feel
19

unrelated to the underlying platform. It has more powerful and flexible components than AWT. In addition to
familiar components such as buttons, check boxes and labels, Swing provides several advanced components
such as tabbed panel, scroll panes, trees, tables, and lists.
Unlike AWT components, Swing components are not implemented by platform-specific code. Instead they
are written entirely in Java and therefore are platform-independent. The term "lightweight" is used to describe
such an element.
Swing is a platform-independent, Model-View-Controller GUI framework for Java, which follows a single-
threaded programming model. Additionally, this framework provides a layer of abstraction between the code
structure and graphic presentation of a Swing-based GUI.
Swing is platform-independent because it is completely written in Java. Complete documentation for all
Swing classes can be found in the Java API Guide.
Swing is a highly modular-based architecture, which allows for the "plugging" of various custom
implementations of specified framework interfaces: Users can provide their own custom implementation(s)
of these components to override the default implementations using Java's inheritance mechanism.
Swing is a component-based framework, whose components are all ultimately derived from
the javax.swing.JComponent class. Swing objects asynchronously fire events, have bound properties, and
respond to a documented set of methods specific to the component. Swing components are Java
Beans components, compliant with the Java Beans Component Architecture specifications

Java Applet:
A Java applet is a small application written in Java and delivered to users in the form of bytecode. The user
launches the Java applet from a web page and it is then executed within a Java Virtual Machine (JVM) in
a process separate from the web browser itself. A Java applet can appear in a frame of the web page, a new
application window, Sun's Applet Viewer or a stand-alone tool for testing applets. Java applets were
introduced in the first version of the Java language in 1995.
Java applets can be written in any programming language that compiles to Java bytecode. They are usually
written in Java but other languages. Java applets run at very fast speeds comparable to, but generally slower
than, other compiled languages such as C++.
20

Every applet is an extension of the java.applet.Applet class. The base Applet class provides methods that a
derived Applet class may call to obtain information and services from the browser context.
Applets are used to provide interactive features to web applications that cannot be provided by HTML alone.
They can capture mouse input and also have controls like buttons or check boxes. In response to the user
action an applet can change the provided graphic content. This makes applets well suitable for
demonstration, visualization and teaching. There are online applet collections for studying various subjects,
from physics to heart physiology.
An applet can also be a text area only, providing, for instance, a cross platform command-line interface to
some remote system. If needed, an applet can leave the dedicated area and run as a separate window.
However, applets have very little control over web page content outside the applet dedicated area, so they
are less useful for improving the site appearance in general (while applets like news
tickers or WYSIWYG editors are also known). Applets can also play media in formats that are not natively
supported by the browser
HTML pages may embed parameters that are passed to the applet. Hence the same applet may appear
differently depending on the parameters that were passed.
As applets were available before CSS and DHTML were standard, they were also widely used for trivial
effects like rollover navigation buttons. Heavily criticized, this usage is now declining. There are some
important differences between an applet and a standalone Java application, including the following:
An applet is a Java class that extends the java.applet.Applet class.
A main () method is not invoked on an applet, and an applet class will not define main ().
Applets are designed to be embedded within an HTML page.
When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's
machine.
A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a separate
runtime environment.
21

The JVM on the user's machine creates an instance of the applet class and invokes various methods during
the applet's lifetime.
Applets have strict security rules that are enforced by the Web browser. The security of an applet is often
referred to as sandbox security, comparing the applet to a child playing in a sandbox with various rules that
must be followed.
Other classes that the applet needs can be downloaded in a single Java Archive (JAR) file.
Life Cycle of an Applet:
Four methods in the Applet class give you the framework on which you build any serious applet:
init: This method is intended for whatever initialization is needed for your applet. It is called after the pram
tags inside the applet tag have been processed.
Start: This method is automatically called after the browser calls the init method. It is also called whenever
the user returns to the page containing the applet after having gone off to other pages.
Stop: This method is automatically called when the user moves off the page on which the applet sits. It can,
therefore, be called repeatedly in the same applet.
Destroy: This method is only called when the browser shuts down normally. Because applets are meant to
live on an HTML page, you should not normally leave resources behind after a user leaves the page that
contains the applet.
Paint: Invoked immediately after the start() method, and also any time the applet needs to repaint itself in
the browser. The paint() method is actually inherited from the java.awt.


4.2.2 IDE: NetBeans
NetBeans is an integrated development environment (IDE) for developing primarily with Java, but also with
other languages, in particular PHP, C/C++, and HTML5. It is also an application platform framework for Java
desktop applications and others.
The NetBeans IDE is written in Java and can run on Windows, OS X, Linux, Solaris and other platforms
supporting a compatibleJVM.
22

The NetBeans Platform allows applications to be developed from a set of modular software
components called modules. Applications based on the NetBeans Platform (including the NetBeans IDE
itself) can be extended by third party developers.
NetBeans began in 1996 as Xelfi (word play on Delphi), a Java IDE student project under the guidance of
the Faculty of Mathematics and Physics at Charles University in Prague. In 1997 Roman Stank formed a
company around the project and produced commercial versions of the NetBeans IDE until it was bought
by Sun Microsystems in 1999. Sun open-sourced the NetBeans IDE in June of the following year. Since then,
the NetBeans community has continued to grow. In 2010, Sun (and thus NetBeans) was acquired by Oracle.
Framework for simplifying the development of Java Swing desktop applications. The NetBeans IDE bundle
for Java SE contains what is needed to start developing NetBeans plugins and NetBeans Platform based
applications; no additional SDK is required.
Applications can install modules dynamically. Any application can include the Update Center module to allow
users of the application to download digitally signed upgrades and new features directly into the running
application. Reinstalling an upgrade or a new release does not force users to download the entire application
again.
The platform offers reusable services common to desktop applications, allowing developers to focus on the
logic specific to their application.
NetBeans IDE is an open-source integrated development environment. NetBeans IDE supports development
of all Java application types (Java SE (including JavaFX), Java ME, web, EJB and mobile applications) out
of the box. Among other features are an Ant-based project system, Maven support, refactorings, version
control (supporting CVS, Subversion, Git, Mercurial and Clearcase).
Modularity: All the functions of the IDE are provided by modules. Each module provides a well defined
function, such as support for theJava language, editing, or support for the CVS versioning system, and SVN.
NetBeans contains all the modules needed for Java development in a single download, allowing the user to
start working immediately. Modules also allow NetBeans to be extended. New features, such as support for
other programming languages, can be added by installing additional modules. For instance, Sun Studio, Sun
Java Studio Enterprise, and Sun Java Studio Creator from Sun Microsystems are all based on the NetBeans
IDE.

23

Chapter 5
High Level Diagram & Low Level Diagram

5.1 UML Diagrams (Unified Modeling Language):
The Unified Modeling Language allows the software engineer to express an analysis model using the
modeling notation that is governed by a set of syntactic semantic and pragmatic rules.
User Model View:
i. This view represents the system from the users perspective.
ii. The analysis representation describes a usage scenario from the end-users perspective.
Structural model view:
i. In this model the data and functionality are arrived from inside the system.
ii. This model view models the static structures.
Behavioral Model View:
It represents the dynamic of behavioral as parts of the system, depicting the interactions of collection between
various structural elements described in the user model and structural model view.
Implementation Model View:
In this the structural and behavioral as parts of the system are represented as they are to be built.
Environmental Model View:
In this the structural and behavioral aspects of the environment in which the system is to be implemented are
represented.



24

5.2 Use case Diagram:
Use Case diagrams identify the functionality provided by the system (use cases), the users who interact with
the system (actors), and the association between the users and the functionality. Use Cases are used in the
Analysis phase of software development to articulate the high-level requirements of the system. The primary
goals of Use Case diagrams include:
Providing a high-level view of what the system does identifying the users ("actors") of the system
Determining areas needing human-computer interfaces Use Cases extend beyond pictorial diagrams. In fact,
text-based use case descriptions are often used to supplement diagrams, and explore use case functionality
in more detail.
Graphical Notation the basic components of Use Case diagrams are the Actor, the Use Case, and the
Association. Actor an Actor, as mentioned, is a user of the system, and is depicted using a stick figure. The
role of the user is written beneath the icon. Actors are not limited to humans. If a system communicates with
another application, and expects input or delivers output, then that application can also be considered an
actor.
A Use Case is functionality provided by the system, Use Cases are depicted with an ellipse. The name of the
use case is written within the ellipse.
Association:
Associations are used to link Actors with Use Cases, and indicate that an Actor participates in the Use Case
in some form. Associations are depicted by a line connecting the Actor and the Use Case.
Generalization relationships:
In UML modeling, a generalization relationship is a relationship in which one model element (the child) is
based on another model element (the parent). Generalization relationships are used in class, component,
deployment, and use-case diagrams to indicate that the child receives all of the attributes, operations, and
relationships that are defined in the parent.
Graphical Notation:
The elements on a Class diagram are classes and the relationships between them. Class Classes are the
building blocks in object-oriented programming. A Class is depicted using a rectangle divided into three
25

sections. The top section is the name of the Class. The middle section defines the properties of the Class.
The bottom section lists the methods of the class. Association An Association is a generic relationship
between two classes, and is modeled by a line connecting the two classes. This line can be qualified with the
type of relationship, and can also feature Multiplicity rules (e.g. one-to-one, one-to-many, many-to-many)or
the relationship Composition If a class cannot exist by itself, and instead must be a member of another class,
then that class has a Composition relationship with the containing class. A Composition relationship is
indicated by a line with a filled diamond.
Dependency When a class uses another class, perhaps as a member variable or a parameter, and so
"depends" on that class, a Dependency relationship is formed. A Dependency relationship is indicated by a
dotted arrow. Aggregation Aggregations indicate a whole-part relationship, and are known as "has-a"
relationships. An Aggregation relationship is indicated by a line with a hollow diamond.
A Generalization relationship is the equivalent of an inheritance relationship in object-oriented terms (an "is-
a" relationship). A Generalization relationship is indicated by an arrow with a hollow arrowhead pointing to
the base, or "parent", class. Sequence diagram A sequence diagram shows, as parallel vertical lines
(lifelines), different processes or objects that live simultaneously, and, as horizontal arrows, the messages
exchanged between them, in the order in which they occur. This allows the specification of simple runtime
scenarios in a graphical manner.

5.3 Class Diagram:
A class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes
the structure of a system by showing the system's classes, their attributes, operations (or methods), and the
relationships among objects.
Class diagrams identify the class structure of a system, including the properties and methods of each class.
Also depicted are the various relationships that can exist between classes, such as an inheritance
relationship. The Class diagram is one of the most widely used diagrams from the UML specification. Part of
the popularity of Class diagrams stems from the fact that many CASE tools, such as Rational XDE, will auto-
generate code in a variety of languages, These tools can synchronize models and code, reducing your
workload, and can also generate Class diagrams from object-oriented code, for those "code-then-design"
maintenance projects .
26


Fig 5.1 Class Diagram of Topology in WSN
27



Fig. 5.2 Class Diagram of Cluster in WSN








28

5.4 Sequence Diagram:
A sequence diagram is a kind of interaction diagram that shows how processes operate with one another
and in what order. It is a construct of a Message Sequence Chart. A sequence diagram shows object
interactions arranged in time sequence. It depicts the objects and classes involved in the scenario and the
sequence of messages exchanged between the objects needed to carry out the functionality of the scenario.
Sequence diagrams are typically associated with use case realizations in the Logical View of the system
under development. Sequence diagrams are sometimes called event diagrams, event scenarios.
A sequence diagram shows, as parallel vertical lines (lifelines), different processes or objects that live
simultaneously, and, as horizontal arrows, the messages exchanged between them, in the order in which
they occur. This allows the specification of simple runtime scenarios in a graphical manner.

Fig. 5.3 Sequence Diagram of WSN




29

5.5 State Transition Diagram:
A state diagram is a type of diagram used in computer science and related fields to describe the behavior of
systems. State diagrams require that the system described is composed of a finite number of states
sometimes, this is indeed the case, while at other times this is a reasonable abstraction. Many forms of state
diagrams exist, which differ slightly and have different semantics.
State transition diagrams have been used right from the beginning in object-oriented modeling. The basic
idea is to define a machine that has a number of states (hence the term finite state machine). The machine
receives events from the outside world, and each event can cause the machine to transition from one state
to another. For an example, take a look at figure 1. Here the machine is a bottle in a bottling plant. It begins
in the empty state. In that state it can receive squirt events. If the squirt event causes the bottle to become
full, then it transitions to the full state, otherwise it stays in the empty state (indicated by the transition back
to its own state). When in the full state the cap event will cause it to transition to the sealed state. The diagram
indicates that a full bottle does not receive squirt events, and that an empty bottle does not receive cap
events. Thus you can get a good sense of what events should occur, and what effect they can have on the
object.
30


Fig. 5.4 State Transition Diagram of Node
31



Fig. 5.5 State Transition Diagram of Node Routing








32

5.6 Collaboration Diagram:
Like sequence diagrams, collaboration diagrams are also interaction diagrams. Collaborations the times that
messages are sent. A collaboration diagram, also called a communication diagram or interaction diagram, is
an illustration of the relationships and interactions among software objects in the Unified Modeling Language
(UML).

Fig. 5.6 Collaboration Diagram of Message Transmission






33

5.7 Activity Diagram:
Activity diagrams are graphical representations of workflows of stepwise activities and actions with support
for choice, iteration and concurrency. In the unified activity diagrams can be used to describe the business
and operational step-by-step workflows of components in a system.
An activity diagram shows the overall flow of control.




Fig. 5.7 Activity diagrams of Message Transmission in WSN


34

Chapter 6

ANT COLONY OPTIMIZATION

Ant Colony Optimization (ACO) is a population-based metaheuristic introduced by Marco Dorigo in 1992. As
the name suggests the technique was inspired by the behaviour of real ants. Ant colonies are able to find
the shortest path between their nest and a food source just by depositing and reacting to pheromones while
they are exploring their environment.

6.1 The Double Bridge Experiment:

Ants choose one of the branches randomly in the beginning of the experiment since pheromone has been
deposited on neither of them yet. Of course, the ants that have chosen the shorter branch reach the food
source before the ants on the longer branch and are therefore also able to deposit pheromone onto the
crossing in front of the food source first. As a consequence, these ants will also be more likely to take the
short branch when they return to the nest and will also be the first ants to deposit pheromone onto the crossing
in front of the nest enforcing the bias towards the short branch. This autocatalytic effect also influences the
behaviour of the ants in the experiment consisting of two branches of equal length. The difference is that in
this case the system converges to one of the branches because one of the branches is used by more ants
incidentally in the beginning of the experiment.

6.2 Ant system:
Ant System (AS) was one of the first ant algorithms. It is inferior to all other variants of ACO variants.
Nevertheless, it proved the concept of ant colony optimization and builds the foundation of all other ant
algorithms.

Pheromone Trail Initialization:
For the TSP the pheromone trails are initialized according to Equation where m is the number of ants and
Cnn is the length of the round-trip obtained by applying the nearest-neighbour heuristic. This heuristic
randomly selects a city and then creates a round-trip by always moving to the nearest city.

35

6.2.1 Elitist Ant System:
It extends the pheromone update mechanism of Ant System with a so-called elitist ant which is the ant that
has found the best solution so far. This ant is allowed to deposit additional pheromone (weighted with a
parameter e) on the edges of the best-so-far solution. The idea behind this is to enforce a stronger bias
towards those edges.

6.2.2 Rank-Based Ant System:
Rank-Based Ant System is another extension of Ant System. As in Elitist Ant System the ant with the best-
so-far solution may update the pheromone trails. This additional pheromone is multiplied by a parameter w.
additionally, the iteration-best w- 1 ants deposit pheromone in every iteration. Their update is multiplied by
w- r where r is their rank among all ants. Rank-Based Ant System performs slightly better than EAS and
significantly better than Ant System.

6.2.3 Max-Min Ant System:
Unlike the other variants discussed so far Max-Min Ant System allows only the iteration-best or the best-so-
far ant to update the pheromone trails. For example, an implementation could allow the iteration-best ant to
deposit pheromone in the even iterations while the best-so-far ant deposits pheromone in the odd iterations.
The ratio of these updates determines whether the algorithm tends to be explorative or more focused on the
search space around the best solution found so far.

6.2.4 Ant Colony System:
It differs in the way solutions are constructed and pheromone trails are updated. ACS even introduces a new
kind of pheromone update that removes pheromone during the construction phase of the algorithm. An Ant
in ACS decides where to move next using a so-called pseudorandom proportional rule.





36

Chapter 7
Screen Shot of Working Code

Fig 7.1 Initialization Phase
Fig 7.2
37



Fig 7.3


Fig 7.4
38


Fig 7.5


Fig 7.6

39

Chapter 8
Conclusion
A significant amount of energy saving will be achieved in wireless sensor networks via short-range
communications with Multi hop routing strategy with a mobile base station.
Reduced number of nodes for data transmission from source to the base station and thus reducing
total energy consumption.
With the help of Ant Colony Optimization algorithm we find the shortest path and that help to
achieve energy efficiency and better performance.
Network will have the ability to identify any malicious node and then to discard that node from the
network.







REFERENCES


[1]. David Johnson and David Maltz, Dynamic Source Routing in ad hoc wireless
networks, Computer Communications Review - Proceedings of SICOMM, August 1996.

[2]. Ant Routing Systen- a routing algorithm based on Ant algorithm applied to simulated
network, Mikkel Bundgard, Troles C. Damgard, W. winther, 2002.

[3]. Artificial AAnts as a computational intelligence technique, Macro Dorigo, Mauro
Birattari, thomos stutzle, published by IRIDIA, 2006.

[4]. Saleh Ali K. Al Omari and Putra Sumari, An overview of Mobile Ad Hoc Networks
for the existing protocols and applications, International Journal on applications of graph
theory in wireless ad hoc networks and sensor networks, vol. 2, no. 1, March 2010.

[5]. N. Sumathi and Dr. Antony Selvadoss Thanamani, Evaluation of energy efficient reactive
routing protocols in QoS enabled routing for MANETs, International Journal of Computer
Applications, vol.14, 2 January 2011.

[6]. Annapurna P Patil, Dr. K. Rajani kanth, Bathey Sharanya, M. P. Dinesh Kumar and
J.Malavika Design of an energy efficient routing protocol for MANETs based on AODV,
IJCSI International Journal of Computer Science Issues, vol. 8, no. 1, Issue 4, July 2011.

[7]. Abdusy Syarif and Riri Fitri Sari, Performance analysis of AODV-UI routing
protocol with energy consumption improvement under mobility models in hybrid ad hoc
network, International Journal on Computer Science and Engineering, vol. 3, no. 7, July
2011.

[8]. Adesign Approach in Data Collection in Wireless Sensor Network with mobile Base
Station, D.B Shanumugam, G. Anitha, K. Vinod kumar, C. Karthi, M.Hema, Dec 2012.

[9]. Dr. Sanjay Sharma and Pushpinder Singh Patheja, Improving AODV routing
protocol with Priority and Power Efficiency in Mobile Ad hoc WiMAX
Network,International Journal of Computer Technology and Electronics Engineering
(IJCTEE), pp. 87-93, vol. 2, Issue 1, February2012.

[10]. Review on security issues and attacks in Wireless Sensor Network. Ashima Singal,
Ratika Sachdeva, published by IEEE 2013.

[11]. Energy efficient approach for Wireless Sensor Network, RAjan kumar, Naveen Prakash,
Published by IEEE June 2013.

You might also like