How to return models from s(CASP)?

I’m using the latest stable version of swipl and the latest version of the s(CASP) library.

In the Ciao implementation of s(CASP), a query returns bindings, an explanation tree, and a model, which is a minimum set of predicates that do (or must, for abductive reasoning) hold for the model to be stable. I think (?) the model is just the same set of terms used in the justification tree, without the tree structure.

I’m just wondering if there is a convenient way to get that set model structure from the SWI-Prolog implementaiton of s(CASP), too, or if I need to collect unique terms from the justification.

My use case is that I am doing abductive queries that return multiple models, each of which represents a possible stable model for the query. I need to be able to get the union of all of the models, find terms that are present in all models, find terms that are present only alongside other terms, things like that.

Thanks in advance!

1 Like

Both the model and the justification tree can be obtained from the model and tree output options of scasp/2, for example:

?- [library(scasp)].
true.

?- [user].
|: p(X) :- not q(X).
|: q(X) :- not p(X).
|: ^D% user://1 compiled 0.00 sec, 2 clauses
true.

?- scasp(p(X), [model(Model), tree(Tree)]).
Model = [p(X), not q(X)],
Tree = query-[p(X)-[(not q(X))-[chs(p(X))-[]]]].

And here’s another example with abduction and multiple generated models:

?- scasp(flies(X), [model(Model)]).
X = sam,
Model = [not ab(sam), bird(sam), flies(sam), o_ab(sam), o_penguin(sam), o_wounded_bird(sam), not penguin(sam), not wounded_bird(...)] ;
X = tweety,
Model = [not ab(tweety), bird(tweety), flies(tweety), o_ab(tweety), o_penguin(tweety), o_wounded_bird(tweety), not penguin(tweety), not wounded_bird(...)] ;
X = john,
Model = [not ab(john), bird(john), flies(john), o_ab(john), o_penguin(john), o_wounded_bird(john), not penguin(john), not wounded_bird(...)] ;
false.

Maybe this facility can suite your needs?

3 Likes

That’s exactly what I needed, thank you @oskardrums.