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

📄 simulation.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     *
     */
    public Document[] getAllMeasures() {
        Document[] tempMeasures = new Document[measures.size()];
        for (int i = 0; i < measures.size(); i++) {
            SimMeasure simMeasure = (SimMeasure) measures.elementAt(i);
            tempMeasures[i] = simMeasure.getMeasure().getNewData();
        }
        return tempMeasures;
    }

    /*
    public NetLog getLog() {
    return log;
    }
    */






    /**
     * Preload jobs in a queue
     */
    public void preload_station(String stationName, int[] jobs) {

        //find the node
        NetNode node = NetSystem.getNode(stationName);

        if (node != null) {
            try {
                //retrieves the input section of the node
                NodeSection section = node.getSection(NodeSection.INPUT);
                if (section instanceof Queue) {
                    //preload jobs for each class
                    ((Queue) section).preloadJobs(jobs);
                }
            } catch (NetException e) {
                return;
            }
        }

    }


    //-------------------------end SUPPORT METHODS---------------------------------//



    //------------------- GETTER AND SETTER ----------------------------------//

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //NEW
    //@author Stefano Omini

    public String getXmlModelDefPath() {
        return xmlModelDefPath;
    }

    public void setXmlModelDefPath(String xmlModelDefPath) {
        this.xmlModelDefPath = xmlModelDefPath;
    }


    public String getXmlSimModelDefPath() {
        return xmlSimModelDefPath;
    }

    public void setXmlSimModelDefPath(String xmlSimModelDefPath) {
        this.xmlSimModelDefPath = xmlSimModelDefPath;
    }

    //end NEW

    //NEW
    //@author Stefano Omini
    public void setRandomEngineSeed(long seed) {
        this.seed = seed;

        randomEng = RandomEngine.makeDefault();
        RandomEngine.setSeed(seed);

    }
    //end NEW


    /**
     *  Sets the max simulation length
     */
    public void setMaxSimulationTime(long maxSimulationTime) {
        this.maxSimulationTime = maxSimulationTime;
        this.timeLimited = true;
    }

    /**
     * Tells whether the simulation has a timer, which sets an upper limit to the
     * simulation time
     * @return true if the simulation has an upper bound for the simulation time
     */
    public boolean isTimeLimited() {
        return timeLimited;
    }


    /**
     * Returns true if the simulation has finished
     * @return true if the simulation has finished
     */
    public boolean hasFinished() {
        return finished;
    }

    //end NEW

    //TODO: servono per blocking
    //NEW
    //@author Stefano Omini
    public QueueNetwork getNetwork() {
        return network;
    }

    /**
     * Returns an array with all the blocking regions defined inside the model
     * @return null if no region has been defined
     */
    public BlockingRegion[] getAllRegions() {
        if (regions.size() == 0) {
            return null;
        }
        BlockingRegion[] regions_vector = new BlockingRegion[regions.size()];

        for (int br = 0; br < regions.size(); br++) {
            regions_vector[br] = (BlockingRegion) regions.get(br);
        }
        return regions_vector;
    }


    /**
     * Returns the array of classes
     * @return the array of classes
     */
    public JobClass[] getClasses() {
        return classes;
    }
    //end NEW



    //NEW
    //@author Stefano Omini
    public void setSimParameters(SimParameters simParameters) {
        this.simParameters = simParameters;
    }
    //end NEW


    //NEW
    //@author Stefano Omini

    public void setPreloadEnabled(boolean preloadEnabled) {
        this.preloadEnabled = preloadEnabled;
    }

    public void setPreload_stationNames(String[] preload_stationNames) {
        this.preload_stationNames = preload_stationNames;
    }

    public void setPreload_initialPopulations(int[][] preload_initialPopulations) {
        this.preload_initialPopulations = preload_initialPopulations;
    }


    //end NEW




    //------------------- end GETTER AND SETTER ----------------------------------//






    //-------------------------SUPPORT CLASSES-------------------------------//


    /**
     * This is a connection between two nodes of the simulation.
     */
    class Connection {
        private String start, end;

        /**
         * Creates a node connection between two stations of the model
         * @param startNode start node
         * @param endNode end node
         */
        public Connection(String startNode, String endNode) {
            start = startNode;
            end = endNode;
        }

        public String getEnd() {
            return end;
        }

        public String getStart() {
            return start;
        }
    }




    /**
     * Creates a measure to be estimated on the simulaton model.
     */
    class SimMeasure {
        private String jClass;
        private Measure measure;
        private String nodeName;
        //see constants in class Simulation
        private int measureType;

        /**
         * Creates a measure to be computed during simulation
         * @param measureType measure type (see constants in class Simulation)
         * @param nodeName node to which this measure refers
         * @param measure Measure object which will control this measure
         * @param jClass class to which this measure refers
         *
         * @throws LoadException
         */
        public SimMeasure(int measureType, String nodeName, Measure measure,
                          String jClass) throws LoadException {

            this.jClass = jClass;
            this.measureType = measureType;
            this.measure = measure;
            this.measure.measureTarget(nodeName, jClass, measureType);
            this.nodeName = nodeName;
            if (this.nodeName == null)
                throw new LoadException("Trying to add a measure to a not-existent node.");
        }

        public Measure getMeasure() {
            return measure;
        }

        public int getMeasureType() {
            return measureType;
        }

        public String getNodeName() {
            return nodeName;
        }

        public String getjClass() {
            return jClass;
        }
    }



    /**
     * Represents a service center in the simulation
     */
    class SimNode {
        private NetNode node;
        //node sections
        private InputSection input;
        private ServiceSection service;
        private OutputSection output;
        //true if the node has been created with all its sections,
        //false otherwise
        private boolean nodeInit;

        //reference nodes are nodes used to compute job throughput or to create jobs
        //(and therefore must receive the START event of simulation)
        private boolean reference = false;

        /**
         * Creates a SimNode object
         * @param name node name
         * @param inSec input section of the node
         * @param serSec service section of the node
         * @param outSec output section of the node
         */
        public SimNode(String name, InputSection inSec, ServiceSection serSec,
                       OutputSection outSec) {
            this.node = new NetNode(name);
            this.input = inSec;
            this.service = serSec;
            this.output = outSec;
//
            nodeInit = true;

            //OLD
            //if (inSec instanceof RandomSource) {
            //NEW
            //@author Stefano Omini
            if ( (inSec instanceof RandomSource) || (inSec instanceof Terminal) ) {
                reference = true;
            }
        }

        /**
         * @deprecated
         * @param nodeName
         */
        public SimNode(String nodeName) {
            this.node = new NetNode(nodeName);
            input = null;
            service = null;
            output = null;
            nodeInit = false;
        }

        public InputSection getInput() {
            return input;
        }

        public NetNode getNode() {
            return node;
        }

        public OutputSection getOutput() {
            return output;
        }

        public ServiceSection getService() {
            return service;
        }

        public void initialize() {
            if (!this.nodeInit) {
            }
        }

        public boolean isReference() {
            return reference;
        }


    }

}

⌨️ 快捷键说明

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