Merge branch 'main' of git.inpt.fr:fainsil/miniproj_idm

This commit is contained in:
Laureηt 2021-10-20 15:59:58 +02:00
commit 952f801e68
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
1188 changed files with 128600 additions and 43189 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,237 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
System.out.println(req);
System.out.println(req.getTarget());
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,235 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,44 @@
import 'simplePDL.ecore'
package simplepdl
context Process
inv validName('Invalid name: ' + self.name):
self.name.matches('[A-Za-z_][A-Za-z0-9_]*')
inv uniqNamesWD: self.processElements
->select(pe | pe.oclIsKindOf(WorkDefinition))
->collect(pe | pe.oclAsType(WorkDefinition))
->forAll(w1, w2 | w1 = w2 or w1.name <> w2.name)
inv uniqNamesRes: self.processElements
->select(pe | pe.oclIsKindOf(Resource))
->collect(pe | pe.oclAsType(Resource))
->forAll(r1, r2 | r1 = r2 or r1.name <> r2.name)
context ProcessElement
def: process(): Process =
Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first()
context WorkSequence
inv successorAndPredecessorInSameProcess('Activities not in the same process : '
+ self.predecessor.name + ' in ' + self.predecessor.process().name+ ' and '
+ self.successor.name + ' in ' + self.successor.process().name):
self.process() = self.successor.process()
and self.process() = self.predecessor.process()
inv notReflexive: self.predecessor <> self.successor
context WorkDefinition
inv nameMin2Char: self.name.matches('..+')
inv weirdName: not self.name.matches('([0-9]*|[a-zA-Z]*|_*)')
context Resource
inv negativeQuantity: self.quantity > 0
inv nameMin2Char: self.name.matches('..+')
inv weirdName: not self.name.matches('([0-9]*|_*)')
context Request
inv negativeQuantity: self.quantity > 0
inv greedy: self.quantity <= self.target.quantity
endpackage

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.*"
id="fr.n7.simplepdl.toDOT.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toDOT.ui.popupMenus.AcceleoGenerateToDOTAction"
enablesFor="+"
id="fr.n7.simplepdl.toDOT.ui.popupMenus.acceleoGenerateToDOTAction"
icon="icons/default.gif"
label="Generate ToDOT"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
System.out.println(req.getTarget().toString() + qty);
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<petrinet:Network
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:petrinet="http://petrinet"
xsi:schemaLocation="http://petrinet petriNet.ecore"
name="gentilNetwork">
<nodes xsi:type="petrinet:Place"
name="debut"
tokens="1"
arcs="//@nodes.2/@arcs.0"/>
<nodes xsi:type="petrinet:Place"
name="fin"
arcs="//@nodes.2/@arcs.1"/>
<nodes xsi:type="petrinet:Transition"
name="debut2fin">
<arcs weight="1"
place="//@nodes.0"/>
<arcs weight="1"
outgoing="true"
place="//@nodes.1"/>
</nodes>
</petrinet:Network>

View file

@ -0,0 +1,146 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfPredecessor(),
transition <- req.getTransitionOfSuccessor(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<petrinet:Network
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:petrinet="http://petrinet"
xsi:schemaLocation="http://petrinet petriNET.ecore"
name="mauvaisNetwork">
<nodes xsi:type="petrinet:Place"
name="okay"
tokens="10"/>
<nodes xsi:type="petrinet:Place"
name="1"
tokens="1"/>
<nodes xsi:type="petrinet:Place"
name="placeNeg"
tokens="-5"/>
<nodes xsi:type="petrinet:Transition"
name="debut2fin">
<arcs weight="-5"
place="//@nodes.1"/>
<arcs weight="1"
outgoing="true"
place="//@nodes.2"/>
</nodes>
</petrinet:Network>

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,139 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfPredecessor(),
transition <- req.getTransitionOfSuccessor(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
System.out.println(req);
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -1,7 +1,6 @@
source.. = src/,\ source.. = src/,\
src-gen/,\ src-gen/,\
xtend-gen/ xtend-gen/
bin.includes = .,\ bin.includes = META-INF/,\
META-INF/,\ .,\
plugin.xml plugin.xml
bin.excludes = **/*.xtend

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<simplepdl:Process
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simplepdl="http://simplepdl"
name="Developpement">
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToSuccessors="//@processElements.4 //@processElements.6 //@processElements.7 //@processElements.8"
name="Conception">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.4"
linksToSuccessors="//@processElements.5"
name="Programmation">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.5 //@processElements.6"
name="RedactionTests"/>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.7 //@processElements.8"
name="RedactionDocs">
<requests
quantity="10"
target="//@processElements.10"/>
<requests
quantity="10"
target="//@processElements.9"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToStart"
predecessor="//@processElements.0"
successor="//@processElements.1"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.1"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="10"
name="Crayon"
requests="//@processElements.3/@requests.1"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="20"
name="Papier"
requests="//@processElements.0/@requests.0 //@processElements.1/@requests.0 //@processElements.3/@requests.0"/>
</simplepdl:Process>

View file

@ -0,0 +1,114 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.predecesor.name + '_finish')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start'),
t_finish: petrinet!Transition(
name <- wd.name + '_finish'),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}

View file

@ -0,0 +1,233 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,158 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfTarget(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.target.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1: petrinet!Arc(
place <- req.getPlaceOfTarget(),
transition <- req.getStartTransitionOfRequester(),
outgoing <- false,
weight <- req.quantity),
arcs2: petrinet!Arc(
place <- req.getPlaceOfTarget(),
transition <- req.getFinishStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<> ' + self.name + '_finished => ([] ~' + self.name + '_running' + ' /\\ [] ~' + self.name + '_idle /\\ [] ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="ASCII"?>
<petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement">
<nodes xsi:type="petrinet:Place" name="Crayon_resource" tokens="10" arcs="//@nodes.21/@arcs.4 //@nodes.24/@arcs.3"/>
<nodes xsi:type="petrinet:Place" name="Papier_resource" tokens="20" arcs="//@nodes.3/@arcs.3 //@nodes.6/@arcs.2 //@nodes.9/@arcs.3 //@nodes.12/@arcs.2 //@nodes.21/@arcs.3 //@nodes.24/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1" arcs="//@nodes.3/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Conception_start">
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.5"/>
<arcs weight="1" outgoing="true" place="//@nodes.4"/>
<arcs weight="15" place="//@nodes.1"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Conception_started" arcs="//@nodes.3/@arcs.2 //@nodes.15/@arcs.3 //@nodes.15/@arcs.4 //@nodes.21/@arcs.5 //@nodes.21/@arcs.6"/>
<nodes xsi:type="petrinet:Place" name="Conception_running" arcs="//@nodes.3/@arcs.1 //@nodes.6/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Conception_finish">
<arcs weight="1" place="//@nodes.5"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
<arcs weight="15" outgoing="true" place="//@nodes.1"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Conception_finished" arcs="//@nodes.6/@arcs.1 //@nodes.9/@arcs.4 //@nodes.9/@arcs.5 //@nodes.24/@arcs.4 //@nodes.24/@arcs.5"/>
<nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1" arcs="//@nodes.9/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_start">
<arcs weight="1" place="//@nodes.8"/>
<arcs weight="1" outgoing="true" place="//@nodes.11"/>
<arcs weight="1" outgoing="true" place="//@nodes.10"/>
<arcs weight="15" place="//@nodes.1"/>
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_started" arcs="//@nodes.9/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Programmation_running" arcs="//@nodes.9/@arcs.1 //@nodes.12/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_finish">
<arcs weight="1" place="//@nodes.11"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
<arcs weight="15" outgoing="true" place="//@nodes.1"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_finished" arcs="//@nodes.12/@arcs.1 //@nodes.18/@arcs.2 //@nodes.18/@arcs.3"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1" arcs="//@nodes.15/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_start">
<arcs weight="1" place="//@nodes.14"/>
<arcs weight="1" outgoing="true" place="//@nodes.17"/>
<arcs weight="1" outgoing="true" place="//@nodes.16"/>
<arcs weight="1" place="//@nodes.4"/>
<arcs weight="1" outgoing="true" place="//@nodes.4"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_started" arcs="//@nodes.15/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_running" arcs="//@nodes.15/@arcs.1 //@nodes.18/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_finish">
<arcs weight="1" place="//@nodes.17"/>
<arcs weight="1" outgoing="true" place="//@nodes.19"/>
<arcs weight="1" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_finished" arcs="//@nodes.18/@arcs.1"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1" arcs="//@nodes.21/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_start">
<arcs weight="1" place="//@nodes.20"/>
<arcs weight="1" outgoing="true" place="//@nodes.23"/>
<arcs weight="1" outgoing="true" place="//@nodes.22"/>
<arcs weight="5" place="//@nodes.1"/>
<arcs weight="5" place="//@nodes.0"/>
<arcs weight="1" place="//@nodes.4"/>
<arcs weight="1" outgoing="true" place="//@nodes.4"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_started" arcs="//@nodes.21/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_running" arcs="//@nodes.21/@arcs.1 //@nodes.24/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish">
<arcs weight="1" place="//@nodes.23"/>
<arcs weight="1" outgoing="true" place="//@nodes.25"/>
<arcs weight="5" outgoing="true" place="//@nodes.1"/>
<arcs weight="5" outgoing="true" place="//@nodes.0"/>
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_finished" arcs="//@nodes.24/@arcs.1"/>
</petrinet:Network>

View file

@ -0,0 +1,44 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_ready: petrinet!Place(
name <- wd.name + '_ready',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
}

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("models/developpement.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
}
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("../fr.n7.petrinet/models/developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.{simplepdl,pdl}"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toLTL.ui.popupMenus.AcceleoGenerateToLTLAction"
enablesFor="+"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.acceleoGenerateToLTLAction"
icon="icons/default.gif"
label="Generate ToLTL"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,158 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfTarget(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.target.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1: petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- false,
weight <- req.quantity),
arcs2: petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getFinishStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[for (wds) before ('[] (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,158 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.resource.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- false,
weight <- req.quantity),
arcs2 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getFinishStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -1,34 +1,38 @@
<?xml version="1.0" encoding="ASCII"?> <?xml version="1.0" encoding="ASCII"?>
<petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement"> <petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement">
<nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1"/> <nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1" arcs="//@nodes.1/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Conception_start"> <nodes xsi:type="petrinet:Transition" name="Conception_start">
<arcs weight="1" place="//@nodes.0"/> <arcs weight="1" place="//@nodes.0"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/> <arcs weight="1" outgoing="true" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/> <arcs weight="1" outgoing="true" place="//@nodes.2"/>
<arcs weight="15"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="Conception_started"/> <nodes xsi:type="petrinet:Place" name="Conception_started" arcs="//@nodes.1/@arcs.2 //@nodes.13/@arcs.3 //@nodes.13/@arcs.4 //@nodes.19/@arcs.5 //@nodes.19/@arcs.6"/>
<nodes xsi:type="petrinet:Place" name="Conception_running"/> <nodes xsi:type="petrinet:Place" name="Conception_running" arcs="//@nodes.1/@arcs.1 //@nodes.4/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Conception_finish"> <nodes xsi:type="petrinet:Transition" name="Conception_finish">
<arcs weight="1" place="//@nodes.3"/> <arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.5"/> <arcs weight="1" outgoing="true" place="//@nodes.5"/>
<arcs weight="15" outgoing="true"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="Conception_finished"/> <nodes xsi:type="petrinet:Place" name="Conception_finished" arcs="//@nodes.4/@arcs.1 //@nodes.7/@arcs.4 //@nodes.7/@arcs.5 //@nodes.22/@arcs.4 //@nodes.22/@arcs.5"/>
<nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1"/> <nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1" arcs="//@nodes.7/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_start"> <nodes xsi:type="petrinet:Transition" name="Programmation_start">
<arcs weight="1" place="//@nodes.6"/> <arcs weight="1" place="//@nodes.6"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/> <arcs weight="1" outgoing="true" place="//@nodes.9"/>
<arcs weight="1" outgoing="true" place="//@nodes.8"/> <arcs weight="1" outgoing="true" place="//@nodes.8"/>
<arcs weight="15"/>
<arcs weight="1" place="//@nodes.5"/> <arcs weight="1" place="//@nodes.5"/>
<arcs weight="1" outgoing="true" place="//@nodes.5"/> <arcs weight="1" outgoing="true" place="//@nodes.5"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_started"/> <nodes xsi:type="petrinet:Place" name="Programmation_started" arcs="//@nodes.7/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Programmation_running"/> <nodes xsi:type="petrinet:Place" name="Programmation_running" arcs="//@nodes.7/@arcs.1 //@nodes.10/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_finish"> <nodes xsi:type="petrinet:Transition" name="Programmation_finish">
<arcs weight="1" place="//@nodes.9"/> <arcs weight="1" place="//@nodes.9"/>
<arcs weight="1" outgoing="true" place="//@nodes.11"/> <arcs weight="1" outgoing="true" place="//@nodes.11"/>
<arcs weight="15" outgoing="true"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_finished"/> <nodes xsi:type="petrinet:Place" name="Programmation_finished" arcs="//@nodes.10/@arcs.1 //@nodes.16/@arcs.2 //@nodes.16/@arcs.3"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1"/> <nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1" arcs="//@nodes.13/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_start"> <nodes xsi:type="petrinet:Transition" name="RedactionTests_start">
<arcs weight="1" place="//@nodes.12"/> <arcs weight="1" place="//@nodes.12"/>
<arcs weight="1" outgoing="true" place="//@nodes.15"/> <arcs weight="1" outgoing="true" place="//@nodes.15"/>
@ -36,30 +40,36 @@
<arcs weight="1" place="//@nodes.2"/> <arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/> <arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_started"/> <nodes xsi:type="petrinet:Place" name="RedactionTests_started" arcs="//@nodes.13/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_running"/> <nodes xsi:type="petrinet:Place" name="RedactionTests_running" arcs="//@nodes.13/@arcs.1 //@nodes.16/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_finish"> <nodes xsi:type="petrinet:Transition" name="RedactionTests_finish">
<arcs weight="1" place="//@nodes.15"/> <arcs weight="1" place="//@nodes.15"/>
<arcs weight="1" outgoing="true" place="//@nodes.17"/> <arcs weight="1" outgoing="true" place="//@nodes.17"/>
<arcs weight="1" place="//@nodes.11"/> <arcs weight="1" place="//@nodes.11"/>
<arcs weight="1" outgoing="true" place="//@nodes.11"/> <arcs weight="1" outgoing="true" place="//@nodes.11"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_finished"/> <nodes xsi:type="petrinet:Place" name="RedactionTests_finished" arcs="//@nodes.16/@arcs.1"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1"/> <nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1" arcs="//@nodes.19/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_start"> <nodes xsi:type="petrinet:Transition" name="RedactionDocs_start">
<arcs weight="1" place="//@nodes.18"/> <arcs weight="1" place="//@nodes.18"/>
<arcs weight="1" outgoing="true" place="//@nodes.21"/> <arcs weight="1" outgoing="true" place="//@nodes.21"/>
<arcs weight="1" outgoing="true" place="//@nodes.20"/> <arcs weight="1" outgoing="true" place="//@nodes.20"/>
<arcs weight="5"/>
<arcs weight="5"/>
<arcs weight="1" place="//@nodes.2"/> <arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/> <arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_started"/> <nodes xsi:type="petrinet:Place" name="RedactionDocs_started" arcs="//@nodes.19/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_running"/> <nodes xsi:type="petrinet:Place" name="RedactionDocs_running" arcs="//@nodes.19/@arcs.1 //@nodes.22/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish"> <nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish">
<arcs weight="1" place="//@nodes.21"/> <arcs weight="1" place="//@nodes.21"/>
<arcs weight="1" outgoing="true" place="//@nodes.23"/> <arcs weight="1" outgoing="true" place="//@nodes.23"/>
<arcs weight="5" outgoing="true"/>
<arcs weight="5" outgoing="true"/>
<arcs weight="1" place="//@nodes.5"/> <arcs weight="1" place="//@nodes.5"/>
<arcs weight="1" outgoing="true" place="//@nodes.5"/> <arcs weight="1" outgoing="true" place="//@nodes.5"/>
</nodes> </nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_finished"/> <nodes xsi:type="petrinet:Place" name="RedactionDocs_finished" arcs="//@nodes.22/@arcs.1"/>
<nodes xsi:type="petrinet:Place" name="Crayon_resource" tokens="10"/>
<nodes xsi:type="petrinet:Place" name="Papier_resource" tokens="20"/>
</petrinet:Network> </petrinet:Network>

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>'self.name + '_finished => ([]-' + self.name + '_running' + ' /\\ []-' + self.name + '_idle)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,158 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.resource.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- false,
weight <- req.quantity),
arcs2 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getFinishStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>' + self.name + '_finished => ([]-' + self.name + '_running' + ' /\\ []-' + self.name + '_idle /\\ []' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement">
<nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1" arcs="//@nodes.4/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Conception_running" arcs="//@nodes.4/@arcs.1 //@nodes.5/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Conception_started" arcs="//@nodes.4/@arcs.2 //@nodes.16/@arcs.3 //@nodes.16/@arcs.4 //@nodes.22/@arcs.3 //@nodes.22/@arcs.4"/>
<nodes xsi:type="petrinet:Place" name="Conception_finished" arcs="//@nodes.5/@arcs.1 //@nodes.10/@arcs.3 //@nodes.10/@arcs.4 //@nodes.23/@arcs.2 //@nodes.23/@arcs.3"/>
<nodes xsi:type="petrinet:Transition" name="Conception_start">
<arcs weight="1" place="//@nodes.0"/>
<arcs weight="1" outgoing="true" place="//@nodes.1"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="Conception_finish">
<arcs weight="1" place="//@nodes.1"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1" arcs="//@nodes.10/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Programmation_running" arcs="//@nodes.10/@arcs.1 //@nodes.11/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Programmation_started" arcs="//@nodes.10/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Programmation_finished" arcs="//@nodes.11/@arcs.1 //@nodes.17/@arcs.2 //@nodes.17/@arcs.3"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_start">
<arcs weight="1" place="//@nodes.6"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.8"/>
<arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="Programmation_finish">
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1" arcs="//@nodes.16/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_running" arcs="//@nodes.16/@arcs.1 //@nodes.17/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_started" arcs="//@nodes.16/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_finished" arcs="//@nodes.17/@arcs.1"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_start">
<arcs weight="1" place="//@nodes.12"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.14"/>
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_finish">
<arcs weight="1" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.15"/>
<arcs weight="1" place="//@nodes.9"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1" arcs="//@nodes.22/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_running" arcs="//@nodes.22/@arcs.1 //@nodes.23/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_started" arcs="//@nodes.22/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_finished" arcs="//@nodes.23/@arcs.1"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_start">
<arcs weight="1" place="//@nodes.18"/>
<arcs weight="1" outgoing="true" place="//@nodes.19"/>
<arcs weight="1" outgoing="true" place="//@nodes.20"/>
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish">
<arcs weight="1" place="//@nodes.19"/>
<arcs weight="1" outgoing="true" place="//@nodes.21"/>
<arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
</nodes>
</petrinet:Network>

View file

@ -0,0 +1,235 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,153 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.resource.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfPredecessor(),
transition <- req.getTransitionOfSuccessor(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,74 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process returns Process:
{Process}
'Process'
name=EString
'{'
('processElements' '{' processElements+=ProcessElement ( "," processElements+=ProcessElement)* '}' )?
'}';
ProcessElement returns ProcessElement:
WorkDefinition | WorkSequence | Guidance | Resource;
EString returns ecore::EString:
STRING | ID;
Guidance returns Guidance:
'Guidance'
'{'
'text' text=EString
('guidances' '(' guidances+=[Guidance|EString] ( "," guidances+=[Guidance|EString])* ')' )?
('elements' '(' elements+=[ProcessElement|EString] ( "," elements+=[ProcessElement|EString])* ')' )?
'}';
WorkDefinition returns WorkDefinition:
{WorkDefinition}
'WorkDefinition'
name=EString
'{'
('guidances' '(' guidances+=[Guidance|EString] ( "," guidances+=[Guidance|EString])* ')' )?
('linksToPredecessors' '(' linksToPredecessors+=[WorkSequence|EString] ( "," linksToPredecessors+=[WorkSequence|EString])* ')' )?
('linksToSuccessors' '(' linksToSuccessors+=[WorkSequence|EString] ( "," linksToSuccessors+=[WorkSequence|EString])* ')' )?
('requests' '{' requests+=Request ( "," requests+=Request)* '}' )?
'}';
WorkSequence returns WorkSequence:
'WorkSequence'
'{'
'linkType' linkType=WorkSequenceType
('guidances' '(' guidances+=[Guidance|EString] ( "," guidances+=[Guidance|EString])* ')' )?
'predecessor' predecessor=[WorkDefinition|EString]
'successor' successor=[WorkDefinition|EString]
'}';
Resource returns Resource:
'Resource'
name=EString
'{'
'quantity' quantity=EInt
('guidances' '(' guidances+=[Guidance|EString] ( "," guidances+=[Guidance|EString])* ')' )?
('requests' '(' requests+=[Request|EString] ( "," requests+=[Request|EString])* ')' )?
'}';
Request returns Request:
'Request'
'{'
'quantity' quantity=EInt
'target' target=[Resource|EString]
'}';
EInt returns ecore::EInt:
'-'? INT;
enum WorkSequenceType returns WorkSequenceType:
startToStart = 'startToStart' | finishToStart = 'finishToStart' | startToFinish = 'startToFinish' | finishToFinish = 'finishToFinish';

View file

@ -1,7 +1,6 @@
source.. = src/,\ source.. = src/,\
src-gen/,\ src-gen/,\
xtend-gen/ xtend-gen/
bin.includes = .,\ bin.includes = META-INF/,\
META-INF/,\ .,\
plugin.xml plugin.xml
bin.excludes = **/*.xtend

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement">
<nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1" arcs="//@nodes.4/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Conception_running" arcs="//@nodes.4/@arcs.1 //@nodes.5/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Conception_started" arcs="//@nodes.4/@arcs.2 //@nodes.16/@arcs.3 //@nodes.16/@arcs.4 //@nodes.22/@arcs.3 //@nodes.22/@arcs.4"/>
<nodes xsi:type="petrinet:Place" name="Conception_finished" arcs="//@nodes.5/@arcs.1 //@nodes.10/@arcs.3 //@nodes.10/@arcs.4 //@nodes.23/@arcs.2 //@nodes.23/@arcs.3"/>
<nodes xsi:type="petrinet:Transition" name="Conception_start">
<arcs weight="1" place="//@nodes.0"/>
<arcs weight="1" outgoing="true" place="//@nodes.1"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
<arcs weight="15" place="//@nodes.25"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="Conception_finish">
<arcs weight="1" place="//@nodes.1"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
<arcs weight="15" outgoing="true" place="//@nodes.25"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1" arcs="//@nodes.10/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Programmation_running" arcs="//@nodes.10/@arcs.1 //@nodes.11/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Programmation_started" arcs="//@nodes.10/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Programmation_finished" arcs="//@nodes.11/@arcs.1 //@nodes.17/@arcs.2 //@nodes.17/@arcs.3"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_start">
<arcs weight="1" place="//@nodes.6"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.8"/>
<arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
<arcs weight="15" place="//@nodes.25"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="Programmation_finish">
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/>
<arcs weight="15" outgoing="true" place="//@nodes.25"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1" arcs="//@nodes.16/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_running" arcs="//@nodes.16/@arcs.1 //@nodes.17/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_started" arcs="//@nodes.16/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_finished" arcs="//@nodes.17/@arcs.1"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_start">
<arcs weight="1" place="//@nodes.12"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.14"/>
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_finish">
<arcs weight="1" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.15"/>
<arcs weight="1" place="//@nodes.9"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1" arcs="//@nodes.22/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_running" arcs="//@nodes.22/@arcs.1 //@nodes.23/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_started" arcs="//@nodes.22/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_finished" arcs="//@nodes.23/@arcs.1"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_start">
<arcs weight="1" place="//@nodes.18"/>
<arcs weight="1" outgoing="true" place="//@nodes.19"/>
<arcs weight="1" outgoing="true" place="//@nodes.20"/>
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
<arcs weight="5" place="//@nodes.25"/>
<arcs weight="5" place="//@nodes.24"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish">
<arcs weight="1" place="//@nodes.19"/>
<arcs weight="1" outgoing="true" place="//@nodes.21"/>
<arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
<arcs weight="5" outgoing="true" place="//@nodes.25"/>
<arcs weight="5" outgoing="true" place="//@nodes.24"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Crayon_resource" tokens="10" arcs="//@nodes.22/@arcs.6 //@nodes.23/@arcs.5"/>
<nodes xsi:type="petrinet:Place" name="Papier_resource" tokens="20" arcs="//@nodes.4/@arcs.3 //@nodes.5/@arcs.2 //@nodes.10/@arcs.5 //@nodes.11/@arcs.2 //@nodes.22/@arcs.5 //@nodes.23/@arcs.4"/>
</petrinet:Network>

View file

@ -1,12 +1,9 @@
source.. = src/,\ source.. = src/,\
src-gen/,\ src-gen/,\
xtend-gen/ xtend-gen/
bin.includes = model/generated/,\ bin.includes = META-INF/,\
.,\ .,\
META-INF/,\
plugin.xml plugin.xml
bin.excludes = **/*.mwe2,\
**/*.xtend
additional.bundles = org.eclipse.xtext.xbase,\ additional.bundles = org.eclipse.xtext.xbase,\
org.eclipse.xtext.common.types,\ org.eclipse.xtext.common.types,\
org.eclipse.xtext.xtext.generator,\ org.eclipse.xtext.xtext.generator,\

View file

@ -0,0 +1,22 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[for (wds) before ('[] (') separator (' /\\ ') after (');')]
[(self.name + '_finished')/]
[/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,28 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_ready: petrinet!Place(
name <- wd.name + '_ready',
marking <- 1,
net <- wd.getProcess())
}

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>' + self.name + '_finished => ([] -' + self.name + '_running' + ' /\\ [] -' + self.name + '_idle /\\ [] ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<> ' + self.name + '_finished => ([] -' + self.name + '_running' + ' /\\ [] -' + self.name + '_idle /\\ [] ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,19 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,95 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart then
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_finished')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start'),
t_finish: petrinet!Transition(
name <- wd.name + '_finish'),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}

View file

@ -0,0 +1,235 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>self.name' + '_finished => []-'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<simplepdl:Process
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simplepdl="http://simplepdl"
name="Developpement">
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToSuccessors="//@processElements.4 //@processElements.6 //@processElements.7 //@processElements.8"
name="Conception">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.4"
linksToSuccessors="//@processElements.5"
name="Programmation">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.5 //@processElements.6"
name="RedactionTests"/>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.7 //@processElements.8"
name="RedactionDocs">
<requests
quantity="5"
target="//@processElements.10"/>
<requests
quantity="5"
target="//@processElements.9"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToStart"
predecessor="//@processElements.0"
successor="//@processElements.1"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.1"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="10"
name="Crayon"
requests="//@processElements.3/@requests.1"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="20"
name="Papier"
requests="//@processElements.0/@requests.0 //@processElements.1/@requests.0 //@processElements.3/@requests.0"/>
</simplepdl:Process>

View file

@ -0,0 +1,158 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.resource.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity),
arcs2 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.*"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toLTL.ui.popupMenus.AcceleoGenerateToLTLAction"
enablesFor="+"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.acceleoGenerateToLTLAction"
icon="icons/default.gif"
label="Generate ToLTL"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')][self.name + '_finished => [] ( ~' + self.name + '_running' + ' /\\ ~' + self.name + '_idle /\\ ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,109 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.predecesor.name + '_finish')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start'),
t_finish: petrinet!Transition(
name <- wd.name + '_finish'),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}

