diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c053550b91381bbd28b1afc82d634bf73a8a..d9b7505b1096bc428abaa017cb79c9d2da247111 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4b4429748d92848a3d820c7b099fbeb941066ae..19869d6658eca905211de6b30978e19634ac3931 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip diff --git a/src/main/config/config.json b/src/main/config/config.json new file mode 100644 index 0000000000000000000000000000000000000000..f2afe7e06c3bf93028ae8dc4d951c682464424b7 --- /dev/null +++ b/src/main/config/config.json @@ -0,0 +1,6 @@ +{ + "tina" : "-R -s 1 -c 0 -t 0 -b 0 -m 0 -v -PNML -bcg", + "pathto" : "", + "sift" : "", + "struct" : "" +} \ No newline at end of file diff --git a/src/main/java/de/tudresden/inf/st/pnml/flatter/Main.java b/src/main/java/de/tudresden/inf/st/pnml/flatter/Main.java index 0e38ad4252b5bb52c2567cc059dd726fec44a516..40db411b5dcb00b4a90038439d008a22831eba0a 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/flatter/Main.java +++ b/src/main/java/de/tudresden/inf/st/pnml/flatter/Main.java @@ -3,6 +3,7 @@ package de.tudresden.inf.st.pnml.flatter; import de.tudresden.inf.st.pnml.flatter.config.ConfigReader; import de.tudresden.inf.st.pnml.flatter.transform.ChannelFlatter; import de.tudresden.inf.st.pnml.flatter.transform.ReferenceFlatter; +import de.tudresden.inf.st.pnml.jastadd.model.*; import de.tudresden.inf.st.pnml.jastadd.model.PnmlParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +29,8 @@ public class Main { }*/ // parse the global not flatted petri net - pnmlPath = "pnml-relast-flatter/src/main/resources/minimal.pnml"; + pnmlPath = "../pnml-relast-nets/src/main/resources/topicTestNets/structureTestNets/topic-structure-correct-3.pnml"; + configPath = "src/main/config/config.json"; PetriNet petriNet = PnmlParser.parsePnml(pnmlPath).get(0); // read config for analyzer from file @@ -46,10 +48,12 @@ public class Main { // flat topic publishers / subscribers to instance based semantics logger.info("[FLATTER] Breaking down topic channels."); PetriNet topicFlattedPetriNet = ChannelFlatter.flatTopicChannels(petriNet); + printNet(topicFlattedPetriNet); + // flat service clients / servers to instance based semantics logger.info("[FLATTER] Breaking down service channels."); - PetriNet serviceFlattedPetriNet = ChannelFlatter.flatTopicChannels(topicFlattedPetriNet); + // PetriNet serviceFlattedPetriNet = ChannelFlatter.flatServiceChannels(topicFlattedPetriNet); // flat input signals @@ -60,8 +64,8 @@ public class Main { // TODO // convert and add inhibitor arcs - NdrioProxy ndrioProxy = new NdrioProxy(); - ndrioProxy.pnml2net(pnmlPath, "pnml-relast-flatter/src/main/resources/minimal.net"); + // NdrioProxy ndrioProxy = new NdrioProxy(); + // ndrioProxy.pnml2net(pnmlPath, "pnml-relast-flatter/src/main/resources/minimal.net"); // insert into tina @@ -84,4 +88,91 @@ public class Main { // TODO } + + public static void printNet(PetriNet petriNet) { + + logger.error("--------------- STRUCTURE ---------------"); + logger.error("----------------- PLACES ----------------"); + + for (Place p : petriNet.allPlaces()) { + //logger.error("id: " + p.getId()); + logger.error("Place " + p.asOutputSignalPlace().getId() + " -- " + p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet()); + } + + logger.error("-------------- TRANSITIONS --------------"); + + for (Transition t : petriNet.allTransitions()) { + + if (t.asInputSignalTransition().getStaticTransitionInformation().isServiceTransitionInformation()) { + logger.error("--- Transition: " + t.getId() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet() + + " service: " + t.asInputSignalTransition().getStaticTransitionInformation().asServiceTransitionInformation().getServiceName() + " ---------"); + } else if(t.asInputSignalTransition().getStaticTransitionInformation().isTopicTransitionInformation()){ + logger.error("--- Transition: " + t.getId() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet() + + " topic: " + t.asInputSignalTransition().getStaticTransitionInformation().asTopicTransitionInformation().getTopic() + " ---------"); + }else{ + logger.error("--- Transition: " + t.getId()); + } + + if(t.asInputSignalTransition().getInputSignalClause() != null && t.asInputSignalTransition().getInputSignalClause().getNumChild() > 0){ + // logger.error("------ Clause: " + t.asInputSignalTransition().getInputSignalClause().printExp()); + } + + for (Place p : t.asInputSignalTransition().incomingPlaces()) { + + logger.error("------ Inputplace: " + p.getId() + " subnet: " + p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet() + " ---------"); + } + + for (Place p : t.asInputSignalTransition().outgoingPlaces()) { + + logger.error("------ Outputplace: " + p.getId() + " subnet: " + p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet() + " ---------"); + } + } + + logger.error("----------------- REF PLACES -----------------"); + + for (RefPlace rp : petriNet.allRefPlaces()){ + logger.error("--- RefPlace: " + rp.getId()); + } + + logger.error("----------------- REF TRANSITIONS -----------------"); + + for (RefTransition rt : petriNet.allRefTransitions()){ + logger.error("--- RefTransition: " + rt.getId()); + } + + logger.error("----------------- ARCS -----------------"); + + for (Arc a : petriNet.allArcs()) { + logger.error("Arc: " + a.getId() + " -- source: " + a.getSource().getId() + " -- target: " + a.getTarget().getId()); + } + + logger.error("--------------- T SIGNALS (STATIC)---------------"); + + for (Transition t : petriNet.allTransitions()) { + InputSignalTransition ist = t.asInputSignalTransition(); + + if (ist != null && ist.getStaticInputSignalBindingList() != null) { + ist.getStaticInputSignalBindingList().forEach(inputSignalBinding -> logger.error(" (" + t.getName().getText() + ") Signal: " + inputSignalBinding.getInputSignalID())); + } + } + + logger.error("--------------- T SIGNALS (MUTUAL)---------------"); + + for (Transition t : petriNet.allTransitions()) { + InputSignalTransition ist = t.asInputSignalTransition(); + + if (ist != null && ist.getMutualInputSignalBindingList() != null) { + ist.getMutualInputSignalBindingList().forEach(inputSignalBinding -> logger.error(" (" + t.getName().getText() + ") Signal: " + inputSignalBinding.getInputSignalID())); + } + } + + // logger.error("--------------- TOOL SPECIFIC ---------------"); + + for (Transition t : petriNet.allTransitions()) { + InputSignalTransition ist = t.asInputSignalTransition(); + if(ist != null && ist.getNumToolspecific() > 0) { + // logger.error("ToolSpecific: (" + ist.getName().getText() + ") " + ist.getToolspecific(0).getFormattedXMLBuffer().toString()); + } + } + } } diff --git a/src/main/java/de/tudresden/inf/st/pnml/flatter/config/ConfigReader.java b/src/main/java/de/tudresden/inf/st/pnml/flatter/config/ConfigReader.java index 45e899c985aec043d5b3d9dd56f8cedc59d384d9..3933f309063ca3c6a23df29b8db8ebce2bbe0fb9 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/flatter/config/ConfigReader.java +++ b/src/main/java/de/tudresden/inf/st/pnml/flatter/config/ConfigReader.java @@ -49,6 +49,7 @@ public class ConfigReader { public String[] getTinaConfigParams(){ Gson gson = new Gson(); + System.out.println("Content " + getConfigFileContent()); FlatterConfig fc = gson.fromJson(getConfigFileContent(), FlatterConfig.class); return fc.tina.split(" "); } diff --git a/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TemplateConstants.java b/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TemplateConstants.java index aaa209dccd3f80615c4a23eb2d15e1c01e728d51..62eba79760fb5bc61d0785fea71c9dbc424116d4 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TemplateConstants.java +++ b/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TemplateConstants.java @@ -7,11 +7,13 @@ public final class TemplateConstants { public static final String PUBLISHER_CONNECTOR_PLACE = "PublisherConnectorPlace"; public static final String PUBLISHER_INPUT_TRANSITION = "PublisherInputTransition"; public static final String PUBLISHER_OVERFLOW_TRANSITION = "PublisherOverflowTransition"; - public static final String PUBLISHER_OUTPUT_TRANSITION = "PublisherOverflowTransition"; + public static final String PUBLISHER_OUTPUT_TRANSITION = "PublisherOutputTransition"; // topic dispatcher public static final String DISPATCHER_INPUT_TRANSITION = "DispatcherInputTransition"; public static final String DISPATCHER_OUTPUT_TRANSITION = "DispatcherOutputTransition"; + public static final String DISPATCHER_INPUT_PLACE = "DispatcherInputPlace"; + public static final String DISPATCHER_OVERFLOW_TRANSITION = "DispatcherOverflowTransition"; // topic callback public static final String CALLBACK_INPUT_PLACE = "CallbackInputPlace"; @@ -26,4 +28,5 @@ public final class TemplateConstants { // channel elements public static final String CHANNEL_CONNECTOR_PLACE = "ChannelConnectorPlace"; public static final String CHANNEL_CONNECTOR_TRANSITION = "ChannelConnectorTransition"; + } diff --git a/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TopicTemplates.java b/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TopicTemplates.java index 59b19eae5d0ec6f9b607d6101240d8d7398c6eec..e77d7e955bf12c79f57b522db55d06eee2c89cf3 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TopicTemplates.java +++ b/src/main/java/de/tudresden/inf/st/pnml/flatter/template/TopicTemplates.java @@ -1,5 +1,6 @@ package de.tudresden.inf.st.pnml.flatter.template; +import de.tudresden.inf.st.pnml.jastadd.model.Name; import de.tudresden.inf.st.pnml.jastadd.model.PetriNet; import de.tudresden.inf.st.pnml.jastadd.model.PnObject; import de.tudresden.inf.st.pnml.jastadd.model.PnmlParser; @@ -8,12 +9,14 @@ public class TopicTemplates extends PnmlTemplate { public static PetriNet getTopicPublisherPetriNet(String idSuffix){ - PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/TopicPublisherTemplate.pnml").get(0); + PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/TopicPublisherTemplate.pnml").get(0); for(PnObject po : templateNet.allObjects()){ if(!po.getId().equals(TemplateConstants.PUBLISHER_TEMPLATE_PAGE)){ po.setId(po.getId() + "-" + idSuffix); - po.getName().setText(po.getName().getText() + "-" + idSuffix); + Name name = new Name(); + name.setText(po.getId() + "-" + idSuffix); + po.setName(name); } } @@ -22,12 +25,14 @@ public class TopicTemplates extends PnmlTemplate { public static PetriNet getTopicDispatcherPetriNet(String idSuffix){ - PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/TopicSubDispatcherTemplate.pnml").get(0); + PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/TopicSubDispatcherTemplate.pnml").get(0); for(PnObject po : templateNet.allObjects()){ if(!po.getId().equals(TemplateConstants.DISPATCHER_TEMPLATE_PAGE)){ po.setId(po.getId() + "-" + idSuffix); - po.getName().setText(po.getName().getText() + "-" + idSuffix); + Name name = new Name(); + name.setText(po.getId() + "-" + idSuffix); + po.setName(name); } } @@ -36,12 +41,14 @@ public class TopicTemplates extends PnmlTemplate { public static PetriNet getTopicCallbackQueuePetriNet(String idSuffix){ - PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/TopicSubCallbackQueueTemplate.pnml").get(0); + PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/TopicSubCallbackQueueTemplate.pnml").get(0); for(PnObject po : templateNet.allObjects()){ if(!po.getId().equals(TemplateConstants.CALLBACK_QUEUE_TEMPLATE_PAGE)){ po.setId(po.getId() + "-" + idSuffix); - po.getName().setText(po.getName().getText() + "-" + idSuffix); + Name name = new Name(); + name.setText(po.getId() + "-" + idSuffix); + po.setName(name); } } diff --git a/src/main/java/de/tudresden/inf/st/pnml/flatter/transform/ChannelFlatter.java b/src/main/java/de/tudresden/inf/st/pnml/flatter/transform/ChannelFlatter.java index acd23b323781d945ad7d484d00ccabc93b238e5a..b4b3a0aaab8dfe4cbf1b6fa065655c719fc7a5e8 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/flatter/transform/ChannelFlatter.java +++ b/src/main/java/de/tudresden/inf/st/pnml/flatter/transform/ChannelFlatter.java @@ -1,5 +1,6 @@ package de.tudresden.inf.st.pnml.flatter.transform; +import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; import de.tudresden.inf.st.pnml.flatter.template.TemplateConstants; import de.tudresden.inf.st.pnml.flatter.template.TopicTemplates; import de.tudresden.inf.st.pnml.jastadd.model.*; @@ -22,6 +23,8 @@ public class ChannelFlatter { int channelCount = 0; List<Transition> topicTransitions = new ArrayList<>(); + List<Arc> arcsToRemove = new ArrayList<>(); + List<Transition> transitionsToRemove = new ArrayList<>(); // process topic transitions for(Transition t : petriNet.allTransitions()){ @@ -61,13 +64,17 @@ public class ChannelFlatter { for (Map.Entry<String, Place> entry : inputMapping.entrySet()) { // include the template publisher - PetriNet publisherPetriNet = TopicTemplates.getTopicPublisherPetriNet("-" + publisherCount); + PetriNet publisherPetriNet = TopicTemplates.getTopicPublisherPetriNet(String.valueOf(publisherCount)); includeTemplateInstance(petriNet, publisherPetriNet, entry.getKey(), entry.getValue().asOutputSignalPlace().getStaticPlaceInformation().getLocation()); // connect the publisher inputs Arc inputArc = new Arc(); Arc overFlowArc = new Arc(); Arc outArc = new Arc(); + inputArc.setId("pub-inputArc-" + publisherCount); + overFlowArc.setId("pub-overFlowArc-" + publisherCount); + outArc.setId("pub-outArc-" + publisherCount); + inputArc.setSource(entry.getValue()); inputArc.setTarget((Node) getPnObjectByID(petriNet, TemplateConstants.PUBLISHER_INPUT_TRANSITION + "-" + publisherCount)); @@ -92,12 +99,13 @@ public class ChannelFlatter { for (Map.Entry<String, List<Place>> entry : outputMapping.entrySet()) { // include dispatcher queues - PetriNet dispatcherNet = TopicTemplates.getTopicDispatcherPetriNet("-" + dispatcherCount); + PetriNet dispatcherNet = TopicTemplates.getTopicDispatcherPetriNet(String.valueOf(dispatcherCount)); includeTemplateInstance(petriNet, dispatcherNet, entry.getKey(), entry.getValue().get(0).asOutputSignalPlace().getStaticPlaceInformation().getLocation()); Arc channelToDispatcherArc = new Arc(); + channelToDispatcherArc.setId("channelToDispatcherArc-" + dispatcherCount); channelToDispatcherArc.setSource((Node) getPnObjectByID(petriNet, TemplateConstants.CHANNEL_CONNECTOR_TRANSITION + "-" + channelCount)); - channelToDispatcherArc.setTarget((Node) getPnObjectByID(petriNet, TemplateConstants.DISPATCHER_INPUT_TRANSITION + "-" + dispatcherCount)); + channelToDispatcherArc.setTarget((Node) getPnObjectByID(petriNet, TemplateConstants.DISPATCHER_INPUT_PLACE + "-" + dispatcherCount)); topPage.addObject(channelToDispatcherArc); petriNet.flushTreeCache(); @@ -105,15 +113,19 @@ public class ChannelFlatter { // include subscriber queues for(Place p : entry.getValue()){ - PetriNet subscriberNet = TopicTemplates.getTopicCallbackQueuePetriNet("-" + callbackCount); + PetriNet subscriberNet = TopicTemplates.getTopicCallbackQueuePetriNet(String.valueOf(callbackCount)); includeTemplateInstance(petriNet, subscriberNet, entry.getKey(), p.asOutputSignalPlace().getStaticPlaceInformation().getLocation()); Arc callbackInputArc = new Arc(); Arc callbackOverFlowArc = new Arc(); Arc callbackOutArc = new Arc(); + callbackInputArc.setId("callbackInputArc-" + dispatcherCount); + callbackOverFlowArc.setId("callbackOverFlowArc-" + dispatcherCount); + callbackOutArc.setId("callbackOutArc-" + dispatcherCount); + callbackInputArc.setSource((Node) getPnObjectByID(petriNet, TemplateConstants.DISPATCHER_OUTPUT_TRANSITION + "-" + dispatcherCount)); - callbackOverFlowArc.setSource((Node) getPnObjectByID(petriNet, TemplateConstants.DISPATCHER_OUTPUT_TRANSITION + "-" + dispatcherCount)); + callbackOverFlowArc.setSource((Node) getPnObjectByID(petriNet, TemplateConstants.CALLBACK_INPUT_PLACE + "-" + dispatcherCount)); callbackInputArc.setTarget((Node) getPnObjectByID(petriNet, TemplateConstants.CALLBACK_INPUT_PLACE + "-" + callbackCount)); callbackOverFlowArc.setTarget((Node) getPnObjectByID(petriNet, TemplateConstants.CALLBACK_OVERFLOW_TRANSITION + "-" + callbackCount)); @@ -129,22 +141,45 @@ public class ChannelFlatter { petriNet.flushTreeCache(); - // clean up old channel - - // TODO + // objects to be cleaned up + arcsToRemove.addAll(t.getInArcs()); + arcsToRemove.addAll(t.getOutArcs()); + transitionsToRemove.add(t); } channelCount++; } - return null; + // clean up old channel data + for(Arc a : arcsToRemove){ + a.removeSelf(); + } + + for(Transition t : transitionsToRemove){ + t.removeSelf(); + } + + petriNet.flushTreeCache(); + + return petriNet; } private static void insertChannelElements(PetriNet petriNet, int channelCount) { - Place channelPlace = new Place(); - Transition channelTransition = new Transition(); + OutputSignalPlace channelPlace = new OutputSignalPlace(); + PlaceInformation newPi = new PlaceInformation(); + newPi.setLocation("channel"); + newPi.setSubNet("channel"); + newPi.setType(PnmlConstants.PLACE_TYPE_DISCRETE); + channelPlace.setMutualPlaceInformation(newPi); + + InputSignalTransition channelTransition = new InputSignalTransition(); + TransitionInformation newTi = new DefaultTransitionInformation(); + newTi.setLocation("channel"); + newTi.setSubNet("channel"); + newTi.setType(PnmlConstants.TRANSITION_TYPE_DISCRETE); + channelTransition.setMutualTransitionInformation(newTi); channelPlace.setId(TemplateConstants.CHANNEL_CONNECTOR_PLACE + "-" + channelCount); channelTransition.setId(TemplateConstants.CHANNEL_CONNECTOR_TRANSITION + "-" + channelCount); @@ -153,6 +188,12 @@ public class ChannelFlatter { topPage.addObject(channelPlace); topPage.addObject(channelTransition); + Arc channelArc = new Arc(); + channelArc.setId("ChannelArc-" + channelCount); + channelArc.setTarget(channelTransition); + channelArc.setSource(channelPlace); + topPage.addObject(channelArc); + petriNet.flushTreeCache(); } @@ -168,22 +209,47 @@ public class ChannelFlatter { // include places, transitions for(Transition t : templateInstance.allTransitions()){ - t.asInputSignalTransition().getMutualTransitionInformation().setSubNet(subnet); - t.asInputSignalTransition().getMutualTransitionInformation().setLocation(location); + + System.out.println("Adding: " + t.getId()); + + TransitionInformation newTi = new DefaultTransitionInformation(); + newTi.setLocation(location); + newTi.setSubNet(subnet); + newTi.setType(t.asInputSignalTransition().getStaticTransitionInformation().getType()); + t.asInputSignalTransition().setMutualTransitionInformation(newTi); + topPage.addObject(t); } for(Place p : templateInstance.allPlaces()){ - p.asOutputSignalPlace().getMutualPlaceInformation().setSubNet(subnet); - p.asOutputSignalPlace().getMutualPlaceInformation().setLocation(location); + + PlaceInformation newPi = new PlaceInformation(); + newPi.setLocation(location); + newPi.setSubNet(subnet); + newPi.setType(p.asOutputSignalPlace().getStaticPlaceInformation().getType()); + p.asOutputSignalPlace().setMutualPlaceInformation(newPi); + topPage.addObject(p); } + petriNet.flushTreeCache(); + // connect elements by arcs for(Arc a : templateInstance.allArcs()){ Arc newArc = new Arc(); + newArc.setId("arc-" + a.getSource().getId() + "-" + a.getTarget().getId()); + System.out.println("Target: " + a.getTarget().getId()); newArc.setTarget((Node) getPnObjectByID(petriNet, a.getTarget().getId())); newArc.setSource((Node) getPnObjectByID(petriNet, a.getSource().getId())); + + if(a.getNumToolspecific() > 0) { + ToolInfo ti = new ToolInfo(); + ti.setFormattedXMLBuffer(a.getToolspecific(0).getFormattedXMLBuffer()); + ti.setTool(a.getToolspecific(0).getTool()); + ti.setVersion(a.getToolspecific(0).getVersion()); + newArc.addToolspecific(ti); + } + topPage.addObject(newArc); } diff --git a/src/main/resources/templates/TopicSubDispatcherTemplate.pnml b/src/main/resources/templates/TopicSubDispatcherTemplate.pnml index 5bf5679759c952a110564fff3d60d5417b881b03..e060187c9d8cf92c105d56b9b0c9a38b46a37d82 100644 --- a/src/main/resources/templates/TopicSubDispatcherTemplate.pnml +++ b/src/main/resources/templates/TopicSubDispatcherTemplate.pnml @@ -142,6 +142,8 @@ </arc> <arc id="arc-6" source="DispatcherInputPlace" target="DispatcherInputTransition"> </arc> + <arc id="arc-7" source="DispatcherInputPlace" target="DispatcherOverflowTransition"> + </arc> </page> </net> </pnml>