Sure, here is a README file for your Eulerian Graph Generator script:
This script generates a random Eulerian graph with a given number of vertices and attempts to find the Eulerian path or circuit within it. The Chinese Postman Problem is a famous problem in graph theory. The problem is to find the shortest path or circuit that visits every edge of a graph. This script provides a solution by generating a random Eulerian graph and finding the Eulerian path or circuit within it.
Elliot Yun
April 23, 2024
To run this script, you need the following Python packages:
networkx
matplotlib
numpy
You can install these packages using pip
:
pip install networkx matplotlib numpy
-
Clone the Repository:
git clone https://github.com/yourusername/postman-graph-visualizer.git cd chinesepostman
-
Run the Script:
python chinesepostman.py
You will be prompted to enter the number of houses (vertices) for the postman to travel to.
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
These imports include necessary libraries for graph generation, plotting, and numerical operations.
Generates a sequence of even integers, representing degrees of vertices in a graph.
Creates and displays an Eulerian graph from a given degree sequence.
Determines if the graph has an Eulerian circuit or path and returns it.
Draws the Eulerian path or circuit on the graph.
The main
function drives the script by:
- Asking the user for the number of houses (vertices).
- Generating an even degree sequence.
- Creating and displaying an Eulerian graph.
- Finding the Eulerian path or circuit.
- Drawing the Eulerian path or circuit if it exists.
Here is a brief example of how the script might run:
Welcome to the Chinese Postman Problem Solver, which is a Eulerian circuit based graph solver.
...
How many houses do you want the postman to travel to? 10
The number of routes that leads to each house is: [2 4 2 2 4 2 2 4 4 4]
Creating Eulerian graph...
Eulerian graph created...
The graph has an Eulerian Circuit, which means it has a Eulerian Path.
[(0, 2), (2, 5), (5, 1), (1, 6), (6, 3), (3, 0), (0, 7), (7, 4), (4, 0)]
Eulerian path/circuit: [(0, 2), (2, 5), (5, 1), (1, 6), (6, 3), (3, 0), (0, 7), (7, 4), (4, 0)]
- The script uses a fixed seed for the random number generator to ensure reproducibility. You can change the seed if you want different random graphs.
- The script uses NetworkX's
eulerize
method to ensure the graph is Eulerian.