ILP vs. Heuristic Approaches
I’ll create a different discrete optimization example.
Let’s explore the Graph Coloring Problem, which has applications in scheduling, register allocation, and resource assignment.
Graph Coloring Problem
The Graph Coloring Problem involves assigning colors to vertices of a graph such that no adjacent vertices share the same color, while minimizing the total number of colors used.
Mathematical Formulation
Let’s define:
- $G = (V, E)$: An undirected graph with vertices $V$ and edges $E$
- $C$: Set of possible colors
- $x_{iv}$: Binary variable (1 if vertex $i$ is assigned color $v$, 0 otherwise)
- $y_v$: Binary variable (1 if color $v$ is used, 0 otherwise)
The objective function is:
$\min \sum_{v \in C} y_v$
Subject to:
- Each vertex must be assigned exactly one color: $\sum_{v \in C} x_{iv} = 1, \forall i \in V$
- Adjacent vertices must have different colors: $x_{iv} + x_{jv} \leq 1, \forall (i,j) \in E, \forall v \in C$
- If color $v$ is assigned to any vertex, then $y_v = 1$: $x_{iv} \leq y_v, \forall i \in V, \forall v \in C$
- All variables are binary: $x_{iv}, y_v \in {0, 1}$
1 | import numpy as np |
Code Explanation
Let me walk through the key components of this solution:
Problem Setup:
- We generate a random graph with a specified number of vertices and edge probability
- The goal is to color the vertices such that no adjacent vertices share the same color, while minimizing the total number of colors used
Mathematical Model:
- We use PuLP to formulate a binary integer programming model
- Decision variables represent the assignment of colors to vertices and whether each color is used
- The objective function minimizes the total number of colors used
- Constraints ensure:
- Each vertex gets exactly one color
- Adjacent vertices have different colors
- Colors are used in sequence (to break symmetry)
Solution Approaches:
- Optimal method: Integer Linear Programming using PuLP
- Greedy method: A simple sequential coloring heuristic
- DSatur algorithm: A more sophisticated heuristic that prioritizes vertices with the highest saturation degree
Visualizations:
- Colored graph visualizations showing the optimal and heuristic solutions
- A comparison chart of the number of colors used by different algorithms
- Degree distribution and adjacency matrix to understand the graph structure
- An analysis of the relationship between graph density and chromatic number
Results
Graph with 20 vertices and 42 edges Average degree: 4.20 Maximum number of colors needed (worst case): 9 Optimal solution status: Optimal Minimum number of colors needed: 4 Vertex coloring: Vertex 0: Color 0 Vertex 1: Color 2 Vertex 2: Color 1 Vertex 3: Color 2 Vertex 4: Color 1 Vertex 5: Color 1 Vertex 6: Color 3 Vertex 7: Color 0 Vertex 8: Color 0 Vertex 9: Color 3 Vertex 10: Color 2 Vertex 11: Color 1 Vertex 12: Color 0 Vertex 13: Color 2 Vertex 14: Color 0 Vertex 15: Color 3 Vertex 16: Color 1 Vertex 17: Color 1 Vertex 18: Color 2 Vertex 19: Color 1 Number of colors with greedy algorithm: 4 Number of colors with DSatur algorithm: 4 Graph density: 0.221




Results Interpretation
The solution provides several key insights:
Optimal Coloring: The integer programming approach finds the minimum number of colors needed (chromatic number of the graph).
Heuristic Performance: We can see how well the greedy and DSatur heuristics perform compared to the optimal solution.
For many graphs, DSatur performs very well with much less computational effort.Graph Structure Impact: The degree distribution, density, and connectivity patterns of the graph directly affect how many colors are needed.
Theoretical Bounds: We compare the results with Brooks’ bound (maximum degree + $1$) and density-based estimates.
Real-World Applications
The Graph Coloring Problem has numerous practical applications:
Scheduling: Assigning time slots to events, classes, or exams to avoid conflicts.
Frequency Assignment: Allocating radio frequencies to transmitters to avoid interference.
Register Allocation: Assigning variables to CPU registers in compiler optimization.
Map Coloring: Coloring geographical maps such that no adjacent regions share the same color.
Task Assignment: Allocating incompatible tasks to different time slots or resources.
Circuit Board Testing: Minimizing the number of tests needed for a printed circuit board.
Sports Scheduling: Creating tournament schedules where teams must play against each other.
This problem demonstrates how discrete optimization can help solve complex allocation problems where resources must be assigned while respecting conflict constraints.
The comparisons between exact and heuristic methods illustrate the trade-offs between solution quality and computational efficiency that are typical in many real-world optimization scenarios.















is the sample mean.


