Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  @Override
  public INetSystem<F, N, P, T, M> clone(Map<N, N> map) {
    INetSystem<F, N, P, T, M> clone = null;
    try {
      clone = (INetSystem<F, N, P, T, M>) NetSystem.class.newInstance();
    } catch (InstantiationException exception) {
      return null;
    } catch (IllegalAccessException exception) {
      return null;
    }

    for (P p : this.getPlaces()) {
      P np = (P) p.clone();
      map.put((N) p, (N) np);
      clone.addPlace(np);
    }

    for (T t : this.getTransitions()) {
      T nt = (T) t.clone();
      map.put((N) t, (N) nt);
      clone.addTransition(nt);
    }

    for (F f : this.getFlow()) {
      clone.addFlow(map.get(f.getSource()), map.get(f.getTarget()));
    }

    for (P p : this.getPlaces()) {
      clone.putTokens((P) map.get(p), this.getTokens(p));
    }

    return clone;
  }
Ejemplo n.º 2
0
  @Override
  public String toDOT() {
    String result = "digraph G {\n";
    result +=
        "graph [fontname=\"Helvetica\" fontsize=\"10\" nodesep=\"0.35\" ranksep=\"0.25 equally\"];\n";
    result +=
        "node [fontname=\"Helvetica\" fontsize=\"10\" fixedsize=\"true\" style=\"filled\" fillcolor=\"white\" penwidth=\"2\"];\n";
    result +=
        "edge [fontname=\"Helvetica\" fontsize=\"10\" arrowhead=\"normal\" color=\"black\"];\n";
    result += "\n";
    result += "node [shape=circle];\n";

    for (P p : this.getPlaces()) {
      Integer n = this.marking.get(p);
      String label =
          ((n == 0) || (n == null)) ? p.getLabel() : p.getLabel() + "[" + n.toString() + "]";
      result +=
          String.format(
              "\tn%s[label=\"%s\" width=\".3\" height=\".3\"];\n",
              p.getId().replace("-", ""), label);
    }

    result += "\n";
    result += "node [shape=box];\n";

    for (T t : this.getTransitions()) {
      String fillColor = this.isEnabled(t) ? " fillcolor=\"#9ACD32\"" : "";
      if (t.isSilent())
        result +=
            String.format(
                "\tn%s[label=\"\" width=\".3\"" + fillColor + " height=\".1\"];\n",
                t.getId().replace("-", ""));
      else
        result +=
            String.format(
                "\tn%s[label=\"%s\" width=\".3\"" + fillColor + " height=\".3\"];\n",
                t.getId().replace("-", ""),
                t.getLabel());
    }

    result += "\n";
    for (F f : this.getFlow()) {
      result +=
          String.format(
              "\tn%s->n%s;\n",
              f.getSource().getId().replace("-", ""), f.getTarget().getId().replace("-", ""));
    }
    result += "}\n";

    return result;
  }