Advertisement
Coolcap5

Untitled

Jan 22nd, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.24 KB | Software | 0 0
  1. BELL MAN FORD                                          
  2.  
  3. import java.uti1.Scanner;
  4. public class p8
  5. private int d[];
  6. private int num_ver;
  7. public static final int max_value=999;
  8. public p8(int num_ver)
  9. this.num_verwum_ver;
  10. d=new int [num_ver+1];
  11. public void be11manfordeva1uation(int source,int a[][])
  12. for(int node=1; node<=num_ver; node++)
  13. d[node]=max_va1ue;
  14. d[source]=0;
  15. for(int node=1; node<=num_ver-1; node++)
  16. for(int sn=1;sn<=num_ver;sn++)
  17. for(int dn=1;dn<=num_ver;dn++)
  18. if(a[sn][dn]!=max_value)
  19. if(d[dn]>d[sn]+a[sn][dn])
  20. d[dn]=d[sn]+a[sn][dn];
  21. for(int sn=1;sn<=num_ver;sn++)
  22. for(int dn=1;dn<wum_ver;dn++)
  23. if(a[sn][dn]!=max_value)
  24. ( if(d[dn]>d[sn]+a[sn][dn])
  25. System.out.println("the graph contains -ve edge cycle");
  26. for(int vertex=1;vertex<=num_ver;vertex++)
  27. System.out.print1n("disten of source"+source+"to"+vertex+"is"+d[vertex]);
  28. public static void main(String args[])
  29. int num_ver=0;
  30. int source;
  31. Scanner scannei=new Scanner(System.in);
  32. System.out.print1n("enter the num of vertices");
  33. num_ver=scanner.nextInt();
  34. int a[][]=new int [num_ver+1] [num_ver+1];
  35. System.out.print1n(”enter the adjacency matrix:");
  36. for(int sn=1;sn<=num_ver;sn++)
  37. for(int dn=1;dn<=num_ver;dn++)
  38. ( a[sn][dn]=scanner.nextInt();
  39. if(sn-dn)
  40. ( a[sn][dn]=1;
  41. continue;
  42. if(a[sn][dn]==0)
  43. a[sn][dn]=max_va1ue;
  44. System.out.println("enter the source vertex");
  45. source=scanner.nextInt();
  46. p8 b=new p8(num_ver);
  47. b.bellmanfordeva1uation(source,a);
  48. scanner.close();
  49. POINT TO POINT                                          set ns [new Simulator]
  50. set nf [open prog1.nam w]
  51. $ns namtrace-all $nf
  52. set nd [open prog1.tr w]
  53. $ns trace-all $nd
  54. proc finish { } {
  55. global ns nf nd
  56. $ns flush-trace
  57. close $nf
  58. close $nd
  59. exec nam prog1.nam &
  60. exit 0
  61. }
  62. set n0 [$ns node]
  63. set n1 [$ns node]
  64. set n2 [$ns node]
  65. $ns duplex-link $n0 $n1 1Mb 10ms DropTail
  66. $ns duplex-link $n1 $n2 512kb 10ms DropTail
  67. $ns queue-limit $n1 $n2 10
  68. set udp0 [new Agent/UDP]
  69. $ns attach-agent $n0 $udp0
  70. set cbr0 [new Application/Traffic/CBR]
  71. $cbr0 set packetSize_ 500
  72. $cbr0 set interval_ 0.005
  73. $cbr0 attach-agent $udp0
  74. set sink [new Agent/Null]
  75. $ns attach-agent $n2 $sink
  76. $ns connect $udp0 $sink
  77. $ns at 0.2 "$cbr0 start"
  78. CN LAB MANUAL
  79. Dept. of ISE, RNSIT. Page 16
  80. $ns at 4.5 "$cbr0 stop"
  81. $ns at 5.0 "finish"
  82. $ns run
  83. Step2: Open text editor, type the below program and save with extention .awk (prog1.awk)
  84. BEGIN {
  85. dcount = 0;
  86. rcount = 0;
  87. }
  88. {
  89. event = $1;
  90. if(event == "d")
  91. {
  92. dcount++;
  93. }
  94. if(event == "r")
  95. {
  96. rcount++;
  97. }
  98. }
  99. END {
  100. printf("The no.of packets dropped : %d\n ",dcount);
  101. printf("The no.of packets recieved : %d\n ",rcount);
  102. }
  103. PING MSG                                                                                                         set ns [new Simulator]
  104. set nf [open prog2.nam w]
  105. $ns namtrace-all $nf
  106. set nd [open prog2.tr w]
  107. $ns trace-all $nd
  108. proc finish {} {
  109. global ns nf nd
  110. $ns flush-trace
  111. close $nf
  112. close $nd
  113. exec nam prog2.nam &
  114. exit 0
  115. }
  116. set n0 [$ns node]
  117. set n1 [$ns node]
  118. set n2 [$ns node]
  119. set n3 [$ns node]
  120. set n4 [$ns node]
  121. set n5 [$ns node]
  122. set n6 [$ns node]
  123. $ns duplex-link $n1 $n0 1Mb 10ms DropTail
  124. $ns duplex-link $n2 $n0 1Mb 10ms DropTail
  125. $ns duplex-link $n3 $n0 1Mb 10ms DropTail
  126. $ns duplex-link $n4 $n0 1Mb 10ms DropTail
  127. $ns duplex-link $n5 $n0 1Mb 10ms DropTail
  128. $ns duplex-link $n6 $n0 1Mb 10ms DropTail
  129. Agent/Ping instproc recv {from rtt} {
  130. $self instvar node_
  131. puts "node [$node_ id] recieved ping answer from \
  132. $from with round-trip-time $rtt ms."
  133. }
  134. set p1 [new Agent/Ping]
  135. set p2 [new Agent/Ping]
  136. set p3 [new Agent/Ping]
  137. set p4 [new Agent/Ping]
  138. set p5 [new Agent/Ping]
  139. set p6 [new Agent/Ping]
  140. $ns attach-agent $n1 $p1
  141. $ns attach-agent $n2 $p2
  142. $ns attach-agent $n3 $p3
  143. $ns attach-agent $n4 $p4
  144. $ns attach-agent $n5 $p5
  145. $ns attach-agent $n6 $p6
  146. $ns queue-limit $n0 $n4 3
  147. $ns queue-limit $n0 $n5 2
  148. $ns queue-limit $n0 $n6 2
  149. $ns queue-limit $n0 $n3 2
  150. $ns queue-limit $n0 $n2 1
  151. $ns queue-limit $n0 $n1 2
  152. $ns connect $p1 $p4
  153. $ns connect $p2 $p5
  154. $ns connect $p3 $p6
  155. $ns connect $p6 $p3
  156. $ns at 0.2 "$p1 send"
  157. $ns at 0.4 "$p2 send"
  158. $ns at 0.6 "$p3 send"
  159. $ns at 1.0 "$p4 send"
  160. $ns at 1.2 "$p5 send"
  161. $ns at 1.4 "$p6 send"
  162. $ns at 2.0 "finish"
  163. $ns run
  164. Step2: Open text editor, type the below program and save with extention .awk (prog2.awk)
  165. BEGIN {
  166. count=0;
  167. }
  168. {
  169. event=$1;
  170. if(event=="d")
  171. {
  172. count++;
  173. }
  174. }
  175. END {
  176. printf("No of packets dropped : %d\n",count);
  177. }
  178. Source Code:
  179. import java.util.Scanner:
  180. public class p12
  181. {
  182. public static void main(String[] args) throws InterruptedException
  183. {
  184. Scanner in new Scanner(System.in);
  185. int n.incoming.outgoing.bs.s=0:
  186. {
  187. System.out.println("enter the bs outgoing rate, inputs, incoming size");
  188. bs in.nextInt():
  189. outgoing in.nextInt();
  190. n=in.nextInt():
  191. incoming in.nextInt();
  192. while(n!=0)
  193. {
  194. System.out.println("incoming size is"+incoming); if(incoming<=(bs-s))
  195. {
  196. s+ incoming:
  197. System.out.println("bucket buffer size is"+s+"out of"+bs);
  198. }
  199. else
  200. {
  201. System.out.println("packet lost="+(incoming-(bs-s)));
  202. sbs:
  203. System.out.println("bucket buffersize is"+s+"out of"+bs):
  204. }
  205. s--outgoing:
  206. {
  207. System.out.println("after outgoing="+s+"packet left out of"+bs+"in buffer");n--;
  208. Thread.sleep(3000):
  209. }
  210. in.close();
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement