-
Notifications
You must be signed in to change notification settings - Fork 3
[Model] MonochromaticTriangle #883
Description
Motivation
MONOCHROMATIC TRIANGLE (GT6) from Garey & Johnson, A1.1. Decide whether the edges of a graph can be 2-colored avoiding monochromatic triangles, equivalently whether a graph's edge set can be partitioned into two triangle-free subgraphs. NP-complete (Burr 1976) via reduction from 3-Satisfiability. Related to Ramsey theory — R(3,3)=6 means any 2-coloring of K_6 must contain a monochromatic triangle.
Associated rules:
- [Rule] 3-SATISFIABILITY to MONOCHROMATIC TRIANGLE #884: 3-SATISFIABILITY → MonochromaticTriangle (classical NP-completeness proof from G&J)
Definition
Name: MonochromaticTriangle
Reference: Garey & Johnson, Computers and Intractability, A1.1 GT6; Burr 1976
Mathematical definition:
INSTANCE: Graph G = (V,E).
QUESTION: Can E be partitioned into two sets E_1, E_2 such that neither (V,E_1) nor (V,E_2) contains a triangle?
Equivalently: is there a 2-coloring of the edges such that no triangle is monochromatic? Note this is a feasibility problem (no parameter K).
Variables
- Count: |E| (one per edge)
- Per-variable domain: {0, 1} (binary: edge color)
- Meaning: The color assigned to each edge. The coloring must ensure that no three mutually adjacent vertices have all three edges the same color.
Schema (data type)
Type name: MonochromaticTriangle
Variants: graph: SimpleGraph
| Field | Type | Description |
|---|---|---|
graph |
SimpleGraph |
The input graph G = (V,E) |
Notes:
- This is a pure feasibility problem:
Value = Or. No threshold parameter. - Key getter methods:
num_vertices()(= |V|),num_edges()(= |E|). - The variable count is |E| (one binary per edge), not |V|.
dims() = vec![2; num_edges].
Complexity
- Decision complexity: NP-complete (Burr, 1976; transformation from 3-Satisfiability). NP-complete even when the graph is a complete graph K_n.
- Best known exact algorithm: O*(2^m) by brute-force enumeration of all 2-colorings of edges, where m = |E|. Trivially YES when the graph has no triangles. By Ramsey theory, any 2-coloring of K_6 must contain a monochromatic triangle.
- Concrete complexity expression:
"2^num_edges"(fordeclare_variants!) - References:
- S.A. Burr (1976). Cited in Garey & Johnson as the source of the NP-completeness proof via 3-SAT reduction.
Extra Remark
Full book text:
INSTANCE: Graph G = (V,E).
QUESTION: Can E be partitioned into two sets E_1 and E_2 such that neither (V,E_1) nor (V,E_2) contains a triangle?
Reference: [Burr, 1976]. Transformation from 3-SATISFIABILITY.
Comment: NP-complete even when K_n (the complete graph on n vertices) is replaced by any larger complete graph.
How to solve
- It can be solved by (existing) bruteforce. (Enumerate all 2^|E| edge colorings; check each for monochromatic triangles.)
- It can be solved by reducing to integer programming.
- Other:
Example Instance
Positive instance (K_4):
V = {0, 1, 2, 3}, E = {(0,1), (0,2), (0,3), (1,2), (1,3), (2,3)} — 6 edges, 4 triangles.
Assign colors: (0,1)→0, (0,2)→0, (0,3)→1, (1,2)→1, (1,3)→0, (2,3)→0.
- Triangle {0,1,2}: edges 0,0,1 — not monochromatic ✓
- Triangle {0,1,3}: edges 0,1,0 — not monochromatic ✓
- Triangle {0,2,3}: edges 0,1,0 — not monochromatic ✓
- Triangle {1,2,3}: edges 1,0,0 — not monochromatic ✓
Answer: YES — a valid 2-coloring exists.
Negative instance (K_6):
The complete graph on 6 vertices has 15 edges. By Ramsey's theorem, R(3,3) = 6, so any 2-coloring of K_6's edges must contain a monochromatic triangle. Answer: NO.
Python validation script
from itertools import combinations
def has_valid_coloring(n, edges):
triangles = []
edge_set = set(edges)
for tri in combinations(range(n), 3):
a, b, c = tri
if (a,b) in edge_set and (a,c) in edge_set and (b,c) in edge_set:
triangles.append(tri)
edge_list = list(edges)
edge_idx = {e: i for i, e in enumerate(edge_list)}
count = 0
for bits in range(2**len(edge_list)):
color = [(bits >> i) & 1 for i in range(len(edge_list))]
valid = True
for a, b, c in triangles:
c1 = color[edge_idx[(a,b)]]
c2 = color[edge_idx[(a,c)]]
c3 = color[edge_idx[(b,c)]]
if c1 == c2 == c3:
valid = False
break
if valid:
count += 1
return count
# K4: should have valid colorings
k4_edges = [(i,j) for i in range(4) for j in range(i+1,4)]
k4_count = has_valid_coloring(4, k4_edges)
assert k4_count > 0
print(f"K4: {k4_count}/64 valid colorings")
# Verify specific coloring
colors = {(0,1):0, (0,2):0, (0,3):1, (1,2):1, (1,3):0, (2,3):0}
for tri in combinations(range(4), 3):
a, b, c = tri
assert not (colors[(a,b)] == colors[(a,c)] == colors[(b,c)])
print("K4 specific coloring verified")
# K5: should still have valid colorings (R(3,3)=6, so K5 is OK)
k5_edges = [(i,j) for i in range(5) for j in range(i+1,5)]
k5_count = has_valid_coloring(5, k5_edges)
assert k5_count > 0
print(f"K5: {k5_count}/{2**10} valid colorings")
# K6: no valid coloring (R(3,3)=6)
# Too many edges (15) for brute force in Python, but the Ramsey result is standard
print("K6: 0 valid colorings (by Ramsey theory R(3,3)=6)")Metadata
Metadata
Assignees
Labels
Type
Projects
Status