All of the solutions for the zebra puzzle have a variable for each of the properties and a domain with the possible values. For instance A for Nationalities, B for pets, ...

Ai with i = 1..5 and the domain for example {Dutch, Spanish, Italian, French, English}

As I've seen in the n-queens puzzle, there can always be multiple representations for a constraint problem. What could be alternative representations for the zebra puzzle?

For example, I was thinking about following representation:

  • HouseOne indices 1..4 with domain {1,2,3,4,5}
  • HouseTwo indices 1..4 with domain {1,2,3,4,5}
  • HouseThree indices 1..4 with domain {1,2,3,4,5}
  • HouseFour indices 1..4 with domain {1,2,3,4,5}
  • HouseFive indices 1..4 with domain {1,2,3,4,5}

Could this work?

  • 3
    $\begingroup$ What's the zebra puzzle? Also: What properties of the representation are you looking for? Why are you asking? As it stands, this question is not answerable: it does not have an objective answer ("What are the alternative representations...?" has many possible answers, not one answer, and it's not clear how to evaluate a candidate answer -- so it's not an ideal fit for this sort of site). Would you care to make your question more focused somehow? $\endgroup$ – D.W. Dec 3 '13 at 16:58
  • $\begingroup$ As this is computer science, I taught the zebra puzzle wouldn't need any explanation. I'll update the question. Is constraint-programming a suitable subject for this sort of site, because, seriously, it seems more people and more people are only interested in saying what should and shouldn't be on stack instead of answering questions... $\endgroup$ – Lieven Cardoen Dec 3 '13 at 18:26
  • 1
    $\begingroup$ Constraint programming is very suitable for the site! What kind of alternative representations are you looking for? Here's one as SAT, does that count? $\endgroup$ – Juho Dec 3 '13 at 18:47
  • 1
    $\begingroup$ Let me help you improve the question. Why are you looking for an alternative representation? Presumably you don't want just any old alternative; you are hoping for an alternative that is better in some respect. OK, that's fine. So, what sense of "better" do you have in mind? If I suggest an alternative, how will you evaluate it? What criteria or metrics will you use to evaluate an alternative? Without that information, I still don't think this question is a good fit for this site's format. The site pages say to avoid questions where every answer is equally valid. $\endgroup$ – D.W. Dec 3 '13 at 23:58
  • 1
    $\begingroup$ For more about what questions are suitable and how to ask a good question, see also meta.stackexchange.com/q/139618/160917 $\endgroup$ – D.W. Dec 4 '13 at 0:00

One representation is as a constraint program.

Another possible representation is as SAT. One of the key steps in representing this using SAT is to encode "one-out-of-$n$" constraints (where a particular object corresponds to a unique other object, so we need it to correspond to exactly one out of the $n$ possible partners for it); these can be encoded in SAT in multiple possible ways. See Encoding 1-out-of-n constraint for SAT solvers for an overview of some technique for that.

Another possible representation is as an integer linear program (ILP).

Yet another possible representation would be to represent it in the Alloy constraint language. Alloy is especially good when you have many constraint variables that are functions or relations over finite domains, and you need to enforce some constraints on those variables. This looks attractive for the zebra puzzle, because the zebra puzzle involves relationships between (for example) houses and house-owners, and those relations could be encoded as an (unknown) relation or function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.