Advertisement
Guest User

Untitled

a guest
May 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 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.  
  70. public void initial(){
  71.  
  72. leitor.collisionDetect(tags.returnTags());
  73.  
  74. }
  75.  
  76. public void lowerBound() {
  77.  
  78.  
  79. for (int i = 0; i < this.qtdSim; i++) {
  80.  
  81. int newFrame = (int) (leitor.succ() + (2 * (leitor.collision())));
  82.  
  83. leitor.redefine(newFrame);
  84. tags.redefine(newFrame);
  85.  
  86. leitor.collisionDetect(tags.returnTags());
  87.  
  88. //this.col[i] = this.col[i] + leitor.collision();
  89. this.col[i] = leitor.collision();
  90. this.succ[i] = leitor.succ();
  91. this.idle[i] = leitor.idle();
  92. this.qtd[i] = tags.getQtd();
  93. this.qtdSlots[i] = leitor.getSize();
  94.  
  95. }
  96.  
  97.  
  98. }
  99.  
  100. public void p1(){
  101.  
  102. for (int i = 0; i < this.qtdSim; i++) {
  103.  
  104.  
  105. //leitor.collisionDetect(tags.returnTags());
  106.  
  107. double Em = leitor.collision() + leitor.succ();
  108.  
  109. double alpha = (leitor.getSize() - 1)/leitor.getSize();
  110.  
  111. double m = (Math.log10(1 - (1 - alpha) * Em))/ Math.log10(alpha);
  112.  
  113. int newFrame = (int) Math.ceil(m);
  114.  
  115. leitor.redefine(newFrame);
  116. tags.redefine(newFrame);
  117.  
  118. leitor.collisionDetect(tags.returnTags());
  119.  
  120. this.col[i] = col[i] + leitor.collision();
  121. this.succ[i] = leitor.succ();
  122. this.idle[i] = leitor.idle();
  123. this.qtd[i] = tags.getQtd();
  124. this.qtdSlots[i] = leitor.getSize();
  125.  
  126. //tags.newTags(newFrame);
  127.  
  128.  
  129. }
  130. }
  131.  
  132. public void p2(){
  133.  
  134. for (int i = 0; i < this.qtdSim; i++) {
  135.  
  136.  
  137. //leitor.collisionDetect(tags.returnTags());
  138.  
  139. double co = leitor.idle();
  140.  
  141. double elem1 = Math.log10(co/leitor.getSize());
  142. double elem2 = Math.log10(1- (1/leitor.getSize()));
  143.  
  144. double m;
  145.  
  146. if(co != 0){
  147. m = elem1/elem2;
  148. } else {
  149. m = 2 * leitor.collision();
  150. }
  151.  
  152. int newFrame = (int) Math.ceil(m);
  153.  
  154.  
  155. leitor.redefine(newFrame);
  156. tags.redefine(newFrame);
  157.  
  158. leitor.collisionDetect(tags.returnTags());
  159.  
  160. this.col[i] = leitor.collision();
  161. this.succ[i] = leitor.succ();
  162. this.idle[i] = leitor.idle();
  163. this.qtd[i] = tags.getQtd();
  164. this.qtdSlots[i] = leitor.getSize();
  165.  
  166. //tags.newTags(newFrame);
  167.  
  168.  
  169. }
  170. }
  171.  
  172.  
  173.  
  174. public void doubler(){
  175.  
  176. for (int i = 0; i < this.qtdSim; i++) {
  177.  
  178. leitor.collisionDetect(tags.returnTags());
  179.  
  180. int newFrame = (int) (2 * (leitor.getSize() ));
  181.  
  182. leitor.redefine(newFrame);
  183. tags.redefine(newFrame);
  184.  
  185. leitor.collisionDetect(tags.returnTags());
  186.  
  187. this.col[i] = leitor.collision();
  188. this.succ[i] = leitor.succ();
  189. this.idle[i] = leitor.idle();
  190.  
  191. }
  192.  
  193. }
  194.  
  195. public int fazEomLee ( double size, double success, double collisions ,double y){
  196. this.b = size/(y-1 * collisions + success);
  197. this.y2 = (1 - Math.log(-1/b))/(b*(1-(1+(1/b)*Math.log(-1/b))));
  198. if (Math.abs(y-y2) < 0.001) {
  199. double f = y2*collisions;
  200. tags.redefine((int) Math.abs(Math.ceil(f/b)));
  201. return (int) f;
  202. }else {
  203. return fazEomLee(size, success, collisions , this.y2);
  204. }
  205. }
  206.  
  207.  
  208.  
  209. public void eomLee() {
  210. for (int i = 0; i < this.qtdSim; i++) {
  211.  
  212. leitor.collisionDetect(tags.returnTags());
  213.  
  214. int newFrame = fazEomLee((double)leitor.getSize(), (double) leitor.succ(), (double) leitor.collision() , 2.0);
  215. leitor.redefine((int) Math.ceil(newFrame));
  216.  
  217. leitor.collisionDetect(tags.returnTags());
  218.  
  219. this.col[i] = leitor.collision();
  220. //this.col[i] = col[i] + 5;
  221. this.succ[i] = leitor.succ();
  222. this.idle[i] = leitor.idle();
  223. this.qtd[i] = tags.getQtd();
  224. this.qtdSlots[i] = leitor.getSize();
  225.  
  226. tags.newTags(newFrame);
  227. }
  228. }
  229.  
  230.  
  231. public void p3() {
  232. for (int i = 0; i < this.qtdSim; i++) {
  233.  
  234. double success = leitor.succ();
  235. double collision = leitor.collision();
  236. double size = leitor.getSize();
  237.  
  238. if (size == collision){
  239. leitor.collisionDetect(tags.returnTags());
  240.  
  241. double value = 12.047;
  242. double numberTags = (value*(leitor.getSize()-1))+2;
  243. this.qtdSlots[i] = numberTags;
  244. tags.redefine((int) Math.ceil(numberTags));
  245. leitor.redefine((int) Math.ceil(numberTags-leitor.succ()));
  246.  
  247. leitor.collisionDetect(tags.returnTags());
  248. this.col[i] = leitor.collision();
  249. //this.col[i] = col[i] + 5;
  250. this.succ[i] = leitor.succ();
  251. this.idle[i] = leitor.idle();
  252. this.qtd[i] = tags.getQtd();
  253. this.qtdSlots[i] = leitor.getSize();
  254. tags.newTags((int) Math.ceil(numberTags));
  255. }else{
  256. leitor.collisionDetect(tags.returnTags());
  257.  
  258. int newFrame = fazEomLee((double)leitor.getSize(), (double) leitor.succ(), (double) leitor.collision() , 2.0);
  259.  
  260. leitor.collisionDetect(tags.returnTags());
  261. this.col[i] = leitor.collision();
  262. //this.col[i] = col[i] + 5;
  263. this.succ[i] = leitor.succ();
  264. this.idle[i] = leitor.idle();
  265. this.qtd[i] = tags.getQtd();
  266. this.qtdSlots[i] = leitor.getSize();
  267. tags.newTags((int) Math.ceil(newFrame));
  268. }
  269. }
  270. }
  271.  
  272. public int[] getSucc() {
  273. return succ;
  274. }
  275.  
  276.  
  277. public int[] getCol() {
  278. return col;
  279. }
  280.  
  281.  
  282. public int[] getIdle() {
  283. return idle;
  284. }
  285.  
  286.  
  287. public Leitor getLeitor(){
  288. return this.leitor;
  289. }
  290.  
  291. public CollectionTags getTags(){
  292. return this.tags;
  293. }
  294.  
  295. public int[] getQtd() {
  296. return qtd;
  297. }
  298.  
  299. public double[] getSlots() {
  300. return qtdSlots;
  301. }
  302.  
  303. public double getMediaCol(){
  304.  
  305. double media = 0;
  306.  
  307. for (int i = 0; i < col.length; i++) {
  308. media = media + col[i];
  309. }
  310.  
  311. return media/col.length;
  312. //return media;
  313. }
  314.  
  315. public double getMediaSucc(){
  316.  
  317. double media = 0;
  318.  
  319. for (int i = 0; i < succ.length; i++) {
  320. media = media + succ[i];
  321. }
  322.  
  323. //return media/succ.length;
  324. return media;
  325. }
  326.  
  327. public double getMediaIdle(){
  328.  
  329. double media = 0;
  330.  
  331. for (int i = 0; i < idle.length; i++) {
  332. media = media + idle[i];
  333. }
  334.  
  335. //return media/idle.length;
  336. return media;
  337. }
  338.  
  339. public double getMediaSlots(){
  340.  
  341. double media = 0;
  342.  
  343. for (int i = 0; i < qtdSlots.length; i++) {
  344. media = media + qtdSlots[i];
  345. }
  346.  
  347. // return media/qtdSlots.length;
  348. return media;
  349. }
  350.  
  351. public double getMediaQtd(){
  352.  
  353. double media = 0;
  354.  
  355. for (int i = 0; i < qtd.length; i++) {
  356. media = media + qtd[i];
  357. }
  358.  
  359. // return media/qtd.length;
  360. return media;
  361. }
  362.  
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement