Commit 87888e2a authored by Erik Müller's avatar Erik Müller

Add interface NT for Place and Transition

parent b9081691
# IntelliJ
.idea/
*.iml
*.iws
# Mac
.DS_Store
# Maven
log/
target/
\ No newline at end of file
......@@ -15,10 +15,10 @@ import petrinet._parser.PetrinetParser;
import petrinet._symboltable.PetrinetLanguage;
import petrinet._symboltable.PetrinetSymbolTableCreator;
import petrinet._symboltable.TransitionSymbol;
import petrinet.analyses.Boundedness;
import petrinet.analyses.Liveness;
import petrinet.analyses.Subclass;
import petrinet.analyses.transformations.Transformation;
import petrinet.analysis.Boundedness;
import petrinet.analysis.Liveness;
import petrinet.analysis.Subclass;
import petrinet.analysis.transformations.Transformation;
import petrinet.cocos.PetrinetCoCos;
import petrinet.prettyprint.PetrinetDotPrinter;
import petrinet.prettyprint.PetrinetPrettyPrinter;
......
package petrinet._ast;
import petrinet.analyses.Boundedness;
import petrinet.analysis.Boundedness;
import java.util.Optional;
......
......@@ -2,7 +2,7 @@ package petrinet._ast;
import de.monticore.symboltable.resolving.ResolvedSeveralEntriesException;
import de.se_rwth.commons.logging.Log;
import petrinet.analyses.Liveness;
import petrinet.analysis.Liveness;
import java.util.List;
import java.util.Optional;
......
package petrinet._ast;
import petrinet.analyses.CoverabilityTree;
import petrinet.analysis.CoverabilityTree;
import java.util.List;
import java.util.Optional;
......
package petrinet._ast;
import petrinet.analyses.Subclass;
import petrinet.analysis.Subclass;
import java.util.Optional;
......
package petrinet.analyses;
package petrinet.analysis;
import de.se_rwth.commons.logging.Log;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import petrinet._ast.ASTPetrinet;
import petrinet._ast.ASTTransition;
......
package petrinet.analyses;
package petrinet.analysis;
/**
* A value representing infinitely many (or arbitrarily many) tokens in a single place.
......
package petrinet.analyses;
package petrinet.analysis;
import de.se_rwth.commons.logging.Log;
import petrinet._ast.ASTTransition;
......
package petrinet.analyses;
package petrinet.analysis;
import de.monticore.literals.literals._ast.ASTIntLiteral;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import de.monticore.literals.literals._ast.ASTIntLiteral;
import petrinet._ast.*;
......
package petrinet.analyses;
package petrinet.analysis;
/**
* A representation of the number of tokens in a place
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import de.monticore.io.paths.ModelPath;
import de.monticore.literals.literals._ast.ASTIntLiteral;
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import de.monticore.io.paths.ModelPath;
import de.monticore.symboltable.GlobalScope;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.api.Test;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import petrinet._ast.ASTPetrinet;
import petrinet.analyses.AbstractAnalysisTest;
import petrinet.analysis.AbstractAnalysisTest;
import petrinet.prettyprint.PetrinetPrettyPrinter;
import static org.junit.jupiter.api.Assertions.assertTrue;
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
......@@ -6,9 +6,9 @@ import org.junit.jupiter.params.provider.CsvSource;
import petrinet._ast.ASTPetrinet;
import petrinet._ast.ASTTransition;
import petrinet._symboltable.TransitionSymbol;
import petrinet.analyses.AbstractAnalysisTest;
import petrinet.analyses.Boundedness;
import petrinet.analyses.Liveness;
import petrinet.analysis.AbstractAnalysisTest;
import petrinet.analysis.Boundedness;
import petrinet.analysis.Liveness;
import petrinet.prettyprint.PetrinetPrettyPrinter;
import java.util.Optional;
......
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4" />
\ No newline at end of file
......@@ -17,6 +17,8 @@
<jsr305.version>3.0.2</jsr305.version>
<junit.version>4.11</junit.version>
<antlr.version>4.7.2</antlr.version>
<pnml.version>2.2.12</pnml.version>
<emf.ecore.version>2.19.0</emf.ecore.version>
<logback.version>1.2.3</logback.version>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
......@@ -189,6 +191,22 @@
<version>${antlr.version}</version>
</dependency>
<dependency>
<groupId>fr.lip6.pnml</groupId>
<artifactId>fr.lip6.pnml.framework.ptnet</artifactId>
<version>${pnml.version}</version>
</dependency>
<dependency>
<groupId>fr.lip6.pnml</groupId>
<artifactId>fr.lip6.pnml.framework.utils</artifactId>
<version>${pnml.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>${emf.ecore.version}</version>
</dependency>
<!-- MontiCore Dependencies -->
<dependency>
<groupId>de.monticore</groupId>
......
......@@ -24,10 +24,12 @@ grammar Petrinet extends de.monticore.literals.Literals {
enum LivenessLevel = "l0live" | "l1live";
TransitionReference = transition:Name@Transition;
symbol Place = "place" Name ("initial" initial:IntLiteral)? ";";
interface PetriNode = Name;
symbol Place implements PetriNode = "place" Name ("initial" initial:IntLiteral)? ";";
astrule Place = outEdge:FromEdge* inEdge:ToEdge*;
symbol Transition = "transition" Name ":" (FromEdge | ToEdge)*;
symbol Transition implements PetriNode = "transition" Name ":" (FromEdge | ToEdge)*;
abstract Edge = count:IntLiteral place:Name@Place;
FromEdge extends Edge = count:IntLiteral "<-" place:Name@Place;
......
......@@ -15,10 +15,10 @@ import petrinet._parser.PetrinetParser;
import petrinet._symboltable.PetrinetLanguage;
import petrinet._symboltable.PetrinetSymbolTableCreator;
import petrinet._symboltable.TransitionSymbol;
import petrinet.analyses.Boundedness;
import petrinet.analyses.Liveness;
import petrinet.analyses.Subclass;
import petrinet.analyses.transformations.Transformation;
import petrinet.analysis.Boundedness;
import petrinet.analysis.Liveness;
import petrinet.analysis.Subclass;
import petrinet.analysis.transformations.Transformation;
import petrinet.cocos.PetrinetCoCos;
import petrinet.prettyprint.PetrinetDotPrinter;
import petrinet.prettyprint.PetrinetPrettyPrinter;
......
package petrinet._ast;
import petrinet.analyses.Boundedness;
import petrinet.analysis.Boundedness;
import java.util.Optional;
......
......@@ -2,7 +2,7 @@ package petrinet._ast;
import de.monticore.symboltable.resolving.ResolvedSeveralEntriesException;
import de.se_rwth.commons.logging.Log;
import petrinet.analyses.Liveness;
import petrinet.analysis.Liveness;
import java.util.List;
import java.util.Optional;
......
package petrinet._ast;
import petrinet.analyses.CoverabilityTree;
import petrinet.analysis.CoverabilityTree;
import java.util.List;
import java.util.Optional;
......
......@@ -13,8 +13,8 @@ public class ASTPlace extends ASTPlaceTOP {
super();
}
public ASTPlace(List<ASTFromEdge> outEdges, List<ASTToEdge> inEdges, String name, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<ASTIntLiteral> initial) {
super(outEdges, inEdges, name, initial);
public ASTPlace(List<ASTFromEdge> outEdges, List<ASTToEdge> inEdges, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<ASTIntLiteral> initial, String name) {
super(outEdges, inEdges, initial, name);
}
/**
......
package petrinet._ast;
import petrinet.analyses.Subclass;
import petrinet.analysis.Subclass;
import java.util.Optional;
......
......@@ -11,8 +11,8 @@ public class ASTTransition extends ASTTransitionTOP {
super();
}
public ASTTransition(String name, List<ASTFromEdge> fromEdges, List<ASTToEdge> toEdges) {
super(name, fromEdges, toEdges);
public ASTTransition(List<ASTFromEdge> fromEdges, List<ASTToEdge> toEdges, String name) {
super(fromEdges, toEdges, name);
}
/**
......
package petrinet.analyses;
package petrinet.analysis;
import de.se_rwth.commons.logging.Log;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import petrinet._ast.ASTPetrinet;
import petrinet._ast.ASTTransition;
......
package petrinet.analyses;
package petrinet.analysis;
/**
* A value representing infinitely many (or arbitrarily many) tokens in a single place.
......
package petrinet.analyses;
package petrinet.analysis;
import de.se_rwth.commons.logging.Log;
import petrinet._ast.ASTTransition;
......
package petrinet.analyses;
package petrinet.analysis;
import de.monticore.literals.literals._ast.ASTIntLiteral;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import de.monticore.literals.literals._ast.ASTIntLiteral;
import petrinet._ast.*;
......
package petrinet.analyses;
package petrinet.analysis;
/**
* A representation of the number of tokens in a place
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import de.monticore.io.paths.ModelPath;
import de.monticore.literals.literals._ast.ASTIntLiteral;
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import petrinet._ast.ASTPetrinet;
......
package petrinet.prettyprint;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import de.monticore.io.paths.ModelPath;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.ResolvingConfiguration;
import fr.lip6.move.pnml.framework.general.PnmlExport;
import fr.lip6.move.pnml.framework.utils.ModelRepository;
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 petrinet._ast.*;
import petrinet._symboltable.PetrinetLanguage;
import petrinet._symboltable.PetrinetSymbolTableCreator;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
public class PetrinetPnmlPrinter {
private final Map<ASTPetriNode, NodeHLAPI> nodeMap = Maps.newHashMap();
private final ASTPetrinet petrinet;
private final Map<ASTPlace, Long> initialMarking;
public PetrinetPnmlPrinter(final ASTPetrinet petrinet, final Map<ASTPlace, Long> initialMarking) {
this.petrinet = petrinet;
this.initialMarking = initialMarking;
}
public void export(final Path outputPath) throws InvalidIDException, VoidRepositoryException {
final PetrinetLanguage lang = new PetrinetLanguage();
// symboltable must be present to resolve places referenced within transitions
createSymbolTable(lang, petrinet);
final String name = petrinet.getName().toLowerCase();
ModelRepository.getInstance().createDocumentWorkspace("void");
final PetriNetDocHLAPI doc = new PetriNetDocHLAPI();
final PetriNetHLAPI net = new PetriNetHLAPI("net",PNTypeHLAPI.COREMODEL, new NameHLAPI(name), doc);
final PageHLAPI page = new PageHLAPI("page", new NameHLAPI("main"), null, net);
petrinet.getPlaceList().forEach(p -> addPlace(p, page));
petrinet.getTransitionList().forEach(t -> {
addTransition(t, page);
t.getFromPlaces()
.forEach(p -> addArc(p, t, page));
t.getToPlaces()
.forEach(p -> addArc(t, p, page));
});
if (initialMarking != null) {
initialMarking.forEach(this::addInitialMarking);
}
final PnmlExport exporter = new PnmlExport();
try {
final String fileName = outputPath.resolve(petrinet.getName().toLowerCase() + ".pnml").toString();
exporter.exportObject(doc, fileName);
} catch (final Exception e) {
e.printStackTrace();
}
ModelRepository.getInstance().destroyCurrentWorkspace();
}
private void addPlace(final ASTPlace place, final PageHLAPI page) {
try {
final PlaceHLAPI pPNML = new PlaceHLAPI(place.getName(), page);
nodeMap.put(place, pPNML);
} catch (final Exception e) {
e.printStackTrace();
}
}
private void addTransition(final ASTTransition transition, final PageHLAPI page) {
try {
final TransitionHLAPI tPNML = new TransitionHLAPI(transition.getName(), page);
nodeMap.put(transition, tPNML);
} catch (final Exception e) {
e.printStackTrace();
}
}
private void addArc(final ASTPetriNode from, final ASTPetriNode to, final PageHLAPI page) {
try {
new ArcHLAPI(getArcLabel(from, to), nodeMap.get(from), nodeMap.get(to), page);
} catch (final Exception e) {
e.printStackTrace();
}
}
private void addInitialMarking(final ASTPlace place, final Long count) {
try {
new PTMarkingHLAPI(count, (PlaceHLAPI) nodeMap.get(place));
} catch (final Exception e) {
e.printStackTrace();
}
}
private String getArcLabel(final ASTPetriNode from, final ASTPetriNode to) {
return Joiner.on("_").join("arc", from.getName(), to.getName());
}
private static void createSymbolTable(final PetrinetLanguage lang, final ASTPetrinet ast) {
final ResolvingConfiguration resolverConfiguration = new ResolvingConfiguration();
resolverConfiguration.addDefaultFilters(lang.getResolvingFilters());
final GlobalScope globalScope = new GlobalScope(new ModelPath(), lang, resolverConfiguration);
final Optional<PetrinetSymbolTableCreator> symbolTable = lang.getSymbolTableCreator(
resolverConfiguration, globalScope);
symbolTable.get().createFromAST(ast);
}
}
package petrinet;
import de.se_rwth.commons.logging.Log;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import petrinet._ast.ASTPetrinet;
......@@ -16,6 +19,16 @@ class PetrinetParserTest {
private static final String valid_path = "src/test/resources/parser/valid/";
private static final String invalid_path = "src/test/resources/parser/invalid/";
@BeforeAll
static void init() {
Log.enableFailQuick(false);
}
@BeforeEach
void setUp() {
Log.getFindings().clear();
}
@ParameterizedTest
@ValueSource(strings = {"H2O.pn", "ExampleNet.pn", "DocExample.pn", "Fig15.pn"})
void checkValid(String modelName) throws IOException {
......@@ -34,4 +47,5 @@ class PetrinetParserTest {
Optional<ASTPetrinet> model = new PetrinetParser().parse(invalid_path + modelName);
assertFalse(model.isPresent());
}
}
package petrinet.analyses;
package petrinet.analysis;
import de.monticore.io.paths.ModelPath;
import de.monticore.symboltable.GlobalScope;
......@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.*;
public abstract class AbstractAnalysisTest {
private static final String modelPath = "src/test/resources/analyses/";
private static final String modelPath = "src/test/resources/analysis/";
private static PetrinetLanguage language;
private static ResolvingConfiguration resolve;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.api.Test;
import petrinet._ast.ASTPetrinet;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.converter.ConvertWith;
......
package petrinet.analyses;
package petrinet.analysis;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
......
package petrinet.analyses.transformations;
package petrinet.analysis.transformations;
import petrinet._ast.ASTPetrinet;
import petrinet.analyses.AbstractAnalysisTest;
import petrinet.analysis.AbstractAnalysisTest;