📄 numberofcustomerparametricanalysis.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
*/
package jmt.gui.common.definitions.parametric;
import jmt.gui.common.definitions.ClassDefinition;
import jmt.gui.common.definitions.SimulationDefinition;
import jmt.gui.common.definitions.StationDefinition;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;
/**
* <p>Title: NumberOfCustomerParametricAnalysis</p>
* <p>Description: this class is used to describe a parametric analysis where the
* varied parameter is the global number of close class jobs. It adds the
* <code >classKey</code> field used to keep the key of the Job-Class whose
* number of jobs will be varied, and a boolean value <code >singleClass</code>
* used to choose the type of service time growth (single or all class).</p>
*
* @author Francesco D'Aquino
* Date: 14-dic-2005
* Time: 11.19.26
*/
public class NumberOfCustomerParametricAnalysis extends ParametricAnalysisDefinition {
private final boolean SINGLE_CLASS = false;
private boolean singleClass;
private Object classKey;
private Vector validParameterValues;
private Object values;
public NumberOfCustomerParametricAnalysis(ClassDefinition cd,StationDefinition sd,SimulationDefinition simd) {
type = PA_TYPE_NUMBER_OF_CUSTOMERS;
classDef = cd;
stationDef = sd;
simDef = simd;
Vector closedClasses = cd.getClosedClassKeys();
if (closedClasses.size() == 1) {
classKey = closedClasses.get(0);
singleClass = true;
}
else singleClass = SINGLE_CLASS;
initialValue = cd.getTotalCloseClassPopulation();
finalValue = cd.getTotalCloseClassPopulation()*2+1;
numberOfSteps = this.searchForAvaibleSteps();
if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
}
/**
* Returns true if only the number of jobs of one class will be increased
* @return true if only the number of jobs of one class will be increased
*/
public boolean isSingleClass() {
return singleClass;
}
/**
* Sets the type of population increase. If <code> isSingleClass</code>
* param is true only the number of jobs of one class will be increased
* @param isSingleClass
*/
public void setSingleClass(boolean isSingleClass) {
if (isSingleClass != singleClass)
simDef.setSaveChanged();
singleClass = isSingleClass;
}
/**
* Gets the class key of the job class whose number of jobs will be
* increased. If the simulation is not single class, the <code> null </code>
* value will be returned
* @return the key of the class whose number of jobs will be increased if the
* parametric analysis is single class, <code> null </code> otherwise.
*/
public Object getReferenceClass() {
if (singleClass) return classKey;
else return null;
}
/**
* Sets the class whose number of jobs will be increased. If <code> singleClass </code>
* value is not true nothing will be done
* @param classKey the key of the class whose number of job will be
* increased
*/
public void setReferenceClass(Object classKey) {
if (singleClass) {
if (this.classKey != classKey)
simDef.setSaveChanged();
this.classKey = classKey;
}
}
/**
* Gets the type of parametric analysis
*
* @return the type of parametric analysis
*/
public String getType() {
return type;
}
/**
* returns the set of values that the varying parameter will assume
* @return a structure containing the set of values that the varying parameter will assume
*/
public Object getValuesSet() {
return values;
}
/**
* Changes the model preparing it for the next step
*
*/
public void changeModel(int step) {
if (step >= numberOfSteps) return;
if (values != null) {
if (singleClass) {
Integer refPop = (Integer)((Vector)values).get(step);
classDef.setClassPopulation(refPop,classKey);
}
else {
Vector classSet = classDef.getClosedClassKeys();
for (int i=0; i<classSet.size(); i++) {
Object thisClass = classSet.get(i);
int thisPop = (int) ((ValuesTable)values).getValue(thisClass,step);
classDef.setClassPopulation(new Integer(thisPop),thisClass);
}
}
simDef.manageJobs();
}
}
/**
* Gets the maximum number of steps compatible with the model definition and the type of parametric analysis and initialize
* the <code>validParameterValues</code> Vector, containing the values that the parameter will assume. If the simulation
* is single class based, it will contain the values of the number of jobs that the reference class will have, otherwise it will
* contain the values of global population.
*
* @return the maximum number of steps
*/
public int searchForAvaibleSteps() {
int max = (int)(finalValue - initialValue)+1;
validParameterValues = new Vector(max,1);
if (singleClass) {
int pop = classDef.getClassPopulation(classKey).intValue();
for (int i=0;i<max;i++) {
validParameterValues.add(new Integer(pop));
pop++;
}
return max;
}
else {
int avaibleSteps=0;
Vector classSet = classDef.getClosedClassKeys();
//calculate the proportion between classes populations
double[] betas = new double[classSet.size()];
int totalPop = classDef.getTotalCloseClassPopulation();
for (int i=0;i<classSet.size();i++) {
double thisPop = classDef.getClassPopulation(classSet.get(i)).doubleValue();
betas[i] = thisPop/totalPop;
}
for (int i=0;i<max;i++) {
int j;
for (j=0;j<classSet.size();j++) {
double thisClassNextNumberOfJobs = totalPop*betas[j];
double intValue = Math.ceil(thisClassNextNumberOfJobs-0.5); //get the closest integer
//if the next-step number of jobs for this class is not
//an integer break the cycle, since this total number of
//job is not valid
if ((thisClassNextNumberOfJobs - intValue) > 0) {
break;
}
}
//check if the cycle was exited before checking all classes
if (!(j<classSet.size())) {
validParameterValues.add(new Integer(totalPop));
avaibleSteps++;
}
totalPop++;
}
return avaibleSteps;
}
}
/**
* Finds the set of possible values of the population on which the
* simulation may be iterated on.
*
*/
public void createValuesSet() {
int maxSteps = validParameterValues.size();
if (singleClass) {
values = new Vector(0,1);
double p = (double)(maxSteps-1)/(double)(numberOfSteps-1);
//int thisStep = 0;
int thisStep;
double sum = 0;
for (int i=0;i<numberOfSteps;i++) {
thisStep = (int)(sum);
((Vector)values).add(validParameterValues.get(thisStep));
sum += p;
}
originalValues = new Integer(classDef.getClassPopulation(classKey).intValue());
}
else {
double p = (double)(maxSteps-1)/(double)(numberOfSteps-1);
int thisStep;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -