Esempio n. 1
0
  /**
   * Checks a Petri net for side conditions and returns a list of side conditions.
   *
   * @param pn the Petri net
   * @return the set of side conditions found in the Petri net.
   */
  public static SideConditions checkSideConditions(PetriNet pn) {
    SideConditions conditions = new SideConditions();

    for (Place p : pn.getPlaces()) {
      // instead of directly checking the post/preset,
      // we are going to check the edges.
      for (Flow a : p.getPostsetEdges()) {
        for (Flow b : p.getPresetEdges()) {
          InterrupterRegistry.throwIfInterruptRequestedForCurrentThread();
          if (a.getTarget().getId().equals(b.getSource().getId())) {
            conditions.add(new SideCondition(p, a.getTransition(), a, b));
          }
        }
      }
    }
    return conditions;
  }
Esempio n. 2
0
  @Override
  public void render(PetriNet pn, Writer writer) throws RenderException, IOException {
    verifyNet(pn);

    STGroup group = new STGroupFile("uniol/apt/io/renderer/impl/BagginsPN.stg", '$', '$');
    ST pnTemplate = group.getInstanceOf("pn");
    pnTemplate.add("name", pn.getName());

    // Handle places
    pnTemplate.add("places", pn.getPlaces());

    List<Place> placeList = new ArrayList<>(pn.getPlaces());

    // Handle transitions (and arcs)
    for (Transition t : pn.getTransitions()) {
      List<IdWeightPair> preset = new ArrayList<>();
      List<IdWeightPair> postset = new ArrayList<>();
      for (Flow e : t.getPresetEdges()) {
        preset.add(new IdWeightPair(placeList.indexOf(e.getSource()), -e.getWeight()));
      }
      for (Flow e : t.getPostsetEdges()) {
        postset.add(new IdWeightPair(placeList.indexOf(e.getTarget()), e.getWeight()));
      }

      pnTemplate.addAggr("transitions.{transition, preset, postset}", t, preset, postset);
    }

    pnTemplate.write(new AutoIndentWriter(writer), new ThrowingErrorListener());
  }