📄 mm1logic.java
字号:
/**
* Copyright (C) 2006, Laboratorio di Valutazione delle Prestazioni - Politecnico di Milano
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Created on 11-mar-2004
*
*/
package jmt.jmarkov.Queues;
import jmt.jmarkov.Queues.Exceptions.InfiniteBufferException;
import jmt.jmarkov.Queues.Exceptions.NoJobsException;
import jmt.jmarkov.Queues.Exceptions.NonErgodicException;
import java.util.Random;
/**
* Contiene gli algoritmi che regolano il funzionamento
* di una coda <b>M/M/1</b>, dove <b>lambda</b> e <b>s</b> rappresentano, rispettivamente,
* i numero di job medio al secondo e il tempo medio di esecuzione di un processo.
* Ricordiamo che in una coda <b>M/M/1</b> gli arrivi e le esecuzioni sono dei processi di Poisson e che
* viene eseguito un solo processo per volta
*
* @author Ernesto
*
*/
public class MM1Logic implements QueueLogic {
//NEW
//@author Stefano Omini
// introduced DEBUG var to skip System.out.println() calls in final release
private static final boolean DEBUG = false;
//end NEW
private double mult = 1.0;
/**
* media degli arrivi [job/ms]
*/
private double lambda;
/**
* media dei tempi di esecuzione [ms]
*/
private double s;
/**
* Utilizzo della coda [job]
*/
private Random rnd;
/**
* Inizializza la coda
* @param lambda rappresenta la media del <i>processo di Poisson</i> che regola gli arrivi <b>[job/s]</b>
* @param s rappresenta la media del <i>processo di Poisson</i> che regola le esecuzioni <b>[ms]</b>
*/
public MM1Logic(double lambda, double s){
this.lambda = lambda;
this.s = s;
rnd = new Random();
}
/* (non-Javadoc)
* @see Queues.QueueLogic#getArrivalTime()
*/
public double getArrivalTime() throws NoJobsException {
if (lambda == 0) throw new NoJobsException();
return (this.getTime(1000.0 * mult / lambda));
}
/* (non-Javadoc)
* @see Queues.QueueLogic#getRunTime()
*/
public double getRunTime() {
return(this.getTime(s * 1000.0 * mult ));
}
/* (non-Javadoc)
* @see Queues.QueueLogic#getStatusProbability(int)
*/
public double getStatusProbability(int status) throws NonErgodicException{
return ((1 - utilization()) * Math.pow(utilization(),(double)status));
}
/**
* Calcola un valore casuale di tempo per una <i>distribuzione di Poisson</i> con
* parametro della distribuzione pari a <b>media</b>.
*
* @param media
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -