⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arrivalrateparametricanalysis.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**    
  * 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 jmt.gui.common.distributions.Distribution;

import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;

/**
 * <p>Title: ArrivalRateParametricAnalysis</p>
 * <p>Description: this class is used to describe a parametric analysis where
 * the varied parameter is the mean value of the arrival rate of an/all open
 * classes. It adds the <code >classKey</code> field used to keep the key of
 * the Job-Class whose service time 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: 12.22.28
 */
public class ArrivalRateParametricAnalysis extends ParametricAnalysisDefinition {
    private final double FROM_ALL = 100;
    private final double TO_ALL = 150;
    private final double INCREMENT_SINGLE = 2;
    private final int STEPS = 10;
    private final boolean SINGLE_CLASS = false;

    private boolean singleClass;
    private Object classKey;

    private Vector avaibleClasses;
    private Object values;

    public ArrivalRateParametricAnalysis(ClassDefinition cd,StationDefinition sd,SimulationDefinition simd) {
        type = PA_TYPE_ARRIVAL_RATE;
        numberOfSteps = STEPS;
        classDef = cd;
        stationDef = sd;
        simDef = simd;
        Vector avaible = new ParametricAnalysisChecker(cd,sd,simd).checkForArrivalRatesParametricSimulationAvaibleClasses();
        if ( (cd.getOpenClassKeys().size() == 1) || (avaible.size() < cd.getOpenClassKeys().size()) ) {
            singleClass = true;
            classKey = avaible.get(0);
            double arrivalRate = 1/(((Distribution)cd.getClassDistribution(classKey)).getMean());
            initialValue = arrivalRate;
            finalValue = arrivalRate*INCREMENT_SINGLE;
        }
        else {
            singleClass = SINGLE_CLASS;
            if (SINGLE_CLASS) {
                double arrivalRate = 1/(((Distribution)cd.getClassDistribution(classKey)).getMean());
                initialValue = arrivalRate;
                finalValue = arrivalRate*INCREMENT_SINGLE;
            }
            else {
                initialValue = FROM_ALL;
                finalValue = TO_ALL;
            }
        }

    }

    /**
     * Returns true if only the arrrival rate of one class will be increased
     * @return true if only the arrrival rate of one class will be increased
     */
    public boolean isSingleClass() {
        return singleClass;
    }

    /**
     * Sets the type of arrrival rate increase. If <code> isSingleClass</code>
     * param is true only the arrrival rate of one class will be increased
     * @param isSingleClass
     */
    public void setSingleClass(boolean isSingleClass) {
        if (singleClass != isSingleClass)
            simDef.setSaveChanged();
        singleClass = isSingleClass;
    }

    /**
     * Sets the default initial Value
     */
    public void setDefaultInitialValue() {
        if (singleClass) {
            double rate = 1/((Distribution)(classDef.getClassDistribution(classKey))).getMean();
            initialValue = rate;
        }
        else{
            initialValue = FROM_ALL;
        }
    }

    /**
     * Sets default final value
     */
    public void setDefaultFinalValue() {
        if (singleClass) {
            double rate = (1/((Distribution)(classDef.getClassDistribution(classKey))).getMean())*INCREMENT_SINGLE;
            finalValue = rate;
        }
        else finalValue = TO_ALL;
    }

    /**
     * Gets the class key of the class whose arrrival rate 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 arrrival rate 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 arrrival rate 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;
    }

    /**
     * Changes the model preparing it for the next step
     *
     */
     public void changeModel(int step) {
        if (step >= numberOfSteps) return;
        if (values != null) {
            if (singleClass) {
                Double refAR = (Double)((Vector)values).get(step);
                Distribution distr = (Distribution)classDef.getClassDistribution(classKey);
                distr.setMean(1/(refAR.doubleValue()));
            }
            else {
                for (int i=0; i<avaibleClasses.size(); i++) {
                    Object thisClass = avaibleClasses.get(i);
                    double refAR = ((ValuesTable)values).getValue(thisClass,step);
                    Distribution distr = (Distribution)classDef.getClassDistribution(thisClass);
                    distr.setMean(1/refAR);
                }
            }
        }
    }

    /**
     * Gets the maximum number of steps compatible with the model definition and the type of parametric analysis.
     *
     * @return the maximum number of steps
     */
    public int searchForAvaibleSteps() {
        return Integer.MAX_VALUE;
    }

    /**
     * Finds the set of possible values of the population on which the
     * simulation may be iterated on.
     *
     */
    public void createValuesSet() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -