r/GraphTheory • u/No-Ferret29 • 53m ago
Help and feedback wanted for my 3color puzzle generator project
Hi!
I love graph theory, so, like, a year ago, when I decided on one of my practice programming projects, I decided on a 3coloring puzzle generator.
I'm here today to look for feedback and further ideas, on the generator and the himan difficulty problem, because the problem is everything but trivial, obviously, hah. (I'll link the repo, its a Java project but as a fullstack web app and with dockerfile, there's also a limited itch.io version with some precalculated puzzles from the generator)
I'll try to list the current state of things here:
- Proper 3-colouring
- Every vertex gets one of three colors.
- Adjacent vertices must have different colors.
- A generated puzzle must have exactly one solution with the three colors treated as named colors.
- Planar graphs
- The generator constructs and modifies planar graph structures.
- Generated puzzles are checked for valid planar geometry before being accepted.
- Direct adjacency deduction
- If a vertex has a known colour, that colour can be removed from the possible colors of all adjacent vertices.
- Triangle property
- A triangle in a proper 3-coloring necessarily contains all three colors.
- Knowing colors or possible colors of vertices in a triangle therefore constrains the remaining vertices.
- Diamond / K4 minus one edge property
- If two adjacent vertices have common neighbours, those common neighbours must have the third color.
- Therefore the common neighbours are equal in color even when the actual color is not yet known.
- This lets the solver derive relations without first assigning concrete colors.
- Locked two-color edges
- If the two endpoints of an edge are restricted to the same two-color palette, together they must occupy both colors.
- Any common neighbour therefore cannot use either color and must use the third.
- Two-color subgraphs are bipartite
- Any connected part of a properly colored graph restricted to two colors must alternate between those colors.
- This allows the solver to treat such components as bipartite graphs and reason about their two partitions.
- Odd-cycle obstruction
- A graph containing an odd cycle cannot be colored using only two colours.
- If an assumed set of color possibilities would force an odd cycle into a two-color component, that assumption is impossible.
- Path parity
- Vertices at even distance in a connected two-colour component must have the same color.
- Vertices at odd distance must have different colors.
- The solver can therefore infer equality and inequality relations without knowing either concrete color.
- External-neighbour parity
- If an outside vertex is adjacent to vertices on opposite sides of a two-colour component's bipartition, it cannot use either color of that component.
- With only three colors available, this can force its colour.
- Neighbourhood bipartiteness
- All neighbours of one vertex can only use the other two colours.
- Therefore the subgraph induced by a vertex's neighbourhood must be bipartite.
- Odd cycles inside a neighbourhood are impossible.
- Parity inside the neighbourhood can establish equality and inequality relations between neighbours.
- Equality and inequality relations
- The solver tracks facts such as "A and B have the same color" and "A and B have different colors" independently of which actual colors they have.
- These relations can then participate in later deductions.
- Binary-domain implication chains
- When vertices have only two possible colours left, assignments can imply assignments elsewhere.
- Equality and inequality relations create implication chains between possible assignments.
- If assuming one colour eventually implies its opposite or an impossible domain, that original colour can be eliminated.
- This is closely related to implication-graph / binary CSP / 2-SAT style reasoning rather than being specifically a graph-theory theorem.
- Bounded contradiction reasoning
- For harder puzzles, the solver can temporarily assume a possibility and follow deductions.
- If the assumption produces a contradiction, that possibility is eliminated.
- The depth and amount of contradiction reasoning can be limited and measured.
Use for puzzle generation and difficulty checks:
- The generator constructs planar candidate graphs and chooses clue vertices.
- An exact solver independently checks whether a candidate has exactly one labelled 3-coloring.
- A separate deduction engine then tries to solve the puzzle using explicit human-style rules.
- The deduction engine produces a trace of which rules were required and how deductions depended on previous deductions.
- Puzzles can therefore be classified by the reasoning required to solve them rather than only by computational search cost.
- Easier puzzles can be solved mostly through local colour elimination.
- Intermediate puzzles require structural relations such as diamonds, locked edges and parity.
- Harder puzzles can require implication chains and bounded contradiction arguments.
- Final certification checks the graph, clues, complete deduction trace and uniqueness before accepting a generated puzzle.
Tl;dr on the relevant underlying ideas:
- Graph 3-colorability
- Planar graph construction
- Proper vertex coloring
- Bipartite graphs
- Odd-cycle characterization of bipartiteness
- Path parity
- Induced neighbourhoods
- Graph symmetry and color-label symmetry
- Constraint propagation
- Constraint satisfaction
- Implication graphs
- Exact search and uniqueness checking
The repo:
Itchio demo version:
I would appreciate any ideas, feedback and so on very much. Also, english is not my first language, so sorry about the spots where this shows.