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

📄 resultscheck.java

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

        Dispatcher_jMVAschema solver = new Dispatcher_jMVAschema(model);
        solver.setDeleteIntermediateFiles(deleteIntermediateSimFiles);
        if (!automaticSeed) {
            solver.setSimulationSeed(userDefinedSeed);
        }
        boolean success = solver.solveModel();
        return success;
    }


    /**
     * Compares the solutions of jMVA and jSIM and writes on log.
     * The wealth of information depends on the value of the "extendedInfo" property.
     * This method can be called only after solving the model in both ways
     * @return an XML file containing the report of solutions check
     */
    private File createTestReport(Document jmva_doc, Document jsim_doc) {

        //data structures which will contain the results

        //computes the number of measures
        int measuresNumber = jsim_doc.getElementsByTagName("measure").getLength();

        logger.debug(measuresNumber + " found in jSIM results.");


        //list of all station results object
        NodeList statRes = jsim_doc.getElementsByTagName("stationresults");
        int statResLength = statRes.getLength();



        //loop over all station results
        for (int s = 0; s < statResLength; s++) {
            //current station element
            Element currStation = (Element) statRes.item(s);
            String currStationName = currStation.getAttribute("station");


            //list of all class results for the current station
            NodeList classRes = currStation.getElementsByTagName("classresults");
            int classResLength = classRes.getLength();


            //loop over all class results
            for (int c = 0; c < classResLength; c++) {
                //current class element
                Element currClass = (Element) classRes.item(c);
                String currClassName = currClass.getAttribute("customerclass");

                //list of all measures
                NodeList measRes = currClass.getElementsByTagName("measure");
                int measResLength = measRes.getLength();

                //loop over all measures
                for (int m = 0; m < measResLength; m++) {
                    Element currMeasure = (Element) measRes.item(m);
                    String currMeasureName = currMeasure.getAttribute("measureType");

                    //measure data
                    boolean success = currMeasure.getAttribute("successful").equalsIgnoreCase("true");

                    double mean, lower, upper, exact;
                    int max, analyzed, discarded;
                    double alfa, precision;
                    String msg, extendedMsg = "";

                    boolean correctConfidenceInterval;

                    String modelName = model_file.getName();
                    int simulationRun = simulationRunsCounter;

                    exact = findExactValue(jmva_doc, currStationName, currClassName, currMeasureName);

                    if (success) {
                        //confidence interval was successfully computed
                        //exact value may be contained or not contained in this interval

                        lower = Double.parseDouble(currMeasure.getAttribute("lowerLimit"));
                        mean = Double.parseDouble(currMeasure.getAttribute("meanValue"));
                        upper = Double.parseDouble(currMeasure.getAttribute("upperLimit"));

                        if (extendedInfo) {
                            max = Integer.parseInt(currMeasure.getAttribute("maxSamples"));
                            analyzed = Integer.parseInt(currMeasure.getAttribute("analyzedSamples"));
                            discarded = Integer.parseInt(currMeasure.getAttribute("discardedSamples"));
                            alfa = Double.parseDouble(currMeasure.getAttribute("alfa"));
                            precision = Double.parseDouble(currMeasure.getAttribute("precision"));

                            extendedMsg = alfa + ";" + precision + ";" + analyzed + ";" +
                                    discarded + ";" + max + ";";
                        }

                        //check whether the exact value is contained into the confidence interval

                        if ((exact >= lower) && (exact <= upper)) {
                            //is contained
                            correctConfidenceInterval = true;

                            msg = modelName + ";" + simulationRun + ";" + currStationName + ";" + currClassName + ";" +
                                    currMeasureName + ";" + exact + ";" + lower + ";" + mean + ";" + upper + ";" +
                                    "CORRECT" + ";";
                            if (extendedInfo) {
                                msg = msg + extendedMsg;
                            }
                            logger.info(msg);

                        } else {
                            //is not contained
                            correctConfidenceInterval = false;

                            msg = modelName + ";" + simulationRun  + ";" + currStationName + ";" + currClassName + ";" +
                                    currMeasureName + ";" + exact + ";" + lower + ";" + mean + ";" + upper + ";" +
                                    "NOT CORRECT" + ";";
                            if (extendedInfo) {
                                msg = msg + extendedMsg;
                            }

                            logger.warn(msg);
                        }

                    } else {
                        //confidence interval not successfully computed
                        correctConfidenceInterval = false;


                        lower = Double.parseDouble(currMeasure.getAttribute("lowerLimit"));
                        mean = Double.parseDouble(currMeasure.getAttribute("meanValue"));
                        upper = Double.parseDouble(currMeasure.getAttribute("upperLimit"));

                        if (extendedInfo) {
                            max = Integer.parseInt(currMeasure.getAttribute("maxSamples"));
                            analyzed = Integer.parseInt(currMeasure.getAttribute("analyzedSamples"));
                            discarded = Integer.parseInt(currMeasure.getAttribute("discardedSamples"));
                            alfa = Double.parseDouble(currMeasure.getAttribute("alfa"));
                            precision = Double.parseDouble(currMeasure.getAttribute("precision"));

                            extendedMsg = alfa + ";" + precision + ";" + analyzed + ";" +
                                    discarded + ";" + max + ";";
                        }


                        msg = modelName + ";" + simulationRun  + ";" + currStationName + ";" + currClassName + ";" +
                                    currMeasureName + ";" + exact + ";" + lower + ";" + mean + ";" + upper + ";" +
                                    "NOT COMPUTED" + ";";
                            if (extendedInfo) {
                                msg = msg + extendedMsg;
                            }

                        logger.warn(msg);

                    }
                }

            }

        }


        return null;
    }




    /**
     * Returns the exact value of the measure requested by the user
     * @param jmvaDocument Document containing the mva solutions
     * @param stat the station measure refers to
     * @param cls the class measure refers to
     * @param type the measure type
     * @return the exact value of the measure, NaN if the requested measure does not exist
     */
    private double findExactValue(Document jmvaDocument, String stat, String cls, String type) {
        //retrieves station results
        NodeList statRes = jmvaDocument.getElementsByTagName("stationresults");
        int statResLength = statRes.getLength();

        for (int i = 0; i < statResLength; i++) {
            //current station
            Element currentStat = (Element) statRes.item(i);

            if (currentStat.getAttribute("station").equalsIgnoreCase(stat)) {
                //it's the correct station

                //retrieves class results of this station
                NodeList classRes = currentStat.getElementsByTagName("classresults");
                int classResLength = classRes.getLength();

                for (int j = 0; j < classResLength; j++) {
                    //current class
                    Element currentCls = (Element) classRes.item(j);

                    if (currentCls.getAttribute("customerclass").equalsIgnoreCase(cls)) {
                        //it's the correct class

                        //retrieves the measures of this (station, class)
                        NodeList measures = currentCls.getElementsByTagName("measure");
                        int measureLength = measures.getLength();

                        for (int k = 0; k < measureLength; k++) {
                            //current measure
                            Element currentMeas = (Element) measures.item(k);

                            if (currentMeas.getAttribute("measureType").equalsIgnoreCase(type)) {
                                //it's the requested measure

                                double exactValue = Double.parseDouble(currentMeas.getAttribute("meanValue"));
                                return exactValue;

                            }

                            //else iterates to next measure
                        }
                    }
                     //else iterates to next class
                }
            }
            //else iterates to next station
        }

        //this point should never been reached!!!

        return Double.NaN;
    }








    /**
     * Load an xml file and returns the corresponding DOM object
     * @param is Input Stream
     * @return the DOM representation of the file
     * @throws FileNotFoundException
     */
    private Document load(InputStream is) throws FileNotFoundException {
		if (is == null)
			throw new FileNotFoundException("File not Found");
		InputSource inputSource = new InputSource(is);
		//create a parser
        DOMParser parser = new DOMParser();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setValidating(true);
		factory.setNamespaceAware(true);

        Document document = null;

		try {
            // turn on schema validation ( note need to set both sax and dom validation )
			parser.setFeature("http://xml.org/sax/features/validation", true);
			parser.setFeature("http://apache.org/xml/features/validation/schema", true);
			parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);


            //NEW
            //TODO: setto lo schema xsd con cui fare il parsing
            String externalSchemaLocation = XSDSchemaLoader.loadSchema(XSDSchemaLoader.JMVA_MODEL_DEFINITION);
            parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                    externalSchemaLocation);
            //end NEW

            try {
                //document parsing
				parser.parse(inputSource);
			} catch (FileNotFoundException e) {
				throw new LoadException("Problems parsing", e);
			}

            //get the w3c document
			document = parser.getDocument();

        } catch (SAXNotRecognizedException e) {
			e.printStackTrace();
		} catch (SAXNotSupportedException e) {
			e.printStackTrace();
		} catch (SAXException sxe) {
			// Error generated during parsing
			Exception x = sxe;
			if (sxe.getException() != null)
				x = sxe.getException();
			x.printStackTrace();

		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

        return document;
    }






}



⌨️ 快捷键说明

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