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

Petri Net corrigé avec Tests complets sans tests 7.5 et 7.4

parent 73b2a5a5
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ public class Arc_SORTANT extends Arc {
@Override
public void valider() {
// On ajoute le nombre de jetons du poids de l'arc
this.place.ajouter_jeton(this.poids);
this.getPlace().ajouter_jeton(this.getPoids());
}
}
\ No newline at end of file
......@@ -180,22 +180,23 @@ public class ReseauPetri implements PetriNetService {
System.out.println("Liste des places :");
// On parcourt la liste des arcs pour afficher les places
// une liste pur les arcs entrants et une liste pour les arcs sortants
for (Place place : this.places) {
List<Arc> arcs_ENTRANTS = new ArrayList<>();
List<Arc> arcs_SORTANTS = new ArrayList<>();
for (Place place : this.places) {
for (Arc arc : this.arcs) {
// we verify getting arc.getPlace() == place
if (arc.getPlace().getId() == place.getId()) {
// we verify if it's an arc entrant
if (arc instanceof Arc_ENTRANT) {
arcs_ENTRANTS.add(arc);
} else {
} else if (arc instanceof Arc_SORTANT) {
arcs_SORTANTS.add(arc);
}
}
}
// entrants / sortants à la place
System.out.println(place.getId() + " : place avec " + place.get_nombre_jetons() + " jetons, "
+ arcs_SORTANTS.size() + " arc simple sortant, " + arcs_ENTRANTS.size() + " arc simple entrant");
+ arcs_ENTRANTS.size() + " arc simple sortant, " + arcs_SORTANTS.size() + " arc simple entrant");
}
System.out.println("Liste des transitions :");
......
......@@ -92,11 +92,11 @@ public class Transition {
boolean tirable = est_tirable();
if (tirable) {
for (Arc_ENTRANT arc_ENTRANT : arcs_ENTRANTS) {
for (Arc_ENTRANT arc_ENTRANT : this.getArcs_ENTRANTS()) {
arc_ENTRANT.valider();
}
for (Arc_SORTANT arc_SORTANT : arcs_SORTANTS) {
for (Arc_SORTANT arc_SORTANT : this.getArcs_SORTANTS()) {
arc_SORTANT.valider();
}
System.out.println("Transition tirée avec succès");
......
......@@ -265,6 +265,29 @@ public class ReseauPetriTest {
Transition T1 = new Transition("T1", Active.generateId(2));
// Active has one Place with 1 jeton
Place P1 = new Place(1, Active.generateId(1));
Active.ajouterPlace(P1);
// Creer l'arc sortant de T1 vers P1
Arc_SORTANT arc = new Arc_SORTANT(T1, P1, 1, Active.generateId(0));
Active.ajouterArc(arc);
T1.ajouterArc_SORTANT(arc);
Active.ajouterTransition(T1);
// Tirer T1
Active.tirer_transition(String.valueOf(T1.getId()));
Active.afficherReseau();
}
@Test
public void testActiverPetri_6() {
ReseauPetri Active = new ReseauPetri();
Transition T1 = new Transition("T1", Active.generateId(2));
// Active has two Places with 0 and 2 jetons
Place P1 = new Place(0, Active.generateId(1));
Place P2 = new Place(2, Active.generateId(1));
......@@ -286,4 +309,129 @@ public class ReseauPetriTest {
Active.afficherReseau();
}
@Test
public void testActiverPetri_7() {
ReseauPetri Active = new ReseauPetri();
Transition T1 = new Transition("T1", Active.generateId(2));
// Active has two Places with 5 and 0 jetons
Place P1 = new Place(5, Active.generateId(1));
Place P2 = new Place(0, Active.generateId(1));
Active.ajouterPlace(P1);
Active.ajouterPlace(P2);
// Creer l'arc entrant simple à T1 de P1
Arc_ENTRANT arc = new Arc_entrant_simple(T1, P1, 3, Active.generateId(0));
Active.ajouterArc(arc);
Arc_SORTANT arc_1 = new Arc_SORTANT(T1, P2, 1, Active.generateId(0));
Active.ajouterArc(arc_1);
T1.ajouterArc_ENTRANT(arc);
T1.ajouterArc_SORTANT(arc_1);
Active.ajouterTransition(T1);
// Tirer T1
Active.tirer_transition(String.valueOf(T1.getId()));
Active.afficherReseau();
}
@Test
public void testActiverPetri_8() {
ReseauPetri Active = new ReseauPetri();
Transition T1 = new Transition("T1", Active.generateId(2));
// Active has two Places with 2 and 1 jetons
Place P1 = new Place(2, Active.generateId(1));
Place P2 = new Place(1, Active.generateId(1));
Active.ajouterPlace(P1);
Active.ajouterPlace(P2);
// Creer l'arc entrant simple à T1 de P1 et de P2
Arc_ENTRANT arc = new Arc_entrant_simple(T1, P1, 1, Active.generateId(0));
Active.ajouterArc(arc);
Arc_ENTRANT arc_1 = new Arc_entrant_simple(T1, P2, 1, Active.generateId(0));
Active.ajouterArc(arc_1);
T1.ajouterArc_ENTRANT(arc);
T1.ajouterArc_ENTRANT(arc_1);
Active.ajouterTransition(T1);
// Tirer T1
Active.tirer_transition(String.valueOf(T1.getId()));
Active.afficherReseau();
}
@Test
public void testActiverPetri_9() {
ReseauPetri Active = new ReseauPetri();
Transition T1 = new Transition("T1", Active.generateId(2));
// Active has two Places with 0 and 1 jetons
Place P1 = new Place(0, Active.generateId(1));
Place P2 = new Place(1, Active.generateId(1));
Active.ajouterPlace(P1);
Active.ajouterPlace(P2);
// Creer l'arc sortant de T1 vers P1 et de P2
Arc_SORTANT arc = new Arc_SORTANT(T1, P1, 1, Active.generateId(0));
Active.ajouterArc(arc);
Arc_SORTANT arc_1 = new Arc_SORTANT(T1, P2, 1, Active.generateId(0));
Active.ajouterArc(arc_1);
T1.ajouterArc_SORTANT(arc);
T1.ajouterArc_SORTANT(arc_1);
Active.ajouterTransition(T1);
// Tirer T1
Active.tirer_transition(String.valueOf(T1.getId()));
Active.afficherReseau();
}
@Test
public void testActiverPetri_10() {
ReseauPetri Active = new ReseauPetri();
Transition T1 = new Transition("T1", Active.generateId(2));
// Active has 4 Places with 1 and 1 jetons and 0 and 0 jetons
Place P1 = new Place(1, Active.generateId(1));
Place P2 = new Place(1, Active.generateId(1));
Place P3 = new Place(0, Active.generateId(1));
Place P4 = new Place(0, Active.generateId(1));
Active.ajouterPlace(P1);
Active.ajouterPlace(P2);
Active.ajouterPlace(P3);
Active.ajouterPlace(P4);
// Creer l'arc entrant simple à T1 de P1 et de P2
Arc_ENTRANT arc = new Arc_entrant_simple(T1, P1, 1, Active.generateId(0));
Active.ajouterArc(arc);
Arc_ENTRANT arc_1 = new Arc_entrant_simple(T1, P2, 1, Active.generateId(0));
Active.ajouterArc(arc_1);
// Creer l'arc sortant de T1 vers P3 et de P4
Arc_SORTANT arc_2 = new Arc_SORTANT(T1, P3, 1, Active.generateId(0));
Active.ajouterArc(arc_2);
Arc_SORTANT arc_3 = new Arc_SORTANT(T1, P4, 1, Active.generateId(0));
Active.ajouterArc(arc_3);
T1.ajouterArc_ENTRANT(arc);
T1.ajouterArc_ENTRANT(arc_1);
T1.ajouterArc_SORTANT(arc_2);
T1.ajouterArc_SORTANT(arc_3);
Active.ajouterTransition(T1);
// Tirer T1
Active.tirer_transition(String.valueOf(T1.getId()));
Active.afficherReseau();
}
}
package org.petriNet;// src/test/java/org/petriNet/TransitionTest.java
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class TransitionTest {
private Transition transition;
private List<Arc_SORTANT> arcs_SORTANTS;
private List<Arc_ENTRANT> arcs_ENTRANTS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment