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

📄 parametricanalysischecker.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 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 jmt.gui.common.distributions.Distribution;

import java.util.Vector;

/**
 * <p>Title: ParametricAnalysisChecker </p>
 * <p>Description: the main task of this class is to check which parametric analysis simulation
 *           are avaible. It offers also some other methods used to get avaible stations and
 *           classes for some types of parametric analysis.</p>
 *
 * @author Francesco D'Aquino
 *         Date: 1-feb-2006
 *         Time: 11.00.12
 */
public class ParametricAnalysisChecker {
    private ClassDefinition cd;
    private StationDefinition sd;
    private SimulationDefinition simd;

    /**
     *
     * @param cd class definition
     * @param sd simulation definition
     * @param simd simulation definition
     */
    public ParametricAnalysisChecker(ClassDefinition cd, StationDefinition sd, SimulationDefinition simd) {
        this.cd = cd;
        this.sd = sd;
        this.simd = simd;
    }

    /**
     * Checks if at least one parametric simulation is avaible.
     * @return true if at least one parametric simulation is avaible.
     */
    public boolean canBeEnabled() {
        boolean canBeEnabled = true;
        Vector classes = cd.getClassKeys();
        Vector stations = sd.getStationKeys();
        if ((classes.size() == 0) || (stations.size() == 0) || (getRunnableParametricAnalysis().length == 0))
            canBeEnabled = false;
        return canBeEnabled;
    }

    /**
     * Gets an array of String containing the description of avaible parametric simulations
     * @return the array
     */
    public String[] getRunnableParametricAnalysis() {
        String[] runnable;
        Vector runnableVector = new Vector(0,1);
        //check if "Number of customer" parametric analysis is runnable
        Vector temp = cd.getClosedClassKeys();
        if (!temp.isEmpty()) runnableVector.add(ParametricAnalysis.PA_TYPE_NUMBER_OF_CUSTOMERS);
        //check if "Population mix" parametric analysis is runnable
        temp = cd.getClosedClassKeys();
        if (temp.size() == 2) runnableVector.add(ParametricAnalysis.PA_TYPE_POPULATION_MIX);
        //check if "Service time" parametric analysis is runnable
        temp = checkForServiceTimesParametricAnalysisAvaibleStations();
        if (!temp.isEmpty()) runnableVector.add(ParametricAnalysis.PA_TYPE_SERVICE_TIMES);
        //check if "Arrival rate" parametric analysis is runnable
        temp = checkForArrivalRatesParametricSimulationAvaibleClasses();
        if (!temp.isEmpty()) runnableVector.add(ParametricAnalysis.PA_TYPE_ARRIVAL_RATE);
        //check if "Seed" parametric analysis is avaible
        if ((!cd.getClassKeys().isEmpty())&&(!sd.getStationKeys().isEmpty())) {
                runnableVector.add(ParametricAnalysis.PA_TYPE_SEED);
        }
        //initilalize runnable array
        runnable = new String[runnableVector.size()];
        for (int i=0; i<runnable.length; i++)
            runnable[i] = (String)runnableVector.get(i);
        return runnable;
    }

    /**
     *  This method has a meaning only if used inside a service times parametric analysis. It
     *  can be used to get the keys of stations avaible to perform that kind of parametric
     *  analysis.
     * @return the Vector containing the keys of avaible stations
     */
    public Vector checkForServiceTimesParametricAnalysisAvaibleStations() {
        Vector avaibleStations = new Vector(0,1);
        Vector stations = sd.getStationKeysNoSourceSink();
        Vector classes = cd.getClassKeys();
        for (int i=0; i<stations.size(); i++) {
            Object thisStation = stations.get(i);
            boolean stationOk = false;
            for (int j=0; j<classes.size(); j++) {
                Object thisClass = classes.get(j);
                Object temp = sd.getServiceTimeDistribution(thisStation,thisClass);
                if (temp instanceof Distribution) {
                    Distribution distr = (Distribution) temp;
                    if (distr.hasMean()) {
                        stationOk = true;
                        break;
                    }
                }
            }
            if (stationOk) avaibleStations.add(thisStation);
        }
        return avaibleStations;
    }

    /**
     * This method has a meaning only if used inside a service times parametric analysis.
     * It can be used to get the keys of classes avaible to perform that kind of parametric
     * analysis.
     * @param stationKey the key of the station whose service times will be varied.
     * @return a Vector containing the keys of avaible classes
     */
    public Vector checkForServiceTimesParametricSimulationAvaibleClasses(Object stationKey) {
        Vector valid = new Vector(0,1);
        Vector classes = cd.getClassKeys();
        for (int j=0; j<classes.size(); j++) {
            Object thisClass = classes.get(j);
            Object temp = sd.getServiceTimeDistribution(stationKey,thisClass);
            if (temp instanceof Distribution) {
                Distribution distr = (Distribution) temp;
                if (distr.hasMean()) {
                    valid.add(thisClass);
                }
            }
        }
        return valid;
    }

    /**
     * This method has a meaning only if used inside an arrival rate parametric analysis.
     * It can be used to get the keys of classes avaible to perform that kind of parametric
     * analysis.
     * @return a Vector containing the keys of avaible classes
     */
    public Vector checkForArrivalRatesParametricSimulationAvaibleClasses() {
        Vector valid = new Vector(0,1);
        Vector classes = cd.getOpenClassKeys();
        for (int j=0; j<classes.size(); j++) {
            Object thisClass = classes.get(j);
            Object temp = cd.getClassDistribution(thisClass);
            if (temp instanceof Distribution) {
                Distribution distr = (Distribution) temp;
                if (distr.hasMean()) {
                    valid.add(thisClass);
                }
            }
        }
        return valid;
    }

}

⌨️ 快捷键说明

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