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

📄 servicetimesparametricanalysis.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: ServiceTimesParametricAnalysis</p>
 * <p>Description: this class is used to describe a parametric analysis where the
 * varied parameter is the mean value of service time inside a station. It
 * adds the <code >classKey</code> and <code >stationKey</code> fields, used
 * to keep the key of the Job-Class and the key of the station 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.03.48
 */
public class ServiceTimesParametricAnalysis 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; //must be < than ParametricAnalysis.MAX_NUMBER_OF_STEPS
    private final boolean SINGLE_CLASS = false;

    private boolean singleClass;
    private Object classKey;
    private Object stationKey;
    private Vector avaibleClasses;

    private Object values;

    public ServiceTimesParametricAnalysis(ClassDefinition cd,StationDefinition sd,SimulationDefinition simd) {
        type = PA_TYPE_SERVICE_TIMES;
        classDef = cd;
        stationDef = sd;
        simDef = simd;
        numberOfSteps = STEPS;
        ParametricAnalysisChecker checker = new ParametricAnalysisChecker(cd,sd,simd);
        stationKey = checker.checkForServiceTimesParametricAnalysisAvaibleStations().get(0);
        Vector avaible = checker.checkForServiceTimesParametricSimulationAvaibleClasses(stationKey);
        if ( (cd.getClassKeys().size() == 1) || (avaible.size() < cd.getClassKeys().size()) ) {
            singleClass = true;
            classKey = avaible.get(0);
            double mean = ((Distribution)(stationDef.getServiceTimeDistribution(stationKey,classKey))).getMean();
            initialValue = mean;
            finalValue = mean*INCREMENT_SINGLE;
        }
        else {
            singleClass = SINGLE_CLASS;
            if (SINGLE_CLASS) {
                double mean = ((Distribution)(stationDef.getServiceTimeDistribution(stationKey,classKey))).getMean();
                initialValue = mean;
                finalValue = mean*INCREMENT_SINGLE;
            }
            else {
                initialValue = FROM_ALL;
                finalValue = TO_ALL;
            }
        }
    }

    /**
     * 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;
    }

    /**
     * Sets the default initial Value
     */
    public void setDefaultInitialValue() {
        if (singleClass) {
            double mean = ((Distribution)(stationDef.getServiceTimeDistribution(stationKey,classKey))).getMean();
            initialValue = mean;
        }
        else{
            initialValue = FROM_ALL;
        }
    }

    /**
     * Sets default final value
     */
    public void setDefaultFinalValue() {
        if (singleClass) {
            double mean = ((Distribution)(stationDef.getServiceTimeDistribution(stationKey,classKey))).getMean();
            finalValue = mean*INCREMENT_SINGLE;
        }
        else finalValue = TO_ALL;
    }

    /**
     * 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;
    }

    /**
     * Get the reference class name
     *
     * @return the name of the class
     */
    public String getReferenceClassName() {
        return classDef.getClassName(classKey);
    }

    /**
     * Gets a TreeMap containing for each property its value. The supported properties are
     * defined as constants inside this class.
     * @return a TreeMap containing the value for each property
     */
    public Map getProperties() {
        TreeMap properties = new TreeMap();
        properties.put(TYPE_PROPERTY,getType());
        properties.put(TO_PROPERTY,Double.toString(finalValue));
        properties.put(STEPS_PROPERTY,Integer.toString(numberOfSteps));
        properties.put(IS_SINGLE_CLASS_PROPERTY,Boolean.toString(singleClass));
        properties.put(REFERENCE_STATION_PROPERTY,stationDef.getStationName(stationKey));
        if (singleClass) properties.put(REFERENCE_CLASS_PROPERTY,classDef.getClassName(classKey));
        return properties;
    }

    /**
     * Sets the value for the specified property. The supported properties are: <br>
     * - TO_PROPERTY  <br>
     * - STEPS_PROPERTY <br>
     * - IS_SINGLE_CLASS_PROPERTY <br>
     * - REFERENCE_STATION_PROPERTY <br>
     * - REFERENCE_CLASS_PROPERTY
     * @param propertyName the name of the property to be set
     * @param value the value to be set
     */
    public void setProperty(String propertyName, String value) {
        if (propertyName.equals(TO_PROPERTY )) {
            finalValue = Double.parseDouble(value);
        }
        else if (propertyName.equals(STEPS_PROPERTY )) {
            numberOfSteps = Integer.parseInt(value);
            if (numberOfSteps > MAX_STEP_NUMBER) numberOfSteps = MAX_STEP_NUMBER;
        }
        else if (propertyName.equals(IS_SINGLE_CLASS_PROPERTY )) {
            singleClass = Boolean.valueOf(value).booleanValue();
        }
        else if (propertyName.equals(REFERENCE_STATION_PROPERTY )) {
            stationKey = stationDef.getStationByName(value);
        }
        else if (propertyName.equals(REFERENCE_CLASS_PROPERTY )) {
            classKey = classDef.getClassByName(value);
        }
    }

    /**
     * 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 station key whose service times will be varied
     * @return the key of the station whose service times will be varied
     */
    public Object getReferenceStation() {
        return stationKey;
    }

    /**
     * Gets name of the whose service times will be varied
     * @return the key of the station whose service times will be varied
     */
    public String getReferenceStationName() {

⌨️ 快捷键说明

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