-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Proposal: Conflict Resolution Optimization Inspired by Physical Locality Principles #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Your guidance would be immensely valuable for my undergraduate thesis. I sincerely hope to receive your feedback and would be deeply grateful for your insights! |
Hi! What do you mean by "layers" exactly? Have you implemented this algorithm? |
I have an implementation using C++, and its class diagram is as follows Details are as follows: WFC Algorithm System ImplementationModular Design & Core ComponentsThe WFC system architecture adopts a modular design, primarily consisting of the following core components: 1. Foundational Definitions (WFCutil.h)
// Core types and data structures
using CellID = Cell *;
template <typename EdgeData>
using TileID = Tile<EdgeData> *;
using EdgeID = GraphEdge *;
using Cells = std::vector<CellID>; 2. Grid System (GridSystem.h)
class GridSystem {
protected:
CellMap cells_;
CellData edgelist_;
public:
void CreateEdge(CellID cellA, CellID cellB);
int getCellsNum();
Cells getNeighbor(CellID id);
virtual void buildGridSystem() = 0;
}; 3. Tile Set (TileSet.h)
class TileSet {
private:
Tiles tiles_;
public:
virtual void buildTileSet() = 0;
virtual bool judgePossibility(std::vector<Tiles> neighborPossibility,
TileID<EdgeData> possibility) = 0;
}; 4. WFC Manager (WFCManager.h)
class WFCManager {
private:
GridSystem* grid_;
TileSet<EdgeData>* tileSet_;
int completedCellCount;
CellID minEntropyCell;
public:
virtual void initialize() = 0;
bool isComplete();
void run();
// Conflict resolution methods
void resolveConflicts();
bool retrospectiveGetSolution(const Cells& layer, int index);
}; Conflict Resolution ImplementationThe system implements layer-based conflict resolution: // Backtracking function for conflict resolution
bool retrospectiveGetSolution(const Cells& layer, int index) {
if (index >= layer.size()) {
// Validate all cells in the layer
for (CellID cell : layer) {
if (wfcCellData[cell].possibility.empty()) {
return false;
}
}
return true;
}
CellID currentCell = layer[index];
Tiles originalPossibilities = wfcCellData[currentCell].possibility;
for (TileID tile : originalPossibilities) {
// Try different tile selections and propagate constraints
cellData.possibility = { tile };
propagateEffects(currentCell);
if (retrospectiveGetSolution(layer, index + 1)) {
return true; // Solution found
}
// Backtrack: Restore state
cellData.possibility = savedPossibilities;
}
return false;
}
// Layered conflict resolution
void resolveConflictsCell(Cells& currentLayer, Cells& visited, int depth) {
// Attempt resolution in current layer
bool solved = retrospectiveGetSolution(currentLayer, 0);
// Recursive expansion if unresolved
if (!solved) {
Cells nextLayer = collectNextLayer(currentLayer, visited);
if (!nextLayer.empty()) {
resolveConflictsCell(nextLayer, visited, depth + 1);
} else {
throw std::runtime_error("Conflict unresolvable: Maximum backtrack depth reached");
}
}
} |
I will organize this code repository after completing my graduation thesis and upload it to GitHub. |
Hi mxgmn,
First, I want to express my deep admiration for the Wave Function Collapse algorithm. Its elegance in merging constraint solving with procedural generation is truly inspiring.
Background & Motivation
My optimization idea stems from a philosophical analogy between WFC and quantum systems:
This leads to a key insight: Most conflicts in WFC can be resolved locally without global backtracking.
Schematic (Mermaid)
It should be noted that this approach offers significant advantages.
First, let’s discuss time complexity. Consider an isolated conflicting cell: in a traditional backtracking approach, we might revert many unnecessary cells. By adopting a layer-by-layer strategy — treating the conflict cell as an uncertainty and iteratively expanding outward — we observe that as we mark cells in outer layers as uncertain, the possibilities for the central conflict cell grow exponentially. Crucially, our layer-wise expansion of the "uncertainty zone" focuses computational effort precisely where it matters most for conflict resolution (though further optimizations remain possible).
Second, I hypothesize that the maximum layer depth (is my
fix(wfc:T)
parameter) is constrained by the inherent properties of the tile set and grid system. By abstracting my library into three components — tile set definitions, grid system configurations, and the WFC process — I argue that for any well-defined WFC system, this layer depth has an intrinsic upper bound. This property allows us to:
You can reach me at:
Thank you for your time and pioneering work!
The text was updated successfully, but these errors were encountered: