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

added first sift and ktzio support

parent e1239b87
No related branches found
No related tags found
No related merge requests found
{
"tina" : "",
"pathto" : "",
"sift" : "-R -k -stats",
"struct" : ""
}
\ No newline at end of file
{
"tina" : "-R -s 1 -c 0 -t 0 -b 0 -m 0 -v -NET",
"tina" : "-R -s 1 -c 0 -t 0 -b 0 -m 0 -v -NET -stats",
"pathto" : "",
"sift" : "",
"struct" : ""
......
package de.tudresden.inf.st.pnml.flatter;
import de.tudresden.inf.st.pnml.flatter.config.ConfigReader;
import de.tudresden.inf.st.pnml.flatter.tina.KtzioProxy;
import de.tudresden.inf.st.pnml.flatter.tina.SiftProxy;
import de.tudresden.inf.st.pnml.flatter.tina.TinaProxy;
import de.tudresden.inf.st.pnml.flatter.transform.ChannelFlatter;
import de.tudresden.inf.st.pnml.flatter.transform.ReferenceFlatter;
......@@ -20,32 +22,35 @@ public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) throws IOException, InvalidIDException {
public static void main(String[] args) throws IOException, InvalidIDException, InterruptedException {
String configPath = (args.length > 1) ? args[1] : null;
String pnmlPath = (args.length > 0) ? args[0] : null;
/* String pnmlPath = (args.length > 0) ? args[0] : null;
if (pnmlPath == null || configPath == null) {
System.out.println("No model found on given input path.");
return;
}
}*/
// parse the global not flatted petri net
// String pnmlPath = "../pnml-relast-nets/src/main/resources/topicTestNets/structureTestNets/topic-structure-correct.pnml";
// String pnmlPath = "../pnml-relast-nets/src/main/resources/useCaseNets/RoboticUseCase-TopLayer.pnml";
String pnmlPath = "../pnml-relast-nets/src/main/resources/useCaseNets/RoboticUseCase-TopLayer-Left.pnml";
// String pnmlPath = "../pnml-relast-nets/src/main/resources/useCaseNets/TopicEvaluation/RoboticUseCase-TopLayer-TopicScale-NoSignals.pnml";
// String pnmlPath = "../pnml-relast-nets/src/main/resources/useCaseNets/RoboticUseCase-AllLayers.pnml";
// String pnmlPath = "../pnml-relast-nets/src/main/resources/serviceTestNets/structureTestNets/service-structure-correct.pnml";
configPath = "src/main/config/config.json";
// String pnmlPath = "../pnml-relast-nets/src/main/resources/useCaseNets/TopicEvaluation/PublisherScale/RoboticUseCase-TopLayer-PublisherScale-6.pnml";
// String pnmlPath = "../pnml-relast-nets/src/main/resources/serviceTestNets/structureTestNets/service-structure-correct.pnml";*/
configPath = "src/main/config/siftConfig.json";
PetriNet petriNet = PnmlParser.parsePnml(pnmlPath).get(0);
// read config for analyzer from file
ConfigReader cr = new ConfigReader(configPath);
String[] tinaConfig = cr.getTinaConfigParams();
String[] siftConfig = cr.getSiftConfigParams();
// make sure that we have a valid marking
System.out.println("[FLATTER] Checking marking.");
for(Place p : petriNet.allPlaces()){
if(p.getInitialMarking() == null){
for (Place p : petriNet.allPlaces()) {
if (p.getInitialMarking() == null) {
System.out.println("[FLATTER] Found NULL-marking. Falling back to 0 ...");
PTMarking marking = new PTMarking();
marking.setText(0);
......@@ -92,20 +97,32 @@ public class Main {
ndrioProxy.includeInhibitorArcs(petriNet, ndrioTargetPath, inhibitorTargetPath);
// insert into tina
System.out.println("[FLATTER] Inserting into tina.");
TinaProxy tinaProxy = new TinaProxy();
String tinaTargetPath = homeDirectory + "/temp/tina/" + "tina-result-" + exportId + ".txt";
tinaProxy.analyzePetriNet(inhibitorTargetPath, tinaTargetPath, tinaConfig);
// insert into pathto
// TODO v2
if(tinaConfig.length > 1){
System.out.println("[FLATTER] Inserting into tina.");
TinaProxy tinaProxy = new TinaProxy();
String tinaTargetPath = homeDirectory + "/temp/tina/" + "tina-result-" + exportId + ".txt";
tinaProxy.analyzePetriNet(inhibitorTargetPath, tinaTargetPath, tinaConfig);
}
// insert into sift
// TODO in v2
if(siftConfig.length > 1){
System.out.println("[FLATTER] Inserting into sift.");
SiftProxy siftProxy = new SiftProxy();
String siftTargetPath = homeDirectory + "/temp/sift/" + "sift-result-" + exportId + ".ktz";
siftProxy.analyzePetriNet(inhibitorTargetPath, siftTargetPath, siftConfig);
System.out.println("[FLATTER] Converting with ktzio.");
KtzioProxy ktzioProxy = new KtzioProxy();
String ktzioPath = homeDirectory + "/temp/sift/" + "sift-result-converted-" + exportId + ".txt";
ktzioProxy.convertBinaryToText(siftTargetPath, ktzioPath);
}
// insert into struct
// TODO in v2
// insert into pathto
// TODO in v2
// combine results and generate report in html/md/xml/json? format
// TODO for v2
......@@ -120,7 +137,7 @@ public class Main {
System.out.println("Place " + p.asOutputSignalPlace().getId() + " -- " + p.asOutputSignalPlace().getStaticPlaceInformation().getSubNet());
if (p.getInitialMarking() != null) {
System.out.println("--- Marking: " + p.getInitialMarking().getText());
}else {
} else {
System.out.println("--- Marking: NULL");
}
}
......@@ -138,19 +155,19 @@ public class Main {
if (t.asInputSignalTransition().getStaticTransitionInformation().isServiceTransitionInformation()) {
System.out.println("--- Transition: " + t.getId() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet()
+ " service: " + t.asInputSignalTransition().getStaticTransitionInformation().asServiceTransitionInformation().getServiceName() + " ---------");
} else if(t.asInputSignalTransition().getStaticTransitionInformation().isTopicTransitionInformation()){
} else if (t.asInputSignalTransition().getStaticTransitionInformation().isTopicTransitionInformation()) {
System.out.println("--- Transition: " + t.getId() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet()
+ " topic: " + t.asInputSignalTransition().getStaticTransitionInformation().asTopicTransitionInformation().getTopic() + " ---------");
}else{
} else {
System.out.println("--- Transition: " + t.getId() + " subnet: " + t.asInputSignalTransition().getStaticTransitionInformation().getSubNet() + " --- name: " + t.getName().getText());
}
// for(Arc a : t.getInArcs()){
// System.out.println("incomming arc: " + a.getId());
// }
// if(t.asInputSignalTransition().getInputSignalClause() != null && t.asInputSignalTransition().getInputSignalClause().getNumChild() > 0){
// System.out.println("------ Clause: " + t.asInputSignalTransition().getInputSignalClause().printExp());
// }
// for(Arc a : t.getInArcs()){
// System.out.println("incomming arc: " + a.getId());
// }
// if(t.asInputSignalTransition().getInputSignalClause() != null && t.asInputSignalTransition().getInputSignalClause().getNumChild() > 0){
// System.out.println("------ Clause: " + t.asInputSignalTransition().getInputSignalClause().printExp());
// }
for (Place p : t.asInputSignalTransition().incomingPlaces()) {
......@@ -165,13 +182,13 @@ public class Main {
System.out.println("----------------- REF PLACES -----------------");
for (RefPlace rp : petriNet.allRefPlaces()){
for (RefPlace rp : petriNet.allRefPlaces()) {
System.out.println("--- RefPlace: " + rp.getId());
}
System.out.println("----------------- REF TRANSITIONS -----------------");
for (RefTransition rt : petriNet.allRefTransitions()){
for (RefTransition rt : petriNet.allRefTransitions()) {
System.out.println("--- RefTransition: " + rt.getId());
}
......@@ -181,8 +198,8 @@ public class Main {
System.out.println("Arc: " + a.getId());
System.out.println("Arc: " + a.getId() + " -- source: " + a.getSource().getId() + " -- target: " + a.getTarget().getId());
if(a.getNumToolspecific() > 0){
// System.out.println("--- toolspecifics: " + a.getToolspecific(0).getFormattedXMLBuffer());
if (a.getNumToolspecific() > 0) {
// System.out.println("--- toolspecifics: " + a.getToolspecific(0).getFormattedXMLBuffer());
}
}
......@@ -206,12 +223,12 @@ public class Main {
}
}
// System.out.println("--------------- TOOL SPECIFIC ---------------");
// System.out.println("--------------- TOOL SPECIFIC ---------------");
for (Transition t : petriNet.allTransitions()) {
InputSignalTransition ist = t.asInputSignalTransition();
if(ist != null && ist.getNumToolspecific() > 0) {
// System.out.println("ToolSpecific: (" + ist.getName().getText() + ") " + ist.getToolspecific(0).getFormattedXMLBuffer().toString());
if (ist != null && ist.getNumToolspecific() > 0) {
// System.out.println("ToolSpecific: (" + ist.getName().getText() + ") " + ist.getToolspecific(0).getFormattedXMLBuffer().toString());
}
}
}
......
......@@ -3,6 +3,11 @@ package de.tudresden.inf.st.pnml.flatter.tina;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public abstract class AbstractTinaProxy {
protected static final Logger logger = LoggerFactory.getLogger(AbstractTinaProxy.class);
......@@ -10,4 +15,28 @@ public abstract class AbstractTinaProxy {
protected boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
protected String homeDirectory = System.getProperty("user.dir");
protected void executeAndRead(ProcessBuilder tinaProcessBuilder, FileWriter fileWriter) {
try {
Process process = tinaProcessBuilder.start();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
fileWriter.write(line + "\n");
}
fileWriter.close();
int exitVal = process.waitFor();
if (exitVal == 0) {
System.exit(0);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
package de.tudresden.inf.st.pnml.flatter.tina;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class KtzioProxy extends AbstractTinaProxy {
public void convertBinaryToText(String inputPath, String outputPath) throws IOException, InterruptedException {
ProcessBuilder ktzioProcessBuilder = new ProcessBuilder();
if (!isWindows) {
File file = new File(outputPath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
List<String> commandParts = new ArrayList<>();
if (homeDirectory.contains("pnml-relast-flatter")) {
commandParts.add(homeDirectory + "/libs/tina-3.7.0/bin/ktzio");
} else {
commandParts.add(homeDirectory + "/pnml-relast-flatter/libs/tina-3.7.0/bin/ktzio");
}
commandParts.add("-KTZ");
commandParts.add("-txt");
commandParts.add(inputPath);
commandParts.add(outputPath);
ktzioProcessBuilder.command(commandParts);
ktzioProcessBuilder.start();
} else {
logger.error("Windows is currently not supported. Exiting ...");
return;
}
}
}
package de.tudresden.inf.st.pnml.flatter.tina;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SiftProxy extends AbstractTinaProxy {
public void analyzePetriNet(String inputPath, String outputPath, String[] config) throws IOException, InterruptedException {
ProcessBuilder siftProcessBuilder = new ProcessBuilder();
if (!isWindows) {
File file = new File(outputPath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
List<String> commandParts = new ArrayList<>();
if (homeDirectory.contains("pnml-relast-flatter")) {
commandParts.add(homeDirectory + "/libs/tina-3.7.0/bin/sift");
} else {
commandParts.add(homeDirectory + "/pnml-relast-flatter/libs/tina-3.7.0/bin/sift");
}
commandParts.addAll(Arrays.asList(config));
commandParts.add(inputPath);
commandParts.add(outputPath);
siftProcessBuilder.command(commandParts);
siftProcessBuilder.start();
} else {
logger.error("Windows is currently not supported. Exiting ...");
return;
}
}
}
......@@ -9,12 +9,7 @@ public class TinaProxy extends AbstractTinaProxy{
public void analyzePetriNet(String inputPath, String outputPath, String[] config) throws IOException {
boolean isWindows = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
String homeDirectory = System.getProperty("user.dir");
ProcessBuilder tinaProcessBuilder = new ProcessBuilder();
// String fileName = "temp/tina/tina-result-" + UUID.randomUUID().toString() + ".txt";
File file = new File(outputPath);
if (!file.exists()) {
......@@ -42,26 +37,6 @@ public class TinaProxy extends AbstractTinaProxy{
return;
}
try {
Process process = tinaProcessBuilder.start();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
fileWriter.write(line + "\n");
}
fileWriter.close();
int exitVal = process.waitFor();
if (exitVal == 0) {
System.exit(0);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
executeAndRead(tinaProcessBuilder, fileWriter);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment