A graph coloring-based helper tool for planning timetables at university.
- Create and name nodes: Represent events, courses, or resources as nodes.
- Create and name edges: Add edges between nodes with a comment describing the relationship or conflict (e.g., "overlap", "conflict").
- Automatic graph coloring: The tool assigns colors to nodes so that no two connected nodes share the same color, minimizing the total number of colors used.
- Visualization: Visualize the graph with colored nodes and labeled edges using matplotlib and networkx.
- JSON input: Define your graph structure in a JSON file for easy editing and sharing.
-
Install dependencies
pip install -r requirements.txt -
Prepare your graph data
Create agraph.jsonfile in the project directory.
Example:{ "nodes": ["A", "B", "C"], "edges": [ {"from": "A", "to": "B", "name": "A and B overlap"}, {"from": "B", "to": "C", "name": "B and C conflict"}, {"from": "A", "to": "C", "name": "A and C are related"} ] }You can also use the provided
graph.json.exampleas a template. -
Run the program
python app.py -
Example output
The script prints the color assignment for each node and the number of colors used, and displays a visualization of the graph.
g = Graph()
g.add_node("A")
g.add_node("B")
g.add_node("C")
g.add_edge("A", "B", "A and B overlap")
g.add_edge("B", "C", "B and C conflict")
g.add_edge("A", "C", "A and C are related")
coloring, num_colors = g.color_graph()
print("Coloring:", coloring)
print("Number of colors used:", num_colors)
g.visualize(coloring)- Python 3.7+
- matplotlib
- networkx
MIT License