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

README with Main and Test descriptions

parent 4c4ffea7
Branches
No related tags found
No related merge requests found
# PetriNet Project # Petri Net
## Overview ## Petri Net Simulator
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 ### Overview
This project provides an implementation of a Petri Net,
a mathematical model used to represent and simulate systems with discrete events.
The primary components of a Petri Net are places, transitions, and arcs.
Places hold tokens, transitions are fired to modify the state of the system, and arcs define the
relationships between places and transitions. The system allows users to define a network of places,
transitions, and arcs, and then fire transitions to simulate the system behavior.
### Features
- **Core Components**: - **Core Components**:
- `Place`: Represents a condition or state in the Petri Net. - `PetriNet`: Represents the Petri Net.
- `Transition`: Represents events that can change the state. - `Place`: Represents a container of tokens.
- `Transition`: Represents events triggered based on the token conditions in connected places.
- `Arc`: Connects places to transitions or transitions to places. - `Arc`: Connects places to transitions or transitions to places.
- `Arc_ENTRANT`: Specific type of arc leading to a transition. - `IncomingArc_Simple`: Transfers tokens based on a weight.
- `Arc_SORTANT`: Specific type of arc leading from a transition. - `IncomingArc_Videur`: Removes all tokens from a place when fired.
- `Arc_zero`: A special arc type with specific rules. - `IncomingArc_Zero` : Fires only when the connected place has no tokens.
- `Arc_videur`: A special arc type with specific rules. - `OutgoingArc`: Adds tokens to a place after a transition is fired.
- **Simulation Features**: - **Simulation Features**:
- Add tokens to places. - Add tokens to places.
...@@ -23,18 +31,18 @@ This project is a Java-based implementation of a **Petri Net** model, a mathemat ...@@ -23,18 +31,18 @@ This project is a Java-based implementation of a **Petri Net** model, a mathemat
- Ensure transitions only fire when conditions are met. - Ensure transitions only fire when conditions are met.
## Requirements ### Requirements
- **Java** version 17 or higher. - **Java** version 17 or higher.
- Any IDE that supports Java (e.g., IntelliJ IDEA, Eclipse). - Any IDE that supports Java (e.g., IntelliJ IDEA, Eclipse).
## Installation ### Installation
1. Clone the repository: 1. Clone the repository:
```bash ```bash
git clone https://gitlab-df.imt-atlantique.fr/k23aroui/mapd_file_rouge git clone https://gitlab-df.imt-atlantique.fr/k23aroui/mapd_file_rouge
cd MAPD_file_rouge cd MAPD_file_rouge
2. Open the project in your favorite IDE. 2. Open the project in your favorite IDE.
## Usage ### Usage
Running the Project Running the Project
To execute the simulation: To execute the simulation:
...@@ -43,6 +51,64 @@ To execute the simulation: ...@@ -43,6 +51,64 @@ To execute the simulation:
Places and their initial token counts. Places and their initial token counts.
Transitions and the arcs connecting them. Transitions and the arcs connecting them.
## Future Enhancements: ### Future Enhancements:
Graphical User Interface: A graphical interface to visualize and interact with Petri nets.
## Tests for PetriNet Implementation
The PetriNetTest class contains a comprehensive suite of unit tests that verify the correctness
and functionality of the PetriNet system. These tests are organized to validate the key components and
operations of a Petri Net, including places, transitions, arcs, and their interactions.
Below is a detailed description of the test cases:
### Basic Place Operations :
- **testAddTokens**: Verifies that tokens can be added to a place.
- **testRemoveTokens**: Verifies that tokens can be removed from a place.
### Network Structure Management
- **testAddPlace**: Verifies that places can be added only once to the Petri Net.
- **testAddTransition**: Verifies that transitions can be added uniquely to the Petri Net.
- **testAddArc**: Validates the addition of arcs, including handling of negative weights and duplicate arcs.
### Petri Net Assembly
- **testAssemblePetri**: Constructs a full Petri Net representing a Mutex system with places, transitions, and arcs. This test ensures:
- Places and transitions are uniquely added.
- The correct number of arcs, places, and transitions are present.
- Complex connections and token flows are correctly assembled.
### Activation and Transition Firing
Tests under this category simulate the firing of transitions and observe token dynamics across the Petri Net:
- **testActivatePetri_1 (RI)**: Tests firing a transition in a simple network with one transition. The result expects the Petri Net to be in the same state after firing.
- **testActivatePetri_2 (RD0)**: Verifies that firing a transition does not remove tokens if the input place has insufficient tokens.
- **testActivatePetri_3 (RD1)**: Tests token reduction when a transition fires with sufficient tokens in the input place.
- **testActivatePetri_4 (RD2)**: Checks for correct token reduction when the input place has more tokens than the arc weight.
- **testActivatePetri_5 (RG0)**: Ensures tokens are added to the output place when a transition fires.
- **testActivatePetri_6 (RM0)**: Simulates token transfer between two places via a transition.
- **testActivatePetri_7 (RM1)**: Validates token transfer where input and output arcs have different weights.
- **testActivatePetri_8 (RGM)**: Tests transitions with multiple input places.
- **testActivatePetri_9 (RDM)**: Simulates transitions with multiple output places.
- **testActivatePetri_10 (RDGM)**: Combines multiple inputs and outputs to validate a complex firing scenario.
### Removal of different components of the Petri Net
- **testRemoveTransition_0 (ST0)** : Validates that a transition can be removed from the Petri Net
After the removal, the transition list size should be zero, and the network structure is updated accordingly.
- **testRemovePlace (SP1)** : Tests the removal of a place from the Petri Net, ensuring that related arcs are also
removed while leaving unrelated transitions intact.
- **testRemoveTransition_1 (ST1)** : Validates the removal of a transition along with its associated arcs while leaving unrelated places intact.
- **testRemoveArc (SA1)** : Ensures that a specific arc can be removed from the Petri Net while keeping its associated places and transitions intact.
### Additional Tests for the specific incoming arc types
Graphical User Interface: A graphical interface to visualize and interact with Petri nets. - **testIncomingArcVideur (SAV)** : Validates the behavior of the IncomingArc_Videur class by removing all tokens from a place when the connected transition fires.
\ No newline at end of file - **testIncomingArcZero (SAZ)** : Tests the IncomingArc_Zero class to ensure that the transition fires only when the connected place has zero tokens.
package org.petriNet;
public class MainPetriNet {
public static void main(String[] args) {
// Create a Petri net
PetriNet reseauPetri = new PetriNet();
// Create places
Place p1 = new Place(1, reseauPetri.generateId(1));
Place p2 = new Place(2, reseauPetri.generateId(2));
Place p3 = new Place(3, reseauPetri.generateId(3));
// Create transitions with empty Arcs_ENTRANT and Arcs_SORTANT
Transition t1 = new Transition("t1", reseauPetri.generateId(2));
Transition t2 = new Transition("t2", reseauPetri.generateId(2));
// Create arcs
IncomingArc a1 = new IncomingArc_Simple(t1, p1, 1, reseauPetri.generateId(0));
OutgoingArc a2 = new OutgoingArc(t1, p2, 1, reseauPetri.generateId(0));
IncomingArc a3 = new IncomingArc_Simple(t2, p2, 1, reseauPetri.generateId(0));
OutgoingArc a4 = new OutgoingArc(t2, p3, 1, reseauPetri.generateId(0));
// Add arcs to transitions
t1.addIncomingArc(a1);
t1.addOutgoingArc(a2);
t2.addIncomingArc(a3);
t2.addOutgoingArc(a4);
// Add a place to each arc
a1.setPlace(p1);
a2.setPlace(p2);
a3.setPlace(p2);
a4.setPlace(p3);
// Add places and transitions to the Petri net
reseauPetri.addPlace(p1);
reseauPetri.addPlace(p2);
reseauPetri.addPlace(p3);
reseauPetri.addTransition(t1);
reseauPetri.addTransition(t2);
// Display the Petri net
reseauPetri.displayState();
}
}
\ No newline at end of file
...@@ -595,8 +595,8 @@ public class PetriNetTest { ...@@ -595,8 +595,8 @@ public class PetriNetTest {
} }
@Test @Test
@DisplayName("ARC ZERO") @DisplayName("SAV")
public void testArcZero() { public void testIncomingArcVideur() {
// Initialize the Petri network // Initialize the Petri network
PetriNet petriNetwork = new PetriNet(); PetriNet petriNetwork = new PetriNet();
...@@ -643,8 +643,8 @@ public class PetriNetTest { ...@@ -643,8 +643,8 @@ public class PetriNetTest {
} }
@Test @Test
@DisplayName("ARC Videur") @DisplayName("SAZ")
public void testArcVideur() { public void testIncomingArcZero() {
// Initialize the Petri network // Initialize the Petri network
PetriNet petriNetwork = new PetriNet(); PetriNet petriNetwork = new PetriNet();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment