I have an application that constructs random images based on constraints. Different colored pixels are randomly selected and placed in a grid that satisfy all constraints. For example (simplifying), there might be a constraint that says if a blue or green pixel is at (0,-1), and red pixels are at (-1,-1) and (-1, 0), then placing a white pixel is prohibited. These coordinates are vectors from the current placement location (i.e. its neighborhood).
Right now I am storing the constraints in an array and looping through them, checking to see if each one is applicable or not. I have to do this for each pixel I place in the grid. So the performance suffers as more constraints are added. Also, it is possible for two constraints to be in conflict but it is not easy to check for that.
I'm thinking that a graph type data structure (tree?) might be a way to store all of the constraints such that I can quickly determine from the pixel neighborhood which (if any) constraints apply. But I can't quite figure out how to make such a structure work, given that a single coordinate can contain multiple colors, and how to tie a set of coordinate/colors to set of prohibited pixel colors. Any ideas?