Package jmt.gui.common.definitions.parametric

Examples of jmt.gui.common.definitions.parametric.ParametricAnalysisDefinition


  @Override
  public void run() {
    StoredResultsModel results = null;
    File simulationFile = null;
    ParametricAnalysisDefinition pad = simd.getParametricAnalysisModel();
    pad.createValuesSet();
    PAResultsModel parametricAnalysisResultsModel = new PAResultsModel((CommonModel) simd);
    for (currentStep = 0; currentStep < pad.getNumberOfSteps(); currentStep++) {
      progressWindow.setStepNumber(currentStep + 1);
      pad.changeModel(currentStep);
      try {
        simulationFile = File.createTempFile("~JModelSimulation", ".xml");
        simulationFile.deleteOnExit();
      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "File exception", "Error", JOptionPane.ERROR_MESSAGE);
      }
      simulationFile.deleteOnExit();
      XMLWriter.writeXML(simulationFile, (CommonModel) simd);
      simulator = new Dispatcher_jSIMschema(simulationFile);
      if (simd.getMaximumDuration().longValue() > 0) {
        timer = new PATimerThread(simulator, simd.getMaximumDuration().doubleValue());
        timer.start();
      }
      try {
        simulator.solveModel();
      } catch (OutOfMemoryError err) {
        simulator.abortAllMeasures();
        simulator.killSimulation();
        progressWindow.stop();
        progressWindow.dispose();
        gui.showErrorMessage("Out of memory error. Try to run Java Virtual Machine with more heap size (-Xmx<num>m)");
        break;
      } catch (Exception ex) {
        simulator.abortAllMeasures();
        simulator.killSimulation();
        gui.handleException(ex);
        break;
      }
      File output = simulator.getSimulation().getOutputFile();
      output.deleteOnExit();
      Document doc = XMLReader.loadXML(output.getAbsolutePath());
      results = new StoredResultsModel();
      XMLResultsReader.parseXML(doc, results);
      for (int i = 0; i < results.getMeasureNumber(); i++) {
        Vector thisMes = results.getValues(i);
        int measureState = results.getMeasureState(i);
        Object value = thisMes.get(0);
        boolean valid;
        valid = measureState == MeasureDefinition.MEASURE_SUCCESS;
        //valueSet[i].add(value);
        //validityMap[i].add(Boolean.valueOf(valid));
        MeasureValue tempValue = (MeasureValue) value;
        parametricAnalysisResultsModel.addSample(i, tempValue.getLowerBound(), tempValue.getMeanValue(), tempValue.getUpperBound(), valid);
      }
      if (timer != null) {
        timer.kill();
        //simulator.killSimulation();
      }
    }
    pad.restoreOriginalValues();
    if (!stopped) {
      progressWindow.finished();
      //PAResultsWindow resWin = new PAResultsWindow(simd.getParametricAnalysisModel(),results,valueSet,validityMap);
      //progressWindow.hide();
      progressWindow.stopAnimation();
View Full Code Here


   * If it is inconsistent with simulation model definition it will be automatically
   * changed when possible.
   */
  private void checkForParametricAnalysisModelModifiedWarning() {
    if (simulation_def.isParametricAnalysisEnabled()) {
      ParametricAnalysisDefinition pad = simulation_def.getParametricAnalysisModel();
      int code = pad.checkCorrectness(false);
      if (code != 0) {
        if (code == 1) {
          warnings[PARAMETRIC_ANALYSIS_MODEL_MODIFIED_WARNING] = true;
        }
        if (code == 2) {
View Full Code Here

        model.setParametricAnalysisEnabled(true);
        String classPath = parametric.getAttribute(XML_A_PARAMETRIC_CLASSPATH);
        try {
          Class[] paramClasses = { ClassDefinition.class, StationDefinition.class, SimulationDefinition.class };
          Object[] params = { model, model, model };
          ParametricAnalysisDefinition pad = (ParametricAnalysisDefinition) Class.forName(classPath).getConstructor(paramClasses)
              .newInstance(params);
          NodeList fields = parametric.getElementsByTagName(XML_E_FIELD);
          for (int i = 0; i < fields.getLength(); i++) {
            Element field = (Element) fields.item(i);
            String fieldName = field.getAttribute(XML_A_FIELD_NAME);
            String fieldValue = field.getAttribute(XML_A_FIELD_VALUE);
            pad.setProperty(fieldName, fieldValue);
          }
          pad.searchForAvaibleSteps();
          pad.createValuesSet();
          model.setParametricAnalysisModel(pad);
        } catch (InvocationTargetException ite) {
          JOptionPane.showMessageDialog(null, "Invocation target exception: " + classPath);
        } catch (NoSuchMethodException nsme) {
          JOptionPane.showMessageDialog(null, "No such method: " + classPath);
View Full Code Here

   * @param model data structure
   */
  static void writeParametricAnalysisInfos(Document doc, Node guiNode, CommonModel model) {
    Element parametric;
    if (model.isParametricAnalysisEnabled()) {
      ParametricAnalysisDefinition pad = model.getParametricAnalysisModel();
      int result = pad.checkCorrectness(false);
      //if the parametric analysis model is not consistent with the model..
      if (result != 0) {
        int choice = JOptionPane.showConfirmDialog(null,
            "The parametric analysis model is not consistent with the simulation model, try to change it?", "JMT - Warning",
            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        //if user chooses ok..
        if (choice == 0) {
          //if the old PAModel could not be corrected..
          if (result == 2) {
            ParametricAnalysisChecker checker = new ParametricAnalysisChecker(model, model, model);
            //if there are no PA simulation avaible, disable parametric analysis
            //and return
            if (!checker.canBeEnabled()) {
              parametric = doc.createElement(XML_E_PARAMETRIC);
              parametric.setAttribute(XML_A_PARAMETRIC_ENABLED, "false");
              return;
            }
            //else set the first avaible
            else {
              String avaibleModel = checker.getRunnableParametricAnalysis()[0];
              pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(avaibleModel, model, model, model);
            }
          }
          //else the PAModel can be corrected, so correct it
          else {
            pad.checkCorrectness(true);
          }
        }
      }
      //save parametric analysis configuration
      Map<String, String> properties = pad.getProperties();
      Set<String> keys = properties.keySet();
      parametric = doc.createElement(XML_E_PARAMETRIC);
      parametric.setAttribute(XML_A_PARAMETRIC_ENABLED, Boolean.toString(model.isParametricAnalysisEnabled()));
      parametric.setAttribute(XML_A_PARAMETRIC_CLASSPATH, pad.getClass().toString().replaceFirst("class ", ""));
      Iterator<String> it = keys.iterator();
      while (it.hasNext()) {
        Object thisParam = it.next();
        Element field = doc.createElement(XML_E_FIELD);
        field.setAttribute(XML_A_FIELD_NAME, thisParam.toString());
View Full Code Here

      simd.setParametricAnalysisModel(null);
      simd.setParametricAnalysisEnabled(false);
    } else {
      enabler.setEnabled(true);
      enabler.setSelected(simd.isParametricAnalysisEnabled());
      ParametricAnalysisDefinition pad = simd.getParametricAnalysisModel();
      parameters = pac.getRunnableParametricAnalysis();
      for (String parameter : parameters) {
        chooser.addItem(parameter);
      }
      String temp = parameters[0];
      if (pad == null) {
        pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(temp, cd, sd, simd);
        simd.setParametricAnalysisModel(pad);
      } else {
        int code = pad.checkCorrectness(true); //check correctness of the PAD and if it is possible corrects it
        if (code != 2) {
          chooser.setSelectedItem(pad.getType());
        } else { //the old type of parametric analysis is no more avaible
          pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(temp, cd, sd, simd);
          simd.setParametricAnalysisModel(pad);
        }
      }
View Full Code Here

    chooser.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        String param = (String) chooser.getSelectedItem();
        if (parameterOptionPanel != null) {
          remove(parameterOptionPanel);
          ParametricAnalysisDefinition temp = ParametricAnalysisModelFactory.createParametricAnalysisModel(param, cd, sd, simd);
          simd.setParametricAnalysisModel(temp);
          simd.setSaveChanged();
          parameterOptionPanel = createPanel(temp);
          add(parameterOptionPanel, BorderLayout.CENTER);
          doLayout();
View Full Code Here

TOP

Related Classes of jmt.gui.common.definitions.parametric.ParametricAnalysisDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.