Skip to content
Snippets Groups Projects
Commit 0a9b5734 authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

working on net-split algorithm, extended grammar for toolspecifics

parent a7ef5645
No related branches found
No related tags found
No related merge requests found
aspect PnDistribution {
/*
syn lazy String Transition.location() {
return de.tudresden.inf.st.pnml.ToolSpecificsParser.getLocationFromToolSpecifics(this.getToolspecificList());
}
......@@ -35,4 +36,20 @@ aspect PnDistribution {
syn lazy Integer Transition.outputLimit(){
return de.tudresden.inf.st.pnml.ToolSpecificsParser.getTransitionInputLimit(this.getToolspecificList());
}
*/
syn lazy TransitionInformation InputSignalTransition.getTransitionInformation() {
TransitionInformation tInfo = de.tudresden.inf.st.pnml.ToolSpecificsParser.getTransitionInformation(this.getToolspecificList());
return tInfo;
}
syn lazy PlaceInformation OutputSignalPlace.getPlaceInformation() {
PlaceInformation pInfo = de.tudresden.inf.st.pnml.ToolSpecificsParser.getPlaceInformation(this.getToolspecificList());
return pInfo;
}
}
\ No newline at end of file
InputSignalBinding : PnObject ::= <TransitionID:String> <InputSignalID:String> <InputSignalValue:int>;
OutputSignalBinding : PnObject ::= <PlaceID:String> <OutputSignalID:String> /<OutputSignalValue:String>/ EqualityOM:EqualityOutputMapping* ThresholdOM:ThresholdOutputMapping* RangeOM:RangeOutputMapping*;
TransitionInformation ::= <Location:String> <Type:String> <InputLimit:java.lang.Integer> <OutputLimit:java.lang.Integer> <Topic:String> <SubNet:String>;
PlaceInformation ::= <Location:String> <Type:String> <SubNet:String>;
InputSignalTransition : Transition ::= /InputSignalBinding*/;
InputSignalTransition : Transition ::= /InputSignalBinding*/ /TransitionInformation/;
OutputSignalPlace : Place ::= /OutputSignalBinding*/;
OutputMapping;
......
......@@ -24,6 +24,7 @@ public class Main {
public static void main(String[] args) {
List<PetriNet> petriNets = parsePnml("src/main/resources/minimal_global.pnml");
GlobalToLocalNetsPostProcessor.disconnectNets(petriNets.get(0));
}
......
......@@ -7,6 +7,12 @@ public final class PnmlConstants {
public static final String TRANSITION_TYPE_TOPIC = "topicTransitionType";
public static final String TRANSITION_TOPIC_TYPE_LIMITED_IN = "limitedChannelInType";
public static final String TRANSITION_TOPIC_TYPE_UNLIMITED_IN = "unlimitedChannelInType";
public static final String TRANSITION_TOPIC_TYPE_LIMITED_OUT = "limitedChannelOutType";
public static final String TRANSITION_TOPIC_TYPE_UNLIMITED_OUT = "unlimitedChannelOutType";
public static final String PLACE_TYPE_DISCRETE = "discretePlaceType";
public static final String PLACE_TYPE_CONTINUOUS = "continuousPlaceType";
......
package de.tudresden.inf.st.pnml;
import de.tudresden.inf.st.pnml.jastadd.model.JastAddList;
import de.tudresden.inf.st.pnml.jastadd.model.PlaceInformation;
import de.tudresden.inf.st.pnml.jastadd.model.ToolInfo;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import de.tudresden.inf.st.pnml.jastadd.model.TransitionInformation;
import fr.lip6.move.pnml.framework.utils.PNMLUtils;
import fr.lip6.move.pnml.ptnet.hlapi.PetriNetDocHLAPI;
import org.slf4j.Logger;
......@@ -23,7 +25,7 @@ public class ToolSpecificsParser {
private static final Logger logger = LoggerFactory.getLogger(ToolSpecificsParser.class);
public static String getLocationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) {
private static String getLocationFromToolSpecifics(JastAddList<ToolInfo> toolInfos) {
if (toolInfos.getNumChild() > 0) {
try {
......@@ -55,7 +57,7 @@ public class ToolSpecificsParser {
|| type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC)) {
return type;
} else {
logger.error("Error: Invalid transition type configured.");
logger.error("Error: Invalid transition type configured: " + type + ".");
}
}
......@@ -67,7 +69,7 @@ public class ToolSpecificsParser {
return null;
}
public static String getPlaceTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) {
private static String getPlaceTypeFromToolSpecifics(JastAddList<ToolInfo> toolInfos) {
if (toolInfos.getNumChild() > 0) {
try {
......@@ -78,8 +80,6 @@ public class ToolSpecificsParser {
String type = typeList.item(0).getTextContent();
if (type.equals(PnmlConstants.PLACE_TYPE_DISCRETE) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS)) {
return type;
} else {
logger.error("Error: Invalid transition type configured.");
}
}
......@@ -90,7 +90,7 @@ public class ToolSpecificsParser {
return null;
}
public static String getTopic(JastAddList<ToolInfo> toolInfos) {
private static String getTopic(JastAddList<ToolInfo> toolInfos) {
if (toolInfos.getNumChild() > 0) {
try {
......@@ -105,6 +105,7 @@ public class ToolSpecificsParser {
if (type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC)) {
return topicList.item(0).getTextContent();
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
......@@ -127,7 +128,7 @@ public class ToolSpecificsParser {
if (type != null && (type.equals(PnmlConstants.TRANSITION_TYPE_DISCRETE)
|| type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS) || type.equals(PnmlConstants.PLACE_TYPE_CONTINUOUS)
|| type.equals(PnmlConstants.PLACE_TYPE_DISCRETE))){
|| type.equals(PnmlConstants.PLACE_TYPE_DISCRETE) || type.equals(PnmlConstants.TRANSITION_TYPE_TOPIC))) {
NodeList snList = doc.getElementsByTagName(PnmlConstants.SUBNET_KEY);
......@@ -142,11 +143,11 @@ public class ToolSpecificsParser {
return null;
}
public static String getTransitionSubnetInfo(JastAddList<ToolInfo> toolInfos){
private static String getTransitionSubnetInfo(JastAddList<ToolInfo> toolInfos) {
return getSubnetInfoInternal(toolInfos);
}
public static String getPlaceSubnetInfo(JastAddList<ToolInfo> toolInfos){
private static String getPlaceSubnetInfo(JastAddList<ToolInfo> toolInfos) {
return getSubnetInfoInternal(toolInfos);
}
......@@ -171,14 +172,41 @@ public class ToolSpecificsParser {
return -1;
}
public static int getTransitionOutputLimit(JastAddList<ToolInfo> toolInfos) {
private static int getTransitionOutputLimit(JastAddList<ToolInfo> toolInfos) {
return getTransitionLimitsInternal(toolInfos, PnmlConstants.OUTPUT_LIMIT_KEY);
}
public static int getTransitionInputLimit(JastAddList<ToolInfo> toolInfos) {
private static int getTransitionInputLimit(JastAddList<ToolInfo> toolInfos) {
return getTransitionLimitsInternal(toolInfos, PnmlConstants.INPUT_LIMIT_KEY);
}
public static TransitionInformation getTransitionInformation(JastAddList<ToolInfo> toolInfos) {
TransitionInformation ti = new TransitionInformation();
ti.setInputLimit(getTransitionInputLimit(toolInfos));
ti.setOutputLimit(getTransitionOutputLimit(toolInfos));
ti.setLocation(getLocationFromToolSpecifics(toolInfos));
ti.setType(getTransitionTypeFromToolSpecifics(toolInfos));
if(!ti.getType().equals(PnmlConstants.TRANSITION_TYPE_TOPIC)){
ti.setTopic(getTopic(toolInfos));
}
ti.setSubNet(getTransitionSubnetInfo(toolInfos));
return ti;
}
public static PlaceInformation getPlaceInformation(JastAddList<ToolInfo> toolInfos) {
PlaceInformation pi = new PlaceInformation();
pi.setLocation(getLocationFromToolSpecifics(toolInfos));
pi.setSubNet(getPlaceSubnetInfo(toolInfos));
pi.setType(getPlaceTypeFromToolSpecifics(toolInfos));
return pi;
}
private static Document parseToolSpecifics(JastAddList<ToolInfo> toolInfos) throws ParserConfigurationException, SAXException, IOException {
StringBuffer toolInfoStringBuffer = toolInfos.getChild(0).getFormattedXMLBuffer();
......
package de.tudresden.inf.st.postprocessing;
import de.tudresden.inf.st.pnml.PnmlConstants;
import de.tudresden.inf.st.pnml.jastadd.model.PetriNet;
import de.tudresden.inf.st.pnml.jastadd.model.Transition;
import de.tudresden.inf.st.pnml.jastadd.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashSet;
import java.util.Set;
public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> {
private static final Logger logger = LoggerFactory.getLogger(GlobalToLocalNetsPostProcessor.class);
public static PetriNet disconnectNets(PetriNet petriNet){
Set<Transition> transitionSet = petriNet.allTransitions();
Set<Transition> transitionsToAdd = new HashSet<>();
Set<Transition> transitionsToRemove = new HashSet<>();
for(Transition transition : petriNet.allTransitions()){
InputSignalTransition channelIst = transition.asInputSignalTransition();
// logger.error("infos: " + channelIst.getTransitionInformation());
if(channelIst.getTransitionInformation().getType().equals(PnmlConstants.TRANSITION_TYPE_TOPIC)){
logger.info("Found topic transition: " + transition.getId());
// handle refs?
transitionsToRemove.add(transition);
for(Transition transition : transitionSet){
if(transition.type().equals(PnmlConstants.TRANSITION_TYPE_TOPIC)){
// transition.incomingPlaces());
// STEP 1: Get location/subnet of source/target - places
String inLocation = null;
String outLocation = null;
String inSubNet = null;
String outSubNet = null;
for(Place p : channelIst.incomingPlaces()){
inLocation = p.asOutputSignalPlace().getPlaceInformation().getLocation();
inSubNet = p.asOutputSignalPlace().getPlaceInformation().getSubNet();
break;
}
for(Place p : channelIst.outgoingPlaces()){
outLocation = p.asOutputSignalPlace().getPlaceInformation().getLocation();
outSubNet = p.asOutputSignalPlace().getPlaceInformation().getSubNet();
break;
}
// STEP 1: Create new source and target Transition
InputSignalTransition sourceIst = channelIst.treeCopyNoTransform();
sourceIst.getName().setText(sourceIst.getName().getText() + "-source");
sourceIst.setId(sourceIst.getId() + "-source");
sourceIst.getTransitionInformation().setSubNet(inSubNet);
sourceIst.getTransitionInformation().setLocation(inLocation);
// TODO: the attributized infos need to be written back to XML
sourceIst.setToolspecificList(new JastAddList<>());
if(sourceIst.getTransitionInformation().getInputLimit() >= 0 ){
sourceIst.getTransitionInformation().setType(PnmlConstants.TRANSITION_TOPIC_TYPE_LIMITED_OUT);
}else{
sourceIst.getTransitionInformation().setType(PnmlConstants.TRANSITION_TOPIC_TYPE_UNLIMITED_OUT);
}
InputSignalTransition targetIst = channelIst.treeCopyNoTransform();
targetIst.getName().setText(targetIst.getName().getText() + "-target");
targetIst.setId(sourceIst.getId() + "-target");
targetIst.getTransitionInformation().setSubNet(outSubNet);
targetIst.getTransitionInformation().setLocation(outLocation);
// TODO: the attributized infos need to be written back to XML
targetIst.setToolspecificList(new JastAddList<>());
if(targetIst.getTransitionInformation().getOutputLimit() >= 0 ){
sourceIst.getTransitionInformation().setType(PnmlConstants.TRANSITION_TOPIC_TYPE_LIMITED_IN);
}else{
sourceIst.getTransitionInformation().setType(PnmlConstants.TRANSITION_TOPIC_TYPE_UNLIMITED_IN);
}
// STEP 2: Reconnect Input Signals
//for(InputSignalBinding isb : channelIst.getInputSignalBindingList()){
// inputIst.addInputSignalBinding(isb);
//}
// STEP 3: Get all incoming arcs and connect them to new output transition
for(Arc arc : channelIst.getInArcList()){
arc.setTarget(sourceIst);
//logger.error("###");
//break;
}
// STEP 4: Gel all outgoing arcs and connect them to new input transition
for(Arc arc : channelIst.getOutArcList()){
arc.setSource(targetIst);
//logger.error("+++");
//break;
}
// STEP 5: Add new transitions to net
transitionsToAdd.add(sourceIst);
transitionsToAdd.add(targetIst);
}
}
// STEP 6: Remove "old transition"
petriNet.allTransitions().removeAll(transitionsToRemove);
petriNet.allTransitions().addAll(transitionsToAdd);
return petriNet;
}
private static StringBuffer buildToolSpecifics(String type, String location, String subnet, String inputLimit, String outputLimit){
// TODO TBD
return null;
}
}
......@@ -168,6 +168,7 @@ public class IoPetriNetPostProcessor implements PostProcessor<PetriNet> {
Document doc = dBuilder.parse(fromStringBuffer(toolInfoStringBuffer));
doc.getDocumentElement().normalize();
logger.error("############################# tttttttttttttttttttttttt");
return doc;
}
......
......@@ -53,8 +53,8 @@
</place>
<place id="p2">
<toolspecific tool="de.tudresden.inf.st.pnml.distributedPN" version="0.0.1">
<location>node-1</location>
<subnet>subnet-1</subnet>
<location>node-2</location>
<subnet>subnet-2</subnet>
<type>discretePlaceType</type>
<outputsignalbindings>
<outputsignalbinding>
......@@ -79,6 +79,8 @@
</outputsignalbinding>
</outputsignalbindings>
</toolspecific>
<toolspecific tool="de.tudresden.inf.st.pnml.NEWTOOL" version="0.0.1">
</toolspecific>
<name>
<text>p2</text>
<graphics>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment