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

fixed splitter

parent 9aa8b514
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,8 @@ public class Main { ...@@ -17,6 +17,8 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
String inputPath = (args.length > 0) ? args[0] : null; 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) { if (inputPath == null) {
logger.error("No model found on given input path."); logger.error("No model found on given input path.");
...@@ -51,8 +53,8 @@ public class Main { ...@@ -51,8 +53,8 @@ public class Main {
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++) { for (int j = 0; j < disconnectedPetriNets.get(i).size(); j++) {
logger.info("Exporting split Petri net containing: "); // logger.info("Exporting split Petri net containing: ");
PostProcessingUtils.printNet(disconnectedPetriNets.get(i).get(j), true, false); // PostProcessingUtils.printNet(disconnectedPetriNets.get(i).get(j), true, false);
try { try {
PnmlExporter.serializeToPnmlFile(disconnectedPetriNets.get(i).get(j), "-pnml-net-" + i + "-" + j); PnmlExporter.serializeToPnmlFile(disconnectedPetriNets.get(i).get(j), "-pnml-net-" + i + "-" + j);
......
...@@ -45,21 +45,21 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { ...@@ -45,21 +45,21 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> {
// cut the service transitions // cut the service transitions
PetriNet serviceCutNet = cutServiceTransitions(topicCutNet); PetriNet serviceCutNet = cutServiceTransitions(topicCutNet);
Set<String> locations = getNodes(serviceCutNet); Set<String> locations = getNodePageIds(serviceCutNet);
updateToolSpecificsWithPlaceInfos(serviceCutNet); updateToolSpecificsWithPlaceInfos(serviceCutNet);
logger.info("##############################################################################################"); //logger.info("##############################################################################################");
PostProcessingUtils.printNet(serviceCutNet, true, false);
// serialize for deep copy // serialize for deep copy
String serializedNetPath = PnmlExporter.serializeToPnmlFile(serviceCutNet, "-pre-split.pnml"); String serializedNetPath = PnmlExporter.serializeToPnmlFile(serviceCutNet, "-pre-split");
int netSuffix = 0; int netSuffix = 0;
// filter deep copy elements by location // filter deep copy elements by location
for (String location : locations) { for (String location : locations) {
System.out.println("Creating deep copy for: " + location);
List<PetriNet> reParsedPetriNets = PnmlParser.parsePnml(serializedNetPath, false); List<PetriNet> reParsedPetriNets = PnmlParser.parsePnml(serializedNetPath, false);
for (PetriNet pn : reParsedPetriNets) { for (PetriNet pn : reParsedPetriNets) {
PetriNet separatedNet = createdSeparatedNetByNode(pn, location); PetriNet separatedNet = createdSeparatedNetByNode(pn, location);
...@@ -76,27 +76,18 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { ...@@ -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()) { for(Page page : petriNet.allPages()){
if (place.asDinerosPlace().getStaticPlaceInformation().getNode() != null) { if(page.getType() != null && page.getType().equals(PnmlConstants.PAGE_TYPE_NODE)){
allLocations.add(place.asDinerosPlace().getStaticPlaceInformation().getNode()); System.out.println("Found node page: " + page.getId());
} else { nodePagesIds.add(page.getId());
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.");
} }
} }
return allLocations; return nodePagesIds;
} }
private PetriNet cutServiceTransitions(PetriNet petriNet) { private PetriNet cutServiceTransitions(PetriNet petriNet) {
...@@ -199,70 +190,50 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { ...@@ -199,70 +190,50 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> {
private static PetriNet createdSeparatedNetByNode(PetriNet petriNet, String node) { private static PetriNet createdSeparatedNetByNode(PetriNet petriNet, String node) {
System.out.println("Creating separate net for: " + node);
Set<String> removedTransitionIds = new HashSet<>(); Set<String> removedTransitionIds = new HashSet<>();
Set<String> removedPlaceIds = new HashSet<>(); Set<String> removedPlaceIds = new HashSet<>();
Set<String> removedRefTransitionIds = new HashSet<>(); Set<String> removedRefTransitionIds = new HashSet<>();
Set<String> removeRefPlaceIds = new HashSet<>(); Set<String> removeRefPlaceIds = new HashSet<>();
for (Place place : petriNet.allPlaces()) { deleteOnNoMatch(node, petriNet.allPlaces(), removedPlaceIds);
if (!place.asDinerosPlace().getStaticPlaceInformation().getNode().equals(node)) { deleteOnNoMatch(node, petriNet.allTransitions(), removedTransitionIds);
removedPlaceIds.add(place.getId()); deleteOnNoMatch(node, petriNet.allRefPlaces(), removeRefPlaceIds);
} deleteOnNoMatch(node, petriNet.allRefTransitions(), removedRefTransitionIds);
}
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());
}
}
for (Arc arc : petriNet.allArcs()) { for (Arc arc : petriNet.allArcs()) {
if (removedTransitionIds.contains(arc.getSource().getId()) || removedTransitionIds.contains(arc.getTarget().getId()) if (removedTransitionIds.contains(arc.getSource().getId()) || removedTransitionIds.contains(arc.getTarget().getId())
|| removedPlaceIds.contains(arc.getSource().getId()) || removedPlaceIds.contains(arc.getTarget().getId()) || removedPlaceIds.contains(arc.getSource().getId()) || removedPlaceIds.contains(arc.getTarget().getId())
|| removedRefTransitionIds.contains(arc.getSource().getId()) || removedRefTransitionIds.contains(arc.getTarget().getId()) || removedRefTransitionIds.contains(arc.getSource().getId()) || removedRefTransitionIds.contains(arc.getTarget().getId())
|| removeRefPlaceIds.contains(arc.getSource().getId()) || removeRefPlaceIds.contains(arc.getTarget().getId())) { || removeRefPlaceIds.contains(arc.getSource().getId()) || removeRefPlaceIds.contains(arc.getTarget().getId())) {
logger.info("REMOVING ARC " + arc.getId() + " from net");
arc.removeSelf(); arc.removeSelf();
} }
} }
for (Place place : petriNet.allPlaces()) { for (Place place : petriNet.allPlaces()) {
if (!place.asDinerosPlace().getStaticPlaceInformation().getNode().equals(node)) { if (removedPlaceIds.contains(place.getId())) {
logger.info("REMOVING PLACE " + place.getId() + " from net"); System.out.println("removing: " + place.getId());
place.removeSelf(); place.removeSelf();
} }
} }
for (RefPlace place : petriNet.allRefPlaces()) { for (RefPlace place : petriNet.allRefPlaces()) {
if (!place.getNode().equals(node)) { if (removeRefPlaceIds.contains(place.getId())) {
logger.info("REMOVING REF PLACE " + place.getId() + " from net"); System.out.println("removing: " + place.getId());
place.removeSelf(); place.removeSelf();
} }
} }
for (RefTransition transition : petriNet.allRefTransitions()) { for (RefTransition transition : petriNet.allRefTransitions()) {
if (!transition.getNode().equals(node)) { if (removedRefTransitionIds.contains(transition.getId())) {
logger.info("REMOVING REF TRANSITION " + transition.getId() + " from net");
transition.removeSelf(); transition.removeSelf();
} }
} }
for (Transition transition : petriNet.allTransitions()) { for (Transition transition : petriNet.allTransitions()) {
if (!transition.asDinerosTransition().getStaticTransitionInformation().getNode().equals(node)) { if (removedTransitionIds.contains(transition.getId())) {
logger.info("REMOVING TRANSITION " + transition.getId() + " from net");
transition.removeSelf(); transition.removeSelf();
} }
...@@ -287,6 +258,24 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> { ...@@ -287,6 +258,24 @@ public class GlobalToLocalNetsPostProcessor implements PostProcessor<PetriNet> {
return 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) { private void updateToolSpecificsWithPlaceInfos(PetriNet petriNet) {
ToolInfo ti = buildToolSpecifics(); ToolInfo ti = buildToolSpecifics();
......
...@@ -54,37 +54,18 @@ public class PostProcessingUtils { ...@@ -54,37 +54,18 @@ public class PostProcessingUtils {
.getStaticPlaceInformation().getSubNet().equals(subNet)).collect(Collectors.toSet()); .getStaticPlaceInformation().getSubNet().equals(subNet)).collect(Collectors.toSet());
} }
private static Set<Arc> getInternalArcsBySubnet(String subNet, PetriNet petriNet) { private static boolean pageIsEmpty(Page page) {
for (PnObject o : page.getObjects()) {
Set<Arc> internalArcs = new HashSet<>(); if (o.isPlaceObject() || o.isTransitionObject()
Set<String> subNetTransitionIds = getTransitionIDsBySubnet(subNet, petriNet); || o.isRefTransitionObject() || o.isRefPlaceObject()) {
Set<String> subNetPlaceIds = getPlaceIDsBySubnet(subNet, petriNet); return false;
} else if (o.isPageNode()) {
if (!pageIsEmpty(o.asPage())) {
for (Arc arc : petriNet.allArcs()) { return false;
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);
} }
} }
return true;
return externalArcs;
} }
/////////////////////////////// ///////////////////////////////
...@@ -96,99 +77,15 @@ public class PostProcessingUtils { ...@@ -96,99 +77,15 @@ public class PostProcessingUtils {
List<Page> pagesToRemove = new ArrayList<>(); List<Page> pagesToRemove = new ArrayList<>();
for (Page p : petriNet.allPages()) { for (Page p : petriNet.allPages()) {
if(p.getNumObject() == 0){ if(pageIsEmpty(p)){
System.out.println("Removing page: " + p.getId());
pagesToRemove.add(p); 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 //////////////////// // LOGGING ////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment