Educational Blog: March 2015

Thursday 19 March 2015

How to put navigation bar and how to put posts on different pages in Blo...

Tuesday 17 March 2015

DSDV Protocol TCL Script

# A 100-node example for ad-hoc simulation with AODV

# 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)            CMUPriQueue    ;# 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)            3                        ;# number of mobilenodes
set val(rp)             DSDV                       ;# routing protocol
set val(x)              500                        ;# X dimension of topography
set val(y)              400                        ;# Y dimension of topography
set val(stop)           150                        ;# time of simulation end

#-------Event scheduler object creation--------#

set ns              [new Simulator]
#Creating trace file and nam file
set tracefd       [open dsr.tr w]
set windowVsTime2 [open win.tr w]
set namtrace      [open dsr.nam w]  

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes
        $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
                  
      for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]    
      }

# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 490.0
$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# 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";

}

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
exec nam dsr.nam &
exit 0
}


$ns run


Output

img1

img2

img3

img4

img5

img6

AODV Protocol TCL Script

# A 100-node example for ad-hoc simulation with AODV

# 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)            3                        ;# number of mobilenodes
set val(rp)             AODV                       ;# routing protocol
set val(x)              500                        ;# X dimension of topography
set val(y)              400                        ;# Y dimension of topography
set val(stop)           150                        ;# time of simulation end

#-------Event scheduler object creation--------#

set ns              [new Simulator]
#Creating trace file and nam file
set tracefd       [open dsr.tr w]
set windowVsTime2 [open win.tr w]
set namtrace      [open dsr.nam w]  

$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

# set up topography object
set topo       [new Topography]

$topo load_flatgrid $val(x) $val(y)

create-god $val(nn)

# configure the nodes
        $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
                  
      for {set i 0} {$i < $val(nn) } { incr i } {
            set node_($i) [$ns node]    
      }

# Provide initial location of mobilenodes
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 490.0
$node_(1) set Y_ 285.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 150.0
$node_(2) set Y_ 240.0
$node_(2) set Z_ 0.0

# Generation of movements
$ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0"
$ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0"
$ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0"

# Set a TCP connection between node_(0) and node_(1)
set tcp [new Agent/TCP/Newreno]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp
$ns attach-agent $node_(1) $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 10.0 "$ftp start"

# Printing the window size
proc plotWindow {tcpSource file} {
global ns
set time 0.01
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 10.1 "plotWindow $tcp $windowVsTime2"

# 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";
}

# ending nam and the simulation
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "stop"
$ns at 150.01 "puts \"end simulation\" ; $ns halt"
proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
exec nam dsr.nam &
exit 0
}


$ns run


Output

img1


img2

img3

img4

img5

img6

img7

img8

img9

Thursday 12 March 2015

HTML Form

<html>
<body>
<form>
ID No
<br />
<input type="text" maxlength="5">
<br />
<br />

Name<br />
<input type="text" size="20" value="Neeta Tadha" readonly="readonly"><br/>
<br />

Phone
<br/><input type="text" value="XXXX-XXXXXXX" disabled="disabled">
<br/>
<br />

Password
<br /><input type="password">
<br />
<br />

Gender
<br /><input type="radio" name="gender" value="M">Male
<input type="radio" name="gender" value="F" checked>Female
<br />
<br />

Language
<br /><input type="checkbox" checked>English
<input type="checkbox">Gujarati
<input type="checkbox">Hindi
<br />
<br />

Education

<select>
<option>Graduation</option>
<option selected>Post Graduation</option>
</select>
<br />
<br />

Address
<br />
<textarea rows="2" cols="30">Write Here....</textarea>
<br />
<br />

Image<br />
<input type="text">
<input type="file">

<br />
<br />

<input type="button" value="Button">
<input type="reset" value="Reset Form">
<input type="submit" value="Submit Form">

</form>
</body>
</html>


Output :

img1

Wednesday 11 March 2015

HTML Table

