Esempio n. 1
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());
  }
Esempio n. 2
0
 // Verify that the net can be expressed in BAGGINS file format.
 private static void verifyNet(PetriNet pn) throws RenderException {
   if (pn.getTransitions().isEmpty()) {
     // untested, maybe BAGGINS supports this unimportant feature ...
     throw new RenderException(
         "Cannot express Petri nets without transitions in the BAGGINS " + " file format");
   }
   if (pn.getPlaces().isEmpty()) {
     // untested, maybe BAGGINS supports this unimportant feature ...
     throw new RenderException(
         "Cannot express Petri nets without places in the BAGGINS " + " file format");
   }
   if (pn.getInitialMarking().hasOmega()) {
     throw new RenderException(
         "Cannot express an initial marking with at least one OMEGA "
             + "token in the BAGGINS file format");
   }
 }
Esempio n. 3
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;
  }