예제 #1
0
  static void addFinalPlace(
      ArrayList<Place> places, ArrayList<Transition> transitions, PetriNet pn) {
    Place p = null;
    boolean endTransitionsExist = false;

    for (int i = 0; i < transitions.size(); i++) {
      Transition t = transitions.get(i);
      String id = t.toString();
      if (id.length() > 2 && id.substring(0, 3).equals("END")) {
        if (!endTransitionsExist) {
          p = new Place("END", pn);
          pn.addPlace(p);
          places.add(p);
        }
        PNEdge finalEdge = new PNEdge(t, p);
        pn.addEdge(finalEdge);
        endTransitionsExist = true;
      }
    }
  }
예제 #2
0
  public static PetriNet read(InputStream input) throws IOException {
    PetriNet pn = new PetriNet();
    ArrayList<Transition> transitions = new ArrayList<Transition>();
    ArrayList<Place> places = new ArrayList<Place>();

    BufferedReader in = new BufferedReader(new InputStreamReader(input));
    ArrayList<String> events;
    ArrayList<String> stParts;
    String sRead, s;

    do { // go through comments
      sRead = in.readLine();
    } while (sRead.charAt(0) == '#');
    sRead = in.readLine();
    // get the set of events and create PN transitions
    s = sRead.substring(sRead.indexOf("  ") + 2);
    events = new ArrayList<String>(Arrays.asList(s.split(" ")));
    for (String o : events) {
      // Transition t = new Transition(o, pn);
      o = repairTransitionString(o);
      Transition t = new Transition(new LogEvent(o, ""), pn);
      t.setIdentifier(o);
      pn.addTransition(t);
      transitions.add(t);
    }
    in.readLine();
    // reading the main lines
    sRead = in.readLine();
    sRead = sRead.replace("/", PetrifyConstants.EDGEDOCSSEPARATOR); // dot
    // doesn't
    // eat
    // '/'
    // symbols
    while (sRead.charAt(0) != '.') {
      // look for new transitions (with "__") and new places and add them
      // to the lists
      stParts = checkForNewTransitionsAndPlaces(sRead, transitions, places, pn);
      if (isPlace(stParts.get(0))) {
        Place placeFirst = findPlace(stParts.get(0), places);
        for (int i = 1; i < stParts.size(); i++) {
          String stRepaired = repairTransitionString(stParts.get(i));
          Transition aTransition = findTransition(stRepaired, transitions);
          PNEdge newEdge = new PNEdge(placeFirst, aTransition);
          pn.addEdge(newEdge);
        }
      } else {
        String stRepaired = repairTransitionString(stParts.get(0));
        Transition transitionFirst = findTransition(stRepaired, transitions);
        for (int i = 1; i < stParts.size(); i++) {
          Place aPlace = findPlace(stParts.get(i), places);
          PNEdge newEdge = new PNEdge(transitionFirst, aPlace);
          pn.addEdge(newEdge);
        }
      }
      sRead = in.readLine();
      sRead = sRead.replace("/", PetrifyConstants.EDGEDOCSSEPARATOR);
    }
    // makeEndsBlack(transitions); // end transitions must be black
    addFinalPlace(places, transitions, pn);
    return pn;
  }