diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..939b0f8e1a8f0dd08bce143f1dc0fed95fa98844 --- /dev/null +++ b/Readme.md @@ -0,0 +1,48 @@ +# PetriNet Project + +## Overview +This project is a Java-based implementation of a **Petri Net** model, a mathematical representation of distributed systems. The project focuses on modeling and simulating various Petri Net components such as **places**, **transitions**, and **arcs**, while also providing functionality to simulate state changes based on these elements. + +## Features +- **Core Components**: + - `Place`: Represents a condition or state in the Petri Net. + - `Transition`: Represents events that can change the state. + - `Arc`: Connects places to transitions or transitions to places. + - `Arc_ENTRANT`: Specific type of arc leading to a transition. + - `Arc_SORTANT`: Specific type of arc leading from a transition. + - `Arc_zero`: A special arc type with specific rules. + - `Arc_videur`: A special arc type with specific rules. + +- **Simulation Features**: + - Add tokens to places. + - Trigger transitions based on firing conditions. + - Simulate the state evolution of the Petri Net. + +- **Validation**: + + - Ensure transitions only fire when conditions are met. + + +## Requirements +- **Java** version 17 or higher. +- Any IDE that supports Java (e.g., IntelliJ IDEA, Eclipse). + +## Installation +1. Clone the repository: + ```bash + git clone https://gitlab-df.imt-atlantique.fr/k23aroui/mapd_file_rouge + cd MAPD_file_rouge +2. Open the project in your favorite IDE. + +## Usage +Running the Project +To execute the simulation: + +- Compile and run the Main class. +- Configure your Petri Net setup in Main.java by specifying: + Places and their initial token counts. + Transitions and the arcs connecting them. + +## Future Enhancements: + +Graphical User Interface: A graphical interface to visualize and interact with Petri nets. \ No newline at end of file diff --git a/src/main/java/org/petriNet/ReseauPetri.java b/src/main/java/org/petriNet/ReseauPetri.java index 5da57000402b648c9ac49400607f3d8103a9a61c..91041755aaa0f76f2a9712909b8d0c34480d8822 100644 --- a/src/main/java/org/petriNet/ReseauPetri.java +++ b/src/main/java/org/petriNet/ReseauPetri.java @@ -194,13 +194,13 @@ public class ReseauPetri implements PetriNetService { * 1 transition * 2 arcs * Liste des places : - * 1 : place avec 4 jetons, 1 arc simple sortant, 0 arc simple entrant - * 2 : place avec 0 jetons, 0 arc simple sortant, 1 arc simple entrant + * 1 : place avec 4 jetons, 1 arc sortant, 0 arc entrant + * 2 : place avec 0 jetons, 0 arc sortant, 1 arc entrant * Liste des transitions * 1 : transition, 1 arc entrant, 1 arc sortant * Liste des arcs : - * 1 : arc simple poids 1 (place avec 4 jetons vers transition) - * 2 : arc simple poids 1 (transition vers place avec 0 jetons) + * 1 : arc poids 1 (place avec 4 jetons vers transition) + * 2 : arc poids 1 (transition vers place avec 0 jetons) */ System.out.println("Réseau de Petri"); @@ -227,7 +227,7 @@ public class ReseauPetri implements PetriNetService { } // entrants / sortants à la place System.out.println(place.getId() + " : place avec " + place.get_nombre_jetons() + " jetons, " - + arcs_ENTRANTS.size() + " arc simple sortant, " + arcs_SORTANTS.size() + " arc simple entrant"); + + arcs_ENTRANTS.size() + " arc sortant, " + arcs_SORTANTS.size() + " arc entrant"); } System.out.println("Liste des transitions :"); @@ -239,10 +239,10 @@ public class ReseauPetri implements PetriNetService { System.out.println("Liste des arcs :"); for (Arc arc : this.arcs) { if (arc instanceof Arc_ENTRANT) { - System.out.println(arc.getId() + " : arc simple poids " + arc.getPoids() + " (" + System.out.println(arc.getId() + " : arc poids " + arc.getPoids() + " (" + "Place d'Id " + arc.getPlace().getId() + " vers " + arc.getTransition().getNom() + ")"); } else { - System.out.println(arc.getId() + " : arc simple poids " + arc.getPoids() + " (" + System.out.println(arc.getId() + " : arc poids " + arc.getPoids() + " (" + arc.getTransition().getNom() + " vers " + "Place d'Id " + arc.getPlace().getId() + ")"); } } diff --git a/src/test/java/org/petriNet/ReseauPetriTest.java b/src/test/java/org/petriNet/ReseauPetriTest.java index 1f4c30cf9d5a8e1f42fdf09c24cbfb438f2b3bb2..f5a8ac18ae790ad895e726c143fdcc7b11ae049b 100644 --- a/src/test/java/org/petriNet/ReseauPetriTest.java +++ b/src/test/java/org/petriNet/ReseauPetriTest.java @@ -605,12 +605,100 @@ public class ReseauPetriTest { assertEquals(0, Destruction.getArcs().size(), "SA1"); } - - - - - - + @Test + @DisplayName("ARC ZERO") + public void testArczero() { + // Initialize the Petri network + ReseauPetri petriNetwork = new ReseauPetri(); + + // Create places + Place place1 = new Place(3, petriNetwork.generateId(1)); + Place place2 = new Place(0, petriNetwork.generateId(1)); + + // Add places to the network + petriNetwork.ajouterPlace(place1); + petriNetwork.ajouterPlace(place2); + + // Create a transition + Transition transition1 = new Transition("T1", petriNetwork.generateId(2)); + + // Add the transition to the network + petriNetwork.ajouterTransition(transition1); + + // Create arcs and add them to the network + // Incoming arc from place2 to transition1 with weight 1 + Arc_zero incomingArc_zero = new Arc_zero(transition1, place2, 1, petriNetwork.generateId(0)); + petriNetwork.ajouterArc(incomingArc_zero); + transition1.ajouterArc_ENTRANT(incomingArc_zero); + + // Outgoing arc from transition1 to place1 with weight 1 + Arc_SORTANT outgoingArc = new Arc_SORTANT(transition1, place1, 1, petriNetwork.generateId(0)); + petriNetwork.ajouterArc(outgoingArc); + transition1.ajouterArc_SORTANT(outgoingArc); + + // Display the initial state of the Petri network + System.out.println("Initial State of Petri Network:"); + petriNetwork.afficherReseau(); + + // Activate the transition + System.out.println("\nActivating transition T1..."); + petriNetwork.tirer_transition(String.valueOf(transition1.getId())); + + // Display the state of the Petri network after activation + System.out.println("\nState of Petri Network after Transition T1 Activation:"); + petriNetwork.afficherReseau(); + + // Assertions to verify the correct state of the Petri network + assertEquals(4, place1.get_nombre_jetons(), "Tokens in Place 1 should be 4"); + assertEquals(0, place2.get_nombre_jetons(), "Tokens in Place 2 should be 0"); + } + @Test + @DisplayName("ARC Videur") + public void testArcvideur() { + // Initialize the Petri network + ReseauPetri petriNetwork = new ReseauPetri(); + + // Create places + Place place1 = new Place(2, petriNetwork.generateId(1)); + Place place2 = new Place(4, petriNetwork.generateId(1)); + + // Add places to the network + petriNetwork.ajouterPlace(place1); + petriNetwork.ajouterPlace(place2); + + // Create a transition + Transition transition1 = new Transition("T1", petriNetwork.generateId(2)); + + // Add the transition to the network + petriNetwork.ajouterTransition(transition1); + + // Create arcs and add them to the network + // Incoming arc from place2 to transition1 with weight 1 + Arc_videur incomingArc_videur = new Arc_videur(transition1, place2, 1, petriNetwork.generateId(0)); + petriNetwork.ajouterArc(incomingArc_videur); + transition1.ajouterArc_ENTRANT(incomingArc_videur); + + // Outgoing arc from transition1 to place1 with weight 1 + Arc_SORTANT outgoingArc = new Arc_SORTANT(transition1, place1, 1, petriNetwork.generateId(0)); + petriNetwork.ajouterArc(outgoingArc); + transition1.ajouterArc_SORTANT(outgoingArc); + + // Display the initial state of the Petri network + System.out.println("Initial State of Petri Network:"); + petriNetwork.afficherReseau(); + + // Activate the transition + System.out.println("\nActivating transition T1..."); + petriNetwork.tirer_transition(String.valueOf(transition1.getId())); + + // Display the state of the Petri network after activation + System.out.println("\nState of Petri Network after Transition T1 Activation:"); + petriNetwork.afficherReseau(); + + // Assertions to verify the correct state of the Petri network + assertEquals(3, place1.get_nombre_jetons(), "Tokens in Place 1 should be 3"); + assertEquals(0, place2.get_nombre_jetons(), "Tokens in Place 2 should be 0"); + } }