diff --git a/src/main/jastadd/Navigation.jrag b/src/main/jastadd/Navigation.jrag index 59043ee36178bcbef0a1aac9670e3075acf6e6d9..14412b3fcf825ad21d146e1a879f530c27e7f5c3 100644 --- a/src/main/jastadd/Navigation.jrag +++ b/src/main/jastadd/Navigation.jrag @@ -2,20 +2,16 @@ aspect Navigation { inh PetriNet PnObject.petriNet(); eq PetriNet.getChild().petriNet() = this; - syn java.util.Collection<Place> Transition.incomingPlaces() { - java.util.Set<Place> incomingPlaces = new java.util.HashSet<>(); - for (Arc incomingArc : getInArcList()) { - incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); - } - return incomingPlaces; + syn java.util.Collection<Place> TransitionNode.incomingPlaces() { + java.util.Set<Place> incomingPlaces = new java.util.HashSet<>(); + de.tudresden.inf.st.pnml.PnmlRefTransitionResolver.resolveIncomingPlaces(this, incomingPlaces); + return incomingPlaces; } - syn java.util.Collection<Place> Transition.outgoingPlaces() { - java.util.Set<Place> outgoingPlaces = new java.util.HashSet<>(); - for (Arc outgoingArc : getOutArcList()) { - outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); - } - return outgoingPlaces; + syn java.util.Collection<Place> TransitionNode.outgoingPlaces() { + java.util.Set<Place> outgoingPlaces = new java.util.HashSet<>(); + de.tudresden.inf.st.pnml.PnmlRefTransitionResolver.resolveOutgoingPlaces(this, outgoingPlaces); + return outgoingPlaces; } inh Page PnObject.ContainingPage(); @@ -40,6 +36,27 @@ aspect Navigation { syn boolean TransitionInformation.isDefaultTransitionInformation() = false; eq DefaultTransitionInformation.isDefaultTransitionInformation() = true; + syn boolean TransitionNode.isRefTransition() = false; + eq RefTransition.isRefTransition() = true; + + syn boolean TransitionNode.isTransition() = false; + eq Transition.isTransition() = true; + + syn boolean PlaceNode.isRefPlace() = false; + eq RefPlace.isRefPlace() = true; + + syn Place PlaceNode.asPlace() = null; + eq Place.asPlace() = this; + + syn boolean PlaceNode.isPlace() = false; + eq Place.isPlace() = true; + + syn RefTransition TransitionNode.asRefTransition() = null; + eq RefTransition.asRefTransition() = this; + + syn Transition TransitionNode.asTransition() = null; + eq Transition.asTransition() = this; + syn TransitionNode Node.asTransitionNode() = null; eq TransitionNode.asTransitionNode() = this; @@ -90,4 +107,19 @@ aspect Navigation { Page contributes this to PetriNet.allPages() for petriNet(); + + coll java.util.Set<TransitionNode> PetriNet.allTransitionNodes() [new java.util.HashSet()] root PetriNet; + TransitionNode contributes this + to PetriNet.allTransitionNodes() + for petriNet(); + + coll java.util.Set<RefTransition> PetriNet.allRefTransitions() [new java.util.HashSet()] root PetriNet; + RefTransition contributes this + to PetriNet.allRefTransitions() + for petriNet(); + + coll java.util.Set<RefPlace> PetriNet.allRefPlaces() [new java.util.HashSet()] root PetriNet; + RefPlace contributes this + to PetriNet.allRefPlaces() + for petriNet(); } diff --git a/src/main/jastadd/distribution/DistributedPN.jadd b/src/main/jastadd/distribution/DistributedPN.jadd index 7414924cd771afa14823154b32df8cae9c3a0ff5..1205d2aa1f22e24444e68ffd70d6ddfeeb93d1cb 100644 --- a/src/main/jastadd/distribution/DistributedPN.jadd +++ b/src/main/jastadd/distribution/DistributedPN.jadd @@ -10,13 +10,6 @@ aspect PnDistribution { return this.getMutualTransitionInformation(); } - /* syn lazy PlaceInformation OutputSignalPlace.getPlaceInformation() { - - PlaceInformation pInfo = de.tudresden.inf.st.pnml.ToolSpecificsParser.getPlaceInformation(this.getToolspecificList()); - - return pInfo; - }*/ - syn lazy PlaceInformation OutputSignalPlace.getStaticPlaceInformation() { if(this.getMutualPlaceInformation() == null){ @@ -26,4 +19,20 @@ aspect PnDistribution { return this.getMutualPlaceInformation(); } + + syn lazy String RefTransition.getLocation() { + return de.tudresden.inf.st.pnml.ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String RefTransition.getSubNet() { + return de.tudresden.inf.st.pnml.ToolSpecificsParser.getSubnetFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String RefPlace.getLocation() { + return de.tudresden.inf.st.pnml.ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList()); + } + + syn lazy String RefTransition.getSubnet() { + return de.tudresden.inf.st.pnml.ToolSpecificsParser.getSubnetFromToolSpecifics(this.getToolspecificList()); + } } \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/export/PnmlExporter.java b/src/main/java/de/tudresden/inf/st/export/PnmlExporter.java index 9fcbe2db56405b2308ae66ae9fa88bacb1381da8..7458062a5f387fbd9f0dc9892137663b139e75fb 100644 --- a/src/main/java/de/tudresden/inf/st/export/PnmlExporter.java +++ b/src/main/java/de/tudresden/inf/st/export/PnmlExporter.java @@ -35,8 +35,14 @@ public class PnmlExporter { // convert and include transitions Set<TransitionHLAPI> convertedTransitions = convertAndIncludeTransitions(petriNet, convertedPages); + // convert and include reference transitions + Set<RefTransitionHLAPI> convertedRefTransitions = convertAndIncludeRefTransitions(petriNet, convertedPages, convertedTransitions); + + // convert and include reference places + Set<RefPlaceHLAPI> convertedRefPlaces = convertAndIncludeRefPlaces(petriNet, convertedPages, convertedPlaces); + // convert and include arcs - Set<ArcHLAPI> convertedArcs = convertAndIncludeArcs(petriNet, convertedPages, convertedPlaces, convertedTransitions); + Set<ArcHLAPI> convertedArcs = convertAndIncludeArcs(petriNet, convertedPages, convertedPlaces, convertedTransitions, convertedRefTransitions, convertedRefPlaces); // export the created objects to pnml String targetPath = UUID.randomUUID().toString() + fileNameSuffix + ".pnml"; @@ -77,16 +83,121 @@ public class PnmlExporter { return hasFailed ? null : targetPath; } + private static Set<RefTransitionHLAPI> convertAndIncludeRefTransitions(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<TransitionHLAPI> convertedTransitions){ + + Set<RefTransitionHLAPI> convertedRefTransitions = new HashSet<>(); + TransitionHLAPI rootTransition = null; + + // get the root transition to construct reference tree + for(RefTransition r: petriNet.allRefTransitions()){ + if(r.getRef().isTransition()){ + for(TransitionHLAPI th : convertedTransitions){ + if(th.getId().equals(r.getRef().asTransition().getId())){ + rootTransition = th; + break; + } + } + break; + } + } + + // construct the first reference level + for(RefTransition r: petriNet.allRefTransitions()){ + assert rootTransition != null; + if(r.getRef().getId().equals(rootTransition.getId())){ + RefTransitionHLAPI rth = PrimitiveElementsConverter.convertRefTransitionToPnmlObject(r, rootTransition, null); + for(PageHLAPI pageHLAPI : convertedPages){ + if(pageHLAPI.getId().equals(r.ContainingPage().getId())){ + assert rth != null; + rth.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefTransitions.add(rth); + } + } + + // construct the remaining levels + for(RefTransition r: petriNet.allRefTransitions()){ + for(RefTransitionHLAPI convRef: convertedRefTransitions){ + if(convRef.getId().equals(r.getRef().getId())){ + RefTransitionHLAPI convertedTransition = PrimitiveElementsConverter.convertRefTransitionToPnmlObject(r, null,convRef); + for(PageHLAPI pageHLAPI : convertedPages){ + if(pageHLAPI.getId().equals(r.ContainingPage().getId())){ + assert convertedTransition != null; + convertedTransition.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefTransitions.add(convertedTransition); + } + } + } + return convertedRefTransitions; + } + + private static Set<RefPlaceHLAPI> convertAndIncludeRefPlaces(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<PlaceHLAPI> convertedPlaces){ + + + Set<RefPlaceHLAPI> convertedRefPlaces = new HashSet<>(); + PlaceHLAPI rootPlace = null; + + // get the root transition to construct reference tree + for(RefPlace p: petriNet.allRefPlaces()){ + if(p.getRef().isPlace()) { + for (PlaceHLAPI ph : convertedPlaces) { + if (ph.getId().equals(p.getRef().getId())) { + rootPlace = ph; + break; + } + } + break; + } + } + + // construct the first reference level + for(RefPlace p: petriNet.allRefPlaces()){ + assert rootPlace != null; + if(p.getRef().getId().equals(rootPlace.getId())){ + RefPlaceHLAPI rph = PrimitiveElementsConverter.convertRefPlaceToPnmlObject(p, rootPlace, null); + for(PageHLAPI pageHLAPI : convertedPages){ + if(pageHLAPI.getId().equals(p.ContainingPage().getId())){ + assert rph != null; + rph.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefPlaces.add(rph); + } + } + + // construct the remaining levels + for(RefPlace p: petriNet.allRefPlaces()){ + for(RefPlaceHLAPI convRef: convertedRefPlaces){ + if(convRef.getId().equals(p.getRef().getId())){ + RefPlaceHLAPI rph = PrimitiveElementsConverter.convertRefPlaceToPnmlObject(p, null,convRef); + for(PageHLAPI pageHLAPI : convertedPages){ + if(pageHLAPI.getId().equals(p.ContainingPage().getId())){ + assert rph != null; + rph.setContainerPageHLAPI(pageHLAPI); + break; + } + } + convertedRefPlaces.add(rph); + } + } + } + return convertedRefPlaces; + } + private static Set<PlaceHLAPI> convertAndIncludePlaces(PetriNet petriNet, Set<PageHLAPI> convertedPages) { Set<PlaceHLAPI> convertedPlaces = new HashSet<>(); for (Place p : petriNet.allPlaces()) { PlaceHLAPI convertedPlace = PrimitiveElementsConverter.convertPlaceToPnmlObject(p.asOutputSignalPlace()); - Page containingPage = p.ContainingPage(); - for(PageHLAPI pageHLAPI : convertedPages){ - if(pageHLAPI.getId().equals(containingPage.getId())){ + if(pageHLAPI.getId().equals(p.ContainingPage().getId())){ assert convertedPlace != null; convertedPlace.setContainerPageHLAPI(pageHLAPI); break; @@ -103,10 +214,8 @@ public class PnmlExporter { for(Transition t: petriNet.allTransitions()){ TransitionHLAPI convertedTransition = PrimitiveElementsConverter.convertTransitionToPnmlObject(t.asInputSignalTransition()); - Page containingPage = t.ContainingPage(); - for(PageHLAPI pageHLAPI : convertedPages){ - if(pageHLAPI.getId().equals(containingPage.getId())){ + if(pageHLAPI.getId().equals(t.ContainingPage().getId())){ assert convertedTransition != null; convertedTransition.setContainerPageHLAPI(pageHLAPI); break; @@ -117,7 +226,8 @@ public class PnmlExporter { return convertedTransitions; } - private static Set<ArcHLAPI> convertAndIncludeArcs(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<PlaceHLAPI> convertedPlaces, Set<TransitionHLAPI> convertedTransitions) { + private static Set<ArcHLAPI> convertAndIncludeArcs(PetriNet petriNet, Set<PageHLAPI> convertedPages, Set<PlaceHLAPI> convertedPlaces, + Set<TransitionHLAPI> convertedTransitions, Set<RefTransitionHLAPI> convertedRefTransitions, Set<RefPlaceHLAPI> convertedRefPlaces) { Set<ArcHLAPI> convertedArcs = new HashSet<>(); for(Arc a : petriNet.allArcs()){ @@ -147,6 +257,31 @@ public class PnmlExporter { } } + // also include arcs to/from refs + if(source == null || target == null){ + for(RefTransitionHLAPI rth : convertedRefTransitions){ + if(rth.getId().equals(a.getSource().getId())){ + source = rth; + break; + } + if(rth.getId().equals(a.getTarget().getId())){ + target = rth; + break; + } + } + + for(RefPlaceHLAPI rph : convertedRefPlaces){ + if(rph.getId().equals(a.getSource().getId())){ + source = rph; + break; + } + if(rph.getId().equals(a.getTarget().getId())){ + target = rph; + break; + } + } + } + ArcHLAPI convertedArc = PrimitiveElementsConverter.convertArcToPnmlObject(a, source, target); Page containingPage = a.ContainingPage(); @@ -168,26 +303,30 @@ public class PnmlExporter { private static Set<PageHLAPI> buildPageTrees(PetriNet petriNet, PetriNetHLAPI net) { Set<PageHLAPI> convertedPages = new HashSet<>(); + // Set<String> processedPageIds = new HashSet<>(); - getTopLevelPages(petriNet).forEach(page -> convertedPages.add(ComplexElementsConverter.convertTopLevelPageContainerToPnmlObject(page, net))); - + List<Page> topLevelPages = getTopLevelPages(petriNet); List<Page> nonTopLevelPages = getNonTopLevelPages(petriNet); - Set<String> processedPageIds = new HashSet<>(); - for (int i = 0; i < nonTopLevelPages.size(); i++) { - Page parent = nonTopLevelPages.get(i).ContainingPage(); + for(Page page : topLevelPages){ + convertedPages.add(ComplexElementsConverter.convertTopLevelPageContainerToPnmlObject(page, net)); + // processedPageIds.add(page.getId()); + } + + for (Page nonTopLevelPage : nonTopLevelPages) { + Page parent = nonTopLevelPage.ContainingPage(); for (PageHLAPI convertedPage : convertedPages) { - if (parent.getId().equals(convertedPage.getId()) && !processedPageIds.contains(convertedPage.getId())) { - processedPageIds.add(convertedPage.getId()); - convertedPages.add(ComplexElementsConverter.convertNonTopLevelPageContainerToPnmlObject(nonTopLevelPages.get(i), convertedPage)); + if (parent.getId().equals(convertedPage.getId())) {//&& !processedPageIds.contains(convertedPage.getId())) { + // processedPageIds.add(convertedPage.getId()); + convertedPages.add(ComplexElementsConverter.convertNonTopLevelPageContainerToPnmlObject(nonTopLevelPage, convertedPage)); break; } } - if ((processedPageIds.size() != nonTopLevelPages.size()) && (i == (nonTopLevelPages.size() - 1))) { - i = -1; - } + // if ((processedPageIds.size() != nonTopLevelPages.size()) && (i == (nonTopLevelPages.size() - 1))) { + // i = -1; + // } } return convertedPages; diff --git a/src/main/java/de/tudresden/inf/st/export/PrimitiveElementsConverter.java b/src/main/java/de/tudresden/inf/st/export/PrimitiveElementsConverter.java index 250b3a2972e50f258ad2f5fd1460109e0aa90754..87c43d91e92288d7781b104c2504157e2cf1dc2f 100644 --- a/src/main/java/de/tudresden/inf/st/export/PrimitiveElementsConverter.java +++ b/src/main/java/de/tudresden/inf/st/export/PrimitiveElementsConverter.java @@ -1,18 +1,12 @@ package de.tudresden.inf.st.export; -import de.tudresden.inf.st.pnml.jastadd.model.Arc; -import de.tudresden.inf.st.pnml.jastadd.model.InputSignalTransition; -import de.tudresden.inf.st.pnml.jastadd.model.OutputSignalPlace; +import de.tudresden.inf.st.pnml.jastadd.model.*; import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException; import fr.lip6.move.pnml.framework.utils.exception.VoidRepositoryException; import fr.lip6.move.pnml.ptnet.hlapi.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class PrimitiveElementsConverter { - private static final Logger logger = LoggerFactory.getLogger(PrimitiveElementsConverter.class); - private static StringBuffer clipToolSpecificsFormattedXmlBuffer(String toolName, String toolVersion, StringBuffer formattedXmlBuffer) { if (formattedXmlBuffer != null) { @@ -36,6 +30,83 @@ public class PrimitiveElementsConverter { return formattedXmlBuffer; } + public static RefTransitionHLAPI convertRefTransitionToPnmlObject(RefTransition refTransition, TransitionHLAPI referencedTransition, RefTransitionHLAPI referencedRefTransition){ + + try { + RefTransitionHLAPI r; + + if(referencedTransition != null){ + r = new RefTransitionHLAPI(refTransition.getId(), referencedTransition); + }else{ + r = new RefTransitionHLAPI(refTransition.getId(), referencedRefTransition); + } + + if(refTransition.getName() != null){ + r.setNameHLAPI(new NameHLAPI(refTransition.getName().getText())); + } + + if(refTransition.getNodeGraphics() != null && refTransition.getNodeGraphics().getLine() != null + && refTransition.getNodeGraphics().getDimension() != null){ + r.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + refTransition.getNodeGraphics().getPosition().getX(), refTransition.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(refTransition.getNodeGraphics().getDimension().getX(), refTransition.getNodeGraphics().getDimension().getY()), + null, null)); // TODO + } + + refTransition.getToolspecificList().forEach(toolInfo -> + r.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), + clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + return r; + } catch (InvalidIDException e) { + e.printStackTrace(); + } catch (VoidRepositoryException e) { + e.printStackTrace(); + } + + return null; + } + + public static RefPlaceHLAPI convertRefPlaceToPnmlObject(RefPlace refPlace, PlaceHLAPI referencedPlace, RefPlaceHLAPI referencedRefPlace){ + + try { + + RefPlaceHLAPI r; + + if(referencedPlace != null){ + r = new RefPlaceHLAPI(refPlace.getId(), referencedPlace); + }else{ + r = new RefPlaceHLAPI(refPlace.getId(), referencedRefPlace); + } + + r.setNameHLAPI(new NameHLAPI(refPlace.getName().getText())); + + if(refPlace.getNodeGraphics() != null && refPlace.getNodeGraphics().getLine() != null + && refPlace.getNodeGraphics().getDimension() != null){ + r.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( + new PositionHLAPI( + refPlace.getNodeGraphics().getPosition().getX(), refPlace.getNodeGraphics().getPosition().getY()), + new DimensionHLAPI(refPlace.getNodeGraphics().getDimension().getX(), refPlace.getNodeGraphics().getDimension().getY()), + null, null)); // TODO + } + + refPlace.getToolspecificList().forEach(toolInfo -> + r.addToolspecificsHLAPI(new ToolInfoHLAPI(toolInfo.getTool(), toolInfo.getVersion(), + clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), + toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); + + return r; + } catch (InvalidIDException e) { + e.printStackTrace(); + } catch (VoidRepositoryException e) { + e.printStackTrace(); + } + + return null; + } + public static TransitionHLAPI convertTransitionToPnmlObject(InputSignalTransition inputSignalTransition) { try { @@ -43,7 +114,8 @@ public class PrimitiveElementsConverter { t.setNameHLAPI(new NameHLAPI(inputSignalTransition.getName().getText())); - if (inputSignalTransition.getNodeGraphics() != null && inputSignalTransition.getNodeGraphics().getLine() != null && inputSignalTransition.getNodeGraphics().getDimension() != null) { + if (inputSignalTransition.getNodeGraphics() != null && inputSignalTransition.getNodeGraphics().getLine() != null + && inputSignalTransition.getNodeGraphics().getDimension() != null) { t.setNodegraphicsHLAPI(new NodeGraphicsHLAPI( new PositionHLAPI( inputSignalTransition.getNodeGraphics().getPosition().getX(), inputSignalTransition.getNodeGraphics().getPosition().getY()), @@ -56,9 +128,6 @@ public class PrimitiveElementsConverter { clipToolSpecificsFormattedXmlBuffer(toolInfo.getTool(), toolInfo.getVersion(), toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); - // inputSignalTransition.getToolspecificList().forEach(toolInfo -> - // logger.error("EXPORTING TOOLSPEC: " + toolInfo.getFormattedXMLBuffer().toString())); - return t; } catch (InvalidIDException | VoidRepositoryException e) { e.printStackTrace(); @@ -85,7 +154,11 @@ public class PrimitiveElementsConverter { toolInfo.getFormattedXMLBuffer()), toolInfo.getToolInfoGrammarURI(), null))); // TODO tranfer graphics - p.setInitialMarkingHLAPI(new PTMarkingHLAPI(Long.valueOf(outputSignalPlace.getInitialMarking().getText()))); + if(outputSignalPlace.getInitialMarking() != null){ + p.setInitialMarkingHLAPI(new PTMarkingHLAPI(Long.valueOf(outputSignalPlace.getInitialMarking().getText()))); + }else{ + p.setInitialMarkingHLAPI(new PTMarkingHLAPI(0L)); + } return p; } catch (InvalidIDException | VoidRepositoryException e) { e.printStackTrace(); diff --git a/src/main/java/de/tudresden/inf/st/pnml/Main.java b/src/main/java/de/tudresden/inf/st/pnml/Main.java index 62323d4a457a1b83937eb052f2096281d96f0c17..f47221e64f5926296229b02a31b881ab35d91265 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/Main.java +++ b/src/main/java/de/tudresden/inf/st/pnml/Main.java @@ -1,8 +1,7 @@ package de.tudresden.inf.st.pnml; import de.tudresden.inf.st.export.PnmlExporter; -import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; -import de.tudresden.inf.st.pnml.jastadd.model.RefTransition; +import de.tudresden.inf.st.pnml.jastadd.model.*; import de.tudresden.inf.st.postprocessing.GlobalToLocalNetsPostProcessor; import de.tudresden.inf.st.postprocessing.PostProcessingUtils; import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException; @@ -25,14 +24,20 @@ public class Main { return; } - //List<PetriNet> petriNets = PnmlParser.parsePnml("src/main/nets/jointTestNet2.pnml"); + //List<PetriNet> petriNets = PnmlParser.parsePnml("src/main/nets/refNet2.pnml"); List<PetriNet> petriNets = PnmlParser.parsePnml(inputPath); List<List<PetriNet>> disconnectedPetriNets = new ArrayList<>(); + // petriNets.forEach(pn -> disconnectedPetriNets.add(GlobalToLocalNetsPostProcessor.disconnectNets(pn))); - petriNets.forEach(pn -> disconnectedPetriNets.add(GlobalToLocalNetsPostProcessor.disconnectNets(pn))); + for(PetriNet pn : petriNets){ + PostProcessingUtils.printNet(pn); + List<PetriNet> pnl = GlobalToLocalNetsPostProcessor.disconnectNets(pn); + disconnectedPetriNets.add(pnl); + PostProcessingUtils.printNet(pnl.get(0)); + } - for(List<PetriNet> petriNetList : disconnectedPetriNets){ + for(List<PetriNet> petriNetList : disconnectedPetriNets){ for(PetriNet petriNet : petriNetList){ PostProcessingUtils.cleanEmptyPages(petriNet); petriNet.flushTreeCache(); @@ -41,7 +46,7 @@ public class Main { logger.info("------------------------------------------------------------------------------------"); - for(int i = 0; i < disconnectedPetriNets.size(); i++){ + for(int i = 0; i < disconnectedPetriNets.size(); i++){ for(int j = 0; j < disconnectedPetriNets.get(i).size(); j++){ logger.info("Exporting splitted Petri net containing: "); PostProcessingUtils.printNet(disconnectedPetriNets.get(i).get(j)); diff --git a/src/main/java/de/tudresden/inf/st/pnml/PnmlRefTransitionResolver.java b/src/main/java/de/tudresden/inf/st/pnml/PnmlRefTransitionResolver.java new file mode 100644 index 0000000000000000000000000000000000000000..ede9604fd0ccac95bd1054213caa5df159685ffc --- /dev/null +++ b/src/main/java/de/tudresden/inf/st/pnml/PnmlRefTransitionResolver.java @@ -0,0 +1,53 @@ +package de.tudresden.inf.st.pnml; + +import de.tudresden.inf.st.pnml.jastadd.model.Arc; +import de.tudresden.inf.st.pnml.jastadd.model.Place; +import de.tudresden.inf.st.pnml.jastadd.model.RefTransition; +import de.tudresden.inf.st.pnml.jastadd.model.TransitionNode; + +import java.util.Set; + +public class PnmlRefTransitionResolver { + + public static void resolveIncomingPlaces(TransitionNode transitionNode, Set<Place> incomingPlaces){ + + if(transitionNode.isTransition()){ + for (Arc incomingArc : transitionNode.getInArcList()) { + incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); + } + return; + } + + if(transitionNode.isRefTransition()){ + RefTransition rt = transitionNode.asRefTransition(); + TransitionNode subRt = rt.get_impl_ref(); + + for (Arc incomingArc : transitionNode.getInArcList()) { + incomingPlaces.add(incomingArc.getSource().asPlaceNode().place()); + } + + resolveIncomingPlaces(subRt, incomingPlaces); + } + } + + public static void resolveOutgoingPlaces(TransitionNode transitionNode, Set<Place> outgoingPlaces){ + + if(transitionNode.isTransition()){ + for (Arc outgoingArc : transitionNode.getOutArcList()) { + outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); + } + return; + } + + if(transitionNode.isRefTransition()){ + RefTransition rt = transitionNode.asRefTransition(); + TransitionNode subRt = rt.get_impl_ref(); + + for (Arc outgoingArc : transitionNode.getInArcList()) { + outgoingPlaces.add(outgoingArc.getTarget().asPlaceNode().place()); + } + + resolveIncomingPlaces(subRt, outgoingPlaces); + } + } +} diff --git a/src/main/java/de/tudresden/inf/st/pnml/ToolSpecificsParser.java b/src/main/java/de/tudresden/inf/st/pnml/ToolSpecificsParser.java index 45dcf890dcd615eda1df56569f65fbb528e597c5..d757b1c916d28f0d091371b1d48ef8313739180f 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/ToolSpecificsParser.java +++ b/src/main/java/de/tudresden/inf/st/pnml/ToolSpecificsParser.java @@ -21,7 +21,7 @@ public class ToolSpecificsParser { private static final Logger logger = LoggerFactory.getLogger(ToolSpecificsParser.class); - private static String getLocationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + public static String getLocationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { if (toolInfos.getNumChild() > 0) { try { @@ -135,15 +135,19 @@ public class ToolSpecificsParser { return null; } + public static String getSubnetFromToolSpecifics(JastAddList<ToolInfo> toolInfos) { + return getSubnetInfoInternal(toolInfos); + } + private static String getSubnetInfoInternal(JastAddList<ToolInfo> toolInfos) { if (toolInfos.getNumChild() > 0) { try { Document doc = parseToolSpecifics(toolInfos); - String typeTrans = getTransitionTypeFromToolSpecifics(toolInfos); - String typePlace = getPlaceTypeFromToolSpecifics(toolInfos); + // String typeTrans = getTransitionTypeFromToolSpecifics(toolInfos); + // String typePlace = getPlaceTypeFromToolSpecifics(toolInfos); - String type = typePlace == null ? typeTrans : typePlace; + // String type = typePlace == null ? typeTrans : typePlace; // if (type != null && (type.equals(PnmlConstants.TRANSITION_TYPE_DISCRETE) // || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) diff --git a/src/main/java/de/tudresden/inf/st/postprocessing/GlobalToLocalNetsPostProcessor.java b/src/main/java/de/tudresden/inf/st/postprocessing/GlobalToLocalNetsPostProcessor.java index 16d2626bd8f9d59e31ec88c87d66e9aa50768cb0..064627f497cab6c8cff231d6c4d850d38b07161d 100644 --- a/src/main/java/de/tudresden/inf/st/postprocessing/GlobalToLocalNetsPostProcessor.java +++ b/src/main/java/de/tudresden/inf/st/postprocessing/GlobalToLocalNetsPostProcessor.java @@ -37,13 +37,9 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { // cut the topic transitions PetriNet topicCuttedNet = cutTopicTransitions(petriNet); - //logger.error("topicCuttedNet: --------------------------------------------"); - //printNet(petriNet); // cut the service transitions PetriNet serviceCuttedNet = cutServiceTransitions(topicCuttedNet); - //logger.error("serviceCuttedNet: --------------------------------------------"); - //printNet(serviceCuttedNet); Set<String> locations = getLocations(serviceCuttedNet); @@ -54,7 +50,6 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { for (String location : locations) { List<PetriNet> reParsedPetriNets = PnmlParser.parsePnml(serializedNetPath); - for (PetriNet pn : reParsedPetriNets) { PetriNet separatedNet = createdSeparatedNetByLocation(pn, location); pns.add(separatedNet); diff --git a/src/main/java/de/tudresden/inf/st/postprocessing/IoPetriNetPostProcessor.java b/src/main/java/de/tudresden/inf/st/postprocessing/IoPetriNetPostProcessor.java index a262bd7c15ea8d37cd1817f08a0ccb8211bc6f5c..7da7fe99fc50d64aca75cd551399e55f02e763f7 100644 --- a/src/main/java/de/tudresden/inf/st/postprocessing/IoPetriNetPostProcessor.java +++ b/src/main/java/de/tudresden/inf/st/postprocessing/IoPetriNetPostProcessor.java @@ -36,6 +36,10 @@ public class IoPetriNetPostProcessor implements PostProcessor<PetriNet> { private static JastAddList<InputSignalBinding> parseInputSignalBindingDefinitionsInternal(Document doc) { + if(doc == null){ + return null; + } + NodeList isBindingDefList = doc.getElementsByTagName(PnmlConstants.INPUT_SIGNAL_BINDINGS_KEY); JastAddList<InputSignalBinding> jastAddBindingList = new JastAddList<>(); @@ -160,6 +164,10 @@ public class IoPetriNetPostProcessor implements PostProcessor<PetriNet> { private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException { + if(toolInfos == null || toolInfos.getNumChild() == 0){ + return null; + } + StringBuffer toolInfoStringBuffer = toolInfos.getChild(0).getFormattedXMLBuffer(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); diff --git a/src/main/java/de/tudresden/inf/st/postprocessing/PostProcessingUtils.java b/src/main/java/de/tudresden/inf/st/postprocessing/PostProcessingUtils.java index 5df65934284e46c882fb3a76d6ca70f5483cc757..016a642aff7558a69b9951c69b49d151a0bbaecb 100644 --- a/src/main/java/de/tudresden/inf/st/postprocessing/PostProcessingUtils.java +++ b/src/main/java/de/tudresden/inf/st/postprocessing/PostProcessingUtils.java @@ -205,7 +205,7 @@ public class PostProcessingUtils { logger.info("----------------- PLACES ----------------"); for (Place p : petriNet.allPlaces()) { - logger.info("Place " + p.asOutputSignalPlace().getName().getText() + " -- " + p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet()); + logger.info("Place " + p.asOutputSignalPlace().getName().getText() + " -- " + p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet()); } logger.info("-------------- TRANSITIONS --------------"); @@ -215,9 +215,11 @@ public class PostProcessingUtils { if (t.asInputSignalTransition().getStaticTransitionInformation().isServiceTransitionInformation()) { logger.info("--- Transition: " + t.getName().getText() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet() + " service: " + t.asInputSignalTransition().getStaticTransitionInformation().asServiceTransitionInformation().getServiceName() + " ---------"); - } else { - logger.info("--- Transition: " + t.getName().getText() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet() + } else if(t.asInputSignalTransition().getStaticTransitionInformation().isTopicTransitionInformation()){ + logger.info("--- Transition: " + t.getName().getText() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet() + " topic: " + t.asInputSignalTransition().getStaticTransitionInformation().asTopicTransitionInformation().getTopic() + " ---------"); + }else{ + logger.info("--- Transition: " + t.getId()); } for (Place p : t.asInputSignalTransition().incomingPlaces()) { @@ -234,8 +236,7 @@ public class PostProcessingUtils { logger.info("----------------- ARCS -----------------"); for (Arc a : petriNet.allArcs()) { - - logger.info("Arc: " + a.getId() + " -- source: " + a.getSource().getName().getText() + " -- target: " + a.getTarget().getName().getText()); + logger.info("Arc: " + a.getId() + " -- source: " + a.getSource().getId() + " -- target: " + a.getTarget().getId()); } logger.info("--------------- T SIGNALS (STATIC)---------------"); @@ -262,7 +263,9 @@ public class PostProcessingUtils { for (Transition t : petriNet.allTransitions()) { InputSignalTransition ist = t.asInputSignalTransition(); - logger.info("ToolSpecific: (" + ist.getName().getText() + ") " + ist.getToolspecific(0).getFormattedXMLBuffer().toString()); + if(ist != null && ist.getNumToolspecific() > 0) { + logger.info("ToolSpecific: (" + ist.getName().getText() + ") " + ist.getToolspecific(0).getFormattedXMLBuffer().toString()); + } } } } diff --git a/src/main/nets/refNet1.pnml b/src/main/nets/refNet1.pnml new file mode 100644 index 0000000000000000000000000000000000000000..4fccb61f2aa05869eacdf1f817a2049f78572c17 --- /dev/null +++ b/src/main/nets/refNet1.pnml @@ -0,0 +1,92 @@ +<pnml xmlns="http://www.pnml.org/version-2009/grammar/pnml"> + <net id="n-E2D0-BCF46-0" type ="http://www.pnml.org/version-2009/grammar/ptnet"> + <name> + <text>minimal</text> + </name> + + <page id="top"> + <page id="p1"> + <place id="pRefSrc"> + <name> + <text>pRefSrc</text> + <graphics> + <offset x="0" y="-10" /> + </graphics> + </name> + <initialMarking> + <text>1</text> + </initialMarking> + <graphics> + <position x="30" y="50"/> + </graphics> + </place> + <referenceTransition id="rt1" ref="t-E2D0-BCFAC-4"> + <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1"> + <location>loc1</location> + <subnet>s1</subnet> + </toolspecific> + </referenceTransition> + <arc id="rin" source="pRefSrc" target="rt1"> + </arc> + </page> + + <page id="p2"> + <place id="p-E2D0-BCF6F-2"> + <name> + <text>p0</text> + <graphics> + <offset x="0" y="-10" /> + </graphics> + </name> + <initialMarking> + <text>1</text> + </initialMarking> + <graphics> + <position x="30" y="50"/> + </graphics> + </place> + <place id="p-E2D0-BCF9D-3"> + <name> + <text>p1</text> + <graphics> + <offset x="0" y="-10" /> + </graphics> + </name> + <graphics> + <position x="635" y="90"/> + </graphics> + </place> + <transition id="t-E2D0-BCFAC-4"> + <name> + <text>t0</text> + <graphics> + <offset x="0" y="0" /> + </graphics> + </name> + <graphics> + <position x="300" y="50"/> + </graphics> + </transition> + <transition id="t-E2D0-BCFBD-5"> + <name> + <text>t1</text> + <graphics> + <offset x="0" y="0" /> + </graphics> + </name> + <graphics> + <position x="285" y="205"/> + </graphics> + </transition> + <arc id="e-E2D0-BCFCD-6" source="t-E2D0-BCFBD-5" target="p-E2D0-BCF6F-2"> + </arc> + <arc id="e-E2D0-BCFDB-7" source="p-E2D0-BCF9D-3" target="t-E2D0-BCFBD-5"> + </arc> + <arc id="e-E2D0-BCFF3-8" source="t-E2D0-BCFAC-4" target="p-E2D0-BCF9D-3"> + </arc> + <arc id="e-E2D0-BCFFB-9" source="p-E2D0-BCF6F-2" target="t-E2D0-BCFAC-4"> + </arc> + </page> + </page> + </net> +</pnml> diff --git a/src/main/nets/refNet2.pnml b/src/main/nets/refNet2.pnml new file mode 100644 index 0000000000000000000000000000000000000000..79ddbd85a756225a82d7dae153e3a1b9d85770f4 --- /dev/null +++ b/src/main/nets/refNet2.pnml @@ -0,0 +1,98 @@ +<pnml xmlns="http://www.pnml.org/version-2009/grammar/pnml"> + <net id="n-E2D0-BCF46-0" type ="http://www.pnml.org/version-2009/grammar/ptnet"> + <name> + <text>minimal</text> + </name> + + <page id="top"> + <page id="p1"> + <transition id="tRefIn"> + <name> + <text>tRefIn</text> + <graphics> + <offset x="0" y="0" /> + </graphics> + </name> + <graphics> + <position x="285" y="205"/> + </graphics> + </transition> + <referencePlace id="rp1" ref="p-E2D0-BCF6F-2"> + <toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.1"> + <location>loc1</location> + <subnet>s1</subnet> + </toolspecific> + <name> + <text>rp1</text> + <graphics> + <offset x="0" y="0" /> + </graphics> + </name> + <graphics> + <position x="20" y="20"/> + </graphics> + <arc id="rin" source="tRefIn" target="rp1"> + </arc> + </referencePlace> + </page> + + <page id="p2"> + <place id="p-E2D0-BCF6F-2"> + <name> + <text>p0</text> + <graphics> + <offset x="0" y="-10" /> + </graphics> + </name> + <initialMarking> + <text>1</text> + </initialMarking> + <graphics> + <position x="30" y="50"/> + </graphics> + </place> + <place id="p-E2D0-BCF9D-3"> + <name> + <text>p1</text> + <graphics> + <offset x="0" y="-10" /> + </graphics> + </name> + <graphics> + <position x="635" y="90"/> + </graphics> + </place> + <transition id="t-E2D0-BCFAC-4"> + <name> + <text>t0</text> + <graphics> + <offset x="0" y="0" /> + </graphics> + </name> + <graphics> + <position x="300" y="50"/> + </graphics> + </transition> + <transition id="t-E2D0-BCFBD-5"> + <name> + <text>t1</text> + <graphics> + <offset x="0" y="0" /> + </graphics> + </name> + <graphics> + <position x="285" y="205"/> + </graphics> + </transition> + <arc id="e-E2D0-BCFCD-6" source="t-E2D0-BCFBD-5" target="p-E2D0-BCF6F-2"> + </arc> + <arc id="e-E2D0-BCFDB-7" source="p-E2D0-BCF9D-3" target="t-E2D0-BCFBD-5"> + </arc> + <arc id="e-E2D0-BCFF3-8" source="t-E2D0-BCFAC-4" target="p-E2D0-BCF9D-3"> + </arc> + <arc id="e-E2D0-BCFFB-9" source="p-E2D0-BCF6F-2" target="t-E2D0-BCFAC-4"> + </arc> + </page> + </page> + </net> +</pnml>