Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BELL MAN FORD
- import java.uti1.Scanner;
- public class p8
- private int d[];
- private int num_ver;
- public static final int max_value=999;
- public p8(int num_ver)
- this.num_verwum_ver;
- d=new int [num_ver+1];
- public void be11manfordeva1uation(int source,int a[][])
- for(int node=1; node<=num_ver; node++)
- d[node]=max_va1ue;
- d[source]=0;
- for(int node=1; node<=num_ver-1; node++)
- for(int sn=1;sn<=num_ver;sn++)
- for(int dn=1;dn<=num_ver;dn++)
- if(a[sn][dn]!=max_value)
- if(d[dn]>d[sn]+a[sn][dn])
- d[dn]=d[sn]+a[sn][dn];
- for(int sn=1;sn<=num_ver;sn++)
- for(int dn=1;dn<wum_ver;dn++)
- if(a[sn][dn]!=max_value)
- ( if(d[dn]>d[sn]+a[sn][dn])
- System.out.println("the graph contains -ve edge cycle");
- for(int vertex=1;vertex<=num_ver;vertex++)
- System.out.print1n("disten of source"+source+"to"+vertex+"is"+d[vertex]);
- public static void main(String args[])
- int num_ver=0;
- int source;
- Scanner scannei=new Scanner(System.in);
- System.out.print1n("enter the num of vertices");
- num_ver=scanner.nextInt();
- int a[][]=new int [num_ver+1] [num_ver+1];
- System.out.print1n(”enter the adjacency matrix:");
- for(int sn=1;sn<=num_ver;sn++)
- for(int dn=1;dn<=num_ver;dn++)
- ( a[sn][dn]=scanner.nextInt();
- if(sn-dn)
- ( a[sn][dn]=1;
- continue;
- if(a[sn][dn]==0)
- a[sn][dn]=max_va1ue;
- System.out.println("enter the source vertex");
- source=scanner.nextInt();
- p8 b=new p8(num_ver);
- b.bellmanfordeva1uation(source,a);
- scanner.close();
- POINT TO POINT set ns [new Simulator]
- set nf [open prog1.nam w]
- $ns namtrace-all $nf
- set nd [open prog1.tr w]
- $ns trace-all $nd
- proc finish { } {
- global ns nf nd
- $ns flush-trace
- close $nf
- close $nd
- exec nam prog1.nam &
- exit 0
- }
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- $ns duplex-link $n0 $n1 1Mb 10ms DropTail
- $ns duplex-link $n1 $n2 512kb 10ms DropTail
- $ns queue-limit $n1 $n2 10
- set udp0 [new Agent/UDP]
- $ns attach-agent $n0 $udp0
- set cbr0 [new Application/Traffic/CBR]
- $cbr0 set packetSize_ 500
- $cbr0 set interval_ 0.005
- $cbr0 attach-agent $udp0
- set sink [new Agent/Null]
- $ns attach-agent $n2 $sink
- $ns connect $udp0 $sink
- $ns at 0.2 "$cbr0 start"
- CN LAB MANUAL
- Dept. of ISE, RNSIT. Page 16
- $ns at 4.5 "$cbr0 stop"
- $ns at 5.0 "finish"
- $ns run
- Step2: Open text editor, type the below program and save with extention .awk (prog1.awk)
- BEGIN {
- dcount = 0;
- rcount = 0;
- }
- {
- event = $1;
- if(event == "d")
- {
- dcount++;
- }
- if(event == "r")
- {
- rcount++;
- }
- }
- END {
- printf("The no.of packets dropped : %d\n ",dcount);
- printf("The no.of packets recieved : %d\n ",rcount);
- }
- PING MSG set ns [new Simulator]
- set nf [open prog2.nam w]
- $ns namtrace-all $nf
- set nd [open prog2.tr w]
- $ns trace-all $nd
- proc finish {} {
- global ns nf nd
- $ns flush-trace
- close $nf
- close $nd
- exec nam prog2.nam &
- exit 0
- }
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set n5 [$ns node]
- set n6 [$ns node]
- $ns duplex-link $n1 $n0 1Mb 10ms DropTail
- $ns duplex-link $n2 $n0 1Mb 10ms DropTail
- $ns duplex-link $n3 $n0 1Mb 10ms DropTail
- $ns duplex-link $n4 $n0 1Mb 10ms DropTail
- $ns duplex-link $n5 $n0 1Mb 10ms DropTail
- $ns duplex-link $n6 $n0 1Mb 10ms DropTail
- Agent/Ping instproc recv {from rtt} {
- $self instvar node_
- puts "node [$node_ id] recieved ping answer from \
- $from with round-trip-time $rtt ms."
- }
- set p1 [new Agent/Ping]
- set p2 [new Agent/Ping]
- set p3 [new Agent/Ping]
- set p4 [new Agent/Ping]
- set p5 [new Agent/Ping]
- set p6 [new Agent/Ping]
- $ns attach-agent $n1 $p1
- $ns attach-agent $n2 $p2
- $ns attach-agent $n3 $p3
- $ns attach-agent $n4 $p4
- $ns attach-agent $n5 $p5
- $ns attach-agent $n6 $p6
- $ns queue-limit $n0 $n4 3
- $ns queue-limit $n0 $n5 2
- $ns queue-limit $n0 $n6 2
- $ns queue-limit $n0 $n3 2
- $ns queue-limit $n0 $n2 1
- $ns queue-limit $n0 $n1 2
- $ns connect $p1 $p4
- $ns connect $p2 $p5
- $ns connect $p3 $p6
- $ns connect $p6 $p3
- $ns at 0.2 "$p1 send"
- $ns at 0.4 "$p2 send"
- $ns at 0.6 "$p3 send"
- $ns at 1.0 "$p4 send"
- $ns at 1.2 "$p5 send"
- $ns at 1.4 "$p6 send"
- $ns at 2.0 "finish"
- $ns run
- Step2: Open text editor, type the below program and save with extention .awk (prog2.awk)
- BEGIN {
- count=0;
- }
- {
- event=$1;
- if(event=="d")
- {
- count++;
- }
- }
- END {
- printf("No of packets dropped : %d\n",count);
- }
- Source Code:
- import java.util.Scanner:
- public class p12
- {
- public static void main(String[] args) throws InterruptedException
- {
- Scanner in new Scanner(System.in);
- int n.incoming.outgoing.bs.s=0:
- {
- System.out.println("enter the bs outgoing rate, inputs, incoming size");
- bs in.nextInt():
- outgoing in.nextInt();
- n=in.nextInt():
- incoming in.nextInt();
- while(n!=0)
- {
- System.out.println("incoming size is"+incoming); if(incoming<=(bs-s))
- {
- s+ incoming:
- System.out.println("bucket buffer size is"+s+"out of"+bs);
- }
- else
- {
- System.out.println("packet lost="+(incoming-(bs-s)));
- sbs:
- System.out.println("bucket buffersize is"+s+"out of"+bs):
- }
- s--outgoing:
- {
- System.out.println("after outgoing="+s+"packet left out of"+bs+"in buffer");n--;
- Thread.sleep(3000):
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement