Skip to content
Snippets Groups Projects
Commit 36f7080e authored by “Khaoula's avatar “Khaoula
Browse files

réseau presque fini avec Main non executable :(((

parent df3fabc9
Branches
No related tags found
No related merge requests found
package org.petriNet;
public class MainPetriNet {
public static void main(String[] args) {
// Create a Petri net
ReseauPerti reseauPerti = new ReseauPerti();
// Create places
Place p1 = new Place(1,3);
Place p2 = new Place(2,3);
Place p3 = new Place(3,3);
// Create transitions with empty Arcs_ENTRANT and Arcs_SORTANT
Transition t1 = new Transition(1, new ArrayList<Arc_ENTRANT>(), new ArrayList<Arc_SORTANT>());
Transition t2 = new Transition(2, new ArrayList<Arc_ENTRANT>(), new ArrayList<Arc_SORTANT>());
// Create arcs
Arc_ENTRANT a1 = new Arc_ENTRANT(p1, t1, 1);
Arc_SORTANT a2 = new Arc_SORTANT(p2, t1, 1);
Arc_ENTRANT a3 = new Arc_ENTRANT(p2, t2, 1);
Arc_SORTANT a4 = new Arc_SORTANT(p3, t2, 1);
// Add arcs to transitions
t1.ajouterArc_ENTRANT(a1);
t1.ajouterArc_SORTANT(a2);
t2.ajouterArc_ENTRANT(a3);
t2.ajouterArc_SORTANT(a4);
// Add arcs to places
//p1.addArc(a1);
//p2.addArc(a2);
//p2.addArc(a3);
//p3.addArc(a4);
// Add places and transitions to the Petri net
reseauPerti.ajouterPlace(p1);
reseauPerti.ajouterPlace(p2);
reseauPerti.ajouterPlace(p3);
reseauPerti.ajouterTransition(t1);
reseauPerti.ajouterTransition(t2);
// Display the Petri net
reseauPerti.afficherEtat();
// Test the est_tirable method
System.out.println("t1 est tirable : " + t1.est_tirable());
System.out.println("t2 est tirable : " + t2.est_tirable());
// Test the tirer method
if (t1.est_tirable()) {
reseauPerti.tirerTransition(t1);
}
if (t2.est_tirable()) {
reseauPerti.tirerTransition(t2);
}
// Display the Petri net again
reseauPerti.afficherEtat();
}
}
\ No newline at end of file
......@@ -12,4 +12,11 @@ public interface PetriNetService {
public void afficherEtat();
/**
* afficher le réseau de petri
* On a trouver que cette fonction et utile pour visualiser
* le réseau de petri
*/
public void afficherReseau();
}
......@@ -49,8 +49,34 @@ public class ReseauPerti implements PetriNetService {
@Override
public void afficherEtat() {
// TODO Auto-generated method stub
// afficher le nombre de jetons dans chaque place
for (Place place : places) {
System.out.println("Place " + place.getId() + " : " + place.getNbrJetons());
}
}
@Override
public void afficherReseauPetri() {
// TODO Auto-generated method stub
/**
* afficher les places, les transitions et les arcs
* comme un dessin du réseau de petri
* les places comme des cercles
* les transitions comme des rectangles
* les arcs comme des flèches
* les poinds des arcs à côté des flèches
* les jetons des points dans les places
* relier les arcs aux places et aux transitions par des flèches
*/
// afficher Petri Net
System.out.println("Petri Net : ");
// afficher les places, les arcs, le poid et les transitions
for (Arc arc : arcs) {
System.out.println("Arc : " + arc.getPlace().getId() + " -> " + arc.getTransition().getId() + " : " + arc.getPoids());
}
}
......@@ -3,10 +3,26 @@ package org.petriNet;
public class Transition {
private int id;
private List<Arc_SORTANT> arcs_SORTANTS;
private List<Arc_ENTRANT> arcs_ENTRANTS;
public Transition(int id) {
public Transition(int id, List<Arc_SORTANT> arcs_SORTANTS, List<Arc_ENTRANT> arcs_ENTRANTS) {
this.id = id;
this.arcs_SORTANTS = new ArrayList<Arc_SORTANT>();
this.arcs_ENTRANTS = new ArrayList<Arc_ENTRANT>();
}
/**
* On ajoute deux méthodes pour pouvoir ajouter les arcs entrants et
* sortants à la transition
* c'est une différence par rapport au diagramme de classe soumis
*/
public void ajouterArc_SORTANT(Arc_SORTANT arc_SORTANT) {
this.arcs_SORTANTS.add(arc_SORTANT);
}
public void ajouterArc_ENTRANT(Arc_ENTRANT arc_ENTRANT) {
this.arcs_ENTRANTS.add(arc_ENTRANT);
}
public boolean est_tirable() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment