Advertisement
Guest User

Untitled

a guest
May 6th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. package simulador;
  2.  
  3. import tags.CollectionTags;
  4. import leitor.Leitor;
  5.  
  6. public class Simulador {
  7.  
  8. private int qtdSim;
  9.  
  10. private double mediaCol;
  11. private double mediaSucc;
  12. private double mediaIdle;
  13.  
  14. private Leitor leitor;
  15. private CollectionTags tags;
  16.  
  17. private int[] succ;
  18. private int[] col;
  19. private int[] idle;
  20. private int[] qtd;
  21. private double[] qtdSlots;
  22. private static double b;
  23. private static double y2;
  24.  
  25. public Simulador(){
  26. this.qtdSim = 10;
  27. this.succ = new int[this.qtdSim];
  28. this.col = new int[this.qtdSim];
  29. this.idle = new int[this.qtdSim];
  30. this.qtd = new int[this.qtdSim];
  31. this.qtdSlots = new double[this.qtdSim];
  32. this.leitor = new Leitor(64);
  33. this.tags = new CollectionTags();
  34. this.b = 0;
  35. initial();
  36. }
  37.  
  38. public Simulador(int sim){
  39. this.qtdSim = sim;
  40. this.succ = new int[this.qtdSim];
  41. this.col = new int[this.qtdSim];
  42. this.idle = new int[this.qtdSim];
  43. this.qtd = new int[this.qtdSim];
  44. this.qtdSlots = new double[this.qtdSim];
  45. this.leitor = new Leitor(64);
  46. this.tags = new CollectionTags();
  47. this.b = 0;
  48.  
  49. initial();
  50.  
  51. }
  52.  
  53. public Simulador(int tags, int sim){
  54. this.qtdSim = sim;
  55. this.succ = new int[this.qtdSim];
  56. this.col = new int[this.qtdSim];
  57. this.idle = new int[this.qtdSim];
  58. this.qtd = new int[this.qtdSim];
  59. this.qtdSlots = new double[this.qtdSim];
  60. this.leitor = new Leitor(64);
  61. this.tags = new CollectionTags(tags,64);
  62. this.b = 0;
  63. this.y2 = 0;
  64.  
  65. initial();
  66. }
  67.  
  68.  
  69. public void initial(){
  70.  
  71. leitor.collisionDetect(tags.returnTags());
  72.  
  73. }
  74.  
  75. public void lowerBound() {
  76.  
  77.  
  78. for (int i = 0; i < this.qtdSim; i++) {
  79.  
  80.  
  81.  
  82. int newFrame = (int) (leitor.succ() + (2 * (leitor.collision())));
  83. leitor.redefine(newFrame);
  84. tags.redefine(newFrame);
  85.  
  86. leitor.collisionDetect(tags.returnTags());
  87.  
  88. this.col[i] = leitor.collision();
  89. this.succ[i] = leitor.succ();
  90. this.idle[i] = leitor.idle();
  91. this.qtd[i] = tags.getQtd();
  92. this.qtdSlots[i] = leitor.getSize();
  93.  
  94. }
  95.  
  96.  
  97. }
  98.  
  99. public void p1(){
  100.  
  101. for (int i = 0; i < this.qtdSim; i++) {
  102.  
  103.  
  104. leitor.collisionDetect(tags.returnTags());
  105.  
  106. double Em = leitor.collision() + leitor.succ();
  107.  
  108. double alpha = (leitor.getSize() - 1)/leitor.getSize();
  109.  
  110. double m = (Math.log10(1 - (1 - alpha) * Em))/ Math.log10(alpha);
  111.  
  112. int newFrame = (int) Math.ceil(m);
  113.  
  114. leitor.redefine(newFrame);
  115. tags.redefine(newFrame);
  116.  
  117. leitor.collisionDetect(tags.returnTags());
  118.  
  119. this.col[i] = leitor.collision();
  120. this.succ[i] = leitor.succ();
  121. this.idle[i] = leitor.idle();
  122. this.qtd[i] = tags.getQtd();
  123. this.qtdSlots[i] = leitor.getSize();
  124.  
  125. tags.newTags(newFrame);
  126.  
  127.  
  128. }
  129. }
  130.  
  131. public void p2(){
  132.  
  133. for (int i = 0; i < this.qtdSim; i++) {
  134.  
  135.  
  136. leitor.collisionDetect(tags.returnTags());
  137.  
  138. double co = leitor.idle();
  139.  
  140. double elem1 = Math.log10(co/leitor.getSize());
  141. double elem2 = Math.log10(1- (1/leitor.getSize()));
  142.  
  143. double m;
  144.  
  145. if(co != 0){
  146. m = elem1/elem2;
  147. } else {
  148. m = 2 * leitor.collision();
  149. }
  150.  
  151. int newFrame = (int) Math.ceil(m);
  152.  
  153.  
  154. leitor.redefine(newFrame);
  155. tags.redefine(newFrame);
  156.  
  157. leitor.collisionDetect(tags.returnTags());
  158.  
  159. this.col[i] = leitor.collision();
  160. this.succ[i] = leitor.succ();
  161. this.idle[i] = leitor.idle();
  162. this.qtd[i] = tags.getQtd();
  163. this.qtdSlots[i] = leitor.getSize();
  164.  
  165. tags.newTags(newFrame);
  166.  
  167.  
  168. }
  169. }
  170.  
  171.  
  172.  
  173. public void doubler(){
  174.  
  175. for (int i = 0; i < this.qtdSim; i++) {
  176.  
  177. leitor.collisionDetect(tags.returnTags());
  178.  
  179. int newFrame = (int) (2 * (leitor.getSize() ));
  180.  
  181. leitor.redefine(newFrame);
  182. tags.redefine(newFrame);
  183.  
  184. leitor.collisionDetect(tags.returnTags());
  185.  
  186. this.col[i] = leitor.collision();
  187. this.succ[i] = leitor.succ();
  188. this.idle[i] = leitor.idle();
  189.  
  190. }
  191.  
  192. }
  193.  
  194. public int fazEomLee ( double size, double success, double collisions ,double y){
  195. this.b = size/(y-1 * collisions + success);
  196. this.y2 = (1 - Math.log(-1/b))/(b*(1-(1+(1/b)*Math.log(-1/b))));
  197. if (Math.abs(y-y2) < 0.001) {
  198. double f = y2*collisions;
  199. tags.redefine((int) Math.abs(Math.ceil(f/b)));
  200. return (int) f;
  201. }else {
  202. return fazEomLee(size, success, collisions , this.y2);
  203. }
  204. }
  205.  
  206.  
  207.  
  208. public void eomLee() {
  209. for (int i = 0; i < this.qtdSim; i++) {
  210.  
  211. leitor.collisionDetect(tags.returnTags());
  212.  
  213. int newFrame = fazEomLee((double)leitor.getSize(), (double) leitor.succ(), (double) leitor.collision() , 2.0);
  214. leitor.redefine((int) Math.ceil(newFrame));
  215.  
  216. leitor.collisionDetect(tags.returnTags());
  217.  
  218. this.col[i] = leitor.collision();
  219. //this.col[i] = col[i] + 5;
  220. this.succ[i] = leitor.succ();
  221. this.idle[i] = leitor.idle();
  222. this.qtd[i] = tags.getQtd();
  223. this.qtdSlots[i] = leitor.getSize();
  224.  
  225. tags.newTags(newFrame);
  226. }
  227. }
  228.  
  229.  
  230. public void p3() {
  231. for (int i = 0; i < this.qtdSim; i++) {
  232.  
  233. double success = leitor.succ();
  234. double collision = leitor.collision();
  235. double size = leitor.getSize();
  236.  
  237. if (size == collision){
  238. leitor.collisionDetect(tags.returnTags());
  239.  
  240. double value = 12.047;
  241. double numberTags = (value*(leitor.getSize()-1))+2;
  242. this.qtdSlots[i] = numberTags;
  243. tags.redefine((int) Math.ceil(numberTags));
  244. leitor.redefine((int) Math.ceil(numberTags-leitor.succ()));
  245.  
  246. leitor.collisionDetect(tags.returnTags());
  247. this.col[i] = leitor.collision();
  248. //this.col[i] = col[i] + 5;
  249. this.succ[i] = leitor.succ();
  250. this.idle[i] = leitor.idle();
  251. this.qtd[i] = tags.getQtd();
  252. this.qtdSlots[i] = leitor.getSize();
  253. tags.newTags((int) Math.ceil(numberTags));
  254. }else{
  255. leitor.collisionDetect(tags.returnTags());
  256.  
  257. int newFrame = fazEomLee((double)leitor.getSize(), (double) leitor.succ(), (double) leitor.collision() , 2.0);
  258.  
  259. leitor.collisionDetect(tags.returnTags());
  260. this.col[i] = leitor.collision();
  261. //this.col[i] = col[i] + 5;
  262. this.succ[i] = leitor.succ();
  263. this.idle[i] = leitor.idle();
  264. this.qtd[i] = tags.getQtd();
  265. this.qtdSlots[i] = leitor.getSize();
  266. tags.newTags((int) Math.ceil(newFrame));
  267. }
  268. }
  269. }
  270.  
  271.  
  272.  
  273. public int[] getSucc() {
  274. return succ;
  275. }
  276.  
  277.  
  278. public int[] getCol() {
  279. return col;
  280. }
  281.  
  282.  
  283. public int[] getIdle() {
  284. return idle;
  285. }
  286.  
  287.  
  288. public Leitor getLeitor(){
  289. return this.leitor;
  290. }
  291.  
  292. public CollectionTags getTags(){
  293. return this.tags;
  294. }
  295.  
  296. public int[] getQtd() {
  297. return qtd;
  298. }
  299.  
  300. public double[] getSlots() {
  301. return qtdSlots;
  302. }
  303.  
  304. public double getMediaCol(){
  305.  
  306. double media = 0;
  307.  
  308. for (int i = 0; i < col.length; i++) {
  309. media = media + col[i];
  310. }
  311.  
  312. return media/col.length;
  313. }
  314.  
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement