A sophisticated Petri Net simulator built with Python, featuring a modern GUI, parallel processing capabilities, and interactive animations.
This application implements a Petri Net simulator with a graphical user interface. It allows users to create, visualize, and analyze Petri nets, including support for cyclic transitions and parallel state space exploration.
- Modern GUI with Tkinter
- Interactive visualization using Matplotlib
- Real-time token movement animation
- Support for cyclic transitions
- Parallel state space exploration using MPI
- Marking graph generation and visualization
- Transaction history tracking
python >= 3.7
mpi4py
tkinter
matplotlib
networkx
numpy
- Ensure you have Python installed
- Install required packages:
pip install mpi4py matplotlib networkx numpy
- Run the application:
mpiexec -n 2 python main.py
class Place:
def __init__(self, name, tokens=0, pos=(0, 0)):
self.name = name
self.tokens = tokens
self.pos = pos
Represents a place in the Petri net with:
name
: Unique identifiertokens
: Number of tokens in the placepos
: Position coordinates for visualization
class Transition:
def __init__(self, name, inputs, outputs, pos=(0, 0)):
self.name = name
self.inputs = inputs
self.outputs = outputs
self.pos = pos
Represents a transition with:
inputs
: List of input placesoutputs
: List of output places- Methods for checking if enabled and firing transitions
class MarkingGraph:
def __init__(self):
self.nodes = []
self.edges = []
Manages the marking graph structure for state space exploration.
def __init__(self, is_master=True):
self.is_master = is_master
# ... GUI setup code
Sets up the main application window and initializes GUI components.
- Left Panel: Controls for adding places and transitions
- Right Panel: Petri net visualization
- Transaction History: Logs all actions
- Animation Controls: Play/pause/replay functionality
def animate_marking(self, marking_graph):
# Handles token movement animation
- Calculates token movements
- Manages cyclic transitions
- Uses easing functions for smooth animation
def start_exploration(self):
# Parallel exploration of reachable states
- Uses MPI for parallel processing
- Generates marking graph
- Identifies cycles
def update_petri_visualization(self):
# Updates the Petri net display
- Draws places, transitions, and tokens
- Handles dynamic updates
- Manages layout
The animation system uses several components:
- Path calculation between places and transitions
- Easing functions for smooth movement
- Cyclic transition handling
- Frame-by-frame updates
def has_cycle(edges):
# Detects cycles in the marking graph
- Uses NetworkX for cycle detection
- Ensures proper animation of cyclic paths
-
Add Places:
- Enter place name and token count
- Click "Add Place"
-
Add Transitions:
- Enter transition name
- Select input and output places
- Click "Add Transition"
-
Explore Petri Net:
- Click "Explore Petri Net" to start analysis
- View animation of token movements
- Check transaction history
# Load example Petri net
def load_example(self):
# Creates a simple Petri net with cycles
- Uses MPI for state space exploration
- Master-worker architecture
- Load balancing across processes
- Frame-based animation using Matplotlib
- Smooth token movement with easing
- Proper cycle handling
- Dynamic marking updates
- Marking tracking
- Transaction history
- Edge processing for cycles
- Safe animation cleanup
- Process synchronization
- GUI state management
Feel free to submit issues and enhancement requests.