View file

@ -0,0 +1,158 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfTarget(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.target.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1: petrinet!Arc(
place <- req.getPlaceOfTarget(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- false,
weight <- req.quantity),
arcs2: petrinet!Arc(
place <- req.getPlaceOfTarget(),
transition <- req.getFinishStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.pdl"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toLTL.ui.popupMenus.AcceleoGenerateToLTLAction"
enablesFor="+"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.acceleoGenerateToLTLAction"
icon="icons/default.gif"
label="Generate ToLTL"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,107 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_finished')
->asSequence()->first()
endif;
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.predecesor.name + '_finish')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start'),
t_finish: petrinet!Transition(
name <- wd.name + '_finish'),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
}
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
System.out.println(place.getName());
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,146 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.resource.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfPredecessor(),
transition <- req.getTransitionOfSuccessor(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,235 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
}
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,233 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.simplepdl"
id="fr.n7.simplepdl.toDOT.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toDOT.ui.popupMenus.AcceleoGenerateToDOTAction"
enablesFor="+"
id="fr.n7.simplepdl.toDOT.ui.popupMenus.acceleoGenerateToDOTAction"
icon="icons/default.gif"
label="Generate ToDOT"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')][self.name + '_finished => []( ~' + self.name + '_running' + ' /\\ ~' + self.name + '_idle /\\ ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')][self.name + '_finished'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.pdl"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toLTL.ui.popupMenus.AcceleoGenerateToLTLAction"
enablesFor="+"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.acceleoGenerateToLTLAction"
icon="icons/default.gif"
label="Generate ToLTL"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,238 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
System.out.println(req);
System.out.println(req.getTarget());
System.out.println(req.getRequester());
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,22 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[for (wds) before ('[] ((') separator (') /\\ (') after ('));')]
[self.name.concat('_finished')/]
[/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (req.getTarget() != null) {
System.out.println(req.getTarget());
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
System.out.println(req.getTarget() + qty);
if (req.getTarget() != null) {
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,116 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}

View file

@ -0,0 +1,22 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] (') separator (' /\\ ') after (');')]
[(self.name + '_finished')/]
[/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,72 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start'),
t_finish: petrinet!Transition(
name <- wd.name + '_finish'),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1),
}

View file

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="ASCII"?>
<petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement">
<nodes xsi:type="petrinet:Place" name="Crayon_resource" tokens="10" arcs="//@nodes.21/@arcs.4 //@nodes.24/@arcs.3"/>
<nodes xsi:type="petrinet:Place" name="Papier_resource" tokens="20" arcs="//@nodes.3/@arcs.3 //@nodes.6/@arcs.2 //@nodes.9/@arcs.3 //@nodes.12/@arcs.2 //@nodes.21/@arcs.3 //@nodes.24/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1" arcs="//@nodes.3/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Conception_start">
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.5"/>
<arcs weight="1" outgoing="true" place="//@nodes.4"/>
<arcs weight="15" place="//@nodes.1"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Conception_started" arcs="//@nodes.3/@arcs.2 //@nodes.15/@arcs.3 //@nodes.15/@arcs.4 //@nodes.21/@arcs.5 //@nodes.21/@arcs.6"/>
<nodes xsi:type="petrinet:Place" name="Conception_running" arcs="//@nodes.3/@arcs.1 //@nodes.6/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Conception_finish">
<arcs weight="1" place="//@nodes.5"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
<arcs weight="15" outgoing="true" place="//@nodes.1"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Conception_finished" arcs="//@nodes.6/@arcs.1 //@nodes.9/@arcs.4 //@nodes.9/@arcs.5 //@nodes.24/@arcs.4 //@nodes.24/@arcs.5"/>
<nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1" arcs="//@nodes.9/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_start">
<arcs weight="1" place="//@nodes.8"/>
<arcs weight="1" outgoing="true" place="//@nodes.11"/>
<arcs weight="1" outgoing="true" place="//@nodes.10"/>
<arcs weight="15" place="//@nodes.1"/>
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_started" arcs="//@nodes.9/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Programmation_running" arcs="//@nodes.9/@arcs.1 //@nodes.12/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_finish">
<arcs weight="1" place="//@nodes.11"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
<arcs weight="15" outgoing="true" place="//@nodes.1"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_finished" arcs="//@nodes.12/@arcs.1 //@nodes.18/@arcs.2 //@nodes.18/@arcs.3"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1" arcs="//@nodes.15/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_start">
<arcs weight="1" place="//@nodes.14"/>
<arcs weight="1" outgoing="true" place="//@nodes.17"/>
<arcs weight="1" outgoing="true" place="//@nodes.16"/>
<arcs weight="1" place="//@nodes.4"/>
<arcs weight="1" outgoing="true" place="//@nodes.4"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_started" arcs="//@nodes.15/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_running" arcs="//@nodes.15/@arcs.1 //@nodes.18/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_finish">
<arcs weight="1" place="//@nodes.17"/>
<arcs weight="1" outgoing="true" place="//@nodes.19"/>
<arcs weight="1" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_finished" arcs="//@nodes.18/@arcs.1"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1" arcs="//@nodes.21/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_start">
<arcs weight="1" place="//@nodes.20"/>
<arcs weight="1" outgoing="true" place="//@nodes.23"/>
<arcs weight="1" outgoing="true" place="//@nodes.22"/>
<arcs weight="5" place="//@nodes.1"/>
<arcs weight="5" place="//@nodes.0"/>
<arcs weight="1" place="//@nodes.4"/>
<arcs weight="1" outgoing="true" place="//@nodes.4"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_started" arcs="//@nodes.21/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_running" arcs="//@nodes.21/@arcs.1 //@nodes.24/@arcs.0"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish">
<arcs weight="1" place="//@nodes.23"/>
<arcs weight="1" outgoing="true" place="//@nodes.25"/>
<arcs weight="5" outgoing="true" place="//@nodes.1"/>
<arcs weight="5" outgoing="true" place="//@nodes.0"/>
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_finished" arcs="//@nodes.24/@arcs.1"/>
</petrinet:Network>

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>'self.name + '_finished => ([]-' + self.name + '_running' + ' []-' + self.name + '_idle)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<petrinet:Network xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:petrinet="http://petrinet" name="Developpement">
<nodes xsi:type="petrinet:Place" name="Conception_idle" tokens="1" arcs="//@nodes.4/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Conception_running" arcs="//@nodes.4/@arcs.1 //@nodes.5/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Conception_started" arcs="//@nodes.4/@arcs.2 //@nodes.16/@arcs.3 //@nodes.16/@arcs.4 //@nodes.22/@arcs.3 //@nodes.22/@arcs.4"/>
<nodes xsi:type="petrinet:Place" name="Conception_finished" arcs="//@nodes.5/@arcs.1 //@nodes.10/@arcs.3 //@nodes.10/@arcs.4 //@nodes.23/@arcs.2 //@nodes.23/@arcs.3"/>
<nodes xsi:type="petrinet:Transition" name="Conception_start">
<arcs weight="1" place="//@nodes.0"/>
<arcs weight="1" outgoing="true" place="//@nodes.1"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="Conception_finish">
<arcs weight="1" place="//@nodes.1"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Programmation_idle" tokens="1" arcs="//@nodes.10/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Programmation_running" arcs="//@nodes.10/@arcs.1 //@nodes.11/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="Programmation_started" arcs="//@nodes.10/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="Programmation_finished" arcs="//@nodes.11/@arcs.1 //@nodes.17/@arcs.2 //@nodes.17/@arcs.3"/>
<nodes xsi:type="petrinet:Transition" name="Programmation_start">
<arcs weight="1" place="//@nodes.6"/>
<arcs weight="1" outgoing="true" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.8"/>
<arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="Programmation_finish">
<arcs weight="1" place="//@nodes.7"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionTests_idle" tokens="1" arcs="//@nodes.16/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_running" arcs="//@nodes.16/@arcs.1 //@nodes.17/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_started" arcs="//@nodes.16/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionTests_finished" arcs="//@nodes.17/@arcs.1"/>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_start">
<arcs weight="1" place="//@nodes.12"/>
<arcs weight="1" outgoing="true" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.14"/>
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="RedactionTests_finish">
<arcs weight="1" place="//@nodes.13"/>
<arcs weight="1" outgoing="true" place="//@nodes.15"/>
<arcs weight="1" place="//@nodes.9"/>
<arcs weight="1" outgoing="true" place="//@nodes.9"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_idle" tokens="1" arcs="//@nodes.22/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_running" arcs="//@nodes.22/@arcs.1 //@nodes.23/@arcs.0"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_started" arcs="//@nodes.22/@arcs.2"/>
<nodes xsi:type="petrinet:Place" name="RedactionDocs_finished" arcs="//@nodes.23/@arcs.1"/>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_start">
<arcs weight="1" place="//@nodes.18"/>
<arcs weight="1" outgoing="true" place="//@nodes.19"/>
<arcs weight="1" outgoing="true" place="//@nodes.20"/>
<arcs weight="1" place="//@nodes.2"/>
<arcs weight="1" outgoing="true" place="//@nodes.2"/>
</nodes>
<nodes xsi:type="petrinet:Transition" name="RedactionDocs_finish">
<arcs weight="1" place="//@nodes.19"/>
<arcs weight="1" outgoing="true" place="//@nodes.21"/>
<arcs weight="1" place="//@nodes.3"/>
<arcs weight="1" outgoing="true" place="//@nodes.3"/>
</nodes>
<nodes xsi:type="petrinet:Place" name="Crayon_resource" tokens="10"/>
<nodes xsi:type="petrinet:Place" name="Papier_resource" tokens="20"/>
</petrinet:Network>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.pdl"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toLTL.ui.popupMenus.AcceleoGenerateToLTLAction"
enablesFor="+"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.acceleoGenerateToLTLAction"
icon="icons/default.gif"
label="Generate ToLTL"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,237 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
network.getNodes().add(res);
}
}
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getPlace().getName())) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.pdl"
nameFilter="*.simplepdl"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toLTL.ui.popupMenus.AcceleoGenerateToLTLAction"
enablesFor="+"
id="fr.n7.simplepdl.toLTL.ui.popupMenus.acceleoGenerateToLTLAction"
icon="icons/default.gif"
label="Generate ToLTL"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>'self.name + '_finished => []-'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,234 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
// Conversion des WorkDefinition en Node et Transition
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
System.out.println(place.getName());
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
// Conversion des WorkSequence en Node et Transition
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')][self.name + '_finished => []( ~' + self.name + '_running' + ' /\\ ~' + self.name + '_idle /\\ [] ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,153 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir la place correspondant au predecesseur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecessor.name + '_finished')
->asSequence()->first()
endif;
-- Obtenir la transition correspondant au successeur d'une WorkSequence
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_finish')
->asSequence()->first()
endif;
-- Obtenir la place correspondant a la Resource d'une Request
helper context simplepdl!Request
def: getPlaceOfResource(): petrinet!Place =
petrinet!Place.allInstances()
->select(p | p.name = self.resource.name + '_resource')
->asSequence()->first();
-- Obtenir la transition start correspondant au Requester d'une Request
helper context simplepdl!Request
def: getStartTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_start')
->asSequence()->first();
-- Obtenir la transition finish correspondant au Requester d'une Request
helper context simplepdl!Request
def: getFinishTransitionOfRequester(): petrinet!Transition =
petrinet!Transition.allInstances()
->select(t | t.name = self.requester.name + '_finish')
->asSequence()->first();
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!Network (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
network <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
network <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
network <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
network <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start',
network <- wd.process),
t_finish: petrinet!Transition(
name <- wd.name + '_finish',
network <- wd.process),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- false,
weight <- 1),
arc2: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}
-- Traduire une Resource en un motif sur le réseau de Petri
rule Resource2PetriNet {
from res: simplepdl!Resource
to
-- PLACE d'une Resource
place: petrinet!Place(
name <- res.name + '_resource',
tokens <- res.quantity,
network <- res.process)
}
-- Traduire une Request en un motif sur le réseau de Petri
rule Request2PetriNet {
from req: simplepdl!Request
to
-- ARCS d'une Request
arcs1 petrinet!Arc(
place <- req.getPlaceOfResource(),
transition <- req.getStartStransitionOfRequester(),
outgoing <- true,
weight <- req.quantity)
}

