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

📄 paresultsmodel.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;



import jmt.engine.QueueNet.SimConstants;
import jmt.gui.common.definitions.StoredResultsModel.Measure;

import java.util.HashMap;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: francesco
 * Date: 22-feb-2006
 * Time: 12.17.58
 * To change this template use File | Settings | File Templates.
 */
public class PAResultsModel implements MeasureDefinition{
    private Vector measures; // An array with all Measures
    private Vector parameterValues;
    private Vector queueLength = new Vector();
    private Vector queueTime = new Vector();
    private Vector residenceTime = new Vector();
    private Vector responseTime = new Vector();
    private Vector utilization = new Vector();
    private Vector throughput = new Vector();
    private Vector systemThroughput = new Vector();
    private Vector systemResponseTime = new Vector();
    private Vector customerNumber = new Vector();
    private HashMap names = new HashMap();
    //private boolean[] finished;
    //private boolean simulationFinished = false;

    public PAResultsModel(CommonModel model) {
        Vector measureKeys = model.getMeasureKeys();
        measures = new Vector(measureKeys.size());
        for (int i=0; i<measureKeys.size(); i++) {
            Object thisMeasure = measureKeys.get(i);
            String stationName = model.getStationName(model.getMeasureStation(thisMeasure));
            if (stationName == null) stationName = "Network";
            String className = model.getClassName(model.getMeasureClass(thisMeasure));
            if (className == null) className = "All classes";
            String type = model.getMeasureType(thisMeasure);
            String measureName = stationName + "_" + className + "_" + type;
            double thisAlpha = model.getMeasureAlpha(thisMeasure).doubleValue();
            double thisPrecision = model.getMeasurePrecision(thisMeasure).doubleValue();
            // Decodes measure type
            type = type.toLowerCase();
            int numType = 0;
            if (type.startsWith("queue") && type.endsWith("length")) {
                numType = SimConstants.QUEUE_LENGTH;
                queueLength.add(new Integer(i));
            }
            else if (type.startsWith("utilization")) {
                numType = SimConstants.UTILIZATION;
                utilization.add(new Integer(i));
            }

            else if (type.startsWith("throughput")) {
                numType = SimConstants.THROUGHPUT;
                throughput.add(new Integer(i));
            }
            else if (type.startsWith("response") && type.endsWith("time")) {
                numType = SimConstants.RESPONSE_TIME;
                responseTime.add(new Integer(i));
            }
            else if (type.startsWith("residence") && type.endsWith("time")) {
                numType = SimConstants.RESIDENCE_TIME;
                residenceTime.add(new Integer(i));
            }
            else if (type.startsWith("queue") && type.endsWith("time")) {
                numType = SimConstants.QUEUE_TIME;
                queueTime.add(new Integer(i));
            }
            else if (type.startsWith("system")) {
                if  (type.endsWith("throughput")) {
                    numType = SimConstants.SYSTEM_THROUGHPUT;
                    systemThroughput.add(new Integer(i));
                }
                else if (type.endsWith("time")) {
                    numType = SimConstants.SYSTEM_RESPONSE_TIME;
                    systemResponseTime.add(new Integer(i));
                }
            }
            else if (type.startsWith("customer") && type.endsWith("number")) {
                numType = SimConstants.SYSTEM_JOB_NUMBER;
                customerNumber.add(new Integer(i));
            }
            measures.add(new Measure(measureName,stationName,className,thisAlpha,thisPrecision,numType));
        }
        parameterValues = model.getParametricAnalysisModel().getParameterValues();
    }
    
    public PAResultsModel(CommonModel model, boolean loadFromFile) {
        measures = new Vector();
        parameterValues = model.getParametricAnalysisModel().getParameterValues();
    }

