Package org.jamesii.model.carules

Examples of org.jamesii.model.carules.CARulesAntlrDocument


    ISymbolicCAModelInformation info =
        (ISymbolicCAModelInformation) data.getAsDataStructure();

    if (info instanceof SymbolicCAModelInformation
        && info.getModelSource() != null) {
      return new CARulesAntlrDocument(info.getModelSource());
    }

    // if not try to create model source from model information

    if (info.getModelComment() != null) {
      builder.append("/**\n");
      builder.append(info.getModelComment() + "\n");
      builder.append("\n*/\n");
    }

    builder.append("@caversion 1;\n");

    if (info.isWolfram()) {
      builder.append("wolframrule " + info.getWolframRule() + ";\n");
    } else {
      builder.append("dimensions " + info.getDimensions() + ";\n");
      if (info.getNeighborhood().getComment() != null) {
        builder.append("/**\n");
        builder.append(info.getNeighborhood().getComment());
        builder.append("\n*/\n");
      }
      if (info.getNeighborhood() instanceof MooreNeighborhood) {
        builder.append("neighborhood moore;\n");
      } else if (info.getNeighborhood() instanceof NeumannNeighborhood) {
        builder.append("neighborhood neumann;\n");
      } else {
        builder.append("neighborhood free {\n");
        INeighborhood n = info.getNeighborhood();
        for (int i = 0; i < n.getCellCount(); i++) {
          int[] cell = n.getCell(i);
          builder.append("                   [");
          for (int d = 0; d < n.getDimensions(); d++) {
            if (d > 0) {
              builder.append(", ");
            }
            builder.append(cell[d]);
          }
          builder.append("]\n");
        }
        builder.append("                  };\n");
      }

      String st = null;
      for (String s : info.getStates()) {
        if (st != null) {
          st += ", ";
        } else {
          st = "";
        }
        st += s;
      }

      builder.append("state " + st + ";\n\n");

      for (CARule rule : info.getRules()) {

        String c = conditionToString(rule.getCurrentCondition(), info);

        String ruleStr = "";

        if (c.length() > 0) {

          ruleStr += "{";

          ruleStr += c;

          ruleStr += "}";
        }

        if (Double.compare(rule.getProbability(), 1.0) != 0) {
          NumberFormat nFormat = NumberFormat.getNumberInstance();
          nFormat.setGroupingUsed(false);
          nFormat.setMaximumFractionDigits(Integer.MAX_VALUE);
          ruleStr +=
              "[" + nFormat.format(rule.getProbability()).replace(',', '.')
                  + "]";
        }

        ruleStr += " : ";

        ruleStr += conditionToString(rule.getPreCondition(), info);

        ruleStr +=
            " -> " + info.getStates().get(rule.getDestinationState()) + ";\n";

        if (rule.getComment() != null) {
          builder.append("/**\n");
          builder.append(rule.getComment());
          builder.append("\n*/\n");
        }

        builder.append("rule " + ruleStr + "\n");

      }

    }

    return new CARulesAntlrDocument(builder.toString());

  }
View Full Code Here


      }

      CARulesConverter converter = new CARulesConverter();

      ISymbolicModel<?> sm =
          converter.fromDocument(new CARulesAntlrDocument(builder.toString()));

      SymbolicCAModelInformation info =
          (SymbolicCAModelInformation) sm.getAsDataStructure();

      List<CAProblemToken> problems = info.getProblems();
View Full Code Here

        builder.append(line);
        builder.append(System.getProperty("line.separator"));
      }

      ISymbolicCAModel model = new SymbolicCAModel();
      model.setFromDocument(new CARulesAntlrDocument(builder.toString()));
      return model;
    } catch (IOException e) {
      SimSystem.report(e);
    } finally {
      BasicUtilities.close(reader);
View Full Code Here

TOP

Related Classes of org.jamesii.model.carules.CARulesAntlrDocument

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.