diff --git a/src/main/java/de/tudresden/inf/st/pnml/splitter/Main.java b/src/main/java/de/tudresden/inf/st/pnml/splitter/Main.java index c3631b3720d81dd86375d8d7142c4fdcccc778bf..04014571dc6c0d0cf4bbc4eb9812f2b43fdacf8d 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/splitter/Main.java +++ b/src/main/java/de/tudresden/inf/st/pnml/splitter/Main.java @@ -17,6 +17,8 @@ public class Main { public static void main(String[] args) { String inputPath = (args.length > 0) ? args[0] : null; + //String inputPath = "/home/sebastian/git/dineros-public/dineros/" + + // "journal-paper-evaluation/full/model-v4/sorting-wf-synced-safe-sensor-grpn-sig.pnml"; if (inputPath == null) { logger.error("No model found on given input path."); @@ -51,8 +53,8 @@ public class Main { for (int i = 0; i < disconnectedPetriNets.size(); i++) { for (int j = 0; j < disconnectedPetriNets.get(i).size(); j++) { - logger.info("Exporting split Petri net containing: "); - PostProcessingUtils.printNet(disconnectedPetriNets.get(i).get(j), true, false); + // logger.info("Exporting split Petri net containing: "); + // PostProcessingUtils.printNet(disconnectedPetriNets.get(i).get(j), true, false); try { PnmlExporter.serializeToPnmlFile(disconnectedPetriNets.get(i).get(j), "-pnml-net-" + i + "-" + j); diff --git a/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/GlobalToLocalNetsPostProcessor.java b/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/GlobalToLocalNetsPostProcessor.java index f53175a86375189f89ff17a1559b2dbc4907deb5..a30a2931ae12d47985f14bd45617c1ea26b6be19 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/GlobalToLocalNetsPostProcessor.java +++ b/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/GlobalToLocalNetsPostProcessor.java @@ -45,21 +45,21 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { // cut the service transitions PetriNet serviceCutNet = cutServiceTransitions(topicCutNet); - Set<String> locations = getNodes(serviceCutNet); + Set<String> locations = getNodePageIds(serviceCutNet); updateToolSpecificsWithPlaceInfos(serviceCutNet); - logger.info("##############################################################################################"); - PostProcessingUtils.printNet(serviceCutNet, true, false); + //logger.info("##############################################################################################"); // serialize for deep copy - String serializedNetPath = PnmlExporter.serializeToPnmlFile(serviceCutNet, "-pre-split.pnml"); + String serializedNetPath = PnmlExporter.serializeToPnmlFile(serviceCutNet, "-pre-split"); int netSuffix = 0; // filter deep copy elements by location for (String location : locations) { + System.out.println("Creating deep copy for: " + location); List<PetriNet> reParsedPetriNets = PnmlParser.parsePnml(serializedNetPath, false); for (PetriNet pn : reParsedPetriNets) { PetriNet separatedNet = createdSeparatedNetByNode(pn, location); @@ -76,27 +76,18 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { } } - private static Set<String> getNodes(PetriNet petriNet) { + private static Set<String> getNodePageIds(PetriNet petriNet){ - Set<String> allLocations = new HashSet<>(); + Set<String> nodePagesIds = new HashSet<>(); - for (Place place : petriNet.allPlaces()) { - if (place.asDinerosPlace().getStaticPlaceInformation().getNode() != null) { - allLocations.add(place.asDinerosPlace().getStaticPlaceInformation().getNode()); - } else { - logger.error("Found place without location."); - } - } - - for (RefPlace rp : petriNet.allRefPlaces()) { - if (rp.getNode() != null) { - allLocations.add(rp.getNode()); - } else { - logger.error("Found reference place without node."); + for(Page page : petriNet.allPages()){ + if(page.getType() != null && page.getType().equals(PnmlConstants.PAGE_TYPE_NODE)){ + System.out.println("Found node page: " + page.getId()); + nodePagesIds.add(page.getId()); } } - return allLocations; + return nodePagesIds; } private PetriNet cutServiceTransitions(PetriNet petriNet) { @@ -199,70 +190,50 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { private static PetriNet createdSeparatedNetByNode(PetriNet petriNet, String node) { + System.out.println("Creating separate net for: " + node); + Set<String> removedTransitionIds = new HashSet<>(); Set<String> removedPlaceIds = new HashSet<>(); Set<String> removedRefTransitionIds = new HashSet<>(); Set<String> removeRefPlaceIds = new HashSet<>(); - for (Place place : petriNet.allPlaces()) { - if (!place.asDinerosPlace().getStaticPlaceInformation().getNode().equals(node)) { - removedPlaceIds.add(place.getId()); - } - } - - for (Transition transition : petriNet.allTransitions()) { - if (!transition.asDinerosTransition().getStaticTransitionInformation().getNode().equals(node)) { - removedTransitionIds.add(transition.getId()); - } - } - - for (RefPlace place : petriNet.allRefPlaces()) { - if (!place.getNode().equals(node)) { - removeRefPlaceIds.add(place.getId()); - } - } - - for (RefTransition transition : petriNet.allRefTransitions()) { - if (!transition.getNode().equals(node)) { - removedRefTransitionIds.add(transition.getId()); - } - } + deleteOnNoMatch(node, petriNet.allPlaces(), removedPlaceIds); + deleteOnNoMatch(node, petriNet.allTransitions(), removedTransitionIds); + deleteOnNoMatch(node, petriNet.allRefPlaces(), removeRefPlaceIds); + deleteOnNoMatch(node, petriNet.allRefTransitions(), removedRefTransitionIds); for (Arc arc : petriNet.allArcs()) { if (removedTransitionIds.contains(arc.getSource().getId()) || removedTransitionIds.contains(arc.getTarget().getId()) || removedPlaceIds.contains(arc.getSource().getId()) || removedPlaceIds.contains(arc.getTarget().getId()) || removedRefTransitionIds.contains(arc.getSource().getId()) || removedRefTransitionIds.contains(arc.getTarget().getId()) || removeRefPlaceIds.contains(arc.getSource().getId()) || removeRefPlaceIds.contains(arc.getTarget().getId())) { - logger.info("REMOVING ARC " + arc.getId() + " from net"); arc.removeSelf(); } } for (Place place : petriNet.allPlaces()) { - if (!place.asDinerosPlace().getStaticPlaceInformation().getNode().equals(node)) { - logger.info("REMOVING PLACE " + place.getId() + " from net"); + if (removedPlaceIds.contains(place.getId())) { + System.out.println("removing: " + place.getId()); place.removeSelf(); } } for (RefPlace place : petriNet.allRefPlaces()) { - if (!place.getNode().equals(node)) { - logger.info("REMOVING REF PLACE " + place.getId() + " from net"); + if (removeRefPlaceIds.contains(place.getId())) { + System.out.println("removing: " + place.getId()); place.removeSelf(); } } for (RefTransition transition : petriNet.allRefTransitions()) { - if (!transition.getNode().equals(node)) { - logger.info("REMOVING REF TRANSITION " + transition.getId() + " from net"); + if (removedRefTransitionIds.contains(transition.getId())) { transition.removeSelf(); } } for (Transition transition : petriNet.allTransitions()) { - if (!transition.asDinerosTransition().getStaticTransitionInformation().getNode().equals(node)) { - logger.info("REMOVING TRANSITION " + transition.getId() + " from net"); + if (removedTransitionIds.contains(transition.getId())) { transition.removeSelf(); } @@ -287,6 +258,24 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { return petriNet; } + private static void deleteOnNoMatch(String node, Set<? extends PnObject> searchable, Set<String> removedObjects) { + for (PnObject o : searchable) { + if(!o.isArcNode()) { + boolean matches = false; + for (Page cPage : o.ContainingPageTree()) { + if (cPage.getId().equals(node)) { + matches = true; + break; + } + } + if (!matches) { + System.out.println("Removing Object: " + o.getId()); + removedObjects.add(o.getId()); + } + } + } + } + private void updateToolSpecificsWithPlaceInfos(PetriNet petriNet) { ToolInfo ti = buildToolSpecifics(); diff --git a/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/PostProcessingUtils.java b/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/PostProcessingUtils.java index d520b56ff382d684ee7b7851de6df858d1fef1e1..cb1c1ead0865350e6311c2f22c4f37384deeea0d 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/PostProcessingUtils.java +++ b/src/main/java/de/tudresden/inf/st/pnml/splitter/postprocessing/PostProcessingUtils.java @@ -54,142 +54,39 @@ public class PostProcessingUtils { .getStaticPlaceInformation().getSubNet().equals(subNet)).collect(Collectors.toSet()); } - private static Set<Arc> getInternalArcsBySubnet(String subNet, PetriNet petriNet) { - - Set<Arc> internalArcs = new HashSet<>(); - Set<String> subNetTransitionIds = getTransitionIDsBySubnet(subNet, petriNet); - Set<String> subNetPlaceIds = getPlaceIDsBySubnet(subNet, petriNet); - - - for (Arc arc : petriNet.allArcs()) { - if ((subNetTransitionIds.contains(arc.getSource().getId()) && subNetPlaceIds.contains(arc.getTarget().getId())) - || (subNetTransitionIds.contains(arc.getTarget().getId()) && subNetPlaceIds.contains(arc.getSource().getId()))) { - internalArcs.add(arc); - } - } - - return internalArcs; - } - - private static Set<Arc> getExternalArcsBySubnet(String subNet, PetriNet petriNet) { - - Set<Arc> externalArcs = new HashSet<>(); - Set<String> subNetTransitionIds = getTransitionIDsBySubnet(subNet, petriNet); - Set<String> subNetPlaceIds = getPlaceIDsBySubnet(subNet, petriNet); - - for (Arc arc : petriNet.allArcs()) { - if (subNetTransitionIds.contains(arc.getSource().getId()) || subNetPlaceIds.contains(arc.getTarget().getId()) - || subNetTransitionIds.contains(arc.getTarget().getId()) || subNetPlaceIds.contains(arc.getSource().getId())) { - externalArcs.add(arc); + private static boolean pageIsEmpty(Page page) { + for (PnObject o : page.getObjects()) { + if (o.isPlaceObject() || o.isTransitionObject() + || o.isRefTransitionObject() || o.isRefPlaceObject()) { + return false; + } else if (o.isPageNode()) { + if (!pageIsEmpty(o.asPage())) { + return false; + } } } - - return externalArcs; + return true; } /////////////////////////////// // NET MANIPULATION /////////// /////////////////////////////// - public static void cleanEmptyPages(PetriNet petriNet){ + public static void cleanEmptyPages(PetriNet petriNet) { List<Page> pagesToRemove = new ArrayList<>(); - for(Page p : petriNet.allPages()){ - if(p.getNumObject() == 0){ + for (Page p : petriNet.allPages()) { + if(pageIsEmpty(p)){ + System.out.println("Removing page: " + p.getId()); pagesToRemove.add(p); } } - pagesToRemove.forEach(p -> p.removeSelf()); - + pagesToRemove.forEach(ASTNode::removeSelf); } -/* - public static void setSubNetInstanceId(PetriNet petriNet, String subNet, String instanceId) { - - Set<Transition> subNetTransitions = getTransitionsBySubnet(subNet, petriNet); - Set<Place> subNetPlaces = getPlacesBySubnet(subNet, petriNet); - - // update transition instance ids - subNetTransitions.forEach(t -> { - - if (t.asInputSignalTransition().getMutualTransitionInformation() == null) { - - if (t.asInputSignalTransition().getStaticTransitionInformation().isServiceTransitionInformation()) { - - ServiceTransitionInformation oldSti = t.asInputSignalTransition().getStaticTransitionInformation().asServiceTransitionInformation(); - t.asInputSignalTransition().setMutualTransitionInformation(new ServiceTransitionInformation(oldSti.getLocation(), oldSti.getType(), - oldSti.getInputLimit(), oldSti.getOutputLimit(), oldSti.getSubNet(), instanceId, null, oldSti.getServiceName())); - - } else if (t.asInputSignalTransition().getStaticTransitionInformation().isTopicTransitionInformation()) { - - TopicTransitionInformation oldTti = t.asInputSignalTransition().getStaticTransitionInformation().asTopicTransitionInformation(); - t.asInputSignalTransition().setMutualTransitionInformation(new TopicTransitionInformation(oldTti.getLocation(), oldTti.getType(), - oldTti.getInputLimit(), oldTti.getOutputLimit(), oldTti.getSubNet(), instanceId, null, oldTti.getTopic())); - - } else if (t.asInputSignalTransition().getStaticTransitionInformation().isDefaultTransitionInformation()) { - - TransitionInformation oldTi = t.asInputSignalTransition().getStaticTransitionInformation(); - t.asInputSignalTransition().setMutualTransitionInformation(new DefaultTransitionInformation(oldTi.getLocation(), oldTi.getType(), - oldTi.getInputLimit(), oldTi.getOutputLimit(), oldTi.getSubNet(), instanceId, null)); - } - } else { - t.asInputSignalTransition().getMutualTransitionInformation().setInstance(instanceId); - } - }); - - // update place instance ids - subNetPlaces.forEach(p -> { - - if (p.asOutputSignalPlace().getMutualPlaceInformation() == null) { - - PlaceInformation oldPi = p.asOutputSignalPlace().getStaticPlaceInformation(); - p.asOutputSignalPlace().setMutualPlaceInformation(new PlaceInformation(oldPi.getLocation(), oldPi.getType(), oldPi.getSubNet(), instanceId, null)); - - }else{ - p.asOutputSignalPlace().getMutualPlaceInformation().setInstance(instanceId); - } - }); - - }*/ - - /* public static Tuple3<Set<Transition>, Set<Place>, Set<Arc>> copyServiceSubNet(PetriNet petriNet, String subNet, Page parentPage, String instanceId, String templateNetInstanceId) { - - // new elements - Set<Transition> transitionsToAdd = new HashSet<>(); - Set<Place> placesToAdd = new HashSet<>(); - Set<Arc> arcsToAdd = new HashSet<>(); - - Set<Place> placesToRemove = new HashSet<>(); - Set<Arc> arcsToRemove = new HashSet<>(); - - for (Transition transition : petriNet.allTransitions()) { - - InputSignalTransition channelIst = transition.asInputSignalTransition(); - - // just process "subnets" of service transitions - if (channelIst.getStaticTransitionInformation().isServiceTransitionInformation() - && channelIst.getStaticTransitionInformation().getType().equals(PnmlConstants.TRANSITION_TYPE_SERVICE_REQUEST)) { - - int numInArcs = channelIst.getInArcList().toArray(new Arc[0]).length; - String iterSubnet = channelIst.getStaticTransitionInformation().getSubNet(); - - // create deep copies of the transitions - for(Transition t: petriNet.allTransitions()){ - if(t.asInputSignalTransition().getStaticTransitionInformation().getSubNet().equals(iterSubnet)) { - transitionsToAdd.add(CopyPrimitiveElements.copySignalTransition(t.asDinerosTransition(), instanceId + "-", instanceId)); - } - } - } - - } - - - return new Tuple3<>(transitionsToAdd, placesToAdd, arcsToAdd); - }*/ - /////////////////////////////// // LOGGING //////////////////// /////////////////////////////// @@ -266,16 +163,16 @@ public class PostProcessingUtils { DinerosTransition ist = t.asDinerosTransition(); if (ist != null && ist.getMutableTransitionInformation() == null) { - if(ist.getStaticTransitionInformation().isSignalTransitionInformation()){ + if (ist.getStaticTransitionInformation().isSignalTransitionInformation()) { InputSignalClause isc = ist.getStaticTransitionInformation().asSignalTransitionInformation().getClause(); - if(isc != null){ + if (isc != null) { System.out.println(isc.printClause()); } } } } - if(withToolSpecifics) { + if (withToolSpecifics) { System.out.println("--------------- TOOL SPECIFIC ---------------"); for (Transition t : petriNet.allTransitions()) {