2

I have written a few implementations of Wave Function Collapse based on the README of this repo.

My understanding is that the state of each position during the computation is a superposition (set) of tiles that could be placed there, and still follow the constraints.

The README notes that sometimes the algorithm will encounter a contradiction, and cannot continue. My implementations show this.

Given a set of constraints that is solvable, my question is:

Because the state of each position is a superposition of states that would be allowed in that position, how could this cause a contradiction?

All the states that could be chosen for collapse could work, or else they would not be part of the superposition. How could they cause a contradiction if they follow the constraints?

nph
  • 83
  • 5

2 Answers2

4

I think it's best to think through a specific simple example. Here is a diagram showing exactly how the algorithm fails. This is in Figure 3.5 of my PhD dissertation. The Wave Function Collapse algorithm is based on the Model Synthesis Algorithm which is based on AC-4 which stands for "Arc Consistency". All the algorithm guarantees is that there is a consistent path or arc between all of the values.

Here is a simple diagram:

Failure case diagram

The wave function is shown in (d). If we select the 1 label in the bottom right corner, the algorithm will fail. But notice that there is a valid path from the 1 label to every single label in the diagram. Two of these paths are shown in (h) and (i). Each of those paths is a consistent paths from the 1 label to the 2 labels. But those paths are inconsistent with each other and cannot both be simultaneously true as they put a 3 label and 7 label in the same spot.

So why not come up with an algorithm that only allows valid possibilities? Unfortunately, that has been shown to be an NP-hard problem; see Theorem 3.3.4 of my dissertation. This means it would be extremely slow to construct such an algorithm.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • can you define constrains in a way that the algorithm is guaranteed to find a solution? under which conditions we can make such an assumption? – benez Aug 29 '22 at 20:20
  • @benez Yes, absolutely. Some inputs even pretty complicated ones never fail. In Section 3.3.7 of my dissertation I give a step-by-step procedure you can follow that can guarantee your input will not fail. However, while it can detect that some inputs are infallible, but I'm not sure it detects every infallible input. Also sometimes, you can convert an input that fails into an infallible input that's equivalent (Sec. 3.3.8). Also, there is a very good way to deal with failures. You divide the problem into subproblems. Instead of creating all at once you create it in pieces (Sec. 3.3.6). – paulMerrell Aug 30 '22 at 21:52
1

It's because the constraints you apply are local constraints, meaning that during the process of removing patterns from the superposition of patterns you are only taking into considering the local neighbors that have an overlap, but you never actually consider whether a superposition of patterns is valid globally.

Patterns that line up in a local neighborhood for example, don't necessarily need to line up with other parts on the map. It may seem like it should since you've propagated which patterns are supposedly possible, but here again, each propagation step only considers local constraints.