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; }
/** * Calculates the "Behavioral Recall" metric for a given mined model with respect to a log and a * reference model. * * @param model The resulting Petri net generated by a mining algorithm. * @param referenceLog The log to be used during the calculation of the behavioral recall value of * the mined model. * @param referenceModel The Petri net used to measure behavioral recall of the mined model. * @param progress Progress * @return The behavioral recall value (<code>[0, 1]</code>) of the mined model. If the behavioral * recall value cannot be calculated, the value <code>BenchmarkMetric.INVALID_MEASURE_VALUE * </code> is returned. */ public double measure( PetriNet model, LogReader referenceLog, PetriNet referenceModel, Progress progress) { // check precondition: no shared inputs for duplicate tasks if (model.hasDuplicatesWithSharedInputPlaces() == true || referenceModel.hasDuplicatesWithSharedInputPlaces() == true) { return BenchmarkMetric.INVALID_MEASURE_VALUE; } try { HeuristicsNet HNmodel = new PetriNetToHeuristicNetConverter() .toHeuristicsNet( PetriNetToHeuristicNetConverter.removeUnnecessaryInvisibleTasksFromPetriNet( (PetriNet) model.clone())); HeuristicsNet HNreferenceModel = new PetriNetToHeuristicNetConverter() .toHeuristicsNet( PetriNetToHeuristicNetConverter.removeUnnecessaryInvisibleTasksFromPetriNet( (PetriNet) referenceModel.clone())); TraceParsing behavioralMetrics = new TraceParsing(referenceLog, HNreferenceModel, HNmodel); return behavioralMetrics.getRecall(); } catch (Exception e) { System.err.println( "BehavioralRecallMetric >>> Could not calculate the behavioral recall value!"); e.printStackTrace(); } return BenchmarkMetric.INVALID_MEASURE_VALUE; }
public static PetriNet epcToPetriNet(ConfigurableEPC epc) throws SerendipException { PetriNet pn = null; if (null == epc) { throw new SerendipException("No model is available"); } log.debug("Converting EPC: " + epc.getIdentifier()); // Conversion // EPCToPetriNetConverterPlugin epcToPNplugin = new // EPCToPetriNetConverterPlugin(); // pn = epcToPNplugin.convert(epc); pn = EPCToPetriNetConverter.convert(epc, new HashMap(), null, null); // DEBUG Iterator<EPCEvent> events = epc.getEvents().iterator(); while (events.hasNext()) { log.debug(">" + events.next().getIdentifier()); } Iterator<Place> places = pn.getPlaces().iterator(); while (places.hasNext()) { log.debug("]" + places.next().getIdentifier()); } // end DEBUG if (null == pn) { throw new SerendipException("Cannot get the equivalent petrinet of " + epc.getId()); } pn.setName(epc.getIdentifier()); return pn; }
public TreeSet<ProcessQueryResult> getPetriNet(Object o) { TreeSet<ProcessQueryResult> ret = new TreeSet<ProcessQueryResult>(); if (o instanceof PetriNet) { PetriNet q = (PetriNet) o; DataManager dm = DataManager.getInstance(); String strSelectPetriNet = "select process_id, pnml from petrinet"; ResultSet rs = dm.executeSelectSQL(strSelectPetriNet, 0, Integer.MAX_VALUE, dm.getFetchSize()); try { while (rs.next()) { PetriNet c = null; if (dm.getDBName().equalsIgnoreCase("postgresql") || dm.getDBName().equalsIgnoreCase("mysql")) { String str = rs.getString("pnml"); byte[] temp = str.getBytes(); c = PetriNetUtil.getPetriNetFromPnmlBytes(temp); } else if (dm.getDBName().equalsIgnoreCase("derby")) { InputStream in = rs.getAsciiStream("pnml"); PnmlImport pnml = new PnmlImport(); PetriNetResult result = (PetriNetResult) pnml.importFile(in); c = result.getPetriNet(); result.destroy(); in.close(); } else { System.out.println(dm.getDBName() + " unsupported"); System.exit(-1); } long process_id = rs.getLong("process_id"); if (Ullman4PetriNet.subGraphIsomorphism(q, c)) { ret.add(new ProcessQueryResult(process_id, 1)); } c.destroyPetriNet(); } java.sql.Statement stmt = rs.getStatement(); rs.close(); stmt.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return ret; }
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; } } }
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; }
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; }