private void processNames(SimulationSpec s) throws SaveFailedException {
    ArrayList<String> names = new ArrayList<String>();
    String name;
    for (ReactionRule r : s.getRules()) {
      for (IInnerName i : r.getRedex().getInnerNames()) {
        name = "%innername " + normaliseName(i.getName());
        if (!validateSameName(names, name)) {
          names.add(name);
        }
      }
      for (IOuterName o : r.getRedex().getOuterNames()) {
        name = "%outername " + normaliseName(o.getName());
        if (!validateSameName(names, name)) {
          names.add(name);
        }
      }
      for (IInnerName i : r.getReactum().getInnerNames()) {
        name = "%innername " + normaliseName(i.getName());
        if (!validateSameName(names, name)) {
          names.add(name);
        }
      }
      for (IOuterName o : r.getReactum().getOuterNames()) {
        name = "%outername " + normaliseName(o.getName());
        if (!validateSameName(names, name)) {
          names.add(name);
        }
      }
    }
    for (IInnerName i : s.getModel().getInnerNames()) {
      name = "%innername " + normaliseName(i.getName());
      if (!validateSameName(names, name)) {
        names.add(name);
      }
    }
    for (IOuterName o : s.getModel().getOuterNames()) {
      name = "%outername " + normaliseName(o.getName());
      if (!validateSameName(names, name)) {
        names.add(name);
      }
    }
    Collections.sort(names);

    if (names.size() == 0) return;
    write("# Names\n");
    for (String n : names) write(n + ";\n");
    write("\n");
  }
Esempio n. 2
0
  public void process(IBigraph bigraph) throws SaveFailedException {
    printLine("(* string definitions *)");
    for (IControl c : bigraph.getSignature().getControls()) {
      printStringDef(SMLify(c.getName()));
      for (IPort p : c.getPorts()) printStringDef(SMLify(p.getName()));
    }
    for (IEdge e : bigraph.getEdges()) printStringDef(SMLify(e.getName()));
    for (IOuterName o : bigraph.getOuterNames()) printStringDef(SMLify(o.getName()));
    for (IInnerName i : bigraph.getInnerNames()) printStringDef(SMLify(i.getName()));

    printLine("");
    printLine("(* signature *)");
    processIterable(
        bigraph.getSignature().getControls(),
        null,
        "",
        "\n",
        "\n",
        new Processor<IControl>() {
          @Override
          public void proc(IControl c) throws SaveFailedException {
            String name = SMLify(c.getName());
            print("val ");
            print(name);
            print(" = active(");
            print(name);
            print(" --: ");
            processIterable(
                c.getPorts(),
                null,
                "[",
                ", ",
                "]",
                new Processor<IPort>() {
                  @Override
                  public void proc(IPort p) throws SaveFailedException {
                    print(SMLify(p.getName()));
                  }
                });
            print(");");
          }
        });

    printLine("");
    printLine("(* agent *)");
    printLine("val agent = ");
    scope++;

    print("(");
    processIterable(
        bigraph.getOuterNames(),
        "idw[]",
        "idw[",
        ", ",
        "]",
        new Processor<IOuterName>() {
          @Override
          public void proc(IOuterName o) throws SaveFailedException {
            print(SMLify(o.getName()));
          }
        });
    processIterable(
        bigraph.getEdges(),
        "",
        " * -//[",
        ", ",
        "]",
        new Processor<IEdge>() {
          @Override
          public void proc(IEdge e) throws SaveFailedException {
            print(SMLify(e.getName()));
          }
        });
    printLine(")");
    print("o (");
    scope++;

    processIterable(
        bigraph.getInnerNames(),
        "",
        "",
        " || ",
        " || ",
        new Processor<IInnerName>() {
          @Override
          public void proc(IInnerName i) throws SaveFailedException {
            print(SMLify(i.getLink().getName()) + "/" + SMLify(i.getName()));
          }
        });

    processIterable(
        bigraph.getRoots(),
        "idp(0)",
        "",
        "|| ",
        "",
        new Processor<IRoot>() {
          @Override
          public void proc(IRoot r) throws SaveFailedException {
            scope++;
            process(r);
            printLine("");
            scope--;
          }
        });

    scope--;
    printLine(");");
  }