<html>
<body>
<center>Employee Data</center>
<table align="center"border=3>
<tr>
<td width="15%">No.</td>
<td width="40%">Name</td>
<td width="25%">Dept.</td>
<td width="20%" align="right">Salary</td>
</tr>
<tr>
<td>001</td>
<td>Name 1</td>
<td>Admin</td>
<td align="right">95,000</td>
</tr>
<tr>
<td>002</td>
<td>Name 2</td>
<td>Admin</td>
<td align="right">75,000</td>
</tr>
<tr>
<td>003</td>
<td>Name 3</td>
<td>HR</td>
<td align="right">50,000</td>
</tr>
<tr>
<td>004</td>
<td>Name 4</td>
<td>Accounts</td>
<td align="right">35,000</td>
</tr>
<tr>
<td>005</td>
<td>Name 5</td>
<td colspan=2 align="center">Retired</td>
</tr>
<tr>
<td>006</td>
<td>Name 6</td>
<td>Public Relations</td>
<td align="right">35,000</td>
</tr>
<tr>
<td colspan=3>Total Sal<br />(In INR)</td>
<td align="right" valign="bottom">290,000</td>
</tr>
</table>
</body>
</html>



From the above code, You will get output as shown below :

Output


img1

Tuesday 3 March 2015

Rabin Karp

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#define d 10
voidRabinKarpStringMatch(char *, char *, int);
void main()
{
char *Text, *Pattern;
int Number = 11; //Prime Number
clrscr();
printf("\nEnter Text String : ");
gets(Text);
printf("\nEnter Pattern String : ");
gets(Pattern);

RabinKarpStringMatch(Text,Pattern,Number);
getch();
}

voidRabinKarpStringMatch(char *Text, char *Pattern, int Number)
{
intM,N,h,P=0,T=0, TempT, TempP;
inti,j;
       M = strlen(Pattern);
       N = strlen(Text);
       h = (int)pow(d,M-1) % Number;
       for(i=0;i<M;i++)
       {
            P = ((d*P) + ((int)Pattern[i])) % Number;
            TempT = ((d*T) + ((int)Text[i]));
            T =  TempT % Number;
       }
      for(i=0;i<=N-M;i++)
 {
if(P==T)
{
for(j=0;j<M;j++)
if(Text[i+j] != Pattern[j])
break;
if(j == M)
printf("\nPattern Found at Position :  %d",i+1);
        }
TempT=((d*(T - Text[i]*h)) + ((int)Text[i+M]));
        T = TempT % Number;
if(T<0)
            T=T+Number;
      }
}

Divide and Conquer

#include<stdio.h>
 
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))

int tempmax, tempmin;

int* maxmin(const int list[], const int low, const int high, int max, int min)
{
    int mid,max1,min1;
    static int maxAndMin[2]; // to hold the max and min value of list
 
    if (low == high)
    {
        max = list[low];
        min = list[low];
    }          
    else if (low == high-1)
    {
        if (list[low] < list[high])
        {
            tempmax = getMax(tempmax, list[high]);
            tempmin = getMin(tempmin, list[low]);
        }
        else
        {
            tempmax = getMax(tempmax, list[low]);
            tempmin = getMin(tempmin, list[high]);
        }
    }
 
   else
   {
       mid = (low + high) / 2;
       max1 = list[mid+1];
       min1 = list[mid+1];
       maxmin(list, low, mid, max, min);
       maxmin(list, mid+1, high, max1, min1);
       tempmax = getMax(tempmax, max1);
       tempmin = getMin(tempmin, min1);
   }
 
    maxAndMin[0] = tempmax;
    maxAndMin[1] = tempmin;
    return maxAndMin;
}
 
int getMax(int first, int second)
{
    return first > second ? first : second;
}
 
int getMin(int  first, int second)
{
    return  first < second ?  first : second;
}
 
int main(void)
{
    int list[] = {10, 23, 24, 56, 67, 78, 90};
    int *values;
    int size = ARRAY_SIZE(list);
 
    tempmax = tempmin = list[0];
    values = maxmin(list, 0, size-1, list[0], list[0]);
 
    printf("The maximum value is = %2d \n", *values);
    printf("The minimum value is = %2d \n", *(values+1));
    return 0;
}