potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
603 stars 80 forks source link

Constraints without the knowledge of number of variables #350

Closed Genco2 closed 2 years ago

Genco2 commented 2 years ago

Hello, I am currently working on a ASP project. I have a question about constraints. For example, we have a functer with 3 variables, lets say q(X, Y, Z), and we only want the solutions that includes q(X,Y,Z) no matter what X, Y and Z are equal to. I guess, one of the proper ways to implement is adding the constraint ;

:- not q(_,_,_).

However, my question is, what if we do not the number of variables in the q . Maybe, in some cases, we will have q(X,Y) or q(X,Y,Z,Q). Is there a wildcard that corresponds "Eliminate all the solutions without q with no matter of how many variables it has" ? What are your recommendations for such case ? Thanks. Genco Cosgun

MaxOstrowski commented 2 years ago

There is no such thing as a variable arguments thing in ASP. But this does not matter as it should also not be possible to create predicates q with different arities without knowing of it. So you can have a rule: q(X,Y,Z) :- a(X,Y,Z) in your encoding, but then you know that you might get a q/3 predicate in your solution. If you have a rule: q(X,Y) :- b(X,Y) then you know that you might have q/2 in your solutions. But you always know as you write your encoding rules by hand. I would strongly suggest not to auto-generate rules, as clingo is not make for reading a huge rule set. You should rather generate a set of facts as your instance and have a small, fixed set of rules that then create your constraints wrt. the facts. Then you also always know the possible arities of q.

Genco2 commented 2 years ago

Thanks a lot.