View file

@ -0,0 +1,20 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.*"
id="fr.n7.simplepdl.toHTML.ui.popupMenus.contribution.IFile">
<menu id="org.eclipse.acceleo.module.menu" label="Acceleo Model to Text" path="additionsAcceleo">
<groupMarker name="acceleo"/>
</menu>
<action
class="fr.n7.simplepdl.toHTML.ui.popupMenus.AcceleoGenerateToHTMLAction"
enablesFor="+"
id="fr.n7.simplepdl.toHTML.ui.popupMenus.acceleoGenerateToHTMLAction"
icon="icons/default.gif"
label="Generate ToHTML"
menubarPath="org.eclipse.acceleo.module.menu/acceleo"/>
</objectContribution>
</extension>
</plugin>

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("models/developpement.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
}
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ -' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ ' + self.name + '_running /\\ -' + self.name + '_finished) \\/ (-' + self.name + '_idle /\\ -' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['<>' + self.name + '_finished => ([]-' + self.name + '_running' + ' /\\ []-' + self.name + '_idle)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')][self.name + '_finished => []( ~' + self.name + '_running' + ' /\\ ~' + self.name + '_idle /\\ [] ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,21 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name + '_finished'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')]['(' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ' + self.name + '_running /\\ ~' + self.name + '_finished) \\/ (~' + self.name + '_idle /\\ ~' + self.name + '_running /\\ ' + self.name + '_finished)'/][/for]
[for (wds) before ('[] <> ((') separator (') /\\ (') after ('));')][self.name + '_finished => ([] ~' + self.name + '_running' + ' /\\ [] ~' + self.name + '_idle /\\ [] ' + self.name + '_started)'/][/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,107 @@
module SimplePDL2PetriNet;
create OUT: petrinet from IN: simplepdl;
-- Obtenir le processus qui contient ce process element.
-- Remarque: Ce helper ne serait pas utile si une référence opposite
-- avait été placée entre Process et ProcessElement
helper context simplepdl!ProcessElement
def: getProcess(): simplepdl!Process =
simplepdl!Process.allInstances()
->select(p | p.processElements->includes(self))
->asSequence()->first();
helper context simplepdl!WorkSequence
def: getPlaceOfPredecessor(): petrinet!Place =
if self.linkType = #startToStart or self.linkType = #startToFinish then
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_started')
->asSequence()->first()
else
petrinet!Place.allInstances()
->select(p | p.name = self.predecesor.name + '_finished')
->asSequence()->first()
endif;
helper context simplepdl!WorkSequence
def: getTransitionOfSuccessor(): petrinet!Transition =
if self.linkType = #startToStart or self.linkType = #finishToStart then
petrinet!Transition.allInstances()
->select(t | t.name = self.successor.name + '_start')
->asSequence()->first()
else
petrinet!Transition.allInstances()
->select(t | t.name = self.predecesor.name + '_finish')
->asSequence()->first()
endif;
-- Traduire un Process en un PetriNet de même nom
rule Process2PetriNet {
from p: simplepdl!Process
to pn: petrinet!PetriNet (name <- p.name)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkDefinition2PetriNet {
from wd: simplepdl!WorkDefinition
to
-- PLACES d'une WorkDefinition
p_idle: petrinet!Place(
name <- wd.name + '_idle',
tokens <- 1,
net <- wd.process),
p_running: petrinet!Place(
name <- wd.name + '_running',
tokens <- 0,
net <- wd.process),
p_started: petrinet!Place(
name <- wd.name + '_started',
tokens <- 0,
net <- wd.process),
p_finished: petrinet!Place(
name <- wd.name + '_finished',
tokens <- 0,
net <- wd.process),
-- TRANSITIONS d'une WorkDefinition
t_start: petrinet!Transition(
name <- wd.name + '_start'),
t_finish: petrinet!Transition(
name <- wd.name + '_finish'),
-- ARCS d'un WorkDefinition
a_idle2start: petrinet!Arc(
place <- p_idle,
transition <- t_start,
outgoing <- false,
weight <- 1),
a_start2running: petrinet!Arc(
place <- p_running,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_start2started: petrinet!Arc(
place <- p_started,
transition <- t_start,
outgoing <- true,
weight <- 1),
a_running2finish: petrinet!Arc(
place <- p_running,
transition <- t_finish,
outgoing <- false,
weight <- 1),
a_finish2finished: petrinet!Arc(
place <- p_finished,
transition <- t_finish,
outgoing <- true,
weight <- 1)
}
-- Traduire une WorkDefinition en un motif sur le réseau de Petri
rule WorkSequence2PetriNet {
from ws: simplepdl!WorkSequence
to
-- ARCS d'une WorkSequence
arc1: petrinet!Arc(
place <- ws.getPlaceOfPredecessor(),
transition <- ws.getTransitionOfSuccessor(),
outgoing <- true,
weight <- 1)
}

View file

@ -0,0 +1,22 @@
[comment encoding = UTF-8 /]
[module toLTL('http://simplepdl')]
[template public processToLTL(aProcess : Process)]
[comment @main/]
[file (aProcess.name + '.ltl', false, 'UTF-8')]
[let wds : OrderedSet(WorkDefinition) = aProcess.getWDs() ]
[for (wds) before ('[] <> (') separator (' /\\ ') after (');')][self.name.concat('_finished')/][/for]
[for (wds) before ('[] (') separator (' /\\ ') after (');')]
[((self.name + '_finished')/]
[/for]
[/let]
[/file]
[/template]
[query public getWDs(p: Process) : OrderedSet(WorkDefinition) =
p.processElements->select( e | e.oclIsTypeOf(WorkDefinition) )
->collect( e | e.oclAsType(WorkDefinition) )
->asOrderedSet()
/]

View file

@ -0,0 +1,183 @@
/**
*/
package simplepdl.provider;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ViewerNotification;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
/**
* This is the item provider adapter for a {@link simplepdl.WorkSequence} object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class WorkSequenceItemProvider extends ProcessElementItemProvider {
/**
* This constructs an instance from a factory and a notifier.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public WorkSequenceItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
}
/**
* This returns the property descriptors for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);
addLinkTypePropertyDescriptor(object);
addPredecessorPropertyDescriptor(object);
addSuccessorPropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
/**
* This adds a property descriptor for the Link Type feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addLinkTypePropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_WorkSequence_linkType_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_WorkSequence_linkType_feature", "_UI_WorkSequence_type"),
SimplepdlPackage.Literals.WORK_SEQUENCE__LINK_TYPE,
true,
false,
false,
ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
null,
null));
}
/**
* This adds a property descriptor for the Predecessor feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addPredecessorPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_WorkSequence_predecessor_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_WorkSequence_predecessor_feature", "_UI_WorkSequence_type"),
SimplepdlPackage.Literals.WORK_SEQUENCE__PREDECESSOR,
true,
false,
true,
null,
null,
null));
}
/**
* This adds a property descriptor for the Successor feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addSuccessorPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_WorkSequence_successor_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_WorkSequence_successor_feature", "_UI_WorkSequence_type"),
SimplepdlPackage.Literals.WORK_SEQUENCE__SUCCESSOR,
true,
false,
true,
null,
null,
null));
}
/**
* This returns WorkSequence.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object getImage(Object object) {
return overlayImage(object, getResourceLocator().getImage("full/obj16/WorkSequence"));
}
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String getText(Object object) {
WorkSequence ws = (WorkSequence) object;
WorkSequenceType labelValue = ws.getLinkType();
String label = "--" + (labelValue == null ? "?" : labelValue.toString()) + "-->";
String previous = ws.getPredecessor() == null ? "?" : ws.getPredecessor().getName();
String next = ws.getSuccessor() == null ? "?" : ws.getSuccessor().getName();
return label == null || label.length() == 0 ?
getString("_UI_WorkSequence_type") :
getString("_UI_WorkSequence_type") + " " + previous + " " + label + " " + next;
}
/**
* This handles model notifications by calling {@link #updateChildren} to update any cached
* children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void notifyChanged(Notification notification) {
updateChildren(notification);
switch (notification.getFeatureID(WorkSequence.class)) {
case SimplepdlPackage.WORK_SEQUENCE__LINK_TYPE:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
super.notifyChanged(notification);
}
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);
}
}

View file

@ -0,0 +1,236 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des Resource en Places
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name + "_resource");
res.setTokens(qty);
network.getNodes().add(res);
}
}
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setPlace(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setPlace(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setPlace(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setPlace(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setPlace(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
// Conversion des Requests s'il y en a
for (Request req : wd.getRequests()) {
int qty = req.getQuantity();
Place target = null;
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(req.getTarget().getName() + "_resource")) {
target = place;
}
}
}
Arc res2start = myFactory.createArc();
res2start.setPlace(target);
res2start.setOutgoing(false);
res2start.setWeight(qty);
Arc finish2res = myFactory.createArc();
finish2res.setPlace(target);
finish2res.setOutgoing(true);
finish2res.setWeight(qty);
start.getArcs().add(res2start);
finish.getArcs().add(finish2res);
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setPlace(place);
arc2.setPlace(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Some files were not shown because too many files have changed in this diff Show more