summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/ancestor_2/common.py
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-02 01:36:02 +0100
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-03-02 01:36:02 +0100
commitcfbd840591f3b334790ab22daa3cb7b9c49ebc9c (patch)
tree0d8ed9dae561ce04b252d6d52e9b746d6583eaac /prolog/problems/family_relations/ancestor_2/common.py
parent80881f3a6b05474fcd5afe7b3ed30cc7e75e4a92 (diff)
Improved hints for ancestor/2 and descendant/2.
Diffstat (limited to 'prolog/problems/family_relations/ancestor_2/common.py')
-rw-r--r--prolog/problems/family_relations/ancestor_2/common.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/prolog/problems/family_relations/ancestor_2/common.py b/prolog/problems/family_relations/ancestor_2/common.py
index 6690e00..9346e5f 100644
--- a/prolog/problems/family_relations/ancestor_2/common.py
+++ b/prolog/problems/family_relations/ancestor_2/common.py
@@ -27,8 +27,10 @@ hint_type = {
'grandparent_used_markup': HintPopup('grandparent_used_markup'),
'base_case': Hint('base_case'),
'ancestor_to_oneself': Hint('ancestor_to_oneself'),
+ 'ancestor_to_oneself_with_or': Hint('ancestor_to_oneself_with_or'),
'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'),
'wrong_direction': Hint('wrong_direction'),
+ 'only_two_levels_deep': Hint('only_two_levels_deep'),
'timeout': Hint('timeout'),
}
@@ -83,15 +85,23 @@ def hint(code, aux_code):
[{'id': 'grandparent_used'}]
# missing/failed base case
- # TODO: how will ask_truth handle/return timeouts...
- # TODO: timeout is the same as fail in this particular case
if prolog.engine.ask_truthTO(engine_id,
'findall(X/Y, parent(X, Y), L), member(X/Y, L), \+ ancestor(X, Y)'):
return [{'id': 'base_case'}]
+ # two levels deep relation (up to grandparent) only
+ # warning: knowledge base dependent
+ if prolog.engine.ask_truthTO(engine_id,
+ 'findall(_, ancestor(X, Y), L1), length(L1, 23) ; \
+ findall(_, ancestor(X, Y), L2), length(L2, 55)'):
+ return [{'id': 'only_two_levels_deep'}]
+
# ancestor to oneself
if prolog.engine.ask_truthTO(engine_id, 'ancestor(X, X)'):
- return [{'id': 'ancestor_to_oneself'}]
+ if prolog.util.Token('SEMI', ';') in tokens:
+ return [{'id': 'ancestor_to_oneself_with_or'}]
+ else:
+ return [{'id': 'ancestor_to_oneself'}]
# descendant instead of ancestor (wrong direction)
# warning: knowledge base dependent