More Videos...
 

Ns2 code for genetic algorithm

Ns2 code for genetic algorithm

What is genetic algorithm:

Genetic Algorithm (GA) is an adaptive heuristic search algorithm which is based on the evolutionary ideas of natural selection and genetics.

The common techniques of the GAs are modeled to simulate processes in natural systems necessary for evolution.

Reason for genetic algorithm:

Implementation details:

This algorithm evolves the through three operators:

Genetic algorithms are a sub-field of:

Applications of genetic algorithms:

Advantages of GA:

Ns2 code for genetic algorithm:

Creating a new Simulator object

set ns [new Simulator]

set nf [open shot.nam w]

$ns namtrace-all $nf

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam shot.nam &

exit 0

set n0 [$ns node]

set n1 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 1

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]

$ns attach-agent $n1 $null0

$ns connect $udp0 $null0

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 1

$cbr1 attach-agent $udp1

set null1 [new Agent/Null]

$ns attach-agent $n0 $null1

$ns connect $udp1 $null1

for {set i 0} {$i < 10} {incr i} {

set q [expr $i%2]

if {$q==0} {

set a i

set b [expr $i+1]

$ns at a “$cbr0 start”

$ns at b “$cbr0 stop”

}

if {$q!=0} {

set a i

set b [expr $i+1]

$ns at a “$cbr1 start”

$ns at b “$cbr1 stop”

}

}

$ns at 10.0 “finish”

$ns run

List of Projects

Related Pages