Iterator able to verify, but not able to compute #6
-
Hi Dirk, I have below program, which I want to use to solve a group allocation problem. The program is not yet completely defined, but already in some intermediate step I get unexpected results. I don't think its a problem with the package, but rather in the way I define my rules. Best, library(logician)
# I want to solve a group allocation problem
# there are two groups "upper", "lower"
# group sizes should differ no more then 1
# there are rules that must be obeyed, e.g.
# sibblings must be allocated to the same group
database <- logician_database(
person(bart),
person(homer),
person(marge),
person(maggie),
person(lisa),
# sibblings
sibblings(bart, maggie),
sibblings(X,Y) := sibblings(Y,X),
# groupes
group(upper),
group(lower),
# abstract group-definition
person_in_group(bart, upper),
person_in_group(X, A) := person(X) && group(A) && sibblings(X,Y) && person_in_group(Y, A)
)
iter <- logician_query(database = database, question = person_in_group(X,upper))
# only returns bart, but expect also maggie
iter$next_value()
iter <- logician_query(database = database, question = person_in_group(maggie,upper))
# returns true, so the logic works, but the above iterator doesn't find it
iter$next_value() |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
P.S.: It's not purely academic. Something like this could be used in schools or kindergarten for defining cohorts in a pandemic contact reduction scheme. But I am not sure Prolog/ logician are the right tools to solve this with. |
Beta Was this translation helpful? Give feedback.
-
Here is the same thing in SWI Prolog. Suffers from the same problem. This indicates that I should invest more time understanding prolog... person(bart).
person(homer).
person(marge).
person(maggie).
person(lisa).
% sibblings
sibblings(bart, maggie).
sibblings(X,Y) :- sibblings(Y,X).
% groupes
group(upper).
group(lower).
% abstract group-definition
person_in_group(bart, upper).
person_in_group(X, A) :- person(X), group(A), sibblings(X,Y), person_in_group(Y, A). Output: ?- person_in_group(X,upper).
X = bart .
?- person_in_group(maggie,upper).
true . |
Beta Was this translation helpful? Give feedback.
-
Something like that?
library(logician)
# I want to solve a group allocation problem
# there are two groups "upper", "lower"
# group sizes should differ no more then 1
# there are rules that must be obeyed, e.g.
# sibblings must be allocated to the same group
database <- logician_database(
person(bart),
person(homer),
person(marge),
person(maggie),
person(lisa),
# sibblings
sibblings(bart, maggie),
# groupes
group(upper),
group(lower),
# person group relationship
person_group(bart, upper),
# query relation with siblings
person_in_group(X, A) := person(X) && group(A) && person_group(X, A),
person_in_group(Y, A) := sibblings(X, Y) && person_group(X, A)
)
iter <- logician_query(database = database, question = person_in_group(X,upper))
# only returns bart, but expect also maggie
iter$next_value()
#> TRUE
#> X = bart.
iter$next_value()
#> TRUE
#> X = maggie.
iter$next_value()
#> FALSE |
Beta Was this translation helpful? Give feedback.
Something like that?
Two problems IMHO:
siblings(X, Y) := siblings(Y, X)
produces infinite many results. Not a problem per se, but you will never reachFALSE
I think (in this implementation). Does SWI Prolog stop here at some point?person_in_group
in to parts and also to flipX
withY
in the last clause, as you want the sibling and not the initial person.