summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2014-12-22 19:15:34 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:00 +0200
commitc799df6ea970c1335035544c1b2028072b22ebb0 (patch)
treeec967477298df6e24ba5f9c9ebf59e0b2dfafc2e
parent4eb122ed69549e97bf316cf2aee932897cb7ac25 (diff)
Add support for per-problem fact libraries
Each fact library is loaded at most once, so different problems can share the same library (e.g. family-relation problems).
-rw-r--r--prolog/engine.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/prolog/engine.py b/prolog/engine.py
index 8ad8bfa..c859b67 100644
--- a/prolog/engine.py
+++ b/prolog/engine.py
@@ -117,8 +117,7 @@ class PrologEngine(object):
self.answers = {}
# Loads the correct solution [code] to problem [pid].
- # TODO handle library loading.
- def load_solution(self, pid, code):
+ def load_solution(self, pid, code, facts=None):
module = 'solution{}'.format(pid)
fid = PL_open_foreign_frame()
@@ -126,6 +125,10 @@ class PrologEngine(object):
for rule in prolog.util.split(code):
self.call('assertz/1', [Term('{}:({})'.format(module, rule))])
predicates.add('{}:{}'.format(module, self.predicate_indicator(rule)))
+ if facts:
+ for rule in prolog.util.split(facts):
+ self.call('assertz/1', [Term(rule)])
+ predicates.add(self.predicate_indicator(rule))
self.call('compile_predicates/1', [Term([Term(p) for p in predicates])])
PL_discard_foreign_frame(fid)