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

📄 modelchecker.java

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

    /**
     * Checks that there are no sources without a class associated to. If a problem is found it raises
     * to "true" the corresponding position inside the problems array.
     */
    private void checkForSourcesWithNoClassesError() {
        // get the vector of the keys of the stations
        Vector stationKeys = station_def.getStationKeys();

        for (int i=0; i<stationKeys.size();i++) {
            //get the sourceKey at i
            Object thisStationKey = stationKeys.get(i);
            //get the type of the station
            String type = station_def.getStationType(thisStationKey);
            if (type.equals(STATION_TYPE_SOURCE)) {
                //this variable is true if no classes are associated to this source
                boolean noClassesAssociated = true;
                //get the vector of the class keys....
                Vector classKeys = class_def.getClassKeys();
                for (int j=0;j<classKeys.size();j++) {
                    //get the key of the class at j
                    Object thisClassKey = classKeys.get(j);
                    //get the key of the reference station of this class
                    Object refStationKeyForThisClass = class_def.getClassRefStation(thisClassKey);
                    //if the key of the reference station and the key of the source considered
                    //are the same it means that there is at least one class associated to the source
                    if (refStationKeyForThisClass == thisStationKey) noClassesAssociated = false;
                }
                //if the variable noClassesAssociated is still true it means that this source has
                //no classes associated to
                if (noClassesAssociated) {
                    errors[SOURCE_WITH_NO_OPEN_CLASSES_ERROR] = true;
                    sourceWithoutClasses.add(thisStationKey);
                }
            }
        }
    }

    /**
     * Check if there is at least one open class but there are no sinks. If a problem is found it raises
     * to "true" the corresponding position inside the problems array.
     */
    private void checkForNoSinkWithOpenClassError() {
        //vector used to contain the set of open class keys
        Vector openClasses = new Vector(0,1);
        //vector used to contain the complete set class keys
        Vector classes = class_def.getClassKeys();
        //for cicle used to collect the open class keys from the classes vector
        for (int i=0; i<classes.size(); i++) {
            Object thisClassKey = classes.get(i);
            if (class_def.getClassType(thisClassKey) == CLASS_TYPE_OPEN) openClasses.add(thisClassKey);
        }
        //if there is at least one open class
        if (openClasses.size() > 0) {
            //variable counting the number of sink
            int nSink = 0;
            //vector containing the complete set of class keys
            Vector stations = station_def.getStationKeys();
            //for each station ...
            for (int i=0; i<stations.size(); i++) {
                Object thisStationKey = stations.get(i);
                // ... check if it is a sink, in that case increase the nSink variable
                if (station_def.getStationType(thisStationKey).equals(STATION_TYPE_SINK)) nSink++;
            }
            //if no sink was found there is an error
            errors[NO_SINK_WITH_OPEN_CLASSES_ERROR] = nSink == 0;
        }
        //if there are no open classes there are no errors
        else errors[NO_SINK_WITH_OPEN_CLASSES_ERROR] = false;
    }

    /**
     * Checks if there is at least an open class but no source have been defined
     */
    private void checkForOpenClassButNoSourceError() {
        //variable used to count the number of open classes
        int openClasses = 0;
        //vector used to contain the complete set class keys
        Vector classes = class_def.getClassKeys();
        //for cicle used to collect the open class keys from the classes vector
        for (int i=0; i<classes.size(); i++) {
            Object thisClassKey = classes.get(i);
            if (class_def.getClassType(thisClassKey) == CLASS_TYPE_OPEN) openClasses++;
        }
        if (openClasses == 0) errors[OPEN_CLASS_BUT_NO_SOURCE_ERROR] = false;
        else {
            //Vector containing the entire station key set
            Vector stations = station_def.getStationKeys();
            //variable counting the number of source
            int nSource = 0;
            for (int i=0;i<stations.size();i++) {
                Object thisStation = stations.get(i);
                String type = station_def.getStationType(thisStation);
                if (type.equals(STATION_TYPE_SOURCE)) nSource++;
            }
            //if no sources have been defined there is an error
            errors[OPEN_CLASS_BUT_NO_SOURCE_ERROR] = nSource == 0;
        }
    }

    /**
     * Checks if there is at least a sink but no open classes have been defined
     */
    private void checkForSinkButNoOpenClassError() {
        //vector used to contain the complete set of station keys
        Vector stationSet = station_def.getStationKeys();
        //variable used to count the number of sink station
        int nSink = 0;
        //for cycle used to count the number of sink
        for (int i=0; i<stationSet.size(); i++) {
            Object thisStation = stationSet.get(i);
            String stationType = station_def.getStationType(thisStation);
            if (stationType.equals(STATION_TYPE_SINK)) nSink++;
        }
        if (nSink > 0) {
            //variable used to count the number of open class keys
            int nOpenClasses = 0;
            //vector used to contain the complete set class keys
            Vector classes = class_def.getClassKeys();
            //for cicle used to count the number of open class keys
            for (int i=0; i<classes.size(); i++) {
                Object thisClassKey = classes.get(i);
                if (class_def.getClassType(thisClassKey) == CLASS_TYPE_OPEN) nOpenClasses++;
            }
            //if there is at least one open class
            errors[SINK_BUT_NO_OPEN_CLASSES_ERROR] = nOpenClasses <= 0;
        }
        else errors[SINK_BUT_NO_OPEN_CLASSES_ERROR] = false;
    }

    /**
     * Checks:
     * 1) Each Source is forward linked to something.
     * 2) Each Server is forward linked to something.
     * 3) Each Delay is forward linked to something.
     * 4) Each Sink is backward linked to something.
     * If a problem is found it raises to "true" the corresponding position
     * inside the problems array.
     */
    private void checkForStationLinkError() {
        // get the vector of the keys of the stations
        Vector stationKeys = station_def.getStationKeys();

        for (int i=0;i<stationKeys.size();i++) {
            //get the key of the station at i
            Object thisStationKey = stationKeys.get(i);
            //get the type of the station
            String stationType = station_def.getStationType(thisStationKey);

            if (stationType.equals(STATION_TYPE_SOURCE)){
                //get the vector of forward links
                Vector connections = station_def.getForwardConnections(thisStationKey);
                //if the vector is empty the source is not forward connected
                if (connections.isEmpty()) {
                    errors[STATION_LINK_ERROR] = true;
                    stationsWithLinkErrors.add(thisStationKey);
                }

            }

            else if (stationType.equals(STATION_TYPE_SINK)) {
                //get the vector of backward links
                Vector connections = station_def.getBackwardConnections(thisStationKey);
                //if the vector is empty the Sink is not backward connected
                if (connections.isEmpty()) {
                    errors[STATION_LINK_ERROR] = true;
                    stationsWithLinkErrors.add(thisStationKey);
                }
            }

            else  {
                //get the vector of forward links
                Vector connections = station_def.getForwardConnections(thisStationKey);
                //if the vector is empty the Server is not forward connected
                if (connections.isEmpty()) {
                    errors[STATION_LINK_ERROR] = true;
                    stationsWithLinkErrors.add(thisStationKey);
                }
            }

        }
    }

    /**
     * Checks for the existance of empty blocking regions
     * <br>Author: Bertoli Marco
     */
    private void checkForEmptyBlockingRegions() {
        Iterator regionKeys = blocking_def.getRegionKeys().iterator();
        while (regionKeys.hasNext()) {
            Object key = regionKeys.next();
            if (blocking_def.getBlockingRegionStations(key).size() == 0) {
                // Blocking region 'key' is empty
                emptyBlockingRegions.add(key);
                errors[EMPTY_BLOCKING_REGION] = true;
            }
        }
    }

    /**
     * Checks if a station in a blocking region is preloaded
     * <br>Author: Bertoli Marco
     */
    private void checkForPreloadingInBlockingRegions() {
        Iterator regionKeys = blocking_def.getRegionKeys().iterator();
        Vector classes = class_def.getClassKeys();
        while (regionKeys.hasNext()) {
            Object key = regionKeys.next();
            Set stations = blocking_def.getBlockingRegionStations(key);
            Iterator st = stations.iterator();
            while (st.hasNext()) {
                Object stationKey = st.next();
                for (int i=0; i<classes.size(); i++)
                    if(simulation_def.getPreloadedJobs(stationKey, classes.get(i)).intValue() > 0) {
                        errors[PRELOADING_WITH_BLOCKING] = true;
                    }
            }


            if (blocking_def.getBlockingRegionStations(key).size() == 0) {
                // Blocking region 'key' is empty
                emptyBlockingRegions.add(key);
                errors[EMPTY_BLOCKING_REGION] = true;
            }
        }
    }

    /**
     * Checks that no closed classes may be routed into a Sink. If a problem is found it raises
     * to "true" the corresponding position inside the errors array.
     */
    private void checkForRoutingError() {
        //vector collecting all the station keys where routing problems occour
        // for this close class
        Vector problemsPerClass = new Vector(0,1);
        Vector closedClassKeys = class_def.getClosedClassKeys();
        Vector startingPoints = new Vector (0,1);
        //get the vector of the possible starting points
        Vector noSourceSink = station_def.getStationKeysNoSourceSink();
        for (int i=0;i<closedClassKeys.size();i++) {
            //remove all elements from the problemsPerClass vector
            problemsPerClass.removeAllElements();
            //create the vector containing the already visited station keys
            Vector alreadyVisited = new Vector(0,1);
            //get the class at i
            Object thisClassKey = closedClassKeys.get(i);
            //checks for each possible starting point if there are preloaded jobs for the class i.
            //In that case put it into the startingPoints vector
            for (int j=0; j<noSourceSink.size(); j++) {
                Object thisElementKey = noSourceSink.get(j);
                int preloadedJobs = simulation_def.getPreloadedJobs(thisElementKey,thisClassKey).intValue();
                if (preloadedJobs > 0) startingPoints.add(thisElementKey);
            }
            //start the explore algorithm for each of the station containing some preloaded jobs for class i
            for (int j=0; j<startingPoints.size(); j++) {
                //get the element at j
                Object thisStartingPoint = startingPoints.get(j);
                //if this possible starting point has not been visited yet
                if (!alreadyVisited.contains(thisStartingPoint)) {
                    alreadyVisited.add(thisStartingPoint);
                    Vector problemsForThisStartingPoint = exploreForRoutingProblems(thisClassKey,thisStartingPoint,alreadyVisited);
                    for (int k=0;k<problemsForThisStartingPoint.size();k++) {
                        problemsPerClass.add(problemsForThisStartingPoint.get(k));
                    }
                }
            }
            if (!problemsPerClass.isEmpty()) {
                routingErrors.put(thisClassKey,problemsPerClass.clone());
                errors[ROUTING_ERROR] = true;
            }
        }
    }

    /**
     * Checks that no closed classes may be routed into a station whose forward station(s) are
     * all sink. If a problem is found it raises to "true" the corresponding position inside
     * the errors array.
     */
    private void checkForAllForwardStationsAreSinkError() {
        //vector collecting all the station keys where errors occour
        // for this close class
        Vector problemsPerClass = new Vector(0,1);
        Vector closedClassKeys = class_def.getClosedClassKeys();
        Vector startingPoints = new Vector (0,1);
        //get the vector of the possible starting points
        Vector noSourceSink = station_def.getStationKeysNoSourceSink();
        for (int i=0;i<closedClassKeys.size();i++) {
            //remove all elements from the problemsPerClass vector
            problemsPerClass.removeAllElements();
            //create the vector containing the already visited station keys

⌨️ 快捷键说明

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