I have many variable-sized lists containing instances of the same class with attribute foo, and for every list I must apply rules like:
- if there's an element foo=A there cannot be elements with foo in [B,C,D]
- if there's an element foo=X there must by at least one with foo in [Y,Z]
- there can be between MIN and MAX elements foo=BAR
combining the above three rules is probably enough to express any similar constraint I'll ever need. It's something like dependency checking in software packages but I have quantities and lack versions :)
a naïve approach would be:
R_CONFLICT={ A: [B,C,D] }
R_DEPENDS ={ X: [ [Y,Z], W, .. } # means: A depends on either Y or Z, and W
R_MIN ={BAR: n, BAZ: m}
R_MAX ={BAR: o, BAZ: p}
# now just loop over lists to check them..
Is this a problem of Constraint programming? I don't actually need to solve something to get a result, I need to validate my list against some constraints and check if they are satisfied or not. How would you classify this problem and how would you solve it?
For what it's worth, I'm coding in Python, but I welcome a generic programming answer :) If it turns out I must delve in constraint programming I'll probably start by trying python-constraint.