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

📄 servicetimesparametricanalysis.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return stationDef.getStationName(stationKey);
    }

    /**
     * Sets the station whose service times will be varied
     * @param stationKey the station whose service times will be varied
     */
    public void setReferenceStation(Object stationKey) {
        this.stationKey = stationKey;
    }

    /**
     * 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 refST = (Double)((Vector)values).get(step);
                Distribution distr = (Distribution)stationDef.getServiceTimeDistribution(stationKey,classKey);
                distr.setMean(refST.doubleValue());
            }
            else {
                //Vector classSet = classDef.getClassKeys();
                for (int i=0; i<avaibleClasses.size(); i++) {
                    Object thisClass = avaibleClasses.get(i);
                    double refST = ((ValuesTable)values).getValue(thisClass,step);
                    Distribution distr = (Distribution)stationDef.getServiceTimeDistribution(stationKey,thisClass);
                    distr.setMean(refST);
                }
            }
        }
    }

    /**
     * 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 parameter on which the
     * simulation may be iterated on.
     *
     */
    public void createValuesSet() {
        double initialServiceTime;
        if (singleClass) {
            double sum = 0;
            double increment = (finalValue - initialValue)/((double)(numberOfSteps-1));
            values = new Vector(numberOfSteps);
            for (int i=0;i<numberOfSteps;i++) {
                double value = initialValue + sum;
                ((Vector)values).add(new Double(value));
                sum += increment;                              //note that the increment may be < 0
            }
            originalValues = new Double(initialValue);
        }
        else {
            double sum = 1;
            double increment = (finalValue - initialValue)/(100*(double)(numberOfSteps-1));
            //find the set of avaible classes
            Vector allClasses = classDef.getClassKeys();
            avaibleClasses = new Vector(0,1);
            for (int i=0;i<allClasses.size();i++) {
                Object thisClass = allClasses.get(i);
                Object temp = stationDef.getServiceTimeDistribution(stationKey,thisClass);
                if (temp instanceof Distribution) {
                    Distribution distr = (Distribution) temp;
                    if (distr.hasMean()) avaibleClasses.add(thisClass);
                }
            }
            values = new ValuesTable(classDef,avaibleClasses,numberOfSteps);
            for (int i=0; i<numberOfSteps; i++) {
                for (int k=0;k<avaibleClasses.size();k++) {
                    Object thisClass = avaibleClasses.get(k);
                    double thisInitialServiceTime = ((Distribution)stationDef.getServiceTimeDistribution(stationKey,thisClass)).getMean();
                    double value = thisInitialServiceTime*(sum);
                    ((ValuesTable)values).setValue(thisClass,value);
                }
                sum += increment;                                    //note that the increment may be < 0
            }
            //used to save the initial values of service time
            originalValues = new Vector(avaibleClasses.size());
            for (int i=0; i<avaibleClasses.size();i++) {
                Object thisClass = avaibleClasses.get(i);
                double thisServiceTime = ((Distribution)stationDef.getServiceTimeDistribution(stationKey,thisClass)).getMean();
                ((Vector)originalValues).add(new Double(thisServiceTime));
            }
        }
    }

    /**
     * Restore the original values of service times
     */
    public void restoreOriginalValues() {
        if (originalValues != null) {
            if (singleClass) {
                Distribution distr = (Distribution)stationDef.getServiceTimeDistribution(stationKey,classKey);
                Double mean = (Double)originalValues;
                distr.setMean(mean.doubleValue());
            }
            else {
                Vector values = (Vector)originalValues;
                for (int i=0;i<avaibleClasses.size();i++) {
                    Object thisClass = avaibleClasses.get(i);
                    Distribution distr = (Distribution)stationDef.getServiceTimeDistribution(stationKey,thisClass);
                    Double thisValue = (Double)values.get(i);
                    distr.setMean(thisValue.doubleValue());
                }
            }
        }
        //modified = false;
    }

    /**
     * Checks if the PA model is still coherent with simulation model definition. If
     * the <code>autocorrect</code> variable is set to true, if the PA model is no more
     * valid but it can be corrected it will be changed.
     *
     * @param autocorrect if true the PA model will be autocorrected
     *
     * @return 0 - If the PA model is still valid <br>
     *         1 - If the PA model is no more valid, but it will be corrected <br>
     *         2 - If the PA model can be no more used
     */
    public int checkCorrectness(boolean autocorrect) {
        int code = 0;
        Vector classes = classDef.getClassKeys();
        ParametricAnalysisChecker checker = new ParametricAnalysisChecker(classDef,stationDef,simDef);
        //Find the avaible stations
        Vector avaibleStations = checker.checkForServiceTimesParametricAnalysisAvaibleStations();
        if (avaibleStations.isEmpty()) code = 2;     // -> This type of PA is not avaible
        else {
            //if the reference station is no more avaible change reference station
            if (!avaibleStations.contains(stationKey)) {
                code = 1;
                if (autocorrect) {
                    stationKey = avaibleStations.get(0);
                    setDefaultInitialValue();
                    setDefaultFinalValue();
                }
            }
            //Find avaible classes for stationKey
            Vector avaibleClasses = checker.checkForServiceTimesParametricSimulationAvaibleClasses(stationKey);
            //if is single class...
            if (isSingleClass()) {
                // ... and the selected close class is no more avaible
                if (!avaibleClasses.contains(classKey)) {
                    code = 1;
                    if (autocorrect) {
                        classKey = avaibleClasses.get(0);   //change the reference class
                        setDefaultInitialValue();
                        setDefaultFinalValue();
                    }
                }
                else {
                    double mean = ((Distribution)stationDef.getServiceTimeDistribution(stationKey,classKey)).getMean();
                    //If the service time of reference class was changed...
                    if (initialValue != mean) {
                        code = 1;
                        if (autocorrect) {
                            initialValue = mean;
                            finalValue = mean*INCREMENT_SINGLE;
                        }
                    }
                }
            }
            //all class case...
            else {
                if ( (avaibleClasses.size() < classes.size()) || (classes.size() == 1) ) {    //all class parametric analysis is no more avaible
                    code = 1;
                    if (autocorrect) {
                        singleClass = true;
                        classKey = avaibleClasses.get(0);
                        setDefaultInitialValue();
                        setDefaultFinalValue();
                    }
                }
            }
        }
        return code;
    }

    /**
     * Returns the values assumed by the varying parameter
     *
     * @return a Vector containing the values assumed by the varying parameter
     */
    public Vector getParameterValues() {
        Vector assumedValues = new Vector(numberOfSteps);
        if (singleClass) {
            return (Vector)values;
        }
        else {
            ValuesTable temp = (ValuesTable)values;
            double originalValue = ((Double)((Vector)originalValues).get(0)).doubleValue();
            for (int i=0; i<numberOfSteps; i++) {
                double thisValue = temp.getValue(avaibleClasses.get(0),i);
                double ratio = thisValue/originalValue*100;
                assumedValues.add(new Double(ratio));
            }
        }
        return assumedValues;
    }


}

⌨️ 快捷键说明

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