Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package simulador;
- import tags.CollectionTags;
- import leitor.Leitor;
- public class Simulador {
- private int qtdSim;
- private double mediaCol;
- private double mediaSucc;
- private double mediaIdle;
- private Leitor leitor;
- private CollectionTags tags;
- private int[] succ;
- private int[] col;
- private int[] idle;
- private int[] qtd;
- private double[] qtdSlots;
- private static double b;
- private static double y2;
- public Simulador(){
- this.qtdSim = 10;
- this.succ = new int[this.qtdSim];
- this.col = new int[this.qtdSim];
- this.idle = new int[this.qtdSim];
- this.qtd = new int[this.qtdSim];
- this.qtdSlots = new double[this.qtdSim];
- this.leitor = new Leitor(64);
- this.tags = new CollectionTags();
- this.b = 0;
- initial();
- }
- public Simulador(int sim){
- this.qtdSim = sim;
- this.succ = new int[this.qtdSim];
- this.col = new int[this.qtdSim];
- this.idle = new int[this.qtdSim];
- this.qtd = new int[this.qtdSim];
- this.qtdSlots = new double[this.qtdSim];
- this.leitor = new Leitor(64);
- this.tags = new CollectionTags();
- this.b = 0;
- initial();
- }
- public Simulador(int tags, int sim){
- this.qtdSim = sim;
- this.succ = new int[this.qtdSim];
- this.col = new int[this.qtdSim];
- this.idle = new int[this.qtdSim];
- this.qtd = new int[this.qtdSim];
- this.qtdSlots = new double[this.qtdSim];
- this.leitor = new Leitor(64);
- this.tags = new CollectionTags(tags,64);
- this.b = 0;
- this.y2 = 0;
- initial();
- }
- public void initial(){
- leitor.collisionDetect(tags.returnTags());
- }
- public void lowerBound() {
- for (int i = 0; i < this.qtdSim; i++) {
- int newFrame = (int) (leitor.succ() + (2 * (leitor.collision())));
- leitor.redefine(newFrame);
- tags.redefine(newFrame);
- leitor.collisionDetect(tags.returnTags());
- //this.col[i] = this.col[i] + leitor.collision();
- this.col[i] = leitor.collision();
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- this.qtd[i] = tags.getQtd();
- this.qtdSlots[i] = leitor.getSize();
- }
- }
- public void p1(){
- for (int i = 0; i < this.qtdSim; i++) {
- //leitor.collisionDetect(tags.returnTags());
- double Em = leitor.collision() + leitor.succ();
- double alpha = (leitor.getSize() - 1)/leitor.getSize();
- double m = (Math.log10(1 - (1 - alpha) * Em))/ Math.log10(alpha);
- int newFrame = (int) Math.ceil(m);
- leitor.redefine(newFrame);
- tags.redefine(newFrame);
- leitor.collisionDetect(tags.returnTags());
- this.col[i] = col[i] + leitor.collision();
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- this.qtd[i] = tags.getQtd();
- this.qtdSlots[i] = leitor.getSize();
- //tags.newTags(newFrame);
- }
- }
- public void p2(){
- for (int i = 0; i < this.qtdSim; i++) {
- //leitor.collisionDetect(tags.returnTags());
- double co = leitor.idle();
- double elem1 = Math.log10(co/leitor.getSize());
- double elem2 = Math.log10(1- (1/leitor.getSize()));
- double m;
- if(co != 0){
- m = elem1/elem2;
- } else {
- m = 2 * leitor.collision();
- }
- int newFrame = (int) Math.ceil(m);
- leitor.redefine(newFrame);
- tags.redefine(newFrame);
- leitor.collisionDetect(tags.returnTags());
- this.col[i] = leitor.collision();
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- this.qtd[i] = tags.getQtd();
- this.qtdSlots[i] = leitor.getSize();
- //tags.newTags(newFrame);
- }
- }
- public void doubler(){
- for (int i = 0; i < this.qtdSim; i++) {
- leitor.collisionDetect(tags.returnTags());
- int newFrame = (int) (2 * (leitor.getSize() ));
- leitor.redefine(newFrame);
- tags.redefine(newFrame);
- leitor.collisionDetect(tags.returnTags());
- this.col[i] = leitor.collision();
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- }
- }
- public int fazEomLee ( double size, double success, double collisions ,double y){
- this.b = size/(y-1 * collisions + success);
- this.y2 = (1 - Math.log(-1/b))/(b*(1-(1+(1/b)*Math.log(-1/b))));
- if (Math.abs(y-y2) < 0.001) {
- double f = y2*collisions;
- tags.redefine((int) Math.abs(Math.ceil(f/b)));
- return (int) f;
- }else {
- return fazEomLee(size, success, collisions , this.y2);
- }
- }
- public void eomLee() {
- for (int i = 0; i < this.qtdSim; i++) {
- leitor.collisionDetect(tags.returnTags());
- int newFrame = fazEomLee((double)leitor.getSize(), (double) leitor.succ(), (double) leitor.collision() , 2.0);
- leitor.redefine((int) Math.ceil(newFrame));
- leitor.collisionDetect(tags.returnTags());
- this.col[i] = leitor.collision();
- //this.col[i] = col[i] + 5;
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- this.qtd[i] = tags.getQtd();
- this.qtdSlots[i] = leitor.getSize();
- tags.newTags(newFrame);
- }
- }
- public void p3() {
- for (int i = 0; i < this.qtdSim; i++) {
- double success = leitor.succ();
- double collision = leitor.collision();
- double size = leitor.getSize();
- if (size == collision){
- leitor.collisionDetect(tags.returnTags());
- double value = 12.047;
- double numberTags = (value*(leitor.getSize()-1))+2;
- this.qtdSlots[i] = numberTags;
- tags.redefine((int) Math.ceil(numberTags));
- leitor.redefine((int) Math.ceil(numberTags-leitor.succ()));
- leitor.collisionDetect(tags.returnTags());
- this.col[i] = leitor.collision();
- //this.col[i] = col[i] + 5;
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- this.qtd[i] = tags.getQtd();
- this.qtdSlots[i] = leitor.getSize();
- tags.newTags((int) Math.ceil(numberTags));
- }else{
- leitor.collisionDetect(tags.returnTags());
- int newFrame = fazEomLee((double)leitor.getSize(), (double) leitor.succ(), (double) leitor.collision() , 2.0);
- leitor.collisionDetect(tags.returnTags());
- this.col[i] = leitor.collision();
- //this.col[i] = col[i] + 5;
- this.succ[i] = leitor.succ();
- this.idle[i] = leitor.idle();
- this.qtd[i] = tags.getQtd();
- this.qtdSlots[i] = leitor.getSize();
- tags.newTags((int) Math.ceil(newFrame));
- }
- }
- }
- public int[] getSucc() {
- return succ;
- }
- public int[] getCol() {
- return col;
- }
- public int[] getIdle() {
- return idle;
- }
- public Leitor getLeitor(){
- return this.leitor;
- }
- public CollectionTags getTags(){
- return this.tags;
- }
- public int[] getQtd() {
- return qtd;
- }
- public double[] getSlots() {
- return qtdSlots;
- }
- public double getMediaCol(){
- double media = 0;
- for (int i = 0; i < col.length; i++) {
- media = media + col[i];
- }
- return media/col.length;
- //return media;
- }
- public double getMediaSucc(){
- double media = 0;
- for (int i = 0; i < succ.length; i++) {
- media = media + succ[i];
- }
- //return media/succ.length;
- return media;
- }
- public double getMediaIdle(){
- double media = 0;
- for (int i = 0; i < idle.length; i++) {
- media = media + idle[i];
- }
- //return media/idle.length;
- return media;
- }
- public double getMediaSlots(){
- double media = 0;
- for (int i = 0; i < qtdSlots.length; i++) {
- media = media + qtdSlots[i];
- }
- // return media/qtdSlots.length;
- return media;
- }
- public double getMediaQtd(){
- double media = 0;
- for (int i = 0; i < qtd.length; i++) {
- media = media + qtd[i];
- }
- // return media/qtd.length;
- return media;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement