I'm currently working on the Einstein riddle. For those who don't know it: https://udel.edu/~os/riddle.html I have to implement a constraintSolver and my task now is to model the riddle specific constraints and the problem itself and then give the problem into it.
My current plan is to set a value, check all constraints - and if it's still consistent, continue, else use backtracking and continue with something else.
In my backtracking algorithm, I just iterate through the list of domains, in it iterate over the addresses (indices) and in these, iterate over the possible domain-specific values.
The Einstein riddle, however, has 5 domains: colors, nationality, animals, etc
for example : (Domain is just an empty interface)
public enum Colors implements Domain{
RED, BLUE, GREEN;
}
public enum Animals implements Domain{
CAT, DOG, HORSE;
}
[...]
List<List<Domain>> domains = new ... ;
List<Colors> colors = ...
[...]
domains.add(colors)
I thought, using this variant in my backtracking algorithm I wouldn't have to care about the type of the specific domain. However, I can't add the list of colors to the list of domains.
I also tried it with a wildcard - however this doesn't work either. And I don't really like the idea of working just with strings.
Is there a way of getting this to work? (If my general idea is stupid, please tell me, too, but my main question is, if you can abstract the enums so that you can put lists of specific enums in a list of an interface for these enums.
Thanks for any feedback :)
>`. [A `List` is **not a** `List`](https://stackoverflow.com/questions/2660827/java-generics-covariance).
– Boris the Spider Jun 12 '16 at 12:58>` should be **very odd**. You have a `List` where your `List<...>` _is a_ `Domain`.
– Boris the Spider Jun 12 '16 at 13:20