Esempio n. 1
0
  static ArrayList<String> checkForNewTransitionsAndPlaces(
      String sRead, ArrayList<Transition> transitions, ArrayList<Place> places, PetriNet pn) {
    ArrayList<String> stParts = new ArrayList<String>(Arrays.asList(sRead.split(" ")));
    int k;

    for (int i = 0; i < stParts.size(); i++) {
      String st = stParts.get(i);
      if (isPlace(st)) {
        if (findPlace(st, places) == null) {
          Place p = new Place(st, pn);
          pn.addPlace(p);
          places.add(p);
        }
      } else {
        st = repairTransitionString(st);
        k = st.indexOf(PetrifyConstants.EDGEDOCSSEPARATOR);
        if (k != -1) {
          if (findTransition(st, transitions) == null) {
            Transition t = new Transition(new LogEvent(st, ""), pn);
            pn.addTransition(t);
            t.setIdentifier(st);
            transitions.add(t);
          }
        }
      }
    }
    return stParts;
  }
Esempio n. 2
0
 public static Transition findTransition(String identifier, ArrayList<Transition> transitions) {
   for (Transition t : transitions) {
     if (t.getIdentifier().equals(identifier)) {
       return t;
     }
   }
   return null;
 }
Esempio n. 3
0
 static void makeEndsBlack(ArrayList<Transition> transitions) {
   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")) {
       t.setLogEvent(null);
     }
   }
 }
Esempio n. 4
0
 /**
  * This is the edge writing part of the {@link #writeToDot writeToDot} procedure. This part of the
  * visualization gets affected by the probabilities that are displayed at XOR-splits.
  *
  * @param bw the writer used by the framework to create the temporary dot file
  * @throws IOException if writing to the writer fails
  * @todo Peter: figure out how to place the probabilities at the tail of the edge
  */
 protected void writeEdgesToDot(Writer bw) throws IOException {
   try {
     Iterator it = this.getEdges().iterator();
     while (it.hasNext()) {
       ExtendedPNEdge e = (ExtendedPNEdge) (it.next());
       if (e.isPT()) {
         ExtendedPlace p = (ExtendedPlace) e.getSource();
         Transition t = (Transition) e.getDest();
         if (p.getOutEdges().size() > 1) {
           // for all edges coming from places with more than one
           // outgoing edge, display probability in 2 decimal
           // digits
           double prob =
               e.getProbability(
                   currentlySelectedInstances,
                   p.getTotalOutEdgeFrequency(
                       currentlySelectedInstances, advancedSettings[1], failedInstances),
                   advancedSettings[1],
                   failedInstances);
           DecimalFormat digits = new DecimalFormat();
           digits.setMaximumFractionDigits(2);
           digits.setMinimumFractionDigits(2);
           String chance = digits.format(prob);
           // replace commas with dots, since dot forces use of
           // US-Locale
           chance = chance.replace(",", ".");
           bw.write("p" + p.getNumber() + " -> t" + t.getNumber() + " [label=" + chance + "];\n");
         } else {
           // write a normal edge
           bw.write("p" + p.getNumber() + " -> t" + t.getNumber() + ";\n");
         }
       } else {
         // write a normal edge
         Place p = (Place) e.getDest();
         Transition t = (Transition) e.getSource();
         bw.write("t" + t.getNumber() + " -> p" + p.getNumber() + ";\n");
       }
     }
   } catch (Exception ex) {
     Message.add("Failure while updating the visualization.\n" + ex.toString(), 2);
     ex.printStackTrace();
   }
 }
Esempio n. 5
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;
      }
    }
  }
Esempio n. 6
0
  public static PetriNet convert(ConfigurableEPC baseEPC) {
    HashMap<EPCFunction, Transition> functionActivityMapping;
    HashMap<EPCConnector, Place> xorconnectorChoiceMapping;

    // HV: Initialize the mappings.
    functionActivityMapping = new HashMap<EPCFunction, Transition>();
    xorconnectorChoiceMapping = new HashMap<EPCConnector, Place>();

    // Check to use the weights if necessary
    // HV: Add both mappings. On completion, these will be filledd.
    PetriNet petrinet =
        EPCToPetriNetConverter.convert(
            baseEPC, new HashMap(), functionActivityMapping, xorconnectorChoiceMapping);

    HashSet visible = new HashSet();

    // HV: The next block is taken care of by the functionActivityMapping
    // below.
    /*
     * Iterator it = petrinet.getTransitions().iterator(); while
     * (it.hasNext()) { Transition t = (Transition) it.next(); if (t.object
     * instanceof EPCFunction) { // if (t.getLogEvent() != null) { // Add
     * transitions with LogEvent (i.e. referring to functions)
     * visible.add(t); } }
     */

    // HV: Prevent the places mapped onto from being reduced.
    visible.addAll(functionActivityMapping.values());
    visible.addAll(xorconnectorChoiceMapping.values());
    Message.add(visible.toString(), Message.DEBUG);

    Iterator it = petrinet.getPlaces().iterator();
    while (it.hasNext()) {
      Place p = (Place) it.next();
      if (p.inDegree() * p.outDegree() == 0) {
        // Add Initial and final places to visible, i.e. places that
        // refer to in and output events
        visible.add(p);
      }
    }

    // Reduce the PetriNet with Murata rules, while keeping the visible ones
    PetriNetReduction pnred = new PetriNetReduction();
    pnred.setNonReducableNodes(visible);

    HashMap pnMap = new HashMap(); // Used to map pre-reduction nodes to
    // post-reduction nodes.
    PetriNet reduced = pnred.reduce(petrinet, pnMap);

    if (reduced != petrinet) {
      // Update both mappings from pre-reduction nodes to post-reduction
      // nodes.
      HashMap<EPCFunction, Transition> newFunctionActivityMapping =
          new HashMap<EPCFunction, Transition>();
      for (EPCFunction function : functionActivityMapping.keySet()) {
        Transition transition = (Transition) functionActivityMapping.get(function);
        if (pnMap.keySet().contains(transition)) {
          newFunctionActivityMapping.put(function, (Transition) pnMap.get(transition));
        }
      }
      functionActivityMapping = newFunctionActivityMapping;
      HashMap<EPCConnector, Place> newXorconnectorChoiceMapping =
          new HashMap<EPCConnector, Place>();
      for (EPCConnector connector : xorconnectorChoiceMapping.keySet()) {
        Place place = (Place) xorconnectorChoiceMapping.get(connector);
        if (pnMap.keySet().contains(place)) {
          newXorconnectorChoiceMapping.put(connector, (Place) pnMap.get(place));
        }
      }
      xorconnectorChoiceMapping = newXorconnectorChoiceMapping;
    }
    reduced.makeClusters();

    // filter the \nunknown:normal
    ArrayList<Transition> alTrans = reduced.getVisibleTasks();
    for (int i = 0; i < alTrans.size(); i++) {
      Transition t = alTrans.get(i);
      String id = t.getIdentifier();
      int idx = id.indexOf("\\nunknown:normal");
      if (idx > 0) {
        id = id.substring(0, idx);
      }
      // �˴������ֵ��ѯ�滻���е�label
      String mappedId = htDict.get(id);
      if (mappedId != null) {
        t.setIdentifier(mappedId);
      } else {
        t.setIdentifier(id);
      }
    }

    return reduced;
  }
Esempio n. 7
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;
  }