    /**
     * Adds a new measure into this data structure.
     * @param name measure name
     * @param stationName reference station name
     * @param className reference class name
     * @param alpha measure alpha
     * @param precision measure precision
     * @param type type of the measure
     */
    public void addMeasure(String name, String stationName, String className,
                       double alpha, double precision, int type) {
        Measure tmp = new Measure(name, stationName, className, alpha,precision, type);
        measures.add(tmp);
        names.put(name, tmp);
        // Adds measure index to the right Vector
        switch(type) {
            case SimConstants.QUEUE_TIME:
                queueTime.add(new Integer(measures.size()-1));
                break;
            case SimConstants.RESIDENCE_TIME:
                residenceTime.add(new Integer(measures.size()-1));
                break;
            case SimConstants.RESPONSE_TIME:
                responseTime.add(new Integer(measures.size()-1));
                break;
            case SimConstants.UTILIZATION:
                utilization.add(new Integer(measures.size()-1));
                break;
            case SimConstants.THROUGHPUT:
                throughput.add(new Integer(measures.size()-1));
                break;
            case SimConstants.QUEUE_LENGTH:
                queueLength.add(new Integer(measures.size()-1));
                break;
            case SimConstants.SYSTEM_RESPONSE_TIME:
                systemResponseTime.add(new Integer(measures.size()-1));
                break;
            case SimConstants.SYSTEM_JOB_NUMBER:
                customerNumber.add(new Integer(measures.size()-1));
                break;
            case SimConstants.SYSTEM_THROUGHPUT:
                systemThroughput.add(new Integer(measures.size()-1));
                break;
        }
    }

    public void addSample(int measureIndex, double lowerBound, double meanValue,double upperBound, boolean validity) {
        Measure requested = (Measure)measures.get(measureIndex);
        requested.addSample(meanValue,upperBound,lowerBound,validity);
    }
    
    public void addSample(String measureName, double lowerBound, double meanValue,double upperBound, boolean validity) {
        Measure requested = (Measure)names.get(measureName);
        requested.addSample(meanValue,upperBound,lowerBound,validity);
    }
    

    public Vector getParameterValues() {
        return parameterValues;
    }

    /**
     * Returns total number of measures
     *
     * @return number of measures
     */
    public int getMeasureNumber() {
        return measures.size();
    }

    /**
     * Returns the station name of a given measure
     *
     * @param measureIndex index of the measure
     * @return station name
     */
    public String getStationName(int measureIndex) {
        String name = ((Measure)measures.get(measureIndex)).stationName;
        //if (name == null) name = "Network";
        return name;
    }

    /**
     * Returns the class name of a given measure
     *
     * @param measureIndex index of the measure
     * @return class name
     */
    public String getClassName(int measureIndex) {
        String name = ((Measure)measures.get(measureIndex)).className;
        //if (name == null) name = "All classes";
        return name;
    }

    /**
     * Returns the alpha of a given measure
     *
     * @param measureIndex index of the measure
     * @return alpha
     */
    public double getAlpha(int measureIndex) {
        return ((Measure)measures.get(measureIndex)).alpha;
    }

    /**
     * Returns the precision of a given measure
     *
     * @param measureIndex index of the measure
     * @return precision
     */
    public double getPrecision(int measureIndex) {
        return ((Measure)measures.get(measureIndex)).precision;
    }

    /**
     * Returns number of analized samples for a given measure. For parametric
     * analysis this number is equal to the number of performed steps
     *
     * @param measureIndex index of the measure
     * @return number of analized samples
     */
    public int getAnalizedSamples(int measureIndex) {
        return ((Measure)(measures.get(measureIndex))).getNumberOfSamples();
    }

    /**
     * Returns the name of a given measure
     *
     * @param measureIndex index of the measure
     * @return name of the measure
     */
    public String getName(int measureIndex) {
        return ((Measure)measures.get(measureIndex)).name;
    }

    /**
     * Returns the vector of values of a given measure. Each element of the vector
     * is an instance of <code>MeasureValue</code> interface.
     *
     * @param measureIndex index of the measure
     * @return vector of values
     */
    public Vector getValues(int measureIndex) {
        return ((Measure)measures.get(measureIndex)).getValues();
    }

    /**
     * Returns the state of a measure
     *
     * @param measureIndex index of the measure
     * @param step the step
     * @return true if it was computed successfully, false otherwise
     */
    public boolean getMeasureState(int measureIndex,int step) {
        MeasureValue value = (MeasureValue) (getValues(measureIndex).get(step));
        return value.isValid();
    }

    /**
     * Returns the type of a measure
     *
     * @param measureIndex index of the measure
     * @return measure type
     */
    public int getMeasureType(int measureIndex) {
        return ((Measure)measures.get(measureIndex)).type;

⌨️ 快捷键说明

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