Directed Graph Generator is a Python library for creating and analyzing directed graphs commonly used in discrete mathematics and graph theory.
- Create directed graphs programmatically
- Visualize nodes and directed connections
- Analyze graph properties (connectivity, circuits, trails)
- Check for strong/weak connectivity
- Determine Eulerian circuits and trails
- Add/remove nodes and connections dynamically
- Export graphs as visual diagrams
pip install directed-graph-generatorOr install from source:
git clone https://github.com/ayushpatwari/Directed-Graph-Generator.git
cd Directed-Graph-Generator
pip install -r requirements.txtfrom directed_graph_generator import DirectedGraph
# Create a directed graph with nodes and connections
nodes = [1, 2, 3, 4]
connections = [(1, 2), (2, 3), (3, 4), (4, 1)]
graph = DirectedGraph(nodes, connections)
# Generate and display the graph
graph.generate_graph()
# Analyze graph properties
print(f"Graph degree: {graph.degree()}")
print(f"Is connected: {graph.isConnected()}")
print(f"Connectivity type: {graph.connectivenessType()}")
print(f"Is Eulerian circuit: {graph.isEuclideanCircuit()}")
print(f"Is Eulerian trail: {graph.isEuclideanTrail()}")# Add a new node
graph.add_node(5)
# Add a new connection
graph.add_connection(1, 5)
# Remove a node (and all its connections)
graph.remove_node(3)
# Remove a specific connection
graph.remove_connection(1, 2)- Strongly Connected: Every node can reach every other node
- Weakly Connected: The underlying undirected graph is connected
- Not Connected: The graph has disconnected components
- Eulerian Circuit: A circuit that visits every edge exactly once
- Eulerian Trail: A trail that visits every edge exactly once
- Degree: Total number of connections in the graph
- Node Management: Add, remove, and modify nodes
- Connection Management: Add, remove, and modify connections
The main class for creating and manipulating directed graphs.
DirectedGraph(nodes: List[int], connections: List[tuple[int, int]])generate_graph(): Displays the graph visualizationdegree(): Returns the total degree of the graphisConnected(): Checks if the graph is connectedconnectivenessType(): Returns connectivity type ("strong", "weak", or "None")isStronlyConnected(): Checks for strong connectivityisWeaklyConnected(): Checks for weak connectivityisEuclideanCircuit(): Checks if graph is an Eulerian circuitisEuclideanTrail(): Checks if graph is an Eulerian trailadd_node(value): Adds a new nodeadd_connection(start, end): Adds a new connectionremove_node(value): Removes a node and its connectionsremove_connection(start, end): Removes a specific connection
- Python 3.9+
- matplotlib
- networkx
- numpy
Contributions are welcome! Please open issues or submit pull requests.
This project is licensed under the MIT License.
