update package locations to a subdir packages
This commit is contained in:
201
packages/cplint/Artistic
Normal file
201
packages/cplint/Artistic
Normal file
@@ -0,0 +1,201 @@
|
||||
The Artistic License 2.0
|
||||
|
||||
Copyright (c) 2000-2006, The Perl Foundation.
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
This license establishes the terms under which a given free software
|
||||
Package may be copied, modified, distributed, and/or redistributed.
|
||||
The intent is that the Copyright Holder maintains some artistic
|
||||
control over the development of that Package while still keeping the
|
||||
Package available as open source and free software.
|
||||
|
||||
You are always permitted to make arrangements wholly outside of this
|
||||
license directly with the Copyright Holder of a given Package. If the
|
||||
terms of this license do not permit the full use that you propose to
|
||||
make of the Package, you should contact the Copyright Holder and seek
|
||||
a different licensing arrangement.
|
||||
|
||||
Definitions
|
||||
|
||||
"Copyright Holder" means the individual(s) or organization(s)
|
||||
named in the copyright notice for the entire Package.
|
||||
|
||||
"Contributor" means any party that has contributed code or other
|
||||
material to the Package, in accordance with the Copyright Holder's
|
||||
procedures.
|
||||
|
||||
"You" and "your" means any person who would like to copy,
|
||||
distribute, or modify the Package.
|
||||
|
||||
"Package" means the collection of files distributed by the
|
||||
Copyright Holder, and derivatives of that collection and/or of
|
||||
those files. A given Package may consist of either the Standard
|
||||
Version, or a Modified Version.
|
||||
|
||||
"Distribute" means providing a copy of the Package or making it
|
||||
accessible to anyone else, or in the case of a company or
|
||||
organization, to others outside of your company or organization.
|
||||
|
||||
"Distributor Fee" means any fee that you charge for Distributing
|
||||
this Package or providing support for this Package to another
|
||||
party. It does not mean licensing fees.
|
||||
|
||||
"Standard Version" refers to the Package if it has not been
|
||||
modified, or has been modified only in ways explicitly requested
|
||||
by the Copyright Holder.
|
||||
|
||||
"Modified Version" means the Package, if it has been changed, and
|
||||
such changes were not explicitly requested by the Copyright
|
||||
Holder.
|
||||
|
||||
"Original License" means this Artistic License as Distributed with
|
||||
the Standard Version of the Package, in its current version or as
|
||||
it may be modified by The Perl Foundation in the future.
|
||||
|
||||
"Source" form means the source code, documentation source, and
|
||||
configuration files for the Package.
|
||||
|
||||
"Compiled" form means the compiled bytecode, object code, binary,
|
||||
or any other form resulting from mechanical transformation or
|
||||
translation of the Source form.
|
||||
|
||||
|
||||
Permission for Use and Modification Without Distribution
|
||||
|
||||
(1) You are permitted to use the Standard Version and create and use
|
||||
Modified Versions for any purpose without restriction, provided that
|
||||
you do not Distribute the Modified Version.
|
||||
|
||||
|
||||
Permissions for Redistribution of the Standard Version
|
||||
|
||||
(2) You may Distribute verbatim copies of the Source form of the
|
||||
Standard Version of this Package in any medium without restriction,
|
||||
either gratis or for a Distributor Fee, provided that you duplicate
|
||||
all of the original copyright notices and associated disclaimers. At
|
||||
your discretion, such verbatim copies may or may not include a
|
||||
Compiled form of the Package.
|
||||
|
||||
(3) You may apply any bug fixes, portability changes, and other
|
||||
modifications made available from the Copyright Holder. The resulting
|
||||
Package will still be considered the Standard Version, and as such
|
||||
will be subject to the Original License.
|
||||
|
||||
|
||||
Distribution of Modified Versions of the Package as Source
|
||||
|
||||
(4) You may Distribute your Modified Version as Source (either gratis
|
||||
or for a Distributor Fee, and with or without a Compiled form of the
|
||||
Modified Version) provided that you clearly document how it differs
|
||||
from the Standard Version, including, but not limited to, documenting
|
||||
any non-standard features, executables, or modules, and provided that
|
||||
you do at least ONE of the following:
|
||||
|
||||
(a) make the Modified Version available to the Copyright Holder
|
||||
of the Standard Version, under the Original License, so that the
|
||||
Copyright Holder may include your modifications in the Standard
|
||||
Version.
|
||||
|
||||
(b) ensure that installation of your Modified Version does not
|
||||
prevent the user installing or running the Standard Version. In
|
||||
addition, the Modified Version must bear a name that is different
|
||||
from the name of the Standard Version.
|
||||
|
||||
(c) allow anyone who receives a copy of the Modified Version to
|
||||
make the Source form of the Modified Version available to others
|
||||
under
|
||||
|
||||
(i) the Original License or
|
||||
|
||||
(ii) a license that permits the licensee to freely copy,
|
||||
modify and redistribute the Modified Version using the same
|
||||
licensing terms that apply to the copy that the licensee
|
||||
received, and requires that the Source form of the Modified
|
||||
Version, and of any works derived from it, be made freely
|
||||
available in that license fees are prohibited but Distributor
|
||||
Fees are allowed.
|
||||
|
||||
|
||||
Distribution of Compiled Forms of the Standard Version
|
||||
or Modified Versions without the Source
|
||||
|
||||
(5) You may Distribute Compiled forms of the Standard Version without
|
||||
the Source, provided that you include complete instructions on how to
|
||||
get the Source of the Standard Version. Such instructions must be
|
||||
valid at the time of your distribution. If these instructions, at any
|
||||
time while you are carrying out such distribution, become invalid, you
|
||||
must provide new instructions on demand or cease further distribution.
|
||||
If you provide valid instructions or cease distribution within thirty
|
||||
days after you become aware that the instructions are invalid, then
|
||||
you do not forfeit any of your rights under this license.
|
||||
|
||||
(6) You may Distribute a Modified Version in Compiled form without
|
||||
the Source, provided that you comply with Section 4 with respect to
|
||||
the Source of the Modified Version.
|
||||
|
||||
|
||||
Aggregating or Linking the Package
|
||||
|
||||
(7) You may aggregate the Package (either the Standard Version or
|
||||
Modified Version) with other packages and Distribute the resulting
|
||||
aggregation provided that you do not charge a licensing fee for the
|
||||
Package. Distributor Fees are permitted, and licensing fees for other
|
||||
components in the aggregation are permitted. The terms of this license
|
||||
apply to the use and Distribution of the Standard or Modified Versions
|
||||
as included in the aggregation.
|
||||
|
||||
(8) You are permitted to link Modified and Standard Versions with
|
||||
other works, to embed the Package in a larger work of your own, or to
|
||||
build stand-alone binary or bytecode versions of applications that
|
||||
include the Package, and Distribute the result without restriction,
|
||||
provided the result does not expose a direct interface to the Package.
|
||||
|
||||
|
||||
Items That are Not Considered Part of a Modified Version
|
||||
|
||||
(9) Works (including, but not limited to, modules and scripts) that
|
||||
merely extend or make use of the Package, do not, by themselves, cause
|
||||
the Package to be a Modified Version. In addition, such works are not
|
||||
considered parts of the Package itself, and are not subject to the
|
||||
terms of this license.
|
||||
|
||||
|
||||
General Provisions
|
||||
|
||||
(10) Any use, modification, and distribution of the Standard or
|
||||
Modified Versions is governed by this Artistic License. By using,
|
||||
modifying or distributing the Package, you accept this license. Do not
|
||||
use, modify, or distribute the Package, if you do not accept this
|
||||
license.
|
||||
|
||||
(11) If your Modified Version has been derived from a Modified
|
||||
Version made by someone other than you, you are nevertheless required
|
||||
to ensure that your Modified Version complies with the requirements of
|
||||
this license.
|
||||
|
||||
(12) This license does not grant you the right to use any trademark,
|
||||
service mark, tradename, or logo of the Copyright Holder.
|
||||
|
||||
(13) This license includes the non-exclusive, worldwide,
|
||||
free-of-charge patent license to make, have made, use, offer to sell,
|
||||
sell, import and otherwise transfer the Package with respect to any
|
||||
patent claims licensable by the Copyright Holder that are necessarily
|
||||
infringed by the Package. If you institute patent litigation
|
||||
(including a cross-claim or counterclaim) against any party alleging
|
||||
that the Package constitutes direct or contributory patent
|
||||
infringement, then this Artistic License to you shall terminate on the
|
||||
date that such litigation is filed.
|
||||
|
||||
(14) Disclaimer of Warranty:
|
||||
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
|
||||
IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
||||
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
|
||||
LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
18
packages/cplint/COPYRIGHT_SLG
Normal file
18
packages/cplint/COPYRIGHT_SLG
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
Copyright (C) 1993 Southern Methodist University,
|
||||
1993 SUNY at Stony Brook
|
||||
|
||||
Everyone is granted permission to use, copy, and distribute this
|
||||
software free of charge provided that the notices in all files that
|
||||
refer to file COPYRIGHT are kept intact and that file COPYRIGHT is
|
||||
kept in all copies. Modification of this software is permitted
|
||||
provided that all modified files carry prominent notices stating who
|
||||
changed such files and the date of any change.
|
||||
|
||||
This software is provided "as is" with absolutely NO warranties,
|
||||
including the implied warranties of merchantability and fitness for a
|
||||
particular purpose. In no event shall Southern Methodist University,
|
||||
SUNY at Stony Brook, the authors, and/or any other party who may
|
||||
modify and redistribute this software be liable to you for any damages
|
||||
whatsoever arising out of or in connection with the use or performance
|
||||
of this software.
|
||||
168
packages/cplint/Makefile.in
Normal file
168
packages/cplint/Makefile.in
Normal file
@@ -0,0 +1,168 @@
|
||||
#
|
||||
# default base directory for YAP installation
|
||||
# (EROOT for architecture-dependent files)
|
||||
#
|
||||
prefix = @prefix@
|
||||
ROOTDIR = $(prefix)
|
||||
EROOTDIR = @exec_prefix@
|
||||
#
|
||||
# where the binary should be
|
||||
#
|
||||
BINDIR = $(ROOTDIR)/bin
|
||||
#
|
||||
# where YAP should look for libraries
|
||||
#
|
||||
LIBDIR=$(ROOTDIR)/lib/Yap
|
||||
#
|
||||
# where YAP should look for architecture-independent Prolog libraries
|
||||
#
|
||||
SHAREDIR=$(ROOTDIR)/share/Yap
|
||||
#
|
||||
#
|
||||
CC=@CC@
|
||||
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I$(srcdir)/../include
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
#
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
SHELL=/bin/sh
|
||||
RANLIB=@RANLIB@
|
||||
srcdir=@srcdir@
|
||||
SHLIB_CFLAGS=@SHLIB_CFLAGS@
|
||||
SHLIB_SUFFIX=@SHLIB_SUFFIX@
|
||||
CPLINT_CFLAGS=@CPLINT_CFLAGS@
|
||||
CPLINT_LDFLAGS=@CPLINT_LDFLAGS@
|
||||
CPLINT_LIBS=@CPLINT_LIBS@
|
||||
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
|
||||
CWD=$(PWD)
|
||||
#
|
||||
OBJS=cplint_yap.o cplint_Prob.o
|
||||
SOBJS=cplint@SHLIB_SUFFIX@
|
||||
|
||||
|
||||
|
||||
|
||||
CPLINT_SRCDIR = $(srcdir)
|
||||
|
||||
CPLINT_EXDIR = $(srcdir)/examples
|
||||
|
||||
CPLINT_DOCDIR = $(srcdir)/doc
|
||||
|
||||
|
||||
CPLINT_PROGRAMS= \
|
||||
$(CPLINT_SRCDIR)/lpadvel.pl \
|
||||
$(CPLINT_SRCDIR)/lpadclpbn.pl \
|
||||
$(CPLINT_SRCDIR)/lpadsld.pl \
|
||||
$(CPLINT_SRCDIR)/lpad.pl \
|
||||
$(CPLINT_SRCDIR)/cpl.pl
|
||||
|
||||
CPLINT_SEMANTICS_PROGRAMS= \
|
||||
$(CPLINT_SRCDIR)/semlpadsld.pl \
|
||||
$(CPLINT_SRCDIR)/semlpad.pl \
|
||||
$(CPLINT_SRCDIR)/semcpl.pl \
|
||||
$(CPLINT_SRCDIR)/slg.pl
|
||||
|
||||
CPLINT_TEST_PROGRAMS= \
|
||||
$(CPLINT_SRCDIR)/testlpadvel.pl \
|
||||
$(CPLINT_SRCDIR)/testlpadclpbn.pl \
|
||||
$(CPLINT_SRCDIR)/testlpadsld_gbtrue.pl \
|
||||
$(CPLINT_SRCDIR)/testlpadsld_gbfalse.pl \
|
||||
$(CPLINT_SRCDIR)/testlpad.pl \
|
||||
$(CPLINT_SRCDIR)/testcpl.pl \
|
||||
$(CPLINT_SRCDIR)/testsemlpadsld.pl \
|
||||
$(CPLINT_SRCDIR)/testsemlpad.pl \
|
||||
$(CPLINT_SRCDIR)/testsemcpl.pl
|
||||
|
||||
CPLINT_EXAMPLES= \
|
||||
$(CPLINT_EXDIR)/dice.cpl \
|
||||
$(CPLINT_EXDIR)/dice.uni \
|
||||
$(CPLINT_EXDIR)/mendel.cpl \
|
||||
$(CPLINT_EXDIR)/mendels.cpl \
|
||||
$(CPLINT_EXDIR)/mendels.uni \
|
||||
$(CPLINT_EXDIR)/alarm.cpl \
|
||||
$(CPLINT_EXDIR)/coin.cpl \
|
||||
$(CPLINT_EXDIR)/coin.uni \
|
||||
$(CPLINT_EXDIR)/coin2.cpl \
|
||||
$(CPLINT_EXDIR)/coin2.uni \
|
||||
$(CPLINT_EXDIR)/student.cpl \
|
||||
$(CPLINT_EXDIR)/student.uni \
|
||||
$(CPLINT_EXDIR)/exapprox.cpl \
|
||||
$(CPLINT_EXDIR)/exapprox.uni \
|
||||
$(CPLINT_EXDIR)/exrange.cpl \
|
||||
$(CPLINT_EXDIR)/exrange.uni \
|
||||
$(CPLINT_EXDIR)/ex.cpl \
|
||||
$(CPLINT_EXDIR)/ex.uni \
|
||||
$(CPLINT_EXDIR)/school_simple.cpl \
|
||||
$(CPLINT_EXDIR)/school_simple.uni \
|
||||
$(CPLINT_EXDIR)/school.cpl \
|
||||
$(CPLINT_EXDIR)/paper_ref.cpl \
|
||||
$(CPLINT_EXDIR)/paper_ref_not.cpl \
|
||||
$(CPLINT_EXDIR)/paper_ref_simple.cpl \
|
||||
$(CPLINT_EXDIR)/threesideddice.cpl \
|
||||
$(CPLINT_EXDIR)/threesideddice.uni \
|
||||
$(CPLINT_EXDIR)/twosideddice.cpl \
|
||||
$(CPLINT_EXDIR)/female.cpl \
|
||||
$(CPLINT_EXDIR)/hiv.cpl \
|
||||
$(CPLINT_EXDIR)/hiv.uni \
|
||||
$(CPLINT_EXDIR)/invalid.cpl \
|
||||
$(CPLINT_EXDIR)/invalid.uni \
|
||||
$(CPLINT_EXDIR)/light.cpl \
|
||||
$(CPLINT_EXDIR)/light.uni \
|
||||
$(CPLINT_EXDIR)/throws.cpl \
|
||||
$(CPLINT_EXDIR)/throws.uni \
|
||||
$(CPLINT_EXDIR)/trigger.cpl \
|
||||
$(CPLINT_EXDIR)/trigger.uni \
|
||||
$(CPLINT_EXDIR)/win.cpl \
|
||||
$(CPLINT_EXDIR)/win.uni \
|
||||
$(CPLINT_EXDIR)/exist.cpl \
|
||||
$(CPLINT_EXDIR)/exist.uni \
|
||||
$(CPLINT_EXDIR)/exist1.cpl \
|
||||
$(CPLINT_EXDIR)/exist1.uni
|
||||
|
||||
CPLINT_DOCS=\
|
||||
$(CPLINT_DOCDIR)/manual.bbl \
|
||||
$(CPLINT_DOCDIR)/manual.tex \
|
||||
$(CPLINT_DOCDIR)/manual.pdf \
|
||||
$(CPLINT_DOCDIR)/manual.html \
|
||||
$(CPLINT_DOCDIR)/manual.css \
|
||||
$(CPLINT_DOCDIR)/manual0x.png \
|
||||
$(CPLINT_DOCDIR)/Makefile
|
||||
|
||||
|
||||
all: $(SOBJS)
|
||||
|
||||
cplint_yap.o: $(srcdir)/cplint_yap.c $(srcdir)/cplint.h
|
||||
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(CPLINT_CFLAGS) $(srcdir)/cplint_yap.c -o cplint_yap.o
|
||||
|
||||
cplint_Prob.o: $(srcdir)/cplint_Prob.c $(srcdir)/cplint.h
|
||||
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(CPLINT_CFLAGS) $(srcdir)/cplint_Prob.c -o cplint_Prob.o
|
||||
|
||||
|
||||
|
||||
@DO_SECOND_LD@cplint@SHLIB_SUFFIX@: cplint_yap.o cplint_Prob.o
|
||||
@DO_SECOND_LD@ @CPLINT_SHLIB_LD@ -o cplint@SHLIB_SUFFIX@ $(CPLINT_LDFLAGS) cplint_yap.o cplint_Prob.o $(CPLINT_LIBS)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK
|
||||
|
||||
install: all
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/cplint
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/cplint/examples
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/cplint/doc
|
||||
for h in $(CPLINT_PROGRAMS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||
for h in $(CPLINT_EXAMPLES); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/cplint/examples; done
|
||||
for h in $(CPLINT_DOCS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/cplint/doc; done
|
||||
for h in $(CPLINT_TEST_PROGRAMS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/cplint; done
|
||||
for h in $(CPLINT_SEMANTICS_PROGRAMS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(LIBDIR)
|
||||
|
||||
installcheck:
|
||||
for h in ${CPLINT_TEST_PROGRAMS}; do echo "t. halt." | yap -l $$h; done
|
||||
|
||||
# use the following target to run individual tests, e.g. make testlpad
|
||||
test%:
|
||||
echo "t. halt." | yap -l $(CPLINT_SRCDIR)/$@.pl
|
||||
|
||||
40
packages/cplint/README
Normal file
40
packages/cplint/README
Normal file
@@ -0,0 +1,40 @@
|
||||
This directory contains the code of the LPAD anc CP-logic interpreter cplint
|
||||
|
||||
COMPILATION:
|
||||
This package requires GLU (a subpackage of VIS) and GLIB version 1.2.
|
||||
You can download GLU from http://vlsi.colorado.edu/~vis/getting_VIS_2.1.html
|
||||
You can download GLIB from http://www.gtk.org/. This is a standard Linux package
|
||||
so it is easy to install using the package management software of your Linux
|
||||
distribution
|
||||
|
||||
INSTALLATION:
|
||||
Install glu:
|
||||
1) downlad glu-2.1.tar.gz
|
||||
2) decompress it
|
||||
3) cd glu-2.1
|
||||
3) mkdir arch
|
||||
4) cd arch
|
||||
5) ../configure
|
||||
6) make
|
||||
7) su
|
||||
8) make install
|
||||
This will install glu into /usr/local, if you want to install to a different DIR
|
||||
use ../configure --prefix DIR
|
||||
|
||||
Installation of cplint:
|
||||
When compiling Yap, use
|
||||
configure --enable-cplint
|
||||
Under Windows, you have to use cygwin (glu does not compile under MinGW), so
|
||||
configure --enable-cplint --enable-cygwin
|
||||
If you installed glu in DIR, use --enable-cplint=DIR
|
||||
|
||||
|
||||
FEEDBACK:
|
||||
|
||||
Send feedback to:
|
||||
|
||||
Fabrizio Riguzzi
|
||||
University of Ferrara
|
||||
Dept. of Engineering
|
||||
fabrizio.riguzzi@unife.it
|
||||
http://www.ing.unife.it/Docenti/FabrizioRiguzzi/
|
||||
157
packages/cplint/cpl.pl
Normal file
157
packages/cplint/cpl.pl
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
File cpl.pl
|
||||
Computes the semantics of CP-logic programs
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
*/
|
||||
|
||||
:-use_module(lpad,[slg/3,setting/2,set/2]).
|
||||
|
||||
:-use_module(semcpl,[build/0,print/0]).
|
||||
|
||||
:-use_module(library(lists)).
|
||||
|
||||
p(File):-
|
||||
lpad:p(File).
|
||||
|
||||
sc(Goals,Evidences,Prob,CPUTime1,0.0,WallTime1,0.0):-
|
||||
statistics(cputime,[_,_]),
|
||||
statistics(walltime,[_,_]),
|
||||
lpad:convert_to_goal(Goals,Goal),
|
||||
lpad:convert_to_goal(Evidences,Evidence),
|
||||
solve_cond(Goal,Evidence,Prob),
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000.
|
||||
|
||||
sc(Goals,Evidences,Prob):-
|
||||
lpad:convert_to_goal(Goals,Goal),
|
||||
lpad:convert_to_goal(Evidences,Evidence),
|
||||
solve_cond(Goal,Evidence,Prob).
|
||||
|
||||
|
||||
solve_cond(Goal,Evidence,Prob):-
|
||||
(setof((DerivE,D),slg(Evidence,DerivE,D),LCouplesE)->
|
||||
separate(LCouplesE,LCDupE,LDefClE),
|
||||
lpad:rem_dup_lists(LCDupE,[],LCE),
|
||||
lpad:build_formula(LCE,FormulaE,[],VarE),
|
||||
lpad:var2numbers(VarE,0,NewVarE),
|
||||
lpad:compute_prob(NewVarE,FormulaE,ProbE,0),
|
||||
solve_cond_goals(Goal,LCE,ProbGE,LGE,LDefClGE),
|
||||
(setof((R,S),N^(member(C,LGE),member((N,R,S),C)),LDisClGE)->
|
||||
true
|
||||
;
|
||||
LDisClGE=[]
|
||||
),
|
||||
append(LDefClGE,LDefClE,LDefDup),
|
||||
remove_duplicates(LDefDup,LDef),
|
||||
append(LDisClGE,LDef,LCl),
|
||||
test_validity(LCl),
|
||||
Prob is ProbGE/ProbE
|
||||
;
|
||||
format("P(Evidence)=0~n",[]),
|
||||
Prob=undefined
|
||||
).
|
||||
|
||||
solve_cond_goals(Goals,LE,ProbGE,LGE,LDefClGE):-
|
||||
(setof((DerivGE,D),find_deriv_GE(LE,Goals,DerivGE,D),LCouplesGE)->
|
||||
separate(LCouplesGE,LCDupGE,LDefClGE),
|
||||
lpad:rem_dup_lists(LCDupGE,[],LGE),
|
||||
lpad:build_formula(LGE,FormulaGE,[],VarGE),
|
||||
lpad:var2numbers(VarGE,0,NewVarGE),
|
||||
lpad:call_compute_prob(NewVarGE,FormulaGE,ProbGE)
|
||||
;
|
||||
ProbGE=0
|
||||
).
|
||||
|
||||
find_deriv_GE(LD,GoalsList,Deriv,Def):-
|
||||
member(D,LD),
|
||||
lpad:slg(GoalsList,D,DerivDup,[],Def),
|
||||
remove_duplicates(DerivDup,Deriv).
|
||||
|
||||
s(GoalsList,Prob):-
|
||||
lpad:convert_to_goal(GoalsList,Goal),
|
||||
solve(Goal,Prob).
|
||||
|
||||
s(GoalsList,Prob,CPUTime1,0.0,WallTime1,0.0):-
|
||||
statistics(cputime,[_,_]),
|
||||
statistics(walltime,[_,_]),
|
||||
lpad:convert_to_goal(GoalsList,Goal),
|
||||
solve(Goal,Prob),
|
||||
statistics(cputime,[_,CT1]),
|
||||
CPUTime1 is CT1/1000,
|
||||
statistics(walltime,[_,WT1]),
|
||||
WallTime1 is WT1/1000.
|
||||
|
||||
solve(Goal,Prob):-
|
||||
(setof((C,D),slg(Goal,C,D),LCouples)->
|
||||
separate(LCouples,LCDup,LDefCl),
|
||||
(member(unsound,LCDup)->
|
||||
format("Unsound program ~n",[]),
|
||||
Prob=unsound
|
||||
;
|
||||
lpad:rem_dup_lists(LCDup,[],L),
|
||||
(ground(L)->
|
||||
lpad:build_formula(L,Formula,[],Var),
|
||||
lpad:var2numbers(Var,0,NewVar),
|
||||
(setting(savedot,true)->
|
||||
format("Variables: ~p~n",[Var]),
|
||||
lpad:compute_prob(NewVar,Formula,_Prob,1)
|
||||
;
|
||||
lpad:compute_prob(NewVar,Formula,Prob,0)
|
||||
),
|
||||
(setof((R,S),N^(member(C,LCDup),member((N,R,S),C)),LDisCl)->
|
||||
true
|
||||
;
|
||||
LDisCl=[]
|
||||
),
|
||||
append(LDisCl,LDefCl,LCl),
|
||||
test_validity(LCl)
|
||||
;
|
||||
format("It requires the choice of a head atom from a non ground head~n~p~n",[L]),
|
||||
Prob=non_ground
|
||||
)
|
||||
)
|
||||
;
|
||||
Prob=0
|
||||
).
|
||||
|
||||
test_validity(L):-
|
||||
retractall(semcpl:root(_)),
|
||||
retractall(semcpl:clauses(_)),
|
||||
retractall(semcpl:herbrand_base(_)),
|
||||
retractall(semcpl:node(_,_,_,_,_)),
|
||||
retractall(semcpl:new_number(_)),
|
||||
assert(semcpl:new_number(0)),
|
||||
get_clauses_hb(L,LC,HBDup),
|
||||
remove_duplicates(HBDup,HB0),
|
||||
delete(HB0, '' ,HB),
|
||||
assert(semcpl:herbrand_base(HB)),
|
||||
assert(semcpl:clauses(LC)),
|
||||
build.
|
||||
|
||||
get_clauses_hb([],[],[]):-!.
|
||||
|
||||
get_clauses_hb([(R,S)|T],[r(Head,Body)|TR],HB):-
|
||||
lpad:rule(R,S,_,Head,Body),!,
|
||||
get_atoms(Head,Atoms),
|
||||
append(Atoms,HB0,HB),
|
||||
get_clauses_hb(T,TR,HB0).
|
||||
|
||||
get_clauses_hb([(R,S)|T],[r([Head:1],Body)|TR],HB):-
|
||||
lpad:def_rule(R,S,Head,Body),
|
||||
append([Head],HB0,HB),
|
||||
get_clauses_hb(T,TR,HB0).
|
||||
|
||||
get_atoms([],[]):-!.
|
||||
|
||||
get_atoms([H:_P|T],[H|TA]):-
|
||||
get_atoms(T,TA).
|
||||
|
||||
separate([],[],[]):-!.
|
||||
|
||||
separate([(C,D)|T],[C|TC],Cl):-
|
||||
append(D,Cl0,Cl),
|
||||
separate(T,TC,Cl0).
|
||||
|
||||
49
packages/cplint/cplint.h
Normal file
49
packages/cplint/cplint.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
LPAD and CP-Logic interpreter
|
||||
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
This package uses the library cudd, see http://vlsi.colorado.edu/~fabio/CUDD/
|
||||
for the relative license.
|
||||
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
#include "cuddInt.h"
|
||||
#include "array.h"
|
||||
#include "mtr.h"
|
||||
#include "avl.h"
|
||||
#include "YapInterface.h"
|
||||
#include <glib.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int var,value;
|
||||
} factor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nVal,nBit;
|
||||
array_t * probabilities;
|
||||
array_t * booleanVars;
|
||||
} variable;
|
||||
|
||||
|
||||
void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20]);
|
||||
void createExpression(array_t * expression, YAP_Term t);
|
||||
void init_my_predicates(void);
|
||||
int compare(char *a, char *b);
|
||||
gint my_equal(gconstpointer v,gconstpointer v2);
|
||||
guint my_hash(gconstpointer key);
|
||||
void dealloc(gpointer key,gpointer value,gpointer user_data);
|
||||
|
||||
|
||||
|
||||
DdNode * retFunction(DdManager * mgr, array_t * expression,array_t * v);
|
||||
DdNode * retTerm(DdManager * mgr,array_t *factors,array_t * v);
|
||||
DdNode * retFactor(DdManager * mgr, factor f, array_t * v);
|
||||
|
||||
double Prob(DdNode *node, array_t * vars,array_t * bVar2mVar, GHashTable * nodes);
|
||||
|
||||
double ProbBool(DdNode *node, int bits, int nBit,int posBVar,variable v,
|
||||
array_t * vars,array_t * bVar2mVar, GHashTable * nodes);
|
||||
209
packages/cplint/cplint_Prob.c
Normal file
209
packages/cplint/cplint_Prob.c
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
LPAD and CP-Logic interpreter
|
||||
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
This package uses the library cudd, see http://vlsi.colorado.edu/~fabio/CUDD/
|
||||
for the relative license.
|
||||
|
||||
|
||||
This file contains the definition of Prob and ProbBool plus the functions
|
||||
for building the BDD
|
||||
*/
|
||||
|
||||
|
||||
#include "cplint.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int correctPosition(int index,variable v, DdNode * node,int posBVar);
|
||||
|
||||
|
||||
|
||||
DdNode * retFunction(DdManager * mgr,array_t *expression, array_t *v)
|
||||
/* given an expression term1+term2+...+termn, returns the BDD that implements that function */
|
||||
{
|
||||
array_t * term;
|
||||
DdNode * tNode, * tmp, *tmp1;
|
||||
int i;
|
||||
|
||||
i=0;
|
||||
tNode=Cudd_ReadLogicZero(mgr);
|
||||
Cudd_Ref(tNode);
|
||||
while(i<array_n(expression))
|
||||
{
|
||||
term=array_fetch(array_t * ,expression,i);
|
||||
tmp=retTerm(mgr,term,v);
|
||||
Cudd_Ref(tmp);
|
||||
tmp1=Cudd_bddOr(mgr,tNode,tmp);
|
||||
Cudd_Ref(tmp1);
|
||||
Cudd_RecursiveDeref(mgr,tNode);
|
||||
tNode=tmp1;
|
||||
i++;
|
||||
}
|
||||
return tNode;
|
||||
}
|
||||
|
||||
DdNode * retTerm(DdManager * mgr,array_t *term, array_t * v)
|
||||
/* given a term V1=v1 and V2=v2 ... Vn=vn, returns the BDD that implements that function */
|
||||
{
|
||||
factor f;
|
||||
DdNode * fNode, * tmp, *tmp1;
|
||||
int i;
|
||||
|
||||
i=0;
|
||||
fNode=Cudd_ReadOne(mgr);
|
||||
Cudd_Ref(fNode);
|
||||
while (i<array_n(term))
|
||||
{
|
||||
f=array_fetch(factor, term, i);
|
||||
tmp=retFactor(mgr,f,v);
|
||||
Cudd_Ref(tmp);
|
||||
tmp1= Cudd_bddAnd(mgr,fNode,tmp);
|
||||
Cudd_Ref(tmp1);
|
||||
Cudd_RecursiveDeref(mgr,fNode);
|
||||
fNode=tmp1;
|
||||
i++;
|
||||
}
|
||||
return fNode;
|
||||
}
|
||||
|
||||
DdNode * retFactor(DdManager * mgr, factor f, array_t * vars)
|
||||
/* given a factor V=v, returns the BDD that implements that function */
|
||||
{
|
||||
int varIndex;
|
||||
int value;
|
||||
int i;
|
||||
int bit;
|
||||
variable v;
|
||||
DdNode * node, *booleanVar, * tmp;
|
||||
array_t * booleanVars;
|
||||
|
||||
|
||||
varIndex=f.var;
|
||||
value=f.value;
|
||||
v=array_fetch(variable, vars, varIndex);
|
||||
booleanVars=v.booleanVars;
|
||||
i=v.nBit-1;
|
||||
node=Cudd_ReadOne(mgr);
|
||||
Cudd_Ref(node);
|
||||
/* booelan var with index 0 in v.booleanVars is the most significant */
|
||||
do {
|
||||
booleanVar=array_fetch(DdNode *,booleanVars,i);
|
||||
bit=value & 01;
|
||||
if (bit)
|
||||
{
|
||||
tmp=Cudd_bddAnd(mgr,node,booleanVar);
|
||||
Cudd_Ref(tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp=Cudd_bddAnd(mgr,node,Cudd_Not(booleanVar));
|
||||
Cudd_Ref(tmp);
|
||||
}
|
||||
value=value>>1;
|
||||
i--;
|
||||
Cudd_RecursiveDeref(mgr,node);
|
||||
node=tmp;
|
||||
} while (i>=0);
|
||||
return node;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
double Prob(DdNode *node, array_t * vars,array_t * bVar2mVar, GHashTable * nodes)
|
||||
/* compute the probability of the expression rooted at node
|
||||
nodes is used to store nodes for which the probability has alread been computed
|
||||
so that it is not recomputed
|
||||
*/
|
||||
{
|
||||
int index,mVarIndex,nBit;
|
||||
variable v;
|
||||
double res;
|
||||
double value;
|
||||
double * value_p;
|
||||
DdNode **key;
|
||||
double *rp;
|
||||
|
||||
index=node->index;
|
||||
if (Cudd_IsConstant(node))
|
||||
{
|
||||
value=node->type.value;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
value_p=g_hash_table_lookup(nodes,&node);
|
||||
if (value_p!=NULL)
|
||||
{
|
||||
return *value_p;
|
||||
}
|
||||
else
|
||||
{
|
||||
mVarIndex=array_fetch(int,bVar2mVar,index);
|
||||
v=array_fetch(variable,vars,mVarIndex);
|
||||
nBit=v.nBit;
|
||||
res=ProbBool(node,0,nBit,0,v,vars,bVar2mVar,nodes);
|
||||
key=(DdNode **)malloc(sizeof(DdNode *));
|
||||
*key=node;
|
||||
rp=(double *)malloc(sizeof(double));
|
||||
*rp=res;
|
||||
g_hash_table_insert(nodes, key, rp);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double ProbBool(DdNode *node, int bits, int nBit,int posBVar,variable v,
|
||||
array_t * vars,array_t * bVar2mVar, GHashTable * nodes)
|
||||
/* explores a group of binary variables making up the multivalued variable v */
|
||||
{
|
||||
DdNode *T,*F;
|
||||
double p,res;
|
||||
array_t * probs;
|
||||
|
||||
probs=v.probabilities;
|
||||
if (nBit==0)
|
||||
{
|
||||
if (bits>=array_n(probs))
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
p=array_fetch(double,probs,bits);
|
||||
res=p*Prob(node,vars,bVar2mVar,nodes);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (correctPosition(node->index,v,node,posBVar))
|
||||
{
|
||||
T = node->type.kids.T;
|
||||
F = node->type.kids.E;
|
||||
bits=bits<<1;
|
||||
|
||||
res=ProbBool(T,bits+1,nBit-1,posBVar+1,v,vars,bVar2mVar,nodes)+
|
||||
ProbBool(F,bits,nBit-1,posBVar+1,v,vars,bVar2mVar,nodes);
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
bits=bits<<1;
|
||||
res=ProbBool(node,bits+1,nBit-1,posBVar+1,v,vars,bVar2mVar,nodes)+
|
||||
ProbBool(node,bits,nBit-1,posBVar+1,v,vars,bVar2mVar,nodes);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int correctPosition(int index,variable v, DdNode * node,int posBVar)
|
||||
/* returns 1 is the boolean variable with index posBVar is in the correct position
|
||||
currently explored by ProbBool */
|
||||
{
|
||||
DdNode * bvar;
|
||||
|
||||
bvar=array_fetch(DdNode *,v.booleanVars,posBVar);
|
||||
return bvar->index==index;
|
||||
}
|
||||
256
packages/cplint/cplint_yap.c
Normal file
256
packages/cplint/cplint_yap.c
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
LPAD and CP-Logic interpreter
|
||||
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
This package uses the library cudd, see http://vlsi.colorado.edu/~fabio/CUDD/
|
||||
for the relative license.
|
||||
|
||||
|
||||
This file contains the functions for interfacing Yap and C
|
||||
The arguments of the predicate compute_prob are parsed and translated into C data
|
||||
structures
|
||||
*/
|
||||
|
||||
#include "cplint.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
unsigned long dividend;
|
||||
|
||||
FILE *open_file (char *filename, const char *mode);
|
||||
void reverse(char s[]);
|
||||
static int compute_prob(void);
|
||||
|
||||
void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20])
|
||||
/* adds the boolean variables to the BDD and returns
|
||||
an array_t containing them (array_t is defined in the util library of glu)
|
||||
returns also the names of the variables to be used to save the ADD in dot format
|
||||
*/
|
||||
{
|
||||
YAP_Term varTerm,probTerm;
|
||||
int varIndex,nVal,i,b;
|
||||
variable v;
|
||||
char numberVar[10],numberBit[10];
|
||||
double p;
|
||||
b=0;
|
||||
|
||||
while(YAP_IsPairTerm(t))
|
||||
{
|
||||
varTerm=YAP_HeadOfTerm(t);
|
||||
varIndex=YAP_IntOfTerm(YAP_HeadOfTerm(varTerm));
|
||||
|
||||
varTerm=YAP_TailOfTerm(varTerm);
|
||||
nVal=YAP_IntOfTerm(YAP_HeadOfTerm(varTerm));
|
||||
varTerm=YAP_TailOfTerm(varTerm);
|
||||
probTerm=YAP_HeadOfTerm(varTerm);
|
||||
v.nVal=nVal;
|
||||
v.nBit=(int)ceil(log(nVal)/log(2));
|
||||
v.probabilities=array_alloc(double,0);
|
||||
v.booleanVars=array_alloc(DdNode *,0);
|
||||
for (i=0;i<nVal;i++)
|
||||
{
|
||||
if (create_dot)
|
||||
{
|
||||
strcpy(inames[b+i],"X");
|
||||
sprintf(numberVar,"%d",varIndex);
|
||||
strcat(inames[b+i],numberVar);
|
||||
strcat(inames[b+i],"_");
|
||||
sprintf(numberBit,"%d",i);
|
||||
strcat(inames[b+i],numberBit);
|
||||
}
|
||||
p=YAP_FloatOfTerm(YAP_HeadOfTerm(probTerm));
|
||||
array_insert(double,v.probabilities,i,p);
|
||||
probTerm=YAP_TailOfTerm(probTerm);
|
||||
array_insert(DdNode *,v.booleanVars,i,Cudd_bddIthVar(mgr,b+i));
|
||||
array_insert(int,bVar2mVar,b+i,varIndex);
|
||||
}
|
||||
Cudd_MakeTreeNode(mgr,b,nVal,MTR_FIXED);
|
||||
b=b+nVal;
|
||||
array_insert(variable,vars,varIndex,v);
|
||||
t=YAP_TailOfTerm(t);
|
||||
}
|
||||
}
|
||||
|
||||
void createExpression(array_t * expression, YAP_Term t)
|
||||
/* returns the expression as an array_t of terms (cubes) starting from the prolog lists of terms
|
||||
each term is an array_t of factors obtained from a prolog list of factors
|
||||
each factor is a couple (index of variable, index of value) obtained from a prolog list containing
|
||||
two integers
|
||||
*/
|
||||
{
|
||||
YAP_Term termTerm,factorTerm;
|
||||
factor f;
|
||||
int i,j;
|
||||
array_t * term;
|
||||
|
||||
i=0;
|
||||
while(YAP_IsPairTerm(t))
|
||||
{
|
||||
term=array_alloc(factor,0);
|
||||
termTerm=YAP_HeadOfTerm(t);
|
||||
j=0;
|
||||
while(YAP_IsPairTerm(termTerm))
|
||||
{
|
||||
factorTerm=YAP_HeadOfTerm(termTerm);
|
||||
f.var=YAP_IntOfTerm(YAP_HeadOfTerm(factorTerm));
|
||||
f.value=YAP_IntOfTerm(YAP_HeadOfTerm(YAP_TailOfTerm(factorTerm)));
|
||||
array_insert(factor,term,j,f);
|
||||
termTerm=YAP_TailOfTerm(termTerm);
|
||||
j++;
|
||||
}
|
||||
array_insert(array_t *,expression,i,term);
|
||||
t=YAP_TailOfTerm(t);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static int compute_prob(void)
|
||||
/* this is the function that implements the compute_prob predicate used in pp.pl
|
||||
*/
|
||||
{
|
||||
YAP_Term out,arg1,arg2,arg3,arg4;
|
||||
array_t * variables,* expression, * bVar2mVar;
|
||||
DdNode * function, * add;
|
||||
DdManager * mgr;
|
||||
int nBVar,i,j,intBits,create_dot;
|
||||
FILE * file;
|
||||
DdNode * array[1];
|
||||
char * onames[1];
|
||||
char inames[1000][20];
|
||||
char * names[1000];
|
||||
GHashTable * nodes; /* hash table that associates nodes with their probability if already
|
||||
computed, it is defined in glib */
|
||||
Cudd_ReorderingType order;
|
||||
arg1=YAP_ARG1;
|
||||
arg2=YAP_ARG2;
|
||||
arg3=YAP_ARG3;
|
||||
arg4=YAP_ARG4;
|
||||
|
||||
mgr=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
|
||||
variables=array_alloc(variable,0);
|
||||
bVar2mVar=array_alloc(int,0);
|
||||
create_dot=YAP_IntOfTerm(arg4);
|
||||
createVars(variables,arg1,mgr,bVar2mVar,create_dot,inames);
|
||||
//Cudd_PrintInfo(mgr,stderr);
|
||||
|
||||
/* automatic variable reordering, default method CUDD_REORDER_SIFT used */
|
||||
//printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
|
||||
//printf("order %d\n",order);
|
||||
|
||||
Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME);
|
||||
/* Cudd_AutodynEnable(mgr, CUDD_REORDER_RANDOM_PIVOT);
|
||||
printf("status %d\n",Cudd_ReorderingStatus(mgr,&order));
|
||||
printf("order %d\n",order);
|
||||
printf("%d",CUDD_REORDER_RANDOM_PIVOT);
|
||||
*/
|
||||
|
||||
|
||||
expression=array_alloc(array_t *,0);
|
||||
createExpression(expression,arg2);
|
||||
|
||||
function=retFunction(mgr,expression,variables);
|
||||
/* the BDD build by retFunction is converted to an ADD (algebraic decision diagram)
|
||||
because it is easier to interpret and to print */
|
||||
add=Cudd_BddToAdd(mgr,function);
|
||||
//Cudd_PrintInfo(mgr,stderr);
|
||||
|
||||
if (create_dot)
|
||||
/* if specified by the user, a dot file for the BDD is written to cpl.dot */
|
||||
{
|
||||
nBVar=array_n(bVar2mVar);
|
||||
for(i=0;i<nBVar;i++)
|
||||
names[i]=inames[i];
|
||||
array[0]=add;
|
||||
onames[0]="Out";
|
||||
file = open_file("cpl.dot", "w");
|
||||
Cudd_DumpDot(mgr,1,array,names,onames,file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
nodes=g_hash_table_new(my_hash,my_equal);
|
||||
intBits=sizeof(unsigned int)*8;
|
||||
/* dividend is a global variable used by my_hash
|
||||
it is equal to an unsigned int with binary representation 11..1 */
|
||||
dividend=1;
|
||||
for(j=1;j<intBits;j++)
|
||||
{
|
||||
dividend=(dividend<<1)+1;
|
||||
}
|
||||
out=YAP_MkFloatTerm(Prob(add,variables,bVar2mVar,nodes));
|
||||
g_hash_table_foreach (nodes,dealloc,NULL);
|
||||
g_hash_table_destroy(nodes);
|
||||
Cudd_Quit(mgr);
|
||||
array_free(variables);
|
||||
array_free(bVar2mVar);
|
||||
array_free(expression);
|
||||
return(YAP_Unify(out,arg3));
|
||||
}
|
||||
/*
|
||||
int compare(char *a, char *b)
|
||||
{
|
||||
int aval,bval;
|
||||
aval=(int) *((DdNode **)a);
|
||||
aval=(int) *((DdNode **)b);
|
||||
|
||||
if (aval<bval)
|
||||
return -1;
|
||||
else
|
||||
if (aval>bval)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
void init_my_predicates()
|
||||
/* function required by YAP for intitializing the predicates defined by a C function*/
|
||||
{
|
||||
YAP_UserCPredicate("compute_prob",compute_prob,4);
|
||||
}
|
||||
FILE *
|
||||
open_file(char *filename, const char *mode)
|
||||
/* opens a file */
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(filename, mode)) == NULL) {
|
||||
perror(filename);
|
||||
exit(1);
|
||||
}
|
||||
return fp;
|
||||
|
||||
}
|
||||
void reverse(char s[])
|
||||
/* reverses a string */
|
||||
{
|
||||
int i,c,j;
|
||||
for (i=0,j=strlen(s)-1;i<j;i++,j--)
|
||||
{
|
||||
c=s[i];
|
||||
s[i]=s[j];
|
||||
s[j]=c;
|
||||
}
|
||||
}
|
||||
|
||||
gint my_equal(gconstpointer v,gconstpointer v2)
|
||||
/* function used by GHashTable to compare two keys */
|
||||
{
|
||||
DdNode *a,*b;
|
||||
a=*(DdNode **)v;
|
||||
b=*(DdNode **)v2;
|
||||
return (a==b);
|
||||
}
|
||||
guint my_hash(gconstpointer key)
|
||||
/* function used by GHashTable to hash a key */
|
||||
{
|
||||
unsigned int h;
|
||||
h=(unsigned int)((unsigned long) *((DdNode **)key) % dividend);
|
||||
return h;
|
||||
}
|
||||
void dealloc(gpointer key,gpointer value,gpointer user_data)
|
||||
{
|
||||
free(key);
|
||||
free(value);
|
||||
}
|
||||
90
packages/cplint/doc/manual.bbl
Normal file
90
packages/cplint/doc/manual.bbl
Normal file
@@ -0,0 +1,90 @@
|
||||
\begin{thebibliography}{10}
|
||||
|
||||
\bibitem{DBLP:journals/ngc/AptB91}
|
||||
K.~R. Apt and M.~Bezem.
|
||||
\newblock Acyclic programs.
|
||||
\newblock {\em New Generation Comput.}, 9(3/4):335--364, 1991.
|
||||
|
||||
\bibitem{Blo04-ILP04WIP-IC}
|
||||
H.~Blockeel.
|
||||
\newblock Probabilistic logical models for mendel's experiments: An exercise.
|
||||
\newblock In {\em Inductive Logic Programming ({ILP} 2004), Work in Progress
|
||||
Track}, 2004.
|
||||
|
||||
\bibitem{DBLP:journals/jacm/ChenW96}
|
||||
Weidong Chen and David~Scott Warren.
|
||||
\newblock Tabled evaluation with delaying for general logic programs.
|
||||
\newblock {\em J. ACM}, 43(1):20--74, 1996.
|
||||
|
||||
\bibitem{DBLP:conf/ijcai/RaedtKT07}
|
||||
L.~De~Raedt, A.~Kimmig, and H.~Toivonen.
|
||||
\newblock Problog: A probabilistic prolog and its application in link
|
||||
discovery.
|
||||
\newblock In {\em Proceedings of the 20th International Joint Conference on
|
||||
Artificial Intelligence}, pages 2462--2467, 2007.
|
||||
|
||||
\bibitem{GetFri01-BC}
|
||||
L.~Getoor, N.~Friedman, D.~Koller, and A.~Pfeffer.
|
||||
\newblock Learning probabilistic relational models.
|
||||
\newblock In Saso Dzeroski and Nada Lavrac, editors, {\em Relational Data
|
||||
Mining}. Springer-Verlag, Berlin, 2001.
|
||||
|
||||
\bibitem{Getoor+al:JMLR02}
|
||||
L.~Getoor, N.~Friedman, D.~Koller, and B.~Taskar.
|
||||
\newblock Learning probabilistic models of relational structure.
|
||||
\newblock {\em Journal of Machine Learning Research}, 3:679--707, December
|
||||
2002.
|
||||
|
||||
\bibitem{Rig-AIIA07-IC}
|
||||
Fabrizio Riguzzi.
|
||||
\newblock A top down interpreter for lpad and cp-logic.
|
||||
\newblock In {\em 10th Congress of the Italian Association for Artificial
|
||||
Intelligence}. Springer, 2007.
|
||||
\newblock
|
||||
\href{http://www.ing.unife.it/docenti/FabrizioRiguzzi/Papers/Rig-AIIA07.pdf}%
|
||||
{http://www.ing.unife.it/docenti/FabrizioRiguzzi/Papers/Rig-AIIA07.pdf}.
|
||||
|
||||
\bibitem{Rig-RCRA07-IC}
|
||||
Fabrizio Riguzzi.
|
||||
\newblock A top down interpreter for lpad and cp-logic.
|
||||
\newblock In {\em The 14th RCRA workshop Experimental Evaluation of Algorithms
|
||||
for Solving Problems with Combinatorial Explosion}, 2007.
|
||||
\newblock
|
||||
\href{http://pst.istc.cnr.it/RCRA07/articoli/P19-riguzzi-RCRA07.pdf}{http://%
|
||||
pst.istc.cnr.it/RCRA07/articoli/P19-riguzzi-RCRA07.pdf}.
|
||||
|
||||
\bibitem{SanPagQaz03-UAI-IC}
|
||||
V.~Santos~Costa, D.~Page, M.~Qazi, and J.~Cussens.
|
||||
\newblock {CLP(BN)}: Constraint logic programming for probabilistic knowledge.
|
||||
\newblock In {\em Uncertainty in Artificial Intelligence ({UAI} 2003)}, 2003.
|
||||
|
||||
\bibitem{VenDenBru-JELIA06}
|
||||
J.~Vennekens, M.~Denecker, and M.~Bruynooghe.
|
||||
\newblock Representing causal information about a probabilistic process.
|
||||
\newblock In {\em 10th European Conference on Logics in Artificial
|
||||
Intelligence, JELIA 2006}, LNAI. Springer, September 2006.
|
||||
|
||||
\bibitem{VenVer03-TR}
|
||||
J.~Vennekens and S.~Verbaeten.
|
||||
\newblock Logic programs with annotated disjunctions.
|
||||
\newblock Technical Report CW386, K. U. Leuven, 2003.
|
||||
\newblock
|
||||
\href{http://www.cs.kuleuven.ac.be/~joost/techrep.ps}{http://www.cs.kuleuven%
|
||||
.ac.be/$\sim$joost/techrep.ps}.
|
||||
|
||||
\bibitem{VenVer04-ICLP04-IC}
|
||||
J.~Vennekens, S.~Verbaeten, and M.~Bruynooghe.
|
||||
\newblock Logic programs with annotated disjunctions.
|
||||
\newblock In {\em The 20th International Conference on Logic Programming
|
||||
({ICLP} 2004)}, 2004.
|
||||
\newblock
|
||||
\href{http://www.cs.kuleuven.ac.be/~joost/}{http://www.cs.kuleuven.ac.be/$\sim$joost/}.
|
||||
|
||||
\bibitem{CP-logic-unp}
|
||||
Joost Vennekens, Marc Denecker, and Maurice Bruynooge.
|
||||
\newblock Extending the role of causality in probabilistic modeling.
|
||||
\newblock
|
||||
\href{http://www.cs.kuleuven.ac.be/~joost/cplogic.pdf}{http://www.cs.kuleuve%
|
||||
n.ac.be/$\sim$joost/cplogic.pdf}, 2006.
|
||||
|
||||
\end{thebibliography}
|
||||
113
packages/cplint/doc/manual.css
Normal file
113
packages/cplint/doc/manual.css
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
/* start css.sty */
|
||||
.cmr-7{font-size:70%;}
|
||||
.cmmi-7{font-size:70%;font-style: italic;}
|
||||
.cmmi-10{font-style: italic;}
|
||||
.cmr-17{font-size:170%;}
|
||||
.cmtt-12x-x-144{font-size:172%;font-family: monospace;}
|
||||
.cmtt-12x-x-144{font-family: monospace;}
|
||||
.cmr-12{font-size:120%;}
|
||||
.cmtt-10{font-family: monospace;}
|
||||
.cmtt-10{font-family: monospace;}
|
||||
.cmti-10{ font-style: italic;}
|
||||
p.noindent { text-indent: 0em }
|
||||
p.nopar { text-indent: 0em; }
|
||||
p.indent{ text-indent: 1.5em }
|
||||
@media print {div.crosslinks {visibility:hidden;}}
|
||||
a img { border-top: 0; border-left: 0; border-right: 0; }
|
||||
center { margin-top:1em; margin-bottom:1em; }
|
||||
td center { margin-top:0em; margin-bottom:0em; }
|
||||
.Canvas { position:relative; }
|
||||
img.math{vertical-align:middle;}
|
||||
li p.indent { text-indent: 0em }
|
||||
.enumerate1 {list-style-type:decimal;}
|
||||
.enumerate2 {list-style-type:lower-alpha;}
|
||||
.enumerate3 {list-style-type:lower-roman;}
|
||||
.enumerate4 {list-style-type:upper-alpha;}
|
||||
div.newtheorem { margin-bottom: 2em; margin-top: 2em;}
|
||||
.obeylines-h,.obeylines-v {white-space: nowrap; }
|
||||
div.obeylines-v p { margin-top:0; margin-bottom:0; }
|
||||
.overline{ text-decoration:overline; }
|
||||
.overline img{ border-top: 1px solid black; }
|
||||
td.displaylines {text-align:center; white-space:nowrap;}
|
||||
.centerline {text-align:center;}
|
||||
.rightline {text-align:right;}
|
||||
div.verbatim {font-family: monospace; white-space: nowrap; }
|
||||
table.verbatim {width:100%;}
|
||||
.fbox {padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
|
||||
div.center div.fbox {text-align:center; clear:both; padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
|
||||
table.minipage{width:100%;}
|
||||
div.center, div.center div.center {text-align: center; margin-left:1em; margin-right:1em;}
|
||||
div.center div {text-align: left;}
|
||||
div.flushright, div.flushright div.flushright {text-align: right;}
|
||||
div.flushright div {text-align: left;}
|
||||
div.flushleft {text-align: left;}
|
||||
.underline{ text-decoration:underline; }
|
||||
.underline img{ border-bottom: 1px solid black; margin-bottom:1pt; }
|
||||
.framebox-c, .framebox-l, .framebox-r { padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
|
||||
.framebox-c {text-align:center;}
|
||||
.framebox-l {text-align:left;}
|
||||
.framebox-r {text-align:right;}
|
||||
span.thank-mark{ vertical-align: super }
|
||||
span.footnote-mark sup.textsuperscript, span.footnote-mark a sup.textsuperscript{ font-size:80%; }
|
||||
div.tabular, div.center div.tabular {text-align: center; margin-top:0.5em; margin-bottom:0.5em; }
|
||||
table.tabular td p{margin-top:0em;}
|
||||
table.tabular {margin-left: auto; margin-right: auto;}
|
||||
div.td00{ margin-left:0pt; margin-right:0pt; }
|
||||
div.td01{ margin-left:0pt; margin-right:5pt; }
|
||||
div.td10{ margin-left:5pt; margin-right:0pt; }
|
||||
div.td11{ margin-left:5pt; margin-right:5pt; }
|
||||
table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; }
|
||||
td.td00{ padding-left:0pt; padding-right:0pt; }
|
||||
td.td01{ padding-left:0pt; padding-right:5pt; }
|
||||
td.td10{ padding-left:5pt; padding-right:0pt; }
|
||||
td.td11{ padding-left:5pt; padding-right:5pt; }
|
||||
table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; }
|
||||
.hline hr, .cline hr{ height : 1px; margin:0px; }
|
||||
.tabbing-right {text-align:right;}
|
||||
span.TEX {letter-spacing: -0.125em; }
|
||||
span.TEX span.E{ position:relative;top:0.5ex;left:-0.0417em;}
|
||||
a span.TEX span.E {text-decoration: none; }
|
||||
span.LATEX span.A{ position:relative; top:-0.5ex; left:-0.4em; font-size:85%;}
|
||||
span.LATEX span.TEX{ position:relative; left: -0.4em; }
|
||||
div.float img, div.float .caption {text-align:center;}
|
||||
div.figure img, div.figure .caption {text-align:center;}
|
||||
.marginpar {width:20%; float:right; text-align:left; margin-left:auto; margin-top:0.5em; font-size:85%; text-decoration:underline;}
|
||||
.marginpar p{margin-top:0.4em; margin-bottom:0.4em;}
|
||||
table.equation {width:100%;}
|
||||
.equation td{text-align:center; }
|
||||
td.equation { margin-top:1em; margin-bottom:1em; }
|
||||
td.equation-label { width:5%; text-align:center; }
|
||||
td.eqnarray4 { width:5%; white-space: normal; }
|
||||
td.eqnarray2 { width:5%; }
|
||||
table.eqnarray-star, table.eqnarray {width:100%;}
|
||||
div.eqnarray{text-align:center;}
|
||||
div.array {text-align:center;}
|
||||
div.pmatrix {text-align:center;}
|
||||
table.pmatrix {width:100%;}
|
||||
span.pmatrix img{vertical-align:middle;}
|
||||
div.pmatrix {text-align:center;}
|
||||
table.pmatrix {width:100%;}
|
||||
img.cdots{vertical-align:middle;}
|
||||
.partToc a, .partToc, .likepartToc a, .likepartToc {line-height: 200%; font-weight:bold; font-size:110%;}
|
||||
.caption td.id{font-weight: bold; white-space: nowrap; }
|
||||
table.caption {text-align:center;}
|
||||
h1.partHead{text-align: center}
|
||||
p.bibitem { text-indent: -2em; margin-left: 2em; margin-top:0.6em; margin-bottom:0.6em; }
|
||||
p.bibitem-p { text-indent: 0em; margin-left: 2em; margin-top:0.6em; margin-bottom:0.6em; }
|
||||
.paragraphHead, .likeparagraphHead { margin-top:2em; font-weight: bold;}
|
||||
.subparagraphHead, .likesubparagraphHead { font-weight: bold;}
|
||||
.quote {margin-bottom:0.25em; margin-top:0.25em; margin-left:1em; margin-right:1em; text-align:justify;}
|
||||
.verse{white-space:nowrap; margin-left:2em}
|
||||
div.maketitle {text-align:center;}
|
||||
h2.titleHead{text-align:center;}
|
||||
div.maketitle{ margin-bottom: 2em; }
|
||||
div.author, div.date {text-align:center;}
|
||||
div.thanks{text-align:left; margin-left:10%; font-size:85%; font-style:italic; }
|
||||
div.author{white-space: nowrap;}
|
||||
.quotation {margin-bottom:0.25em; margin-top:0.25em; margin-left:1em; }
|
||||
.abstract p {margin-left:5%; margin-right:5%;}
|
||||
table.abstract {width:100%;}
|
||||
.figure img.graphics {margin-left:10%;}
|
||||
/* end css.sty */
|
||||
|
||||
1047
packages/cplint/doc/manual.html
Normal file
1047
packages/cplint/doc/manual.html
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/cplint/doc/manual.pdf
Normal file
BIN
packages/cplint/doc/manual.pdf
Normal file
Binary file not shown.
458
packages/cplint/doc/manual.tex
Normal file
458
packages/cplint/doc/manual.tex
Normal file
@@ -0,0 +1,458 @@
|
||||
\ifnum\pdfoutput>0 % pdflatex compilation
|
||||
\documentclass[a4paper,12pt]{article}
|
||||
\usepackage[pdftex]{graphicx}
|
||||
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
|
||||
\RequirePackage[hyperindex]{hyperref}
|
||||
\else % htlatex compilation
|
||||
\documentclass{article}
|
||||
\usepackage{graphicx}
|
||||
\DeclareGraphicsExtensions{.png, .gif, .jpg}
|
||||
\newcommand{\href}[2]{\Link[#1]{}{} #2 \EndLink}
|
||||
\newcommand{\hypertarget}[2]{\Link[]{}{#1} #2 \EndLink}
|
||||
\newcommand{\hyperlink}[2]{\Link[]{#1}{} #2 \EndLink}
|
||||
\fi
|
||||
|
||||
|
||||
|
||||
\begin{document}
|
||||
\title{\texttt{cplint} Version beta2.0 Manual}
|
||||
|
||||
|
||||
\author{Fabrizio Riguzzi\\
|
||||
fabrizio.riguzzi@unife.it}
|
||||
|
||||
\maketitle
|
||||
|
||||
|
||||
\section{Introduction}
|
||||
|
||||
|
||||
\texttt{cplint} is a suite of programs for reasoning with LPADs \cite{VenVer03-TR,VenVer04-ICLP04-IC} and CP-logic programs \cite{VenDenBru-JELIA06,CP-logic-unp}.
|
||||
|
||||
It consists of three Prolog modules for answering queries using goal-oriented procedures plus
|
||||
three
|
||||
Prolog modules for answering queries using the definition of the semantics of LPADs and CP-logic.
|
||||
|
||||
The modules for answering queries using using goal-oriented procedures are \texttt{lpadsld.pl}, \texttt{lpad.pl} and
|
||||
\texttt{cpl.pl}:
|
||||
\begin{itemize}
|
||||
\item \texttt{lpadsld.pl}: computes the probability of a query using the top-down procedure described in
|
||||
in \cite{Rig-AIIA07-IC} and \cite{Rig-RCRA07-IC}. It is based on SLDNF resolution and is an adaptation of the interpreter for ProbLog \cite{DBLP:conf/ijcai/RaedtKT07}.
|
||||
|
||||
It was proved correct \cite{Rig-RCRA07-IC} with respect to the semantics of LPADs for range restricted acyclic programs \cite{DBLP:journals/ngc/AptB91} without function symbols.
|
||||
|
||||
It is also able to deal with extensions of LPADs and CP-logic: the clause bodies can contain \texttt{setof} and \texttt{bagof}, the probabilities in the head may be depend on variables in the body and it is possible to specify a uniform distribution in the head with reference to a \texttt{setof} or \texttt{bagof} operator. These extended features have been introduced in order to represent CLP(BN) \cite{SanPagQaz03-UAI-IC} programs and PRM models \cite{Getoor+al:JMLR02}:
|
||||
\texttt{setof} and \texttt{bagof} allow to express dependency of an attribute from an aggregate function of another attribute, as in CLP(BN) and PRM, while the possibility of specifying a uniform distribution allows the use of the reference uncertainty feature of PRM.
|
||||
\item \texttt{lpad.pl}: computes the probability of a query using a top-down procedure based on SLG resolution \cite{DBLP:journals/jacm/ChenW96}. As a consequence, it works for any sound LPADs, i.e., any LPAD such that each of its instances has a two valued well founded model.
|
||||
\item \texttt{cpl.pl}: computes the probability of a query using a top-down procedure based on SLG resolution and moreover checks that the CP-logic program is valid, i.e., that it has at least an execution model.
|
||||
\end{itemize}
|
||||
|
||||
The modules for answering queries using the definition of the semantics of LPADs and CP-logic are \texttt{semlpadsld.pl}, \texttt{semlpad.pl} and
|
||||
\texttt{semcpl.pl}:
|
||||
\begin{itemize}
|
||||
\item \texttt{semlpadsld.pl}: given an LPAD $P$, it generates all the instances of $P$. The probability of a query $Q$ is computed by identifying all the instances where $Q$ is derivable by SLDNF resolution.
|
||||
\item \texttt{semlpad.pl}: given an LPAD $P$, it generates all the instances of $P$. The probability of a query $Q$ is computed by identifying all the instances where $Q$ is derivable by SLG resolution.
|
||||
\item \texttt{semlcpl.pl}: given an LPAD $P$, it builds an execution model of $P$, i.e., a probabilistic process that satisfy the principles of universal causation, sufficient causation, independent causation, no deus ex machina events and temporal precedence. It uses the definition of the semantics given in \cite{CP-logic-unp}.
|
||||
\end{itemize}
|
||||
%For program with function symbols, the semantics of LPADs and CP-logic are not defined. However, the interpreter accepts programs with function symbols and, if it does not go into a loop, it returns an answer. What is the meaning of this answer is subject of current study.
|
||||
|
||||
\section{Installation}
|
||||
\texttt{cplint} is distributed in source code in the CVS version of Yap. It includes Prolog and C files. Download it by following the instruction in \href{http://www.ncc.up.pt/~vsc/Yap/downloads.html}{http://www.ncc.up.pt/$\sim$vsc/Yap/downloads.html}.
|
||||
|
||||
\texttt{cplint} requires glu (a subpackage of vis) and glib-2.0.
|
||||
You can download glu from \href{http://vlsi.colorado.edu/~vis/getting_VIS_2.1.html}{http://vlsi.colorado.edu/$\sim$vis/getting\_VIS\_2.1.html}
|
||||
You can download glib-2.0 (version $\geq 2.0$) from \href{http://www.gtk.org/}{http://www.gtk.org/}. This is a standard GNU package
|
||||
so it is easy to install it using the package management software of your Linux or Cygwin
|
||||
distribution.
|
||||
|
||||
Install glu:
|
||||
\begin{enumerate}
|
||||
\item downlad \texttt{glu-2.1.tar.gz}
|
||||
\item decompress it
|
||||
\item \texttt{cd glu-2.1}
|
||||
\item \texttt{mkdir arch}
|
||||
\item \texttt{cd arch}
|
||||
\item \texttt{../configure}
|
||||
\item \texttt{make}
|
||||
\item \texttt{su}
|
||||
\item \texttt{make install}
|
||||
\end{enumerate}
|
||||
This will install glu into \texttt{/usr/local}, if you want to install to a different \texttt{DIR}
|
||||
use \texttt{../configure --prefix DIR}
|
||||
|
||||
Install Yap together with \texttt{cplint}:
|
||||
when compiling Yap following the instuction of the \texttt{INSTALL} file in the root of the Yap folder, use
|
||||
\begin{verbatim}
|
||||
configure --enable-cplint
|
||||
\end{verbatim}
|
||||
Under Windows, you have to use Cygwin (glu does not compile under MinGW), so\\
|
||||
\begin{verbatim}
|
||||
configure --enable-cplint --enable-cygwin
|
||||
\end{verbatim}
|
||||
If you installed glu in \texttt{DIR}, use \texttt{--enable-cplint=DIR}
|
||||
|
||||
After having performed \texttt{make install} you can do \texttt{make installcheck} that will execute a suite of tests of the various programs. If no error is reported you have a working installation of \texttt{cplint}.
|
||||
|
||||
|
||||
\section{Syntax}
|
||||
|
||||
Disjunction in the head is represented with a semicolon and atoms in the head are separated from probabilities by a colon. For the rest, the usual syntax of Prolog is used.
|
||||
For example, the CP-logic clause
|
||||
$$h_1:p_1\vee \ldots \vee h_n:p_n\leftarrow b_1,\dots,b_m ,\neg c_1,\ldots,\neg c_l$$
|
||||
is represented by
|
||||
\begin{verbatim}
|
||||
h1:p1 ; ... ; hn:pn :- b1,...,bm,\+ c1,....,\+ cl
|
||||
\end{verbatim}
|
||||
No parentheses are necessary. The \texttt{pi} are numeric expressions. It is up to the user to ensure that the numeric expressions are legal, i.e. that they sum up to less than one.
|
||||
|
||||
If the clause has an empty body, it can be represented like this
|
||||
\begin{verbatim}
|
||||
h1:p1 ; ... ;hn:pn.
|
||||
\end{verbatim}
|
||||
If the clause has a single head with probability 1, the annotation can be omitted and the clause takes the form of a normal prolog clause, i.e.
|
||||
\begin{verbatim}
|
||||
h1:- b1,...,bm,\+ c1,...,\+ cl.
|
||||
\end{verbatim}
|
||||
stands for
|
||||
\begin{verbatim}
|
||||
h1:1 :- b1,...,bm,\+ c1,...,\+ cl.
|
||||
\end{verbatim}
|
||||
|
||||
The coin example of \cite{VenVer04-ICLP04-IC} is represented as (see file \texttt{coin.cpl})
|
||||
\begin{verbatim}
|
||||
heads(Coin):1/2 ; tails(Coin):1/2:-
|
||||
toss(Coin),\+biased(Coin).
|
||||
|
||||
heads(Coin):0.6 ; tails(Coin):0.4:-
|
||||
toss(Coin),biased(Coin).
|
||||
|
||||
fair(Coin):0.9 ; biased(Coin):0.1.
|
||||
|
||||
toss(coin).
|
||||
\end{verbatim}
|
||||
The first clause states that if we toss a coin that is not biased it has equal probability of landing heads and tails. The second states that if the coin is biased it has a slightly higher probability of landing heads. The third states that the coin is fair with probability 0.9 and biased with probability 0.1 and the last clause states that we toss a coin with certainty.
|
||||
|
||||
|
||||
|
||||
\section{Commands}
|
||||
All six modules accept the same commands for reading in files and answering queries.
|
||||
The LPAD or CP-logic program must be stored in a text file with extension \texttt{.cpl}. Suppose you have stored the example above in file \texttt{coin.cpl}.
|
||||
In order to answer queries from this program, you have to run Yap,
|
||||
load one of the modules (such as for example \texttt{lpad.pl}) by issuing the command
|
||||
\begin{verbatim}
|
||||
use_module(library(lpad)).
|
||||
\end{verbatim}
|
||||
at the command prompt.
|
||||
Then you must parse the source file \texttt{coin.cpl} with the command
|
||||
\begin{verbatim}
|
||||
p(coin).
|
||||
\end{verbatim}
|
||||
if \texttt{coin.cpl} is in the current directory, or
|
||||
\begin{verbatim}
|
||||
p('path_to_coin/coin').
|
||||
\end{verbatim}
|
||||
if \texttt{coin.cpl} is in a different directory.
|
||||
At this point you can pose query to the program by using the predicate \texttt{s/2} (for solve) that takes as its first argument a conjunction of goals in the form of a list and returns the computed probability as its second argument. For example, the probability of the conjunction \texttt{head(coin),biased(coin)} can be asked with the query
|
||||
\begin{verbatim}
|
||||
s([head(coin),biased(coin)],P).
|
||||
\end{verbatim}
|
||||
For computing the probability of a conjunction given another conjunction you can use the predicate \texttt{sc/3} (for solve conditional) that take takes as input the query conjunction as its first argument, the evidence conjunction as its second argument and returns the probability in its third argument.
|
||||
For example, the probability of the query \texttt{heads(coin)} given the evidence \texttt{biased(coin)} can be asked with the query
|
||||
\begin{verbatim}
|
||||
sc([heads(coin)],[biased(coin)],P).
|
||||
\end{verbatim}
|
||||
After having parsed a program, in order to read in a new program you must restart Yap when using
|
||||
\texttt{semlpadsld.pl} and \texttt{semlpad.pl}. With the other modules, you can directly parse a new program.
|
||||
|
||||
When using \texttt{lpad.pl}, the system can print the message ``Uunsound program'' in the case in which an instance with a three valued well founded model is found. Moreover, it can print the message ``It requires the choice of a head atom from a non ground head'': in this case, in order to answer the query, all the groundings of the culprit clause must be generated, which may be impossible for programs with function symbols.
|
||||
|
||||
When using \texttt{semcpl.pl}, you can print the execution process by using the command \texttt{print.}
|
||||
after \texttt{p(file).} Moreover, you can build an execution process given a context by issuing the command \texttt{parse(file)}. and then
|
||||
\texttt{build(context).} where \texttt{context} is a list of atoms that are true in the context.
|
||||
\texttt{semcpl.pl} can print ``Invalid program'' in the case in which no execution process exists.
|
||||
|
||||
When using \texttt{cpl.pl} you can print a partial execution model including all the clauses involved in the query issued with \texttt{print.} \texttt{cpl.pl} can print the messages ``Uunsound program'', ``It requires the choice of a head atom from a non ground head'' and ``Invalid program''.
|
||||
|
||||
|
||||
The modules make use of a number of parameters in order to control their behavior. They that can be set with the command
|
||||
\begin{verbatim}
|
||||
set(parameter,value).
|
||||
\end{verbatim}
|
||||
from the Yap prompt after having loaded the module.
|
||||
The current value can be read with
|
||||
\begin{verbatim}
|
||||
setting(parameter,Value).
|
||||
\end{verbatim}
|
||||
from the Yap prompt.
|
||||
The available parameters are:
|
||||
\begin{itemize}
|
||||
\item
|
||||
\verb|epsilon_parsing| (valid for all six modules): if (1 - the sum of the probabilities of all the head atoms) is smaller than
|
||||
\verb|epsilon_parsing|
|
||||
then \texttt{cplint} adds the null events to the head. Default value 0.00001
|
||||
\item \verb|save_dot| (valid for all goal-oriented modules): if \texttt{true} a graph representing the BDD is saved in the file \texttt{cpl.dot} in the current directory in dot format.
|
||||
The variables names are of the form \verb|Xn_m| where \texttt{n} is the number of the multivalued
|
||||
variable and \texttt{m} is the number of the binary variable. The correspondence between variables and
|
||||
clauses can be evinced from the message printed on the screen, such as
|
||||
\begin{verbatim}
|
||||
Variables: [(2,[X=2,X1=1]),(2,[X=1,X1=0]),(1,[])]
|
||||
\end{verbatim}
|
||||
where the first element of each couple is the clause number of the input file (starting from 1).
|
||||
In the example above variable \texttt{X0} corresponds to clause \texttt{2} with the substitutions \texttt{X=2,X1=1},
|
||||
variable \texttt{X1} corresponds to clause \texttt{2} with the substitutions \texttt{X=1,X1=0} and
|
||||
variable \texttt{X2} corresponds to clause \texttt{1} with the empty substitution.
|
||||
You can view the graph with \texttt{graphviz} (\href{www.graphviz.org}{www.graphviz.org}) using the
|
||||
command
|
||||
\begin{verbatim}
|
||||
dotty cpl.dot &
|
||||
\end{verbatim}
|
||||
\item \verb|ground_body| (valid for \texttt{lpadsld.pl} and all semantic modules): determines how non ground clauses are treated: if \texttt{true}, ground clauses are obtained from a non ground clause by replacing each variable with a constant, if \texttt{false}, ground clauses are obtained by replacing only variables in the head with a constant. In the case where the body contains variables not in the head, setting it to false means that the body represents an existential event.
|
||||
\end{itemize}
|
||||
|
||||
\section{Semantic Modules}
|
||||
The three semantic modules need to produce a grounding of the program in order to compute the semantics.
|
||||
They require an extra file with extension \texttt{.uni} (for universe) in the same directory where the \texttt{.cpl} file is.
|
||||
|
||||
There are two ways to specify how to ground a program. The first consists in providing the list of constants to which each variable can be instantiated. For example, in our case the current directory will contain a file \texttt{coin.uni} that is a Prolog file containing facts of the form
|
||||
\begin{verbatim}
|
||||
universe(var_list,const_list).
|
||||
\end{verbatim}
|
||||
where \verb|var_list| is a list of variables names (each must be included in single quotes) and \verb|const_list| is a list of constants. The semantic modules generate the grounding by instantiating in all possible ways the variables of \verb|var_list| with the constants of \verb|const_list|. Note that the variables are identified by name, so a variable with the same name in two different clauses will be instantiated with the same constants.
|
||||
|
||||
The other way to specify how to ground a program consists in using mode and type information. For each predicate, the file \texttt{.uni} must contain a fact of the form
|
||||
\begin{verbatim}
|
||||
mode(predicate(t1,...,tn)).
|
||||
\end{verbatim}
|
||||
that specifies the number and types of each argument of the predicate. Then, the list of constants that
|
||||
are in the domain of each type \texttt{ti} must be specified with a fact of the form
|
||||
\begin{verbatim}
|
||||
type(ti,list_of_constants).
|
||||
\end{verbatim}
|
||||
The file \texttt{.uni} can contain both universe and mode declaration, the ones to be used depend on the value of the parameter \texttt{grounding}: with value \texttt{variables}, the universe declarations are used, with value \texttt{modes} the mode declarations are used.
|
||||
|
||||
With \texttt{semcpl.pl} only mode declarations can be used.
|
||||
|
||||
|
||||
|
||||
\section{Extensions}
|
||||
In this section we will present the extensions to the syntax of LPADs and CP-logic programs that \texttt{cplint} can handle.
|
||||
|
||||
The first is the use of some standard Prolog predicates.
|
||||
The bodies can contain the built-in predicates:
|
||||
\begin{verbatim}
|
||||
is/2
|
||||
>/2
|
||||
</2
|
||||
>=/2
|
||||
=</2
|
||||
=:=/2
|
||||
=\=/2
|
||||
true/0
|
||||
false/0
|
||||
=/2
|
||||
==/2
|
||||
\=/2
|
||||
\==/2
|
||||
length/2
|
||||
\end{verbatim}
|
||||
The bodies can also contain the following
|
||||
library predicates:
|
||||
\begin{verbatim}
|
||||
member/2
|
||||
max_list/2
|
||||
min_list/2
|
||||
nth0/3
|
||||
nth/3
|
||||
\end{verbatim}
|
||||
plus the predicate
|
||||
\begin{verbatim}
|
||||
average/2
|
||||
\end{verbatim}
|
||||
that, given a list of numbers, computes its arithmetic mean.
|
||||
|
||||
When using \texttt{lpadsld.pl}, the bodies can contain the predicates \texttt{setof/3} and \texttt{bagof/3} with the same meaning as in Prolog. Existential quantifiers are allowed in both, so for example the query
|
||||
\begin{verbatim}
|
||||
setof(Z, (term(X,Y))^foo(X,Y,Z), L).
|
||||
\end{verbatim}
|
||||
returns all the instantiations of \texttt{Z} such that there exists an instantiation of \texttt{X} and \texttt{Y} for which \texttt{foo(X,Y,Z)} is true.
|
||||
|
||||
An example of the use of \texttt{setof} and \texttt{bagof} is in the file \texttt{female.cpl}:
|
||||
\begin{verbatim}
|
||||
male(C):M/P ; female(C):F/P:-
|
||||
person(C),
|
||||
setof(Male,known_male(Male),LM),
|
||||
length(LM,M),
|
||||
setof(Female,known_female(Female),LF),
|
||||
length(LF,F),
|
||||
P is F+M.
|
||||
|
||||
person(f).
|
||||
|
||||
known_female(a).
|
||||
|
||||
known_female(b).
|
||||
|
||||
known_female(c).
|
||||
|
||||
known_male(d).
|
||||
|
||||
known_male(e).
|
||||
\end{verbatim}
|
||||
The disjunctive rule expresses the probability of a person of unknown sex of being male or female depending on the number of males and females that are known.
|
||||
This is an example of the use of expressions in the probabilities in the head that depend on variables in the body. The probabilities are well defined because they always sum to 1 (unless \texttt{P} is 0).
|
||||
|
||||
Another use of \texttt{setof} and \texttt{bagof} is to have an attribute depend on an aggregate function of another attribute, similarly to what is done in PRM and CLP(BN).
|
||||
|
||||
So, in the classical school example (available in \texttt{student.cpl}) you can find the following
|
||||
clauses:
|
||||
\begin{verbatim}
|
||||
student_rank(S,h):0.6 ; student_rank(S,l):0.4:-
|
||||
bagof(G,R^(registr_stu(R,S),registr_gr(R,G)),L),
|
||||
average(L,Av),Av>1.5.
|
||||
|
||||
student_rank(S,h):0.4 ; student_rank(S,l):0.6:-
|
||||
bagof(G,R^(registr_stu(R,S),registr_gr(R,G)),L),
|
||||
average(L,Av),Av =< 1.5.
|
||||
\end{verbatim}
|
||||
where \verb|registr_stu(R,S)| expresses that registration \texttt{R} refers to student \texttt{S} and \verb|registr_gr(R,G)| expresses that registration \texttt{R} reports grade \texttt{G} which is a natural number. The two clauses express a dependency of the rank of the student from the average of her grades.
|
||||
|
||||
Another extension can be used with \texttt{lpadsld.pl} in order to be able to represent reference uncertainty of PRMs. Reference uncertainty means that the link structure of a relational model is not fixed but is uncertain: this is represented by having the instance referenced in a relationship be chosen uniformly from a set. For example, consider a domain modeling scientific papers: you have a single entity, paper, and a relationship, cites, between paper and itself that connects the citing paper to the cited paper. To represent the fact that the cited paper and the citing paper are selected uniformly from certain sets, the following clauses can be used (see file \verb|paper_ref_simple.cpl|):
|
||||
\begin{verbatim}
|
||||
uniform(cites_cited(C,P),P,L):-
|
||||
bagof(Pap,paper_topic(Pap,theory),L).
|
||||
|
||||
uniform(cites_citing(C,P),P,L):-
|
||||
bagof(Pap,paper_topic(Pap,ai),L).
|
||||
\end{verbatim}
|
||||
The first clauses states that the paper \texttt{P} cited in a citation \texttt{C} is selected uniformly from the set of all papers with topic theory.
|
||||
The second clauses expresses that the citing paper is selected uniformly from the papers with
|
||||
topic ai.
|
||||
|
||||
These clauses make use of the predicate
|
||||
\begin{verbatim}
|
||||
uniform(Atom,Variable,List)
|
||||
\end{verbatim}
|
||||
in the head, where \texttt{Atom} must contain \texttt{Variable}. The meaning is the following: the set of all the atoms obtained by instantiating \texttt{Variable} of \texttt{Atom} with a term taken from \texttt{List} is generated and the head is obtained by having a disjunct for each instantiation with probability $1/N$ where $N$ is the length of \texttt{List}.
|
||||
|
||||
|
||||
A more elaborate example is present in file \verb|paper_ref.cpl|:
|
||||
\begin{verbatim}
|
||||
uniform(cites_citing(C,P),P,L):-
|
||||
setof(Pap,paper(Pap),L).
|
||||
|
||||
cites_cited_group(C,theory):0.9 ; cites_cited_group(C,ai):0.1:-
|
||||
cites_citing(C,P),paper_topic(P,theory).
|
||||
|
||||
cites_cited_group(C,theory):0.01;cites_cited_group(C,ai):0.99:-
|
||||
cites_citing(C,P),paper_topic(P,ai).
|
||||
|
||||
uniform(cites_cited(C,P),P,L):-
|
||||
cites_cited_group(C,T),bagof(Pap,paper_topic(Pap,T),L).
|
||||
\end{verbatim}
|
||||
where the cited paper depends on the topic of the citing paper. In particular, if the topic is theory, the cited paper is selected uniformly from the papers about theory with probability 0.9 and from the papers about ai with probability 0.1. if the topic is ai, the cited paper is selected uniformly from the papers about theory with probability 0.01 and from the papers about ai with probability 0.99.
|
||||
|
||||
PRMs take into account as well existence uncertainty, where the existence of instances is also probabilistic. For example, in the paper domain, the total number of citations may be unknown and a citation between any two paper may have a probability of existing. For example, a citation between two paper may be more probable if they are about the same topic:
|
||||
\begin{verbatim}
|
||||
cites(X,Y):0.005 :-
|
||||
paper_topic(X,theory),paper_topic(Y,theory).
|
||||
|
||||
cites(X,Y):0.001 :-
|
||||
paper_topic(X,theory),paper_topic(Y,ai).
|
||||
|
||||
cites(X,Y):0.003 :-
|
||||
paper_topic(X,ai),paper_topic(Y,theory).
|
||||
|
||||
cites(X,Y):0.008 :-
|
||||
paper_topic(X,ai),paper_topic(Y,ai).
|
||||
\end{verbatim}
|
||||
This is an example where the probabilities in the head do not sum up to one so the null event is automatically added to the head.
|
||||
The first clause states that, if the topic of a paper \texttt{X} is theory and of paper \texttt{Y} is theory, there is a probability of 0.005 that there is a citation from \texttt{X} to \texttt{Y}. The other clauses consider the remaining cases for the topics.
|
||||
|
||||
|
||||
\section{Additional Files}
|
||||
In the directory where Yap keeps the library files (usually \texttt{/usr/local/share/ Yap}) you can find the directory \texttt{cplint} that contains the files:
|
||||
\begin{itemize}
|
||||
\item \verb|testlpadsld_gbtrue.pl, testlpadsld_gbfalse.pl, testlpad.pl,|
|
||||
\verb|testcpl.pl, testsemlpadsld.pl, testsemlpad.pl testsemcpl.pl|: Prolog programs for testing the modules. They are executed when issuing the command \texttt{make installcheck} during the installation. To execute them afterwords, load the file and issue the command \texttt{t.}
|
||||
\item Subdirectory \texttt{examples}:
|
||||
\begin{itemize}
|
||||
\item \texttt{alarm.cpl}: representation of the Bayesian network in Figure 2 of
|
||||
\cite{VenVer04-ICLP04-IC}.
|
||||
\item \texttt{coin.cpl}: coin example from \cite{VenVer04-ICLP04-IC}.
|
||||
\item \texttt{coin2.cpl}: coin example with two coins.
|
||||
\item \texttt{dice.cpl}: dice example from \cite{VenVer04-ICLP04-IC}.
|
||||
\item \verb|twosideddice.cpl, threesideddice.cpl| game with idealized dice with two or three sides. Used in the experiments in \cite{Rig-RCRA07-IC}.
|
||||
\item \texttt{ex.cpl}: first example in \cite{Rig-RCRA07-IC}.
|
||||
\item \texttt{exapprox.cpl}: example showing the problems of approximate inference (see \cite{Rig-RCRA07-IC}).
|
||||
\item \texttt{exrange.cpl}: example showing the problems with non range restricted programs (see \cite{Rig-RCRA07-IC}).
|
||||
\item \texttt{female.cpl}: example showing the dependence of probabilities in the head from variables in the body (from \cite{VenVer04-ICLP04-IC}).
|
||||
\item \texttt{mendel.cpl, mendels.cpl}: programs describing the Mendelian rules of inheritance, taken from \cite{Blo04-ILP04WIP-IC}.
|
||||
\item \verb|paper_ref.cpl, paper_ref_simple.cpl|: paper citations examples, showing reference uncertainty, inspired by \cite{Getoor+al:JMLR02}.
|
||||
\item \verb|paper_ref_not.cpl|: paper citations example showing that negation can be used also for predicates defined by clauses with \texttt{uniform} in the head.
|
||||
\item \texttt{school.cpl}: example inspired by the example \verb|school_32.yap| from the
|
||||
source distribution of Yap in the \texttt{CLPBN} directory.
|
||||
\item \verb|school_simple.cpl|: simplified version of \texttt{school.cpl}.
|
||||
\item \verb|student.cpl|: student example from Figure 1.3 of \cite{GetFri01-BC}.
|
||||
\item \texttt{win.cpl, light.cpl, trigger.cpl, throws.cpl, hiv.cpl,}\\ \texttt{ invalid.cpl}: programs taken from \cite{CP-logic-unp}. \texttt{invalid.cpl} is an example of a program that is invalid but sound.
|
||||
\end{itemize}
|
||||
The files \texttt{*.uni} that are present for some of the examples are used by the semantical modules. Some of the example files contain in an initial comment some queries together with their result.
|
||||
\item Subdirectory \texttt{doc}: contains this manual in latex, html and pdf.
|
||||
\end{itemize}
|
||||
\section{License}
|
||||
\label{license}
|
||||
|
||||
|
||||
|
||||
\texttt{cplint}, as Yap, follows the Artistic License 2.0 that you can find in Yap CVS root dir. The copyright is by Fabrizio Riguzzi.
|
||||
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
The program uses the library \href{http://vlsi.colorado.edu/~fabio/}{CUDD} for manipulating BDDs that is included in glu.
|
||||
For the use of CUDD, the following license must be accepted:
|
||||
|
||||
\vspace{3mm}
|
||||
|
||||
Copyright (c) 1995-2004, Regents of the University of Colorado
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
\begin{itemize}
|
||||
\item
|
||||
Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
\item
|
||||
Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
\item
|
||||
Neither the name of the University of Colorado nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
\end{itemize}
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS \\ AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAU-SED
|
||||
\\ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
\texttt{lpad.pl}, \texttt{semlpad.pl} and \texttt{cpl.pl} are based on the SLG system
|
||||
by \href{http://engr.smu.edu/~wchen/}{Weidong Chen} and \href{http://www.cs.sunysb.edu/~warren/}{David Scott Warren},
|
||||
Copyright (C) 1993 Southern Methodist University, 1993 SUNY at Stony Brook, see the file COYPRIGHT\_SLG for detailed information on this copyright.
|
||||
|
||||
\bibliographystyle{plain}
|
||||
\bibliography{bib}
|
||||
|
||||
\end{document}
|
||||
BIN
packages/cplint/doc/manual0x.png
Normal file
BIN
packages/cplint/doc/manual0x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
7
packages/cplint/examples/alarm.cpl
Normal file
7
packages/cplint/examples/alarm.cpl
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
burg(t):0.1; burg(f):0.9.
|
||||
earthq(t):0.2; earthq(f):0.8.
|
||||
alarm(t):-burg(t),earthq(t).
|
||||
alarm(t):0.8 ; alarm(f):0.2:-burg(t),earthq(f).
|
||||
alarm(t):0.8 ; alarm(f):0.2:-burg(f),earthq(t).
|
||||
alarm(t):0.1 ; alarm(f):0.9:-burg(f),earthq(f).
|
||||
17
packages/cplint/examples/coin.cpl
Normal file
17
packages/cplint/examples/coin.cpl
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
s([heads(C)],P).
|
||||
C = coin
|
||||
P = 0.51 ?;
|
||||
no
|
||||
s([tails(C)],P).
|
||||
C = coin
|
||||
P = 0.49 ?;
|
||||
no
|
||||
|
||||
|
||||
*/
|
||||
|
||||
heads(Coin): 1/2; tails(Coin) : 1/2:-toss(Coin),\+biased(Coin).
|
||||
heads(Coin): 0.6 ; tails(Coin) : 0.4:-toss(Coin),biased(Coin).
|
||||
fair(Coin):0.9 ; biased(Coin):0.1.
|
||||
toss(coin).
|
||||
0
packages/cplint/examples/coin.uni
Normal file
0
packages/cplint/examples/coin.uni
Normal file
23
packages/cplint/examples/coin2.cpl
Normal file
23
packages/cplint/examples/coin2.cpl
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
?- s([heads(C)],P).
|
||||
C = coin1
|
||||
P = 0.51 ? ;
|
||||
C = coin2
|
||||
P = 0.51 ? ;
|
||||
no
|
||||
?- s([tails(C)],P).
|
||||
C = coin1
|
||||
P = 0.49 ? ;
|
||||
C = coin2
|
||||
P = 0.49 ? ;
|
||||
no
|
||||
|
||||
s([tails(coin1)],P).
|
||||
P = 0.49 ?
|
||||
*/
|
||||
|
||||
heads(Coin): 0.5; tails(Coin) : 0.5:-toss(Coin),fair(Coin).
|
||||
heads(Coin): 0.6 ; tails(Coin) : 0.4:-toss(Coin),biased(Coin).
|
||||
fair(Coin):0.9 ; biased(Coin):0.1.
|
||||
toss(coin1).
|
||||
toss(coin2).
|
||||
9
packages/cplint/examples/coin2.uni
Normal file
9
packages/cplint/examples/coin2.uni
Normal file
@@ -0,0 +1,9 @@
|
||||
universe(['Coin'],[coin1,coin2]).
|
||||
|
||||
mode(heads(coin)).
|
||||
mode(tails(coin)).
|
||||
mode(toss(coin)).
|
||||
mode(fair(coin)).
|
||||
mode(biased(coin)).
|
||||
|
||||
type(coin,[coin1,coin2]).
|
||||
29
packages/cplint/examples/dice.cpl
Normal file
29
packages/cplint/examples/dice.cpl
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
s([on(0,1)],P).
|
||||
P = 0.166666666666667 ?;
|
||||
s([\+ on(0,6)],P).
|
||||
P = 0.833333333333333 ?;
|
||||
|
||||
|
||||
s([on(1,1)],P).
|
||||
P = 0.138888888888889 ?
|
||||
s([on(1,6)],P).
|
||||
P = 0.138888888888889 ?
|
||||
s([on(2,1)],P).
|
||||
out of memory
|
||||
s([on(0,1),on(1,1)],P).
|
||||
P = 0.0277777777777778 ?
|
||||
s([on(0,1),on(1,1),on(2,1)],P).
|
||||
P = 0.00462962962962963 ?
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
on(0,1):1/6;on(0,2):1/6;on(0,3):1/6;
|
||||
on(0,4):1/6;on(0,5):1/6;on(0,6):1/6.
|
||||
|
||||
on(X,1):1/6;on(X,2):1/6;on(X,3):1/6;
|
||||
on(X,4):1/6;on(X,5):1/6;on(X,6):1/6:-
|
||||
X1 is X-1,X1>=0,on(X1,_),
|
||||
\+ on(X1,6).
|
||||
2
packages/cplint/examples/dice.uni
Normal file
2
packages/cplint/examples/dice.uni
Normal file
@@ -0,0 +1,2 @@
|
||||
universe(['X'],[1,2]).
|
||||
universe(['X1'],[0,1]).
|
||||
13
packages/cplint/examples/ex.cpl
Normal file
13
packages/cplint/examples/ex.cpl
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
s([a],P).
|
||||
Variables: [(1,[]),(2,[]),(3,[])]
|
||||
P = 0.226 ?
|
||||
*/
|
||||
|
||||
a:0.1.
|
||||
|
||||
|
||||
|
||||
b:0.3;c:0.6.
|
||||
|
||||
a:0.2:- \+ b.
|
||||
6
packages/cplint/examples/ex.uni
Normal file
6
packages/cplint/examples/ex.uni
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
mode(a).
|
||||
|
||||
mode(b).
|
||||
|
||||
mode(c).
|
||||
17
packages/cplint/examples/exapprox.cpl
Normal file
17
packages/cplint/examples/exapprox.cpl
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
|
||||
set(ground_body,true).
|
||||
s([a],P).
|
||||
Variables: [(1,[]),(2,[]),(3,[])]
|
||||
P = 0.1719 ? ;
|
||||
|
||||
set(ground_body,false).
|
||||
?- s([a],P).
|
||||
P = 0.099 ?
|
||||
*/
|
||||
|
||||
a:0.1:-p(X).
|
||||
|
||||
p(1):0.9.
|
||||
|
||||
p(2):0.9.
|
||||
9
packages/cplint/examples/exapprox.uni
Normal file
9
packages/cplint/examples/exapprox.uni
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
universe(['X'],[1,2]).
|
||||
|
||||
|
||||
mode(a).
|
||||
|
||||
mode(p(int)).
|
||||
|
||||
type(int,[1,2]).
|
||||
32
packages/cplint/examples/exist.cpl
Normal file
32
packages/cplint/examples/exist.cpl
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
semlpad.pl
|
||||
ground_body(false)
|
||||
?- s([a],P).
|
||||
P = 0.18 ?
|
||||
|
||||
ground_body(true)
|
||||
?- s([a],P).
|
||||
P = 0.19 ?
|
||||
yes
|
||||
|
||||
|
||||
yes
|
||||
lpad.pl
|
||||
ground_body(false)
|
||||
?- s([a],P).
|
||||
P = 0.02 ?
|
||||
yes
|
||||
ground_body(true)
|
||||
?- s([a],P).
|
||||
P = 0.19 ?
|
||||
yes
|
||||
|
||||
*/
|
||||
|
||||
a:0.5 :- p(X).
|
||||
|
||||
p(X):0.2 :- c(X).
|
||||
|
||||
c(1).
|
||||
|
||||
c(2).
|
||||
8
packages/cplint/examples/exist.uni
Normal file
8
packages/cplint/examples/exist.uni
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
mode(a).
|
||||
|
||||
mode(p(int)).
|
||||
|
||||
mode(c(int)).
|
||||
|
||||
type(int,[1,2]).
|
||||
31
packages/cplint/examples/exist1.cpl
Normal file
31
packages/cplint/examples/exist1.cpl
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
semlpad.pl
|
||||
ground_body(false)
|
||||
?- s([a],P).
|
||||
P = 0.276 ?
|
||||
|
||||
ground_body(true)
|
||||
?- s([a],P).
|
||||
P = 0.3115 ?
|
||||
|
||||
|
||||
yes
|
||||
lpad.pl
|
||||
ground_body(false)
|
||||
?- s([a],P).
|
||||
P = 0.276 ?
|
||||
|
||||
ground_body(true)
|
||||
?- s([a],P).
|
||||
P = 0.3115 ?
|
||||
*/
|
||||
|
||||
a:0.5 :- p(X).
|
||||
|
||||
p(3):0.3.
|
||||
|
||||
p(X):0.2 :- c(X).
|
||||
|
||||
c(1).
|
||||
|
||||
c(2).
|
||||
10
packages/cplint/examples/exist1.uni
Normal file
10
packages/cplint/examples/exist1.uni
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
mode(a).
|
||||
|
||||
mode(p(int)).
|
||||
|
||||
mode(c(int)).
|
||||
|
||||
type(int,[1,2,3]).
|
||||
|
||||
|
||||
21
packages/cplint/examples/exrange.cpl
Normal file
21
packages/cplint/examples/exrange.cpl
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
s([a(X)],P).
|
||||
Variables: [(1,[]),(5,[]),(2,[]),(6,[])]
|
||||
P = 0.2775
|
||||
X = 1 ? ;
|
||||
Variables: [(3,[]),(5,[]),(4,[]),(6,[])]
|
||||
P = 0.36
|
||||
X = 2 ? ;
|
||||
*/
|
||||
|
||||
a(1):0.3:-p(1).
|
||||
|
||||
a(1):0.3:-p(2).
|
||||
|
||||
a(2):0.4:-p(1).
|
||||
|
||||
a(2):0.4:-p(2).
|
||||
|
||||
p(1):0.5.
|
||||
|
||||
p(2):0.5.
|
||||
6
packages/cplint/examples/exrange.uni
Normal file
6
packages/cplint/examples/exrange.uni
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
mode(a(int)).
|
||||
|
||||
mode(p(int)).
|
||||
|
||||
type(int,[1,2]).
|
||||
26
packages/cplint/examples/female.cpl
Normal file
26
packages/cplint/examples/female.cpl
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
s([female(f)],P).
|
||||
P = 0.6 ?
|
||||
s([male(f)],P).
|
||||
P = 0.4 ?
|
||||
|
||||
*/
|
||||
|
||||
|
||||
male(C):M/P;female(C):F/P:-
|
||||
person(C),
|
||||
setof(Male,known_male(Male),LM),
|
||||
length(LM,M),
|
||||
setof(Female,known_female(Female),LF),
|
||||
length(LF,F),
|
||||
P is F+M.
|
||||
|
||||
|
||||
person(f).
|
||||
|
||||
known_female(a).
|
||||
known_female(b).
|
||||
known_female(c).
|
||||
|
||||
known_male(d).
|
||||
known_male(e).
|
||||
27
packages/cplint/examples/hiv.cpl
Normal file
27
packages/cplint/examples/hiv.cpl
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
?- s([hiv(a)],P).
|
||||
P = 0.154 ?
|
||||
yes
|
||||
?- s([hiv(b)],P).
|
||||
P = 0.154 ?
|
||||
yes
|
||||
?- s([hiv(b),hiv(a)],P).
|
||||
P = 0.118 ?
|
||||
yes
|
||||
?- s([\+ hiv(b),\+ hiv(a)],P).
|
||||
P = 0.81 ?
|
||||
yes
|
||||
?- s([ hiv(b),\+ hiv(a)],P).
|
||||
P = 0.036 ?
|
||||
yes
|
||||
?- s([\+ hiv(b),hiv(a)],P).
|
||||
P = 0.036 ?
|
||||
yes
|
||||
*/
|
||||
|
||||
(hiv(a) : 0.1).
|
||||
(hiv(b) : 0.1).
|
||||
(hiv(a) : 0.6) :- hiv(b).
|
||||
(hiv(b) : 0.6) :- hiv(a).
|
||||
hiv(a) :- hiv(a).
|
||||
hiv(b) :- hiv(b).
|
||||
4
packages/cplint/examples/hiv.uni
Normal file
4
packages/cplint/examples/hiv.uni
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
mode(hiv(person)).
|
||||
|
||||
type(person,[a,b]).
|
||||
15
packages/cplint/examples/invalid.cpl
Normal file
15
packages/cplint/examples/invalid.cpl
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
?- s([p],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([q],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([p,q],P).
|
||||
P = 0 ?
|
||||
yes
|
||||
*/
|
||||
|
||||
p : 0.5;q : 0.5:- r.
|
||||
r :- \+ p.
|
||||
r :- \+ q.
|
||||
7
packages/cplint/examples/invalid.uni
Normal file
7
packages/cplint/examples/invalid.uni
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
mode(p).
|
||||
|
||||
mode(r).
|
||||
|
||||
mode(q).
|
||||
26
packages/cplint/examples/light.cpl
Normal file
26
packages/cplint/examples/light.cpl
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
?- p(light).
|
||||
yes
|
||||
?- s([push,replace],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([push,light],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([push,light,replace],P).
|
||||
P = 0 ?
|
||||
yes
|
||||
?- s([light,replace],P).
|
||||
P = 0 ?
|
||||
yes
|
||||
?- s([light],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([replace],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
*/
|
||||
|
||||
push.
|
||||
light : 0.5 :- push.
|
||||
replace :- \+ light.
|
||||
4
packages/cplint/examples/light.uni
Normal file
4
packages/cplint/examples/light.uni
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
mode(push).
|
||||
mode(light).
|
||||
mode(replace).
|
||||
38
packages/cplint/examples/mendel.cpl
Normal file
38
packages/cplint/examples/mendel.cpl
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
this file can not be used with s.pl: it generates too many programs
|
||||
s([cg(s,1,p)],P).
|
||||
P = 0.75 ?
|
||||
s([cg(s,1,w)],P).
|
||||
P = 0.25 ?
|
||||
s([cg(s,2,p)],P).
|
||||
P = 0.25 ?
|
||||
s([cg(s,2,w)],P).
|
||||
P = 0.75 ?
|
||||
s([cg(f,2,w)],P).
|
||||
P = 0.5
|
||||
s([cg(s,2,w)],P).
|
||||
P = 0.75
|
||||
|
||||
*/
|
||||
|
||||
mother(m,s).
|
||||
mother(mm,m).
|
||||
mother(mf,f).
|
||||
father(f,s).
|
||||
father(fm,m).
|
||||
father(ff,f).
|
||||
|
||||
|
||||
cg(mm,1,p).
|
||||
cg(mm,2,w).
|
||||
cg(fm,1,p).
|
||||
cg(fm,2,p).
|
||||
cg(mf,1,w).
|
||||
cg(mf,2,w).
|
||||
cg(ff,1,w).
|
||||
cg(ff,2,p).
|
||||
|
||||
|
||||
cg(X,1,A):0.5 ; cg(X,1,B):0.5 :- mother(Y,X),cg(Y,1,A) , cg(Y,2,B).
|
||||
|
||||
cg(X,2,A):0.5 ; cg(X,2,B):0.5 :- father(Y,X),cg(Y,1,A) , cg(Y,2,B).
|
||||
13
packages/cplint/examples/mendel.uni
Normal file
13
packages/cplint/examples/mendel.uni
Normal file
@@ -0,0 +1,13 @@
|
||||
mode(mother(person,person)).
|
||||
mode(father(person,person)).
|
||||
mode(cg(person,chr,allele)).
|
||||
|
||||
type(person,[s,m,f,mm,fm,mf,ff]).
|
||||
|
||||
type(chr,[1,2]).
|
||||
|
||||
type(allele,[p,w]).
|
||||
|
||||
universe(['X'],[s,m,f]).
|
||||
|
||||
universe(['A','B'],[p,w]).
|
||||
30
packages/cplint/examples/mendels.cpl
Normal file
30
packages/cplint/examples/mendels.cpl
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
this file can not be used with s.pl: it generates too many programs
|
||||
s([cg(s,1,p)],P).
|
||||
P = 0.75 ?
|
||||
s([cg(s,1,w)],P).
|
||||
P = 0.25 ?
|
||||
s([cg(s,2,p)],P).
|
||||
P = 0.25 ?
|
||||
s([cg(s,2,w)],P).
|
||||
P = 0.75 ?
|
||||
s([cg(f,2,w)],P).
|
||||
P = 0.5
|
||||
s([cg(s,2,w)],P).
|
||||
P = 0.75
|
||||
|
||||
*/
|
||||
|
||||
mother(m,s).
|
||||
father(f,s).
|
||||
|
||||
|
||||
cg(m,1,p).
|
||||
cg(m,2,w).
|
||||
cg(f,1,p).
|
||||
cg(f,2,p).
|
||||
|
||||
|
||||
cg(X,1,A):0.5 ; cg(X,1,B):0.5 :- mother(Y,X),cg(Y,1,A) , cg(Y,2,B).
|
||||
|
||||
cg(X,2,A):0.5 ; cg(X,2,B):0.5 :- father(Y,X),cg(Y,1,A) , cg(Y,2,B).
|
||||
13
packages/cplint/examples/mendels.uni
Normal file
13
packages/cplint/examples/mendels.uni
Normal file
@@ -0,0 +1,13 @@
|
||||
mode(mother(person,person)).
|
||||
mode(father(person,person)).
|
||||
mode(cg(person,chr,allele)).
|
||||
|
||||
type(person,[s,m,f]).
|
||||
|
||||
type(chr,[1,2]).
|
||||
|
||||
type(allele,[p,w]).
|
||||
|
||||
universe(['X'],[s]).
|
||||
|
||||
universe(['A','B'],[p,w]).
|
||||
51
packages/cplint/examples/paper_ref.cpl
Normal file
51
packages/cplint/examples/paper_ref.cpl
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
|
||||
?- s([cites_cited(c1,Pap)],P).
|
||||
P = 0.181333333333333,
|
||||
Pap = p1 ? ;
|
||||
P = 0.181333333333333,
|
||||
Pap = p2 ? ;
|
||||
P = 0.228,
|
||||
Pap = p3 ? ;
|
||||
P = 0.181333333333333,
|
||||
Pap = p4 ? ;
|
||||
P = 0.228,
|
||||
Pap = p5 ? ;
|
||||
no
|
||||
|
||||
*/
|
||||
paper(p1).
|
||||
|
||||
paper(p2).
|
||||
|
||||
paper(p3).
|
||||
|
||||
paper(p4).
|
||||
|
||||
paper(p5).
|
||||
|
||||
paper_topic(p1,theory).
|
||||
|
||||
paper_topic(p2,theory).
|
||||
|
||||
paper_topic(p4,theory).
|
||||
|
||||
paper_topic(p3,ai).
|
||||
|
||||
paper_topic(p5,ai).
|
||||
|
||||
cites(c1).
|
||||
|
||||
|
||||
uniform(cites_citing(C,P),P,L):-
|
||||
setof(Pap,paper(Pap),L).
|
||||
|
||||
cites_cited_group(C,theory):0.9;cites_cited_group(C,ai):0.1:-
|
||||
cites_citing(C,P),paper_topic(P,theory).
|
||||
|
||||
cites_cited_group(C,theory):0.01;cites_cited_group(C,ai):0.99:-
|
||||
cites_citing(C,P),paper_topic(P,ai).
|
||||
|
||||
uniform(cites_cited(C,P),P,L):-
|
||||
cites_cited_group(C,T),bagof(Pap,paper_topic(Pap,T),L).
|
||||
|
||||
41
packages/cplint/examples/paper_ref_not.cpl
Normal file
41
packages/cplint/examples/paper_ref_not.cpl
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
s([\+ cites_cited(c1,p1)],P).
|
||||
P = 0.7 ?
|
||||
|
||||
s([cites_citing(c1,p1)],P).
|
||||
P = 0.14 ?
|
||||
|
||||
*/
|
||||
paper(p1).
|
||||
|
||||
paper(p2).
|
||||
|
||||
paper(p3).
|
||||
|
||||
paper(p4).
|
||||
|
||||
paper(p5).
|
||||
|
||||
paper_topic(p1,theory).
|
||||
|
||||
paper_topic(p2,theory).
|
||||
|
||||
paper_topic(p4,theory).
|
||||
|
||||
paper_topic(p3,ai).
|
||||
|
||||
paper_topic(p5,ai).
|
||||
|
||||
cites(c1).
|
||||
|
||||
|
||||
cites_cited_group(C,theory):0.9;cites_cited_group(C,ai):0.1.
|
||||
|
||||
uniform(cites_cited(C,P),P,L):-
|
||||
cites_cited_group(C,T),bagof(Pap,paper_topic(Pap,T),L).
|
||||
|
||||
|
||||
uniform(cites_citing(C,P),P,L):-
|
||||
setof(Paper,paper(Paper),L),
|
||||
cites_cited(C,Pap),
|
||||
\+ cites_cited(C,p1).
|
||||
45
packages/cplint/examples/paper_ref_simple.cpl
Normal file
45
packages/cplint/examples/paper_ref_simple.cpl
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
?- s([cites_cited(c1,Pap)],P).
|
||||
P = 0.333333333333333,
|
||||
Pap = p1 ? ;
|
||||
P = 0.333333333333333,
|
||||
Pap = p2 ? ;
|
||||
P = 0.333333333333333,
|
||||
Pap = p4 ? ;
|
||||
no
|
||||
?- Action (h for help): c
|
||||
| s([cites_citing(c1,Pap)],P).
|
||||
P = 0.5,
|
||||
Pap = p3 ? ;
|
||||
P = 0.5,
|
||||
Pap = p5 ? ;
|
||||
no
|
||||
|
||||
*/
|
||||
paper(p1).
|
||||
|
||||
paper(p2).
|
||||
|
||||
paper(p3).
|
||||
|
||||
paper(p4).
|
||||
|
||||
paper(p5).
|
||||
|
||||
paper_topic(p1,theory).
|
||||
|
||||
paper_topic(p2,theory).
|
||||
|
||||
paper_topic(p4,theory).
|
||||
|
||||
paper_topic(p3,ai).
|
||||
|
||||
paper_topic(p5,ai).
|
||||
|
||||
cites(c1).
|
||||
|
||||
uniform(cites_cited(C,P),P,L):-
|
||||
bagof(Pap,paper_topic(Pap,theory),L).
|
||||
|
||||
uniform(cites_citing(C,P),P,L):-
|
||||
bagof(Pap,paper_topic(Pap,ai),L).
|
||||
796
packages/cplint/examples/school.cpl
Normal file
796
packages/cplint/examples/school.cpl
Normal file
@@ -0,0 +1,796 @@
|
||||
/*
|
||||
Yap run on school_32.yap
|
||||
?- s([professor_ability(p0,X)],P).
|
||||
P = 0.5,
|
||||
X = h ? ;
|
||||
P = 0.1,
|
||||
X = l ? ;
|
||||
P = 0.4,
|
||||
X = m ? ;
|
||||
no
|
||||
?- s([professor_popularity(p0,X)],P).
|
||||
P = 0.531,
|
||||
X = h ? ;
|
||||
P = 0.175,
|
||||
X = l ? ;
|
||||
P = 0.294,
|
||||
X = m ? ;
|
||||
no
|
||||
ok
|
||||
|
||||
sc([professor_ability(p0,X)],[professor_popularity(p0,h)],P).
|
||||
P = 0.847457627118644,
|
||||
X = h ? ;
|
||||
P = 0.00188323917137476,
|
||||
X = l ? ;
|
||||
P = 0.150659133709981,
|
||||
X = m ?
|
||||
ok
|
||||
|
||||
sc([professor_popularity(p0,X)],[professor_ability(p0,h)],P).
|
||||
P = 0.9,
|
||||
X = h ? ;
|
||||
P = 0.01,
|
||||
X = l ? ;
|
||||
P = 0.09,
|
||||
X = m ? ;
|
||||
no
|
||||
ok
|
||||
?- s([registration_grade(r0,X)],P).
|
||||
P = 0.06675,
|
||||
X = 1 ? ;
|
||||
P = 0.16575,
|
||||
X = 2 ? ;
|
||||
Action (";" for more choices, <return> for exit) ? ;
|
||||
P = 0.356,
|
||||
X = 3 ? ;
|
||||
P = 0.4115,
|
||||
X = 4 ?
|
||||
no
|
||||
ok
|
||||
|
||||
sc([registration_grade(r0,X)],[registration_course(r0,C), course_difficulty(C,h)],P).
|
||||
C = c16,
|
||||
P = 0.15,
|
||||
X = 1 ? ;
|
||||
C = c16,
|
||||
P = 0.285,
|
||||
X = 2 ? ;
|
||||
C = c16,
|
||||
P = 0.424,
|
||||
X = 3 ? ;
|
||||
C = c16,
|
||||
P = 0.141,
|
||||
X = 4 ? ;
|
||||
no
|
||||
ok (a=4, ...,d=1)
|
||||
|
||||
sc([registration_grade(r0,X)], [registration_course(r0,C), course_difficulty(C,h), registration_student(r0,S), student_intelligence(S,h)],P).
|
||||
C = c16,
|
||||
P = 0.05,
|
||||
S = s0,
|
||||
X = 1 ? ;
|
||||
C = c16,
|
||||
P = 0.15,
|
||||
S = s0,
|
||||
X = 2 ? ;
|
||||
C = c16,
|
||||
P = 0.6,
|
||||
S = s0,
|
||||
X = 3 ? ;
|
||||
C = c16,
|
||||
P = 0.2,
|
||||
S = s0,
|
||||
X = 4 ? ;
|
||||
no
|
||||
ok
|
||||
|
||||
sc([registration_grade(r0,X)],[registration_course(r0,C), course_difficulty(C,l), registration_student(r0,S), student_intelligence(S,h)],P).
|
||||
C = c16,
|
||||
P = 0.01,
|
||||
S = s0,
|
||||
X = 1 ? ;
|
||||
C = c16,
|
||||
P = 0.02,
|
||||
S = s0,
|
||||
X = 2 ? ;
|
||||
C = c16,
|
||||
P = 0.12,
|
||||
S = s0,
|
||||
X = 3 ? ;
|
||||
C = c16,
|
||||
P = 0.85,
|
||||
S = s0,
|
||||
X = 4 ? ;
|
||||
no
|
||||
ok
|
||||
|
||||
s([registration_satisfaction(r0,X)],P).
|
||||
P = 0.15197525,
|
||||
X = 1 ? ;
|
||||
P = 0.15331025,
|
||||
X = 2 ? ;
|
||||
P = 0.6947145,
|
||||
X = 3 ? ;
|
||||
no
|
||||
ok
|
||||
sc([registration_satisfaction(r0,X)],[ registration_student(r0,S), student_intelligence(S,h)],P).
|
||||
P = 0.0959225,
|
||||
S = s0,
|
||||
X = 1 ? ;
|
||||
P = 0.124515,
|
||||
S = s0,
|
||||
X = 2 ? ;
|
||||
P = 0.7795625,
|
||||
S = s0,
|
||||
X = 3 ? ;
|
||||
no
|
||||
ok (h=3, l=1)
|
||||
|
||||
sc([registration_satisfaction(r0,X)],[registration_grade(r0,4)],P).
|
||||
P = 0.04,
|
||||
X = 1 ? ;
|
||||
P = 0.06,
|
||||
X = 2 ? ;
|
||||
P = 0.9,
|
||||
X = 3 ? ;
|
||||
in Yap:
|
||||
?- registration_satisfaction(r0,X), registration_grade(r0,a).
|
||||
% YAP: no handler for error error(domain_error(bayesian_domain),bind_clpbns(var(grade(r0),[a,b,c,d],[0.2,0.7,0.85,0.1,0.2,0.5,0.01,0.05,0.1,0.6,0.25,0.12,0.3,0.6,0.35,0.04,0.15,0.4,0.15,0.04,0.02,0.4,0.15,0.12,0.5,0.6,0.4,0.05,0.01,0.01,0.2,0.05,0.03,0.45,0.2,0.1],[_D11,_D12]),var(grade(r0),[a,b,c,d],[0.2,0.7,0.85,0.1,0.2,0.5,0.01,0.05,0.1,0.6,0.25,0.12,0.3,0.6,0.35,0.04,0.15,0.4,0.15,0.04,0.02,0.4,0.15,0.12,0.5,0.6,0.4,0.05,0.01,0.01,0.2,0.05,0.03,0.45,0.2,0.1],[_D13,_D12])))
|
||||
|
||||
sc([registration_satisfaction(r0,X)],[registration_grade(r0,1)],P).
|
||||
P = 0.528,
|
||||
X = 1 ? ;
|
||||
P = 0.167,
|
||||
X = 2 ? ;
|
||||
P = 0.305,
|
||||
X = 3 ? ;
|
||||
no
|
||||
?- sc([ registration_grade(r0,X)],[registration_satisfaction(r0,3)],P).
|
||||
P = 0.0293052037923492,
|
||||
X = 1 ? ;
|
||||
P = 0.114760451955444,
|
||||
X = 2 ? ;
|
||||
P = 0.322837654892765,
|
||||
X = 3 ? ;
|
||||
P = 0.533096689359442,
|
||||
X = 4 ? ;
|
||||
no
|
||||
?- registration_satisfaction(r0,X), registration_grade(r0,d).
|
||||
% YAP: no handler for error error(domain_error(bayesian_domain),bind_clpbns(var(grade(r0),[a,b,c,d],[0.2,0.7,0.85,0.1,0.2,0.5,0.01,0.05,0.1,0.6,0.25,0.12,0.3,0.6,0.35,0.04,0.15,0.4,0.15,0.04,0.02,0.4,0.15,0.12,0.5,0.6,0.4,0.05,0.01,0.01,0.2,0.05,0.03,0.45,0.2,0.1],[_D11,_D12]),var(grade(r0),[a,b,c,d],[0.2,0.7,0.85,0.1,0.2,0.5,0.01,0.05,0.1,0.6,0.25,0.12,0.3,0.6,0.35,0.04,0.15,0.4,0.15,0.04,0.02,0.4,0.15,0.12,0.5,0.6,0.4,0.05,0.01,0.01,0.2,0.05,0.03,0.45,0.2,0.1],[_D13,_D12])))
|
||||
|
||||
sc([ registration_grade(r0,X)],[registration_satisfaction(r0,3)],P).
|
||||
?- registration_satisfaction(r0,h), registration_grade(r0,X).
|
||||
% YAP: no handler for error error(domain_error(bayesian_domain),bind_clpbns(var(grade(r0),[a,b,c,d],[0.2,0.7,0.85,0.1,0.2,0.5,0.01,0.05,0.1,0.6,0.25,0.12,0.3,0.6,0.35,0.04,0.15,0.4,0.15,0.04,0.02,0.4,0.15,0.12,0.5,0.6,0.4,0.05,0.01,0.01,0.2,0.05,0.03,0.45,0.2,0.1],[_D11,_D12]),var(grade(r0),[a,b,c,d],[0.2,0.7,0.85,0.1,0.2,0.5,0.01,0.05,0.1,0.6,0.25,0.12,0.3,0.6,0.35,0.04,0.15,0.4,0.15,0.04,0.02,0.4,0.15,0.12,0.5,0.6,0.4,0.05,0.01,0.01,0.2,0.05,0.03,0.45,0.2,0.1],[_D13,_D12])))
|
||||
|
||||
s([course_rating(c0,X)],P).
|
||||
P = 0.5392099,
|
||||
X = h ? ;
|
||||
P = 0.2,
|
||||
X = l ? ;
|
||||
P = 0.2607901,
|
||||
X = m ? ;
|
||||
no
|
||||
yap does not end, starts thrashing
|
||||
sc([course_difficulty(c0,X)],[course_rating(c0,h)],P).
|
||||
P = 0.235185778302661,
|
||||
X = h ? ;
|
||||
P = 0.259096503977393,
|
||||
X = l ? ;
|
||||
P = 0.505717717719945,
|
||||
X = m ? ;
|
||||
no
|
||||
yap does not end, starts thrashing
|
||||
s([course_difficulty(c0,X)],P).
|
||||
P = 0.25,
|
||||
X = h ? ;
|
||||
P = 0.25,
|
||||
X = l ? ;
|
||||
P = 0.5,
|
||||
X = m ? ;
|
||||
no
|
||||
ok
|
||||
student_ranking(s0,X).
|
||||
| ?- s([student_ranking(s0,X)],P).
|
||||
P = 0.33105221125,
|
||||
X = h ? ;
|
||||
P = 0.204865630625,
|
||||
X = l ? ;
|
||||
P = 0.46408215812500003,
|
||||
X = m ?
|
||||
not checked with s
|
||||
yap:
|
||||
true ?
|
||||
yes
|
||||
|
||||
|
||||
sc([student_ranking(s0,X)],[student_intelligence(s0,h)],P).
|
||||
P = 0.42922046875000003,
|
||||
X = h ? ;
|
||||
P = 0.20003319999999997,
|
||||
X = l ? ;
|
||||
P = 0.3707463312499999,
|
||||
X = m ? ;
|
||||
no
|
||||
not checked with s
|
||||
yap:
|
||||
true
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
professor_ability(Key,h):0.50;professor_ability(Key,m): 0.40;professor_ability(Key,l): 0.10.
|
||||
|
||||
professor_popularity(Key, h):0.9; professor_popularity(Key, m):0.09; professor_popularity(Key, l):0.01 :-
|
||||
professor_ability(Key, h).
|
||||
|
||||
professor_popularity(Key, h):0.2; professor_popularity(Key, m):0.6; professor_popularity(Key, l):0.2:-
|
||||
professor_ability(Key, m).
|
||||
|
||||
professor_popularity(Key, h):0.01; professor_popularity(Key, m):0.09; professor_popularity(Key, l):0.9 :-
|
||||
professor_ability(Key,l).
|
||||
|
||||
|
||||
|
||||
registration_course(Key, CKey) :-
|
||||
registration(Key, CKey, _).
|
||||
|
||||
registration_student(Key, SKey) :-
|
||||
registration(Key, _, SKey).
|
||||
|
||||
registration_grade(Key, 4): 0.2;registration_grade(Key, 3): 0.6;registration_grade(Key, 2): 0.15 ;
|
||||
registration_grade(Key, 1): 0.05 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, h) ,
|
||||
course_difficulty(CKey, h).
|
||||
|
||||
registration_grade(Key, 4): 0.7;registration_grade(Key, 3): 0.25;registration_grade(Key, 2): 0.04 ;
|
||||
registration_grade(Key, 1): 0.01 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, h) ,
|
||||
course_difficulty(CKey, m).
|
||||
|
||||
|
||||
registration_grade(Key, 4): 0.85;registration_grade(Key, 3): 0.12;registration_grade(Key, 2): 0.02 ;
|
||||
registration_grade(Key, 1): 0.01 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, h) ,
|
||||
course_difficulty(CKey, l).
|
||||
|
||||
|
||||
registration_grade(Key, 4): 0.1;registration_grade(Key, 3): 0.3;registration_grade(Key, 2): 0.4 ;
|
||||
registration_grade(Key, 1): 0.2 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, m) ,
|
||||
course_difficulty(CKey, h).
|
||||
|
||||
|
||||
registration_grade(Key, 4): 0.2;registration_grade(Key, 3): 0.6;registration_grade(Key, 2): 0.15 ;
|
||||
registration_grade(Key, 1): 0.05 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, m) ,
|
||||
course_difficulty(CKey, m).
|
||||
|
||||
registration_grade(Key, 4): 0.5;registration_grade(Key, 3): 0.35;registration_grade(Key, 2): 0.12;
|
||||
registration_grade(Key, 1): 0.03 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, m) ,
|
||||
course_difficulty(CKey, l).
|
||||
|
||||
registration_grade(Key, 4): 0.01;registration_grade(Key, 3): 0.04;registration_grade(Key, 2): 0.5 ;
|
||||
registration_grade(Key, 1): 0.45 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, l) ,
|
||||
course_difficulty(CKey, h).
|
||||
|
||||
registration_grade(Key, 4): 0.05;registration_grade(Key, 3): 0.15;registration_grade(Key, 2): 0.6 ;
|
||||
registration_grade(Key, 1): 0.2 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, l) ,
|
||||
course_difficulty(CKey, m).
|
||||
|
||||
registration_grade(Key, 4): 0.1;registration_grade(Key, 3): 0.4;registration_grade(Key, 2): 0.4 ;
|
||||
registration_grade(Key, 1): 0.1 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
student_intelligence(SKey, l) ,
|
||||
course_difficulty(CKey, l).
|
||||
|
||||
|
||||
registration_satisfaction(Key, 3): 0.98 ; registration_satisfaction(Key, 2): 0.01 ;
|
||||
registration_satisfaction(Key, 1): 0.01 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, h),
|
||||
registration_grade(Key, 4).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.9 ; registration_satisfaction(Key, 2): 0.09 ;
|
||||
registration_satisfaction(Key, 1): 0.01 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, h),
|
||||
registration_grade(Key, 3).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.8 ; registration_satisfaction(Key, 2): 0.15 ;
|
||||
registration_satisfaction(Key, 1): 0.05 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, h),
|
||||
registration_grade(Key, 2).
|
||||
|
||||
|
||||
|
||||
registration_satisfaction(Key, 3): 0.6 ; registration_satisfaction(Key, 2): 0.3 ;
|
||||
registration_satisfaction(Key, 1): 0.1 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, h),
|
||||
registration_grade(Key, 1).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.9 ; registration_satisfaction(Key, 2): 0.05 ;
|
||||
registration_satisfaction(Key, 1): 0.05 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, m),
|
||||
registration_grade(Key, 4).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.4 ; registration_satisfaction(Key, 2): 0.4 ;
|
||||
registration_satisfaction(Key, 1): 0.2 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, m),
|
||||
registration_grade(Key, 3).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.2 ; registration_satisfaction(Key, 2): 0.3 ;
|
||||
registration_satisfaction(Key, 1): 0.5 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, m),
|
||||
registration_grade(Key, 2).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.01 ; registration_satisfaction(Key, 2): 0.04 ;
|
||||
registration_satisfaction(Key, 1): 0.95 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, m),
|
||||
registration_grade(Key, 1).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.5 ; registration_satisfaction(Key, 2): 0.35 ;
|
||||
registration_satisfaction(Key, 1): 0.15 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, l),
|
||||
registration_grade(Key, 4).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.2 ; registration_satisfaction(Key, 2): 0.3 ;
|
||||
registration_satisfaction(Key, 1): 0.5 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, l),
|
||||
registration_grade(Key, 3).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.01 ; registration_satisfaction(Key, 2): 0.09 ;
|
||||
registration_satisfaction(Key, 1): 0.9 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, l),
|
||||
registration_grade(Key, 2).
|
||||
|
||||
registration_satisfaction(Key, 3): 0.01 ; registration_satisfaction(Key, 2): 0.01 ;
|
||||
registration_satisfaction(Key, 1): 0.98 :-
|
||||
registration(Key, CKey,_),
|
||||
course(CKey, PKey),
|
||||
professor_ability(PKey, l),
|
||||
registration_grade(Key, 1).
|
||||
|
||||
course_rating(CKey, h):0.2; course_rating(CKey, m):0.2;course_rating(CKey, l):0.6:-
|
||||
bagof(Sat, RKey^(registration_course(RKey,CKey), registration_satisfaction(RKey,Sat)), Sats),
|
||||
average(Sats, Av),Av<1.
|
||||
|
||||
course_rating(CKey, h):0.2; course_rating(CKey, m):0.6;course_rating(CKey, l):0.2:-
|
||||
bagof(Sat, RKey^(registration_course(RKey,CKey), registration_satisfaction(RKey,Sat)), Sats),
|
||||
average(Sats, Av),Av<2,Av>=1.
|
||||
|
||||
course_rating(CKey, h):0.6; course_rating(CKey,m):0.2;course_rating(CKey, l):0.2:-
|
||||
bagof(Sat, RKey^(registration_course(RKey,CKey), registration_satisfaction(RKey,Sat)), Sats),
|
||||
average(Sats, Av),Av>=2.
|
||||
|
||||
course_difficulty(Key, h) :0.25 ; course_difficulty(Key, m): 0.5 ; course_difficulty(Key, l) : 0.25.
|
||||
|
||||
student_intelligence(Key, h): 0.5; student_intelligence(Key,m):0.4; student_intelligence(Key,l):0.1.
|
||||
|
||||
student_ranking(Key, h):0.2; student_ranking(Key, m):0.2;student_ranking(Key, l):0.6:-
|
||||
bagof(Grade, CKey^(registration_student(CKey,Key),
|
||||
registration_grade(CKey, Grade)), Grades),
|
||||
average(Grades, Av),Av<1.5.
|
||||
|
||||
student_ranking(Key, h):0.2; student_ranking(Key, m):0.6;student_ranking(Key, l):0.2:-
|
||||
bagof(Grade, CKey^(registration_student(CKey,Key),
|
||||
registration_grade(CKey, Grade)), Grades),
|
||||
average(Grades, Av),Av>=1.5,Av<3.5.
|
||||
|
||||
student_ranking(Key, h):0.6; student_ranking(Key, m):0.2;student_ranking(Key, l):0.2:-
|
||||
bagof(Grade, CKey^(registration_student(CKey,Key),
|
||||
registration_grade(CKey, Grade)), Grades),
|
||||
average(Grades, Av),Av>=3.5.
|
||||
|
||||
|
||||
professor(p0).
|
||||
professor(p1).
|
||||
professor(p2).
|
||||
professor(p3).
|
||||
professor(p4).
|
||||
professor(p5).
|
||||
professor(p6).
|
||||
professor(p7).
|
||||
professor(p8).
|
||||
professor(p9).
|
||||
professor(p10).
|
||||
professor(p11).
|
||||
professor(p12).
|
||||
professor(p13).
|
||||
professor(p14).
|
||||
professor(p15).
|
||||
professor(p16).
|
||||
professor(p17).
|
||||
professor(p18).
|
||||
professor(p19).
|
||||
professor(p20).
|
||||
professor(p21).
|
||||
professor(p22).
|
||||
professor(p23).
|
||||
professor(p24).
|
||||
professor(p25).
|
||||
professor(p26).
|
||||
professor(p27).
|
||||
professor(p28).
|
||||
professor(p29).
|
||||
professor(p30).
|
||||
professor(p31).
|
||||
|
||||
|
||||
course(c0,p24).
|
||||
course(c1,p7).
|
||||
course(c2,p16).
|
||||
course(c3,p27).
|
||||
course(c4,p25).
|
||||
course(c5,p6).
|
||||
course(c6,p28).
|
||||
course(c7,p1).
|
||||
course(c8,p29).
|
||||
course(c9,p23).
|
||||
course(c10,p17).
|
||||
course(c11,p16).
|
||||
course(c12,p11).
|
||||
course(c13,p28).
|
||||
course(c14,p13).
|
||||
course(c15,p7).
|
||||
course(c16,p21).
|
||||
course(c17,p15).
|
||||
course(c18,p8).
|
||||
course(c19,p30).
|
||||
course(c20,p1).
|
||||
course(c21,p23).
|
||||
course(c22,p11).
|
||||
course(c23,p9).
|
||||
course(c24,p0).
|
||||
course(c25,p30).
|
||||
course(c26,p15).
|
||||
course(c27,p4).
|
||||
course(c28,p26).
|
||||
course(c29,p29).
|
||||
course(c30,p31).
|
||||
course(c31,p19).
|
||||
course(c32,p5).
|
||||
course(c33,p14).
|
||||
course(c34,p14).
|
||||
course(c35,p25).
|
||||
course(c36,p21).
|
||||
course(c37,p10).
|
||||
course(c38,p2).
|
||||
course(c39,p20).
|
||||
course(c40,p3).
|
||||
course(c41,p18).
|
||||
course(c42,p9).
|
||||
course(c43,p20).
|
||||
course(c44,p17).
|
||||
course(c45,p19).
|
||||
course(c46,p6).
|
||||
course(c47,p4).
|
||||
course(c48,p12).
|
||||
course(c49,p10).
|
||||
course(c50,p2).
|
||||
course(c51,p22).
|
||||
course(c52,p31).
|
||||
course(c53,p24).
|
||||
course(c54,p0).
|
||||
course(c55,p5).
|
||||
course(c56,p22).
|
||||
course(c57,p13).
|
||||
course(c58,p18).
|
||||
course(c59,p12).
|
||||
course(c60,p27).
|
||||
course(c61,p3).
|
||||
course(c62,p8).
|
||||
course(c63,p26).
|
||||
|
||||
|
||||
student(s0).
|
||||
student(s1).
|
||||
student(s2).
|
||||
student(s3).
|
||||
student(s4).
|
||||
student(s5).
|
||||
student(s6).
|
||||
student(s7).
|
||||
student(s8).
|
||||
student(s9).
|
||||
student(s10).
|
||||
student(s11).
|
||||
student(s12).
|
||||
student(s13).
|
||||
student(s14).
|
||||
student(s15).
|
||||
student(s16).
|
||||
student(s17).
|
||||
student(s18).
|
||||
student(s19).
|
||||
student(s20).
|
||||
student(s21).
|
||||
student(s22).
|
||||
student(s23).
|
||||
student(s24).
|
||||
student(s25).
|
||||
student(s26).
|
||||
student(s27).
|
||||
student(s28).
|
||||
student(s29).
|
||||
student(s30).
|
||||
student(s31).
|
||||
student(s32).
|
||||
student(s33).
|
||||
student(s34).
|
||||
student(s35).
|
||||
student(s36).
|
||||
student(s37).
|
||||
student(s38).
|
||||
student(s39).
|
||||
student(s40).
|
||||
student(s41).
|
||||
student(s42).
|
||||
student(s43).
|
||||
student(s44).
|
||||
student(s45).
|
||||
student(s46).
|
||||
student(s47).
|
||||
student(s48).
|
||||
student(s49).
|
||||
student(s50).
|
||||
student(s51).
|
||||
student(s52).
|
||||
student(s53).
|
||||
student(s54).
|
||||
student(s55).
|
||||
student(s56).
|
||||
student(s57).
|
||||
student(s58).
|
||||
student(s59).
|
||||
student(s60).
|
||||
student(s61).
|
||||
student(s62).
|
||||
student(s63).
|
||||
student(s64).
|
||||
student(s65).
|
||||
student(s66).
|
||||
student(s67).
|
||||
student(s68).
|
||||
student(s69).
|
||||
student(s70).
|
||||
student(s71).
|
||||
student(s72).
|
||||
student(s73).
|
||||
student(s74).
|
||||
student(s75).
|
||||
student(s76).
|
||||
student(s77).
|
||||
student(s78).
|
||||
student(s79).
|
||||
student(s80).
|
||||
student(s81).
|
||||
student(s82).
|
||||
student(s83).
|
||||
student(s84).
|
||||
student(s85).
|
||||
student(s86).
|
||||
student(s87).
|
||||
student(s88).
|
||||
student(s89).
|
||||
student(s90).
|
||||
student(s91).
|
||||
student(s92).
|
||||
student(s93).
|
||||
student(s94).
|
||||
student(s95).
|
||||
student(s96).
|
||||
student(s97).
|
||||
student(s98).
|
||||
student(s99).
|
||||
student(s100).
|
||||
student(s101).
|
||||
student(s102).
|
||||
student(s103).
|
||||
student(s104).
|
||||
student(s105).
|
||||
student(s106).
|
||||
student(s107).
|
||||
student(s108).
|
||||
student(s109).
|
||||
student(s110).
|
||||
student(s111).
|
||||
student(s112).
|
||||
student(s113).
|
||||
student(s114).
|
||||
student(s115).
|
||||
student(s116).
|
||||
student(s117).
|
||||
student(s118).
|
||||
student(s119).
|
||||
student(s120).
|
||||
student(s121).
|
||||
student(s122).
|
||||
student(s123).
|
||||
student(s124).
|
||||
student(s125).
|
||||
student(s126).
|
||||
student(s127).
|
||||
student(s128).
|
||||
student(s129).
|
||||
student(s130).
|
||||
student(s131).
|
||||
student(s132).
|
||||
student(s133).
|
||||
student(s134).
|
||||
student(s135).
|
||||
student(s136).
|
||||
student(s137).
|
||||
student(s138).
|
||||
student(s139).
|
||||
student(s140).
|
||||
student(s141).
|
||||
student(s142).
|
||||
student(s143).
|
||||
student(s144).
|
||||
student(s145).
|
||||
student(s146).
|
||||
student(s147).
|
||||
student(s148).
|
||||
student(s149).
|
||||
student(s150).
|
||||
student(s151).
|
||||
student(s152).
|
||||
student(s153).
|
||||
student(s154).
|
||||
student(s155).
|
||||
student(s156).
|
||||
student(s157).
|
||||
student(s158).
|
||||
student(s159).
|
||||
student(s160).
|
||||
student(s161).
|
||||
student(s162).
|
||||
student(s163).
|
||||
student(s164).
|
||||
student(s165).
|
||||
student(s166).
|
||||
student(s167).
|
||||
student(s168).
|
||||
student(s169).
|
||||
student(s170).
|
||||
student(s171).
|
||||
student(s172).
|
||||
student(s173).
|
||||
student(s174).
|
||||
student(s175).
|
||||
student(s176).
|
||||
student(s177).
|
||||
student(s178).
|
||||
student(s179).
|
||||
student(s180).
|
||||
student(s181).
|
||||
student(s182).
|
||||
student(s183).
|
||||
student(s184).
|
||||
student(s185).
|
||||
student(s186).
|
||||
student(s187).
|
||||
student(s188).
|
||||
student(s189).
|
||||
student(s190).
|
||||
student(s191).
|
||||
student(s192).
|
||||
student(s193).
|
||||
student(s194).
|
||||
student(s195).
|
||||
student(s196).
|
||||
student(s197).
|
||||
student(s198).
|
||||
student(s199).
|
||||
student(s200).
|
||||
student(s201).
|
||||
student(s202).
|
||||
student(s203).
|
||||
student(s204).
|
||||
student(s205).
|
||||
student(s206).
|
||||
student(s207).
|
||||
student(s208).
|
||||
student(s209).
|
||||
student(s210).
|
||||
student(s211).
|
||||
student(s212).
|
||||
student(s213).
|
||||
student(s214).
|
||||
student(s215).
|
||||
student(s216).
|
||||
student(s217).
|
||||
student(s218).
|
||||
student(s219).
|
||||
student(s220).
|
||||
student(s221).
|
||||
student(s222).
|
||||
student(s223).
|
||||
student(s224).
|
||||
student(s225).
|
||||
student(s226).
|
||||
student(s227).
|
||||
student(s228).
|
||||
student(s229).
|
||||
student(s230).
|
||||
student(s231).
|
||||
student(s232).
|
||||
student(s233).
|
||||
student(s234).
|
||||
student(s235).
|
||||
student(s236).
|
||||
student(s237).
|
||||
student(s238).
|
||||
student(s239).
|
||||
student(s240).
|
||||
student(s241).
|
||||
student(s242).
|
||||
student(s243).
|
||||
student(s244).
|
||||
student(s245).
|
||||
student(s246).
|
||||
student(s247).
|
||||
student(s248).
|
||||
student(s249).
|
||||
student(s250).
|
||||
student(s251).
|
||||
student(s252).
|
||||
student(s253).
|
||||
student(s254).
|
||||
student(s255).
|
||||
|
||||
|
||||
registration(r0,c16,s0).
|
||||
registration(r1,c10,s0).
|
||||
registration(r2,c57,s0).
|
||||
registration(r3,c22,s1).
|
||||
registration(r4,c55,s1).
|
||||
registration(r5,c27,s1).
|
||||
registration(r6,c14,s2).
|
||||
registration(r7,c52,s2).
|
||||
registration(r8,c10,s2).
|
||||
registration(r9,c47,s3).
|
||||
registration(r10,c16,s3).
|
||||
registration(r11,c62,s3).
|
||||
registration(r12,c12,s4).
|
||||
registration(r13,c11,s4).
|
||||
registration(r14,c17,s4).
|
||||
registration(r15,c52,s5).
|
||||
registration(r16,c1,s5).
|
||||
registration(r17,c35,s5).
|
||||
registration(r18,c0,s6).
|
||||
registration(r19,c7,s6).
|
||||
registration(r20,c40,s6).
|
||||
52
packages/cplint/examples/school_simple.cpl
Normal file
52
packages/cplint/examples/school_simple.cpl
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
?- s([registration_grade(r0,X)],P).
|
||||
|
||||
|
||||
|
||||
|
||||
student_ranking(s0,X).
|
||||
s([student_ranking(s0,h)],P).
|
||||
P = 0,6646250000000005 ?
|
||||
s([student_ranking(s0,l)],P).
|
||||
P = 0,33537499999999987
|
||||
ok, checked with s.pl
|
||||
*/
|
||||
|
||||
|
||||
|
||||
registration_course(Key, CKey) :-
|
||||
registration(Key, CKey, _).
|
||||
|
||||
registration_student(Key, SKey) :-
|
||||
registration(Key, _, SKey).
|
||||
|
||||
registration_grade(Key, 4): 0.2;
|
||||
registration_grade(Key, 1): 0.8 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
course_difficulty(CKey, h).
|
||||
|
||||
|
||||
registration_grade(Key, 4): 0.85;
|
||||
registration_grade(Key, 1): 0.15 :-
|
||||
registration(Key, CKey, SKey) ,
|
||||
course_difficulty(CKey, l).
|
||||
|
||||
|
||||
course_difficulty(Cou, h) :0.5 ; course_difficulty(Cou, l) : 0.5.
|
||||
|
||||
|
||||
student_ranking(Stu, h):0.2; student_ranking(Stu, l):0.8:-
|
||||
bagof(Grade, CKey^(registration_student(CKey,Stu),
|
||||
registration_grade(CKey, Grade)), Grades),
|
||||
average(Grades, Av),Av<2.
|
||||
|
||||
student_ranking(Stu, h):0.8; student_ranking(Stu, l):0.2:-
|
||||
bagof(Grade, CKey^(registration_student(CKey,Stu),
|
||||
registration_grade(CKey, Grade)), Grades),
|
||||
average(Grades, Av),Av>=2.
|
||||
|
||||
|
||||
|
||||
|
||||
registration(r0,c16,s0).
|
||||
registration(r1,c10,s0).
|
||||
18
packages/cplint/examples/school_simple.uni
Normal file
18
packages/cplint/examples/school_simple.uni
Normal file
@@ -0,0 +1,18 @@
|
||||
universe(['Stu'],[s0]).
|
||||
universe(['Key'],[r0,r1]).
|
||||
universe(['Cou'],[c16,c10]).
|
||||
|
||||
type(stu,[s0]).
|
||||
type(reg,[r0,r1]).
|
||||
type(cou,[c16,c10]).
|
||||
type(gr,[1,4]).
|
||||
type(dif,[h,l]).
|
||||
type(ran,[h,l]).
|
||||
|
||||
mode(registration(reg,cou,stu)).
|
||||
mode(registration_grade(reg,gr)).
|
||||
mode(registration_course(reg,cou)).
|
||||
mode(registration_student(reg,stu)).
|
||||
mode(course_difficulty(cou,dif)).
|
||||
mode(student_ranking(stu,ran)).
|
||||
|
||||
95
packages/cplint/examples/student.cpl
Normal file
95
packages/cplint/examples/student.cpl
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
s([student_rank(jane_doe,h)],P).
|
||||
P = 0.465
|
||||
|
||||
s([student_rank(jane_doe,l)],P).
|
||||
P = 0.535
|
||||
|
||||
s([course_rat(C,h)],P).
|
||||
C = phil101,
|
||||
P = 0.330656
|
||||
|
||||
s([course_rat(C,l)],P).
|
||||
C = phil101,
|
||||
P = 0.669344
|
||||
|
||||
*/
|
||||
professor(gump).
|
||||
%1
|
||||
professor_teach_ab(P,h):0.2;professor_teach_ab(P,l):0.8:-
|
||||
professor(P).
|
||||
%2
|
||||
professor_pop(P,h):0.7;professor_pop(P,l):0.3:-
|
||||
professor_teach_ab(P,h).
|
||||
%3
|
||||
professor_pop(P,h):0.2;professor_pop(P,l):0.8:-
|
||||
professor_teach_ab(P,l).
|
||||
|
||||
student(jane_doe).
|
||||
%4
|
||||
student_int(S,h):0.6;student_int(S,l):0.4:-
|
||||
student(S).
|
||||
%5
|
||||
student_rank(S,h):0.6;student_rank(S,l):0.4:-
|
||||
bagof(G,R^(registr_stu(R,S),registr_gr(R,G)),L),
|
||||
average(L,Av),Av>1.5.
|
||||
%6
|
||||
student_rank(S,h):0.4;student_rank(S,l):0.6:-
|
||||
bagof(G,R^(registr_stu(R,S),registr_gr(R,G)),L),
|
||||
average(L,Av),Av =< 1.5.
|
||||
|
||||
registr(5639).
|
||||
|
||||
registr_cou(5639,phil101).
|
||||
|
||||
registr_stu(5639,jane_doe).
|
||||
|
||||
registr(5640).
|
||||
|
||||
registr_cou(5640,phil101).
|
||||
|
||||
registr_stu(5640,jane_doe).
|
||||
|
||||
%7
|
||||
registr_gr(Reg,1):0.5;registr_gr(Reg,2):0.5:-
|
||||
registr_stu(Reg,S),student_int(S,h),registr_cou(Reg,C),course_dif(C,h).
|
||||
%8
|
||||
registr_gr(Reg,1):0.2;registr_gr(Reg,2):0.8:-
|
||||
registr_stu(Reg,S),student_int(S,h),registr_cou(Reg,C),course_dif(C,l).
|
||||
%9
|
||||
registr_gr(Reg,1):0.8;registr_gr(Reg,2):0.2:-
|
||||
registr_stu(Reg,S),student_int(S,l),registr_cou(Reg,C),course_dif(C,h).
|
||||
%10
|
||||
registr_gr(Reg,1):0.5;registr_gr(Reg,2):0.5:-
|
||||
registr_stu(Reg,S),student_int(S,l),registr_cou(Reg,C),course_dif(C,l).
|
||||
%11
|
||||
registr_sat(Reg,1):0.2;registr_sat(Reg,2):0.8:-
|
||||
registr_gr(Reg,2),registr_cou(Reg,C),course_prof(C,P),
|
||||
professor_teach_ab(P,h).
|
||||
%12
|
||||
registr_sat(Reg,1):0.4;registr_sat(Reg,2):0.6:-
|
||||
registr_gr(Reg,2),registr_cou(Reg,C),course_prof(C,P),
|
||||
professor_teach_ab(P,l).
|
||||
%13
|
||||
registr_sat(Reg,1):0.6;registr_sat(Reg,2):0.4:-
|
||||
registr_gr(Reg,1),registr_cou(Reg,C),course_prof(C,P),
|
||||
professor_teach_ab(P,h).
|
||||
%14
|
||||
registr_sat(Reg,1):0.8;registr_sat(Reg,2):0.2:-
|
||||
registr_gr(Reg,1),registr_cou(Reg,C),course_prof(C,P),
|
||||
professor_teach_ab(P,l).
|
||||
|
||||
course(phil101).
|
||||
|
||||
course_prof(phil101,gump).
|
||||
%15
|
||||
course_dif(C,h):0.5;course_dif(C,l):0.5:-
|
||||
course(C).
|
||||
%16
|
||||
course_rat(C,h):0.8;course_rat(C,l):0.2:-
|
||||
bagof(Stu,R^(registr_cou(R,C),registr_sat(R,Stu)),L),
|
||||
average(L,Av),Av>1.5.
|
||||
%17
|
||||
course_rat(C,h):0.2;course_rat(C,l):0.8:-
|
||||
bagof(Stu,R^(registr_cou(R,C),registr_sat(R,Stu)),L),
|
||||
average(L,Av),Av=< 1.5.
|
||||
29
packages/cplint/examples/student.uni
Normal file
29
packages/cplint/examples/student.uni
Normal file
@@ -0,0 +1,29 @@
|
||||
universe(['S'],[jane_doe]).
|
||||
universe(['P'],[gump]).
|
||||
universe(['Reg'],[5639,5640]).
|
||||
universe(['C'],[phil101]).
|
||||
|
||||
type(prof,[gump]).
|
||||
type(stu,[jane_doe]).
|
||||
type(abi,[l,h]).
|
||||
type(int,[h,l]).
|
||||
type(reg,[5639,5640]).
|
||||
type(cou,[phil101]).
|
||||
type(gr,[1,2]).
|
||||
type(sat,[1,2]).
|
||||
type(dif,[h,l]).
|
||||
type(rat,[h,l]).
|
||||
|
||||
mode(professor(prof)).
|
||||
mode(professor_teach_ab(prof,abi)
|
||||
mode(student(stu)).
|
||||
mode(student_int(stu,int)).
|
||||
mode(registr(reg)).
|
||||
mode(registr_cou(reg,cou)).
|
||||
mode(registr_stu(reg,stu)).
|
||||
mode(registr_gr(reg,gr)).
|
||||
mode(registr_sat(reg,sat)).
|
||||
mode(course(cou)).
|
||||
mode(course_prof(cou,prof)).
|
||||
mode(course_dif(cou,dif)).
|
||||
mode(course_rat(cou,rat)).
|
||||
39
packages/cplint/examples/threesideddice.cpl
Normal file
39
packages/cplint/examples/threesideddice.cpl
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
s([on(0,1)],P).
|
||||
P = 0.333333333333333 ?
|
||||
|
||||
s([on(1,1)],P).
|
||||
P = 0.222222222222222
|
||||
s([on(2,1)],P).
|
||||
P = 0.148148147703704
|
||||
s([on(3,1)],P).
|
||||
% OUT OF DATABASE SPACE ERROR- Database crashed against Stacks
|
||||
s([on(4,1)],P).
|
||||
% OUT OF DATABASE SPACE ERROR- Database crashed against Stacks
|
||||
s([on(5,1)],P).
|
||||
% OUT OF DATABASE SPACE ERROR- Database crashed against Stacks
|
||||
|
||||
s([on(0,1),on(1,1)],P).
|
||||
P = 0.111111111111111
|
||||
s([on(0,1),on(1,1),on(2,1)],P).
|
||||
P = 0.037037037037037
|
||||
sc([on(1,1)],[on(0,1)],P).
|
||||
P = 0.333333333333333
|
||||
|
||||
sc([on(2,1)],[on(0,1)],P).
|
||||
P = 0.222222222222222
|
||||
|
||||
sc([on(3,1)],[on(0,1)],P).
|
||||
P = 0.148148148148148
|
||||
|
||||
sc([on(2,1)],[on(1,1)],P).
|
||||
P = 0.333333333333333 ?
|
||||
|
||||
|
||||
*/
|
||||
on(0,1):1/3;on(0,2):1/3;on(0,3):1/3.
|
||||
|
||||
on(X,1):1/3;on(X,2):1/3;on(X,3):1/3:-
|
||||
X1 is X-1,X1>=0,
|
||||
on(X1,Y),
|
||||
\+ on(X1,3).
|
||||
9
packages/cplint/examples/threesideddice.uni
Normal file
9
packages/cplint/examples/threesideddice.uni
Normal file
@@ -0,0 +1,9 @@
|
||||
mode(on(time,face)).
|
||||
|
||||
type(time,[0,1,2]).
|
||||
|
||||
type(face,[1,2,3]).
|
||||
|
||||
universe(['X'],[0,1,2]).
|
||||
universe(['X1'],[0,1,2]).
|
||||
universe(['Y'],[1,2,3]).
|
||||
21
packages/cplint/examples/throws.cpl
Normal file
21
packages/cplint/examples/throws.cpl
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
no
|
||||
?- s([throws(mary),throws(john),break],P).
|
||||
P = 0.46 ?
|
||||
yes
|
||||
?- s([throws(mary),throws(john),\+break],P).
|
||||
P = 0.04 ?
|
||||
yes
|
||||
?- s([\+ throws(mary),throws(john),break],P).
|
||||
P = 0.3 ?
|
||||
yes
|
||||
?- s([\+ throws(mary),throws(john),\+ break],P).
|
||||
P = 0.2 ?
|
||||
yes
|
||||
?-
|
||||
*/
|
||||
|
||||
break : 0.8 :- throws(mary).
|
||||
break : 0.6 :- throws(john).
|
||||
throws(mary) : 0.5.
|
||||
throws(john).
|
||||
6
packages/cplint/examples/throws.uni
Normal file
6
packages/cplint/examples/throws.uni
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
type(person,[mary,john]).
|
||||
|
||||
mode(break).
|
||||
|
||||
mode(throws(person)).
|
||||
13
packages/cplint/examples/trigger.cpl
Normal file
13
packages/cplint/examples/trigger.cpl
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
|
||||
?- s([death],P).
|
||||
P = 0.305555555555556 ?
|
||||
yes
|
||||
?-
|
||||
*/
|
||||
|
||||
death : 1/6 :- pull_trigger(left_gun).
|
||||
death : 1/6 :- pull_trigger(right_gun).
|
||||
|
||||
pull_trigger(left_gun).
|
||||
pull_trigger(right_gun).
|
||||
4
packages/cplint/examples/trigger.uni
Normal file
4
packages/cplint/examples/trigger.uni
Normal file
@@ -0,0 +1,4 @@
|
||||
mode(death).
|
||||
mode(pull_trigger(gun)).
|
||||
|
||||
type(gun,[left_gun,right_gun]).
|
||||
21
packages/cplint/examples/twosideddice.cpl
Normal file
21
packages/cplint/examples/twosideddice.cpl
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
|
||||
s([on(3,1)],P).
|
||||
P = 0.0625
|
||||
sc([on(3,1)],[on(2,1)],P).
|
||||
P = 0.5 ?
|
||||
|
||||
sc([on(4,1)],[on(2,1)],P).
|
||||
P = 0.25
|
||||
|
||||
sc([on(10,1)],[on(2,1)],P).
|
||||
P = 0.00390625
|
||||
|
||||
|
||||
*/
|
||||
on(0,1):0.5;on(0,2):0.5.
|
||||
|
||||
on(X,1):0.5;on(X,2):0.5:-
|
||||
X1 is X-1,X1>=0,
|
||||
on(X1,Y),
|
||||
\+ on(X1,2).
|
||||
14
packages/cplint/examples/win.cpl
Normal file
14
packages/cplint/examples/win.cpl
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
?- s([win(white)],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([win(black)],P).
|
||||
P = 0.5 ?
|
||||
yes
|
||||
?- s([win(black),win(white)],P).
|
||||
P = 0 ?
|
||||
*/
|
||||
|
||||
win(white) :- \+ win(black).
|
||||
win(black):- \+ win(white).
|
||||
win(white) : 0.5 ; win(black) : 0.5.
|
||||
6
packages/cplint/examples/win.uni
Normal file
6
packages/cplint/examples/win.uni
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
mode(win(player)).
|
||||
|
||||
|
||||
type(player,[white,black]).
|
||||
|
||||
2257
packages/cplint/lpad.pl
Normal file
2257
packages/cplint/lpad.pl
Normal file
File diff suppressed because it is too large
Load Diff
1183
packages/cplint/lpadclpbn.pl
Normal file
1183
packages/cplint/lpadclpbn.pl
Normal file
File diff suppressed because it is too large
Load Diff
1480
packages/cplint/lpadsld.pl
Normal file
1480
packages/cplint/lpadsld.pl
Normal file
File diff suppressed because it is too large
Load Diff
1538
packages/cplint/lpadvel.pl
Normal file
1538
packages/cplint/lpadvel.pl
Normal file
File diff suppressed because it is too large
Load Diff
638
packages/cplint/semcpl.pl
Normal file
638
packages/cplint/semcpl.pl
Normal file
@@ -0,0 +1,638 @@
|
||||
/*
|
||||
|
||||
Program for computing the probability of a query directly according to the
|
||||
semantics
|
||||
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
|
||||
*/
|
||||
|
||||
:-module(semcpl,[p/1,s/2,sc/3,build/0,print/0,set/2]).
|
||||
|
||||
:-use_module(library(lists)).
|
||||
:-dynamic setting/2.
|
||||
%:-set_prolog_flag(unknown,fail).
|
||||
|
||||
setting(epsilon_parsing,0.00001).
|
||||
setting(ground_body,false).
|
||||
/* available values: true, false
|
||||
if true, both the head and the body of each clause will be grounded, otherwise
|
||||
only the head is grounded. In the case in which the body contains variables
|
||||
not appearing in the head, the body represents an existential event */
|
||||
|
||||
/* sc(Goal,Evidence,Probability)
|
||||
computes a conditional probability
|
||||
*/
|
||||
sc(G,E,P):-
|
||||
append(G,E,GE),
|
||||
s(GE,PGE),
|
||||
s(E,PE),
|
||||
(PE\==0->
|
||||
P is PGE/PE
|
||||
;
|
||||
P=undefined
|
||||
).
|
||||
/* s(GoalsList,Prob)
|
||||
computes the probability of a query in the form of a list of literals
|
||||
*/
|
||||
s(GoalsList,Prob):-
|
||||
findall((State,Prob),node(empty,_,_,State,Prob),LL),
|
||||
sum_prob(LL,GoalsList,0,Prob).
|
||||
|
||||
/* sum_prob(List,GoalsList,P0,P)
|
||||
List is a list of couples (State,Prob) where State is an interpretation and
|
||||
Prob is the associated probability.
|
||||
GoalsList is a list of goals.
|
||||
P0/P is an accumulator for the probability
|
||||
sum_prob computes the probability of GoalsList by summing the probability of every
|
||||
state where GoalsList is true
|
||||
*/
|
||||
sum_prob([],_GL,P,P):-!.
|
||||
|
||||
sum_prob([(State,Prob)|T],GL,P0,P):-
|
||||
copy_term(GL,GLC),
|
||||
(body_true(GLC,State)->
|
||||
P1 is P0+Prob
|
||||
;
|
||||
P1 is P0
|
||||
),
|
||||
sum_prob(T,GL,P1,P).
|
||||
|
||||
/* predicates for build the probabilistic process tree */
|
||||
/* build
|
||||
builds the probabilistic process tree with an empty context
|
||||
*/
|
||||
build:-
|
||||
build([]).
|
||||
|
||||
/* build(Context)
|
||||
builds the probabilistic process tree with context Context
|
||||
*/
|
||||
build(Context):-
|
||||
clauses(Cl),
|
||||
herbrand_base(HB),
|
||||
deleteall(HB,Context,HB1),
|
||||
get_new_atom(A),
|
||||
assert(root(A)),
|
||||
build(A,Context,1,Cl,HB1).
|
||||
|
||||
/* build(Parent,State,Prob,Clauses,HB):-
|
||||
Given a parent node, its State, its probability, the list of ground
|
||||
clauses Clauses and the Herbrand Base HB, it builds the tree below Parent.
|
||||
The tree is stored in the database in the form of facts of the form
|
||||
node(Node,Parent,State,r(Head,Body),Prob).
|
||||
Parent is the parent of Node, State is the interpretation associated to
|
||||
Node, r(Head,Body) is the clause associated to Node and Prob is its Probability.
|
||||
The real root of the tree has a dummy parent P for which the fact root(P) is
|
||||
true that is used to access the tree
|
||||
*/
|
||||
build(Parent,State,Prob,Clauses,HB):-
|
||||
get_new_atom(Node),
|
||||
compute_three_valued(State,Clauses,HB,[],Unknowns),
|
||||
choose_clause(Clauses,State,Unknowns,RemainingClauses,Clause),
|
||||
(Clause=empty->
|
||||
(RemainingClauses=[]->
|
||||
assert(node(empty,Node,Parent,State,Prob))
|
||||
;
|
||||
format("Invalid program.~nInterpretation=~p.~nUnknowns atoms=~p.~nClauses=~p~n",[State,Unknowns,RemainingClauses])
|
||||
)
|
||||
;
|
||||
Clause=r(Head,Body),
|
||||
assert(node(r(Head,Body),Node,Parent,State,Prob)),
|
||||
new_states(Node,Head,State,Prob,RemainingClauses,Unknowns)
|
||||
).
|
||||
/* choose_clause(Clauses,Trues,Unknowns,RemainingClauses,Clause)
|
||||
selects a clause whose body is true in the three valued interpretation
|
||||
represented by Trues and Unknowns. The selected clause is returned in Clause
|
||||
and the remaining clauses in RemainingClauses. If no clause has the body
|
||||
true, it returns empty in Clause.
|
||||
*/
|
||||
choose_clause([],_True,_Unk,[],empty):-!.
|
||||
|
||||
choose_clause([r(Head,Body)|T],True,Unk,RemCl,Clause):-
|
||||
copy_term(Body,BodyC),
|
||||
(body_true(BodyC,True,[],Unk)->
|
||||
Clause=r(Head,Body),
|
||||
remove_false(T,True,Unk,RemCl)
|
||||
;
|
||||
(body_false(BodyC,True,[],Unk)->
|
||||
RemCl=RemCl0
|
||||
;
|
||||
RemCl=[r(Head,Body)|RemCl0]
|
||||
),
|
||||
choose_clause(T,True,Unk,RemCl0,Clause)
|
||||
).
|
||||
|
||||
remove_false([],_True,_Unk,[]):-!.
|
||||
|
||||
remove_false([r(Head,Body)|T],True,Unk,RemCl):-
|
||||
copy_term(Body,BodyC),
|
||||
(body_false(BodyC,True,[],Unk)->
|
||||
RemCl=RemCl0
|
||||
;
|
||||
RemCl=[r(Head,Body)|RemCl0]
|
||||
),
|
||||
remove_false(T,True,Unk,RemCl0).
|
||||
|
||||
|
||||
body_true([],_,_,_):-!.
|
||||
|
||||
body_true([\+ H|T],True,False,Unk):-
|
||||
(\+ ground(H)->
|
||||
format("Floundering ~n",[])
|
||||
;
|
||||
true
|
||||
),
|
||||
\+ member(H,True),\+ member(H,Unk),!,
|
||||
body_true(T,True,False,Unk).
|
||||
|
||||
body_true([H|T],True,False,Unk):-
|
||||
H \= (\+ _A),
|
||||
member(H,True),
|
||||
body_true(T,True,False,Unk).
|
||||
|
||||
body_true([H|T],True,False,Unk):-
|
||||
builtin(H),
|
||||
call(H),
|
||||
body_true(T,True,False,Unk).
|
||||
|
||||
body_true([],_):-!.
|
||||
|
||||
body_true([\+ H|T],True):-
|
||||
\+ member(H,True),!,
|
||||
body_true(T,True).
|
||||
|
||||
body_true([H|T],True):-
|
||||
member(H,True),!,
|
||||
body_true(T,True).
|
||||
|
||||
|
||||
body_undef([\+ H|T],True,False,Unk):-
|
||||
member(H,False),!,
|
||||
body_undef(T,True,False,Unk).
|
||||
|
||||
body_undef([\+ H|T],True,False,Unk):-
|
||||
\+ member(H,True),\+ member(H,Unk),!,
|
||||
body_undef(T,True,False,Unk).
|
||||
|
||||
body_undef([\+ H|T],True,False,Unk):-
|
||||
member(H,Unk),!,
|
||||
\+ body_false(T,True,False,Unk).
|
||||
|
||||
body_undef([H|T],True,False,Unk):-
|
||||
member(H,True),!,
|
||||
body_undef(T,True,False,Unk).
|
||||
|
||||
body_undef([H|T],True,False,Unk):-
|
||||
member(H,Unk),!,
|
||||
\+ body_false(T,True,False,Unk).
|
||||
|
||||
/* compute_three_valued(State,Clauses,False,Unknowns0,Unknowns)
|
||||
computes the three valued interpretation associated with State
|
||||
*/
|
||||
compute_three_valued(State,Clauses,False,Unknowns0,Unknowns):-
|
||||
choose_clause_three_val(Clauses,State,False,Unknowns0,RemainingClauses,Clause),
|
||||
(Clause=empty->
|
||||
Unknowns=Unknowns0
|
||||
;
|
||||
Clause=r(Head,_Body),
|
||||
new_int(Head,False,False1,Unknowns0,Unknowns1),
|
||||
compute_three_valued(State,RemainingClauses,False1,Unknowns1,Unknowns)
|
||||
).
|
||||
/* choose_clause_three_val(Clauses,Trues,False,Unknowns,RemainingClauses,Clause)
|
||||
selects a clause whose body is not false in the three valued interpretation
|
||||
represented by Trues, False and Unknowns. The selected clause is returned in Clause
|
||||
and the remaining clauses in RemainingClauses. If no clause has the body
|
||||
true, it returns empty in Clause.
|
||||
*/
|
||||
choose_clause_three_val([],_True,_False,_Unk,_,empty):-!.
|
||||
|
||||
choose_clause_three_val([r(Head,Body)|T],True,False,Unk,RemCl,Clause):-
|
||||
(\+ body_false(Body,True,False,Unk)->
|
||||
Clause=r(Head,Body),
|
||||
RemCl=T
|
||||
;
|
||||
RemCl=[r(Head,Body)|RemCl0],
|
||||
choose_clause_three_val(T,True,False,Unk,RemCl0,Clause)
|
||||
).
|
||||
|
||||
body_false([\+ H|_T],True,_False,_Unk):-
|
||||
(\+ ground(H)->
|
||||
format("Floundering ~n",[])
|
||||
;
|
||||
true
|
||||
),
|
||||
member(H,True),!.
|
||||
|
||||
body_false([\+ H|T],True,False,Unk):-
|
||||
builtin(H),
|
||||
(call(H)->
|
||||
true
|
||||
;
|
||||
body_false(T,True,False,Unk)
|
||||
).
|
||||
|
||||
body_false([\+ _H|T],True,False,Unk):-!,
|
||||
body_false(T,True,False,Unk).
|
||||
|
||||
body_false([H|T],True,False,Unk):-
|
||||
builtin(H),
|
||||
call(H),!,
|
||||
body_false(T,True,False,Unk).
|
||||
|
||||
body_false([H|_T],_True,_False,_Unk):-
|
||||
builtin(H),
|
||||
\+ call(H),!.
|
||||
|
||||
body_false([H|T],True,False,Unk):-
|
||||
findall(H,(member(H,True);member(H,Unk)),LH),!,
|
||||
body_false_list(LH,H,T,True,False,Unk).
|
||||
|
||||
|
||||
body_false_list([],_,_,_,_,_):-!.
|
||||
|
||||
body_false_list([H|T],A,Body,True,False,Unk):-
|
||||
copy_term((A,Body),(AC,BodyC)),
|
||||
AC=H,
|
||||
body_false(BodyC,True,False,Unk),
|
||||
body_false_list(T,A,Body,True,False,Unk).
|
||||
|
||||
|
||||
/* new_int(Head,False0,False,Unk0,Unk)
|
||||
computes a new three valued interpretation from False0/Unk0 by moving the atoms
|
||||
in the head from False to Unk
|
||||
*/
|
||||
new_int([],False,False,Unk,Unk):-!.
|
||||
|
||||
new_int([H:_P|T],False0,False,Unk0,Unk):-
|
||||
(member(H,False0)->
|
||||
delete(False0,H,False1),
|
||||
append(Unk0,[H],Unk1)
|
||||
;
|
||||
False1=False0,
|
||||
Unk1=Unk0
|
||||
),
|
||||
new_int(T,False1,False,Unk1,Unk).
|
||||
|
||||
|
||||
|
||||
/* new_states(Node,Head,State,Prob,Clauses,HB)
|
||||
computest the tree below Node, where Head is the head of the clause
|
||||
associated to Node, Prob is the probability of Node, Clauses is the list
|
||||
of ground clauses yet to be associated to a node and HB is the Herbrand Base.
|
||||
*/
|
||||
new_states(_,[],_,_,_,_):-!.
|
||||
|
||||
|
||||
new_states(Node,[H:P|T],State,Prob,Clauses,HB):-
|
||||
Prob1 is P*Prob,
|
||||
(member(H,State)->
|
||||
NewState=State
|
||||
;
|
||||
append(State,[H],NewState)
|
||||
),
|
||||
build(Node,NewState,Prob1,Clauses,HB),
|
||||
new_states(Node,T,State,Prob,Clauses,HB).
|
||||
|
||||
/* get_new_atom(Atom)
|
||||
returns a new Atom of the form nNumber
|
||||
*/
|
||||
get_new_atom(Atom):-
|
||||
retract(new_number(N)),
|
||||
N1 is N+1,
|
||||
assert(new_number(N1)),
|
||||
number_atom(N,NA),
|
||||
atom_concat('n',NA,Atom).
|
||||
|
||||
/* predicates for printing the probabilistic process tree */
|
||||
print:-
|
||||
root(Root),
|
||||
print_children(Root,"").
|
||||
|
||||
print_children(Parent,Tab):-
|
||||
findall((Node,State,Clause,Prob),node(Clause,Node,Parent,State,Prob),LC),
|
||||
print_list(LC,Tab).
|
||||
|
||||
print_list([],_Tab):-!.
|
||||
|
||||
print_list([(Node,State0,Clause,Prob)|T],Tab):-
|
||||
delete(State0,'',State),
|
||||
(Clause=empty-> % leaf
|
||||
format("~s~p ~f~n",[Tab,State,Prob])
|
||||
;
|
||||
format("~s~p ~p ~f~n",[Tab,State,Clause,Prob]),
|
||||
append(Tab,"| ",Tab1),
|
||||
print_children(Node,Tab1)
|
||||
),
|
||||
print_list(T,Tab).
|
||||
|
||||
|
||||
|
||||
|
||||
/* predicate for parsing the program file */
|
||||
p(File):-
|
||||
parse(File),
|
||||
build.
|
||||
|
||||
parse(File):-
|
||||
retractall(root(_)),
|
||||
retractall(clauses(_)),
|
||||
retractall(herbrand_base(_)),
|
||||
retractall(node(_,_,_,_,_)),
|
||||
retractall(new_number(_)),
|
||||
assert(new_number(0)),
|
||||
atom_concat(File,'.cpl',FilePl),
|
||||
open(FilePl,read,S),
|
||||
read_clauses(S,C),
|
||||
close(S),
|
||||
atom_concat(File,'.uni',FileUni),
|
||||
reconsult(FileUni),
|
||||
process_clauses(C,ClausesVar),
|
||||
instantiate(ClausesVar,[],Clauses),
|
||||
assert(clauses(Clauses)),
|
||||
build_herbrand_base(HB),
|
||||
assert(herbrand_base(HB)).
|
||||
|
||||
|
||||
build_herbrand_base(HB):-
|
||||
findall(A,mode(A),LA),
|
||||
inst_list(LA,[],HB).
|
||||
|
||||
/* inst_list(Atoms,HB0,HB)
|
||||
enlarges the Herbrand Base by instantiating the atoms in Atoms
|
||||
*/
|
||||
inst_list([],HB,HB):-!.
|
||||
|
||||
inst_list([H|T],HB0,HB):-
|
||||
functor(H,F,Args),
|
||||
functor(A,F,Args),
|
||||
findall(A,instantiate_atom_modes(A),LA),
|
||||
append(HB0,LA,HB1),
|
||||
inst_list(T,HB1,HB).
|
||||
|
||||
/* instantiate(Clauses,C0,C)
|
||||
returns in C the set of clauses obtained by grounding Clauses
|
||||
*/
|
||||
instantiate([],C,C).
|
||||
|
||||
instantiate([r(_V,H,B)|T],CIn,COut):-
|
||||
findall(r(H,BOut),instantiate_clause_modes(H,B,BOut),L),
|
||||
append(CIn,L,C1),
|
||||
instantiate(T,C1,COut).
|
||||
|
||||
|
||||
instantiate_clause_modes(H,B,BOut):-
|
||||
instantiate_head_modes(H),
|
||||
instantiate_body_modes(B,BOut).
|
||||
|
||||
|
||||
instantiate_head_modes([]):-!.
|
||||
|
||||
instantiate_head_modes([H:_P|T]):-
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_head_modes(T).
|
||||
|
||||
|
||||
instantiate_body_modes(BL,BL):-
|
||||
setting(ground_body,false),!.
|
||||
|
||||
instantiate_body_modes(BL0,BL):-
|
||||
instantiate_list_modes(BL0,BL).
|
||||
|
||||
|
||||
instantiate_list_modes([],[]).
|
||||
|
||||
instantiate_list_modes([H|T0],T):-
|
||||
builtin(H),!,
|
||||
call(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([\+ H|T0],T):-
|
||||
builtin(H),!,
|
||||
\+ call(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([\+ H|T0],[\+ H|T]):-!,
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([H|T0],[H|T]):-
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
|
||||
instantiate_atom_modes(''):-!.
|
||||
|
||||
instantiate_atom_modes(A):-
|
||||
functor(A,F,NArgs),
|
||||
functor(TA,F,NArgs),
|
||||
A=..[F|Args],
|
||||
mode(TA),
|
||||
TA=..[F|Types],
|
||||
instantiate_args_modes(Args,Types).
|
||||
|
||||
|
||||
instantiate_args_modes([],[]):-!.
|
||||
|
||||
instantiate_args_modes([H|T],[TH|TT]):-
|
||||
type(TH,Constants),
|
||||
member(H,Constants),
|
||||
instantiate_args_modes(T,TT).
|
||||
|
||||
|
||||
/* process_clauses(Terms,Clauses)
|
||||
processes Terms to produce Clauses
|
||||
Terms is a list contatining elements of the form
|
||||
((H:-B),V)
|
||||
Clauses is a list containing elements of the form
|
||||
r(V,HL,BL)
|
||||
where HL is the list of disjuncts in H and BL is the list
|
||||
of literals in B
|
||||
*/
|
||||
process_clauses([(end_of_file,[])],[]).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,HL,BL)|T1]):-
|
||||
H=(_;_),!,
|
||||
list2or(HL1,H),
|
||||
list2and(BL,B),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,HL,BL)|T1]):-
|
||||
H=(_:_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
list2and(BL,B),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,[H:1],BL)|T1]):-!,
|
||||
list2and(BL,B),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,HL,[])|T1]):-
|
||||
H=(_;_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,HL,[])|T1]):-
|
||||
H=(_:_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,[H:1],[])|T1]):-
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_head([H:PH],P,[H:PH1|Null]):-
|
||||
PH1 is PH,
|
||||
PNull is 1-P-PH1,
|
||||
setting(epsilon_parsing,Eps),
|
||||
EpsNeg is - Eps,
|
||||
PNull > EpsNeg,
|
||||
(PNull>Eps->
|
||||
Null=['':PNull]
|
||||
;
|
||||
Null=[]
|
||||
).
|
||||
|
||||
process_head([H:PH|T],P,[H:PH1|NT]):-
|
||||
PH1 is PH,
|
||||
P1 is P+PH1,
|
||||
process_head(T,P1,NT).
|
||||
|
||||
/* read_clauses(S,Clauses)
|
||||
read Clauses from stream S
|
||||
*/
|
||||
read_clauses(S,Clauses):-
|
||||
(setting(ground_body,true)->
|
||||
read_clauses_ground_body(S,Clauses)
|
||||
;
|
||||
read_clauses_exist_body(S,Clauses)
|
||||
).
|
||||
|
||||
read_clauses_ground_body(S,[(Cl,V)|Out]):-
|
||||
read_term(S,Cl,[variable_names(V)]),
|
||||
(Cl=end_of_file->
|
||||
Out=[]
|
||||
;
|
||||
read_clauses_ground_body(S,Out)
|
||||
).
|
||||
|
||||
|
||||
read_clauses_exist_body(S,[(Cl,V)|Out]):-
|
||||
read_term(S,Cl,[variable_names(VN)]),
|
||||
extract_vars_cl(Cl,VN,V),
|
||||
(Cl=end_of_file->
|
||||
Out=[]
|
||||
;
|
||||
read_clauses_exist_body(S,Out)
|
||||
).
|
||||
|
||||
/* extract_vars_cl(Clause,VariableNames,Couples)
|
||||
extract from Clause couples of the form VariableName=Variable
|
||||
*/
|
||||
extract_vars_cl(end_of_file,[]).
|
||||
|
||||
extract_vars_cl(Cl,VN,Couples):-
|
||||
(Cl=(H:-_B)->
|
||||
true
|
||||
;
|
||||
H=Cl
|
||||
),
|
||||
extract_vars(H,[],V),
|
||||
pair(VN,V,Couples).
|
||||
|
||||
extract_vars(Var,V0,V):-
|
||||
var(Var),!,
|
||||
(member_eq(Var,V0)->
|
||||
V=V0
|
||||
;
|
||||
append(V0,[Var],V)
|
||||
).
|
||||
|
||||
extract_vars(Term,V0,V):-
|
||||
Term=..[_F|Args],
|
||||
extract_vars_list(Args,V0,V).
|
||||
|
||||
extract_vars_list([],V,V).
|
||||
|
||||
extract_vars_list([Term|T],V0,V):-
|
||||
extract_vars(Term,V0,V1),
|
||||
extract_vars_list(T,V1,V).
|
||||
|
||||
pair(_VN,[],[]).
|
||||
|
||||
pair([VN= _V|TVN],[V|TV],[VN=V|T]):-
|
||||
pair(TVN,TV,T).
|
||||
|
||||
/* auxiliary predicates */
|
||||
list2or([X],X):-
|
||||
X\=;(_,_),!.
|
||||
|
||||
list2or([H|T],(H ; Ta)):-!,
|
||||
list2or(T,Ta).
|
||||
|
||||
|
||||
list2and([],true):-!.
|
||||
|
||||
list2and([X],X):-
|
||||
X\=(_,_),!.
|
||||
|
||||
list2and([H|T],(H,Ta)):-!,
|
||||
list2and(T,Ta).
|
||||
|
||||
builtin(_A is _B).
|
||||
builtin(_A > _B).
|
||||
builtin(_A < _B).
|
||||
builtin(_A >= _B).
|
||||
builtin(_A =< _B).
|
||||
builtin(_A =:= _B).
|
||||
builtin(_A =\= _B).
|
||||
builtin(true).
|
||||
builtin(false).
|
||||
builtin(_A = _B).
|
||||
builtin(_A==_B).
|
||||
builtin(_A\=_B).
|
||||
builtin(_A\==_B).
|
||||
|
||||
bg(member(_El,_L)).
|
||||
bg(average(_L,_Av)).
|
||||
bg(max_list(_L,_Max)).
|
||||
bg(min_list(_L,_Max)).
|
||||
|
||||
average(L,Av):-
|
||||
sum_list(L,Sum),
|
||||
length(L,N),
|
||||
Av is Sum/N.
|
||||
|
||||
assert_all([]):-!.
|
||||
|
||||
assert_all([(:- G)|T]):-!,
|
||||
call(G),
|
||||
assert_all(T).
|
||||
|
||||
assert_all([H|T]):-!,
|
||||
assertz((H)),
|
||||
assert_all(T).
|
||||
|
||||
assert_all(C):-
|
||||
assertz((C)).
|
||||
|
||||
deleteall(L,[],L).
|
||||
|
||||
deleteall(L,[H|T],LOut):-
|
||||
delete(L,H,L1),
|
||||
deleteall(L1,T,LOut).
|
||||
|
||||
member_eq(A,[H|_T]):-
|
||||
A==H.
|
||||
|
||||
member_eq(A,[_H|T]):-
|
||||
member_eq(A,T).
|
||||
|
||||
/* set(Par,Value) can be used to set the value of a parameter */
|
||||
set(Parameter,Value):-
|
||||
retract(setting(Parameter,_)),
|
||||
assert(setting(Parameter,Value)).
|
||||
529
packages/cplint/semlpad.pl
Normal file
529
packages/cplint/semlpad.pl
Normal file
@@ -0,0 +1,529 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
File semlpad.pl
|
||||
Program for building the semantics of an LPAD
|
||||
Queries are answered by using SLG in every instance
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
*/
|
||||
|
||||
:-module(semlpad,[p/1,s/2,sc/3,set/2]).
|
||||
:-use_module(library(lists)).
|
||||
:-dynamic setting/2.
|
||||
:-set_prolog_flag(unknown,fail).
|
||||
:- dynamic new_number/1.
|
||||
|
||||
:-[library(slg)].
|
||||
:-retract('slg$default'(_D)),assert('slg$default'(tabled)).
|
||||
|
||||
setting(epsilon,0.00001).
|
||||
%setting(ground_body,true).
|
||||
setting(ground_body,false).
|
||||
/* available values: true, false
|
||||
if true, both the head and the body of each clause will be grounded, otherwise
|
||||
only the head is grounded. In the case in which the body contains variables
|
||||
not appearing in the head, the body represents an existential event */
|
||||
|
||||
%setting(grounding,variables).
|
||||
setting(grounding,modes).
|
||||
/* available values: variables, modes
|
||||
if set to variables, the universe facts from the .uni file are used
|
||||
if set to modes, the mode and type declaration from the .uni file are used
|
||||
*/
|
||||
|
||||
setting(verbose,false).
|
||||
|
||||
new_number(0).
|
||||
/* sc(Goal,Evidence,Probability)
|
||||
computes a conditional probability
|
||||
*/
|
||||
sc(Goals,Evidence,Prob):-
|
||||
s(Evidence,ProbE),
|
||||
append(Goals,Evidence,GE),
|
||||
s(GE,ProbGE),
|
||||
Prob is ProbGE/ProbE.
|
||||
|
||||
/* s(GoalsList,Prob)
|
||||
computes the probability of a query in the form of a list of literals
|
||||
*/
|
||||
s(GoalsList,Prob):-
|
||||
program_names(L),
|
||||
convert_to_goal(GoalsList,Goal,L),
|
||||
run_query(L,Goal,0,Prob).
|
||||
|
||||
run_query([],_G,P,P).
|
||||
|
||||
run_query([Prog|T],Goal,PIn,POut):-
|
||||
elab_conj(Prog,Goal,Goal1),
|
||||
slg(Goal1),!,
|
||||
prob(Prog,P),
|
||||
P1 is PIn+P,
|
||||
run_query(T,Goal,P1,POut).
|
||||
|
||||
run_query([_Prog|T],Goal,PIn,POut):-
|
||||
run_query(T,Goal,PIn,POut).
|
||||
|
||||
|
||||
convert_to_goal([Goal],Goal,_Pr):-!.
|
||||
|
||||
convert_to_goal(GoalsList,Head,Pr):-
|
||||
get_new_atom(Atom),
|
||||
extract_vars(GoalsList,[],V),
|
||||
Head=..[Atom|V],
|
||||
list2and(GoalsList,Body),
|
||||
elab_conj(Prog,Head,HeadP),
|
||||
elab_conj(Prog,Body,BodyP),
|
||||
do_term_expansion((HeadP:-BodyP),LC),
|
||||
assert_in_all_prog(LC,Prog,Pr).
|
||||
|
||||
|
||||
get_new_atom(Atom):-
|
||||
retract(new_number(N)),
|
||||
N1 is N+1,
|
||||
assert(new_number(N1)),
|
||||
number_atom(N,NA),
|
||||
atom_concat('$call',NA,Atom).
|
||||
|
||||
|
||||
assert_in_all_prog(_LC,_Prog,[]).
|
||||
|
||||
assert_in_all_prog(LC,Prog,[PrH|PrT]):-
|
||||
copy_term((LC,Prog),(LC1,Prog1)),
|
||||
Prog1=PrH,
|
||||
assert_all(LC1),
|
||||
assert_in_all_prog(LC,Prog,PrT).
|
||||
|
||||
/* predicate for parsing the program file */
|
||||
p(File):-
|
||||
clean_db,
|
||||
atom_concat(File,'.cpl',FilePl),
|
||||
open(FilePl,read,S),
|
||||
read_clauses(S,C),
|
||||
close(S),
|
||||
atom_concat(File,'.uni',FileUni),
|
||||
reconsult(FileUni),
|
||||
process_clauses(C,ClausesVar),
|
||||
instantiate(ClausesVar,[],Clauses),
|
||||
assert(program(1)),
|
||||
assert(program_names([])),
|
||||
create_programs(Clauses).
|
||||
|
||||
clean_db:-
|
||||
findall((P/A),(mode(Atom),functor(Atom,P,A0),A is A0+1),L),
|
||||
findall((P/A),(mode(Atom),functor(Atom,P0,A0),A is A0+2,
|
||||
name(P0,Pl),
|
||||
name(P,[115,108,103,36|Pl]) % 'slg$'
|
||||
),Lslg),
|
||||
abolish_all(L),
|
||||
abolish_all(Lslg),
|
||||
abolish(program/1),
|
||||
abolish(program_names/1),
|
||||
abolish(prob/2).
|
||||
|
||||
|
||||
abolish_all([]).
|
||||
|
||||
abolish_all([(P/A)|T]):-
|
||||
abolish(P/A),
|
||||
abolish_all(T).
|
||||
|
||||
/* create_programs(Clauses)
|
||||
create the instances of the ground LPAD composed by Clauses
|
||||
Each instance is identified by an atom of the form P<Number> where <Number> is an
|
||||
increasing number. An extra argument is added to each atom in the clauses to represent
|
||||
the identifier of the instance.
|
||||
*/
|
||||
create_programs(Clauses):-
|
||||
create_single_program(Clauses,1,Program),
|
||||
retract(program(N)),
|
||||
number_codes(N,NC),
|
||||
atom_codes(NA,NC),
|
||||
atom_concat(p,NA,Name),
|
||||
N1 is N+1,
|
||||
assert(program(N1)),
|
||||
(setting(verbose,true)->
|
||||
format("Writing instance ~d~n",[N])
|
||||
;
|
||||
true
|
||||
),
|
||||
write_program(Name,Program),
|
||||
retract(program_names(L)),
|
||||
append(L,[Name],L1),
|
||||
assert(program_names(L1)),
|
||||
fail.
|
||||
|
||||
create_programs(_).
|
||||
|
||||
write_program(Name,[(prob(P):-true)]):-!,
|
||||
elab_conj(Name,prob(P),Pr),
|
||||
assertz(Pr).
|
||||
|
||||
|
||||
write_program(Name,[(H:-B)|T]):-
|
||||
elab_conj(Name,H,H1),
|
||||
elab_conj(Name,B,B1),
|
||||
do_term_expansion((H1:-B1),LC),
|
||||
assert_all(LC),
|
||||
write_program(Name,T).
|
||||
|
||||
/* elab_conj(Name,Conj0,Conj)
|
||||
adds the extra argument Name to the conjunction Conj0 resulting in Conj
|
||||
*/
|
||||
elab_conj(_Name,true,true):-!.
|
||||
|
||||
elab_conj(Name,\+(B),\+(B1)):-!,
|
||||
elab_conj(Name,B,B1).
|
||||
|
||||
elab_conj(Name,(BL,Rest),(BL1,Rest1)):-!,
|
||||
elab_conj(Name,BL,BL1),
|
||||
elab_conj(Name,Rest,Rest1).
|
||||
|
||||
elab_conj(Name,bagof(V,EV^G,L),bagof(V,EV^GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,bagof(V,G,L),bagof(V,GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,setof(V,EV^G,L),setof(V,EV^GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,setof(V,G,L),setof(V,GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,findall(V,G,L),findall(V,GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(_Name,A,A):-
|
||||
bg(A),!.
|
||||
|
||||
elab_conj(_Name,A,A):-
|
||||
builtin(A),!.
|
||||
|
||||
elab_conj(Name,Lit,Lit1):-
|
||||
Lit\=(_,_),
|
||||
Lit=..[Pred|Args],
|
||||
Lit1=..[Pred,Name|Args].
|
||||
|
||||
|
||||
create_single_program([],P,[(prob(P):-true)]).
|
||||
|
||||
create_single_program([r(H,B)|T],PIn,[(HA:-B)|T1]):-
|
||||
member((HA:P),H),
|
||||
P1 is PIn*P,
|
||||
create_single_program(T,P1,T1).
|
||||
|
||||
/* predicates for producing the ground instances of program clauses */
|
||||
|
||||
/* instantiate(Clauses,C0,C)
|
||||
returns in C the set of clauses obtained by grounding Clauses
|
||||
*/
|
||||
instantiate([],C,C).
|
||||
|
||||
instantiate([r(_V,[H:1],B)|T],CIn,COut):-!,
|
||||
append(CIn,[r([H:1],B)],C1),
|
||||
instantiate(T,C1,COut).
|
||||
|
||||
instantiate([r(V,H,B)|T],CIn,COut):-
|
||||
(setting(grounding,variables)->
|
||||
findall(r(H,BOut),instantiate_clause_variables(V,H,B,BOut),L)
|
||||
;
|
||||
findall(r(H,BOut),instantiate_clause_modes(H,B,BOut),L)
|
||||
),
|
||||
append(CIn,L,C1),
|
||||
instantiate(T,C1,COut).
|
||||
|
||||
|
||||
instantiate_clause_modes(H,B,BOut):-
|
||||
instantiate_head_modes(H),
|
||||
list2and(BL,B),
|
||||
instantiate_body_modes(BL,BLOut),
|
||||
list2and(BLOut,BOut).
|
||||
|
||||
|
||||
instantiate_head_modes([]):-!.
|
||||
|
||||
instantiate_head_modes([H:_P|T]):-
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_head_modes(T).
|
||||
|
||||
|
||||
instantiate_body_modes(BL,BL):-
|
||||
setting(ground_body,false),!.
|
||||
|
||||
instantiate_body_modes(BL0,BL):-
|
||||
instantiate_list_modes(BL0,BL).
|
||||
|
||||
|
||||
instantiate_list_modes([],[]).
|
||||
|
||||
instantiate_list_modes([H|T0],T):-
|
||||
builtin(H),!,
|
||||
call(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([\+ H|T0],T):-
|
||||
builtin(H),!,
|
||||
\+ call(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([\+ H|T0],[\+ H|T]):-!,
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([H|T0],[H|T]):-
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
|
||||
instantiate_atom_modes(''):-!.
|
||||
|
||||
instantiate_atom_modes(A):-
|
||||
functor(A,F,NArgs),
|
||||
functor(TA,F,NArgs),
|
||||
A=..[F|Args],
|
||||
mode(TA),
|
||||
TA=..[F|Types],
|
||||
instantiate_args_modes(Args,Types).
|
||||
|
||||
|
||||
instantiate_args_modes([],[]):-!.
|
||||
|
||||
instantiate_args_modes([H|T],[TH|TT]):-
|
||||
type(TH,Constants),
|
||||
member(H,Constants),
|
||||
instantiate_args_modes(T,TT).
|
||||
|
||||
|
||||
instantiate_clause_variables([],_H,B,BOut):-
|
||||
list2and(BL,B),
|
||||
(setting(ground_body,true)->
|
||||
check_body(BL,BLOut)
|
||||
;
|
||||
BLOut=BL
|
||||
),
|
||||
list2and(BLOut,BOut).
|
||||
|
||||
instantiate_clause_variables([VarName=Var|T],H,BIn,BOut):-
|
||||
universe(VarNames,U),
|
||||
member(VarName,VarNames),
|
||||
member(Var,U),
|
||||
instantiate_clause_variables(T,H,BIn,BOut).
|
||||
|
||||
instantiate_clause_variables([VarName=_Var|T],H,BIn,BOut):-
|
||||
\+ varName_present_variables(VarName),!,
|
||||
instantiate_clause_variables(T,H,BIn,BOut).
|
||||
|
||||
|
||||
varName_present_variables(VarName):-
|
||||
universe(VarNames,_U), member(VarName,VarNames).
|
||||
|
||||
/* check_body(Body0,Body)
|
||||
removes the true builtin literals from Body0. Fails if there is a false builtin literal.
|
||||
*/
|
||||
check_body([],[]).
|
||||
|
||||
check_body([H|T],TOut):-
|
||||
builtin(H),!,
|
||||
call(H),
|
||||
check_body(T,TOut).
|
||||
|
||||
check_body([H|T],[H|TOut]):-
|
||||
check_body(T,TOut).
|
||||
|
||||
|
||||
/* predicates for processing the clauses read from the file */
|
||||
/* process_clauses(Terms,Clauses)
|
||||
processes Terms to produce Clauses
|
||||
Terms is a list contatining elements of the form
|
||||
((H:-B),V)
|
||||
Clauses is a list containing elements of the form
|
||||
r(V,HL,BL)
|
||||
where HL is the list of disjuncts in H and BL is the list
|
||||
of literals in B
|
||||
*/
|
||||
process_clauses([(end_of_file,[])],[]).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,HL,B)|T1]):-
|
||||
H=(_;_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,HL,B)|T1]):-
|
||||
H=(_:_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,[H:1],B)|T1]):-!,
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,HL,true)|T1]):-
|
||||
H=(_;_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,HL,true)|T1]):-
|
||||
H=(_:_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,[H:1],true)|T1]):-
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_head([H:PH],P,[H:PH1|Null]):-
|
||||
PH1 is PH,
|
||||
PNull is 1-P-PH1,
|
||||
setting(epsilon,Eps),
|
||||
EpsNeg is - Eps,
|
||||
PNull > EpsNeg,
|
||||
(PNull>Eps->
|
||||
Null=['':PNull]
|
||||
;
|
||||
Null=[]
|
||||
).
|
||||
|
||||
process_head([H:PH|T],P,[H:PH1|NT]):-
|
||||
PH1 is PH,
|
||||
P1 is P+PH1,
|
||||
process_head(T,P1,NT).
|
||||
|
||||
/* predicates for reading in the program clauses */
|
||||
/* read_clauses(S,Clauses)
|
||||
read Clauses from stream S
|
||||
*/
|
||||
read_clauses(S,Clauses):-
|
||||
(setting(ground_body,true)->
|
||||
read_clauses_ground_body(S,Clauses)
|
||||
;
|
||||
read_clauses_exist_body(S,Clauses)
|
||||
).
|
||||
|
||||
|
||||
read_clauses_ground_body(S,[(Cl,V)|Out]):-
|
||||
read_term(S,Cl,[variable_names(V)]),
|
||||
(Cl=end_of_file->
|
||||
Out=[]
|
||||
;
|
||||
read_clauses_ground_body(S,Out)
|
||||
).
|
||||
|
||||
|
||||
read_clauses_exist_body(S,[(Cl,V)|Out]):-
|
||||
read_term(S,Cl,[variable_names(VN)]),
|
||||
extract_vars_cl(Cl,VN,V),
|
||||
(Cl=end_of_file->
|
||||
Out=[]
|
||||
;
|
||||
read_clauses_exist_body(S,Out)
|
||||
).
|
||||
|
||||
|
||||
/* extract_vars_cl(Clause,VariableNames,Couples)
|
||||
extract from Clause couples of the form VariableName=Variable
|
||||
*/
|
||||
extract_vars_cl(end_of_file,[]).
|
||||
|
||||
extract_vars_cl(Cl,VN,Couples):-
|
||||
(Cl=(H:-_B)->
|
||||
true
|
||||
;
|
||||
H=Cl
|
||||
),
|
||||
extract_vars(H,[],V),
|
||||
pair(VN,V,Couples).
|
||||
|
||||
|
||||
pair(_VN,[],[]).
|
||||
|
||||
pair([VN= _V|TVN],[V|TV],[VN=V|T]):-
|
||||
pair(TVN,TV,T).
|
||||
|
||||
|
||||
extract_vars(Var,V0,V):-
|
||||
var(Var),!,
|
||||
(member_eq(Var,V0)->
|
||||
V=V0
|
||||
;
|
||||
append(V0,[Var],V)
|
||||
).
|
||||
|
||||
extract_vars(Term,V0,V):-
|
||||
Term=..[_F|Args],
|
||||
extract_vars_list(Args,V0,V).
|
||||
|
||||
|
||||
extract_vars_list([],V,V).
|
||||
|
||||
extract_vars_list([Term|T],V0,V):-
|
||||
extract_vars(Term,V0,V1),
|
||||
extract_vars_list(T,V1,V).
|
||||
|
||||
|
||||
/* auxiliary predicates */
|
||||
list2or([X],X):-
|
||||
X\=;(_,_),!.
|
||||
|
||||
list2or([H|T],(H ; Ta)):-!,
|
||||
list2or(T,Ta).
|
||||
|
||||
|
||||
list2and([],true):-!.
|
||||
|
||||
list2and([X],X):-
|
||||
X\=(_,_),!.
|
||||
|
||||
list2and([H|T],(H,Ta)):-!,
|
||||
list2and(T,Ta).
|
||||
|
||||
|
||||
builtin(_A is _B).
|
||||
builtin(_A > _B).
|
||||
builtin(_A < _B).
|
||||
builtin(_A >= _B).
|
||||
builtin(_A =< _B).
|
||||
builtin(_A =:= _B).
|
||||
builtin(_A =\= _B).
|
||||
builtin(true).
|
||||
builtin(false).
|
||||
builtin(_A = _B).
|
||||
builtin(_A==_B).
|
||||
builtin(_A\=_B).
|
||||
builtin(_A\==_B).
|
||||
|
||||
|
||||
bg(member(_El,_L)).
|
||||
bg(average(_L,_Av)).
|
||||
bg(max_list(_L,_Max)).
|
||||
bg(min_list(_L,_Max)).
|
||||
|
||||
|
||||
average(L,Av):-
|
||||
sum_list(L,Sum),
|
||||
length(L,N),
|
||||
Av is Sum/N.
|
||||
|
||||
assert_all([]):-!.
|
||||
|
||||
assert_all([(:- G)|T]):-!,
|
||||
call(G),
|
||||
assert_all(T).
|
||||
|
||||
assert_all([H|T]):-!,
|
||||
assertz((H)),
|
||||
assert_all(T).
|
||||
|
||||
assert_all(C):-
|
||||
assertz((C)).
|
||||
|
||||
member_eq(A,[H|_T]):-
|
||||
A==H,!.
|
||||
|
||||
member_eq(A,[_H|T]):-
|
||||
member_eq(A,T).
|
||||
|
||||
/* set(Par,Value) can be used to set the value of a parameter */
|
||||
set(Parameter,Value):-
|
||||
retract(setting(Parameter,_)),
|
||||
assert(setting(Parameter,Value)).
|
||||
468
packages/cplint/semlpadsld.pl
Normal file
468
packages/cplint/semlpadsld.pl
Normal file
@@ -0,0 +1,468 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
File semlpadsld.pl
|
||||
Program for building the semantics of an LPAD
|
||||
Queries are answered by using Prolog in every instance
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
*/
|
||||
|
||||
:-module(semlpadsld,[p/1,s/2,sc/3,set/2]).
|
||||
:-use_module(library(lists)).
|
||||
:-dynamic setting/2.
|
||||
:-set_prolog_flag(unknown,fail).
|
||||
|
||||
|
||||
setting(epsilon,0.00001).
|
||||
setting(ground_body,false).
|
||||
/* available values: true, false
|
||||
if true, both the head and the body of each clause will be grounded, otherwise
|
||||
only the head is grounded. In the case in which the body contains variables
|
||||
not appearing in the head, the body represents an existential event */
|
||||
|
||||
setting(grounding,modes).
|
||||
/* available values: variables, modes
|
||||
if set to variables, the universe facts from the .uni file are used
|
||||
if set to modes, the mode and type declaration from the .uni file are used
|
||||
*/
|
||||
|
||||
setting(verbose,false).
|
||||
|
||||
|
||||
sc(Goals,Evidence,Prob):-
|
||||
s(Evidence,ProbE),
|
||||
append(Goals,Evidence,GE),
|
||||
s(GE,ProbGE),
|
||||
Prob is ProbGE/ProbE.
|
||||
|
||||
s(GoalsList,Prob):-
|
||||
program_names(L),
|
||||
list2and(GoalsList,Goals),
|
||||
run_query(L,Goals,0,Prob).
|
||||
|
||||
run_query([],_G,P,P).
|
||||
|
||||
run_query([Prog|T],Goal,PIn,POut):-
|
||||
elab_conj(Prog,Goal,Goal1),
|
||||
call(Goal1),
|
||||
prob(Prog,P),
|
||||
P1 is PIn+P,
|
||||
run_query(T,Goal,P1,POut).
|
||||
|
||||
run_query([Prog|T],Goal,PIn,POut):-
|
||||
elab_conj(Prog,Goal,Goal1),
|
||||
\+ call(Goal1),
|
||||
run_query(T,Goal,PIn,POut).
|
||||
|
||||
/* predicate for parsing the program file */
|
||||
p(File):-
|
||||
clean_db,
|
||||
atom_concat(File,'.cpl',FilePl),
|
||||
open(FilePl,read,S),
|
||||
read_clauses(S,C),
|
||||
close(S),
|
||||
atom_concat(File,'.uni',FileUni),
|
||||
reconsult(FileUni),
|
||||
process_clauses(C,ClausesVar),
|
||||
instantiate(ClausesVar,[],Clauses),
|
||||
assert(program(1)),
|
||||
assert(program_names([])),
|
||||
create_programs(Clauses).
|
||||
|
||||
clean_db:-
|
||||
findall((P/A),(mode(Atom),functor(Atom,P,A0),A is A0+1),L),
|
||||
abolish_all(L),
|
||||
abolish(program/1),
|
||||
abolish(program_names/1),
|
||||
abolish(prob/2).
|
||||
|
||||
abolish_all([]).
|
||||
|
||||
abolish_all([(P/A)|T]):-
|
||||
abolish(P/A),
|
||||
abolish_all(T).
|
||||
|
||||
/* create_programs(Clauses)
|
||||
create the instances of the ground LPAD composed by Clauses
|
||||
Each instance is identified by an atom of the form P<Number> where <Number> is an
|
||||
increasing number. An extra argument is added to each atom in the clauses to represent
|
||||
the identifier of the instance.
|
||||
*/
|
||||
create_programs(Clauses):-
|
||||
create_single_program(Clauses,1,Program),
|
||||
retract(program(N)),
|
||||
number_codes(N,NC),
|
||||
atom_codes(NA,NC),
|
||||
atom_concat(p,NA,Name),
|
||||
N1 is N+1,
|
||||
assert(program(N1)),
|
||||
(setting(verbose,true)->
|
||||
format("Writing instance ~d~n",[N])
|
||||
;
|
||||
true
|
||||
),
|
||||
write_program(Name,Program),
|
||||
retract(program_names(L)),
|
||||
append(L,[Name],L1),
|
||||
assert(program_names(L1)),
|
||||
fail.
|
||||
|
||||
create_programs(_).
|
||||
|
||||
|
||||
write_program(_Name,[]).
|
||||
|
||||
write_program(Name,[(H:-B)|T]):-
|
||||
elab_conj(Name,H,H1),
|
||||
elab_conj(Name,B,B1),
|
||||
assertz((H1:-B1)),
|
||||
write_program(Name,T).
|
||||
|
||||
/* elab_conj(Name,Conj0,Conj)
|
||||
adds the extra argument Name to the conjunction Conj0 resulting in Conj
|
||||
*/
|
||||
elab_conj(_Name,true,true):-!.
|
||||
|
||||
elab_conj(Name,\+(B),\+(B1)):-!,
|
||||
elab_conj(Name,B,B1).
|
||||
|
||||
elab_conj(Name,(BL,Rest),(BL1,Rest1)):-!,
|
||||
elab_conj(Name,BL,BL1),
|
||||
elab_conj(Name,Rest,Rest1).
|
||||
|
||||
elab_conj(Name,bagof(V,EV^G,L),bagof(V,EV^GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,bagof(V,G,L),bagof(V,GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,setof(V,EV^G,L),setof(V,EV^GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,setof(V,G,L),setof(V,GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(Name,findall(V,G,L),findall(V,GL,L)):-!,
|
||||
elab_conj(Name,G,GL).
|
||||
|
||||
elab_conj(_Name,A,A):-
|
||||
bg(A),!.
|
||||
|
||||
elab_conj(_Name,A,A):-
|
||||
builtin(A),!.
|
||||
|
||||
elab_conj(Name,Lit,Lit1):-
|
||||
Lit\=(_,_),
|
||||
Lit=..[Pred|Args],
|
||||
Lit1=..[Pred,Name|Args].
|
||||
|
||||
|
||||
create_single_program([],P,[(prob(P):-true)]).
|
||||
|
||||
create_single_program([r(H,B)|T],PIn,[(HA:-B)|T1]):-
|
||||
member((HA:P),H),
|
||||
P1 is PIn*P,
|
||||
create_single_program(T,P1,T1).
|
||||
|
||||
/* predicates for producing the ground instances of program clauses */
|
||||
|
||||
/* instantiate(Clauses,C0,C)
|
||||
returns in C the set of clauses obtained by grounding Clauses
|
||||
*/
|
||||
instantiate([],C,C).
|
||||
|
||||
instantiate([r(_V,[H:1],B)|T],CIn,COut):-!,
|
||||
append(CIn,[r([H:1],B)],C1),
|
||||
instantiate(T,C1,COut).
|
||||
|
||||
instantiate([r(V,H,B)|T],CIn,COut):-
|
||||
(setting(grounding,variables)->
|
||||
findall(r(H,BOut),instantiate_clause_variables(V,H,B,BOut),L)
|
||||
;
|
||||
findall(r(H,BOut),instantiate_clause_modes(H,B,BOut),L)
|
||||
),
|
||||
append(CIn,L,C1),
|
||||
instantiate(T,C1,COut).
|
||||
|
||||
|
||||
instantiate_clause_modes(H,B,BOut):-
|
||||
instantiate_head_modes(H),
|
||||
list2and(BL,B),
|
||||
instantiate_body_modes(BL,BLOut),
|
||||
list2and(BLOut,BOut).
|
||||
|
||||
|
||||
instantiate_head_modes([]):-!.
|
||||
|
||||
instantiate_head_modes([H:_P|T]):-
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_head_modes(T).
|
||||
|
||||
|
||||
instantiate_body_modes(BL,BL):-
|
||||
setting(ground_body,false),!.
|
||||
|
||||
instantiate_body_modes(BL0,BL):-
|
||||
instantiate_list_modes(BL0,BL).
|
||||
|
||||
|
||||
instantiate_list_modes([],[]).
|
||||
|
||||
instantiate_list_modes([H|T0],T):-
|
||||
builtin(H),!,
|
||||
call(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([\+ H|T0],T):-
|
||||
builtin(H),!,
|
||||
\+ call(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([\+ H|T0],[\+ H|T]):-!,
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
instantiate_list_modes([H|T0],[H|T]):-
|
||||
instantiate_atom_modes(H),
|
||||
instantiate_list_modes(T0,T).
|
||||
|
||||
|
||||
instantiate_atom_modes(''):-!.
|
||||
|
||||
instantiate_atom_modes(A):-
|
||||
functor(A,F,NArgs),
|
||||
functor(TA,F,NArgs),
|
||||
A=..[F|Args],
|
||||
mode(TA),
|
||||
TA=..[F|Types],
|
||||
instantiate_args_modes(Args,Types).
|
||||
|
||||
|
||||
instantiate_args_modes([],[]):-!.
|
||||
|
||||
instantiate_args_modes([H|T],[TH|TT]):-
|
||||
type(TH,Constants),
|
||||
member(H,Constants),
|
||||
instantiate_args_modes(T,TT).
|
||||
|
||||
|
||||
instantiate_clause_variables([],_H,B,BOut):-
|
||||
list2and(BL,B),
|
||||
(setting(ground_body,true)->
|
||||
check_body(BL,BLOut)
|
||||
;
|
||||
BLOut=BL
|
||||
),
|
||||
list2and(BLOut,BOut).
|
||||
|
||||
instantiate_clause_variables([VarName=Var|T],H,BIn,BOut):-
|
||||
universe(VarNames,U),
|
||||
member(VarName,VarNames),
|
||||
member(Var,U),
|
||||
instantiate_clause_variables(T,H,BIn,BOut).
|
||||
|
||||
instantiate_clause_variables([VarName=_Var|T],H,BIn,BOut):-
|
||||
\+ varName_present_variables(VarName),!,
|
||||
instantiate_clause_variables(T,H,BIn,BOut).
|
||||
|
||||
|
||||
varName_present_variables(VarName):-
|
||||
universe(VarNames,_U), member(VarName,VarNames).
|
||||
|
||||
/* check_body(Body0,Body)
|
||||
removes the true builtin literals from Body0. Fails if there is a false builtin literal.
|
||||
*/
|
||||
check_body([],[]).
|
||||
|
||||
check_body([H|T],TOut):-
|
||||
builtin(H),!,
|
||||
call(H),
|
||||
check_body(T,TOut).
|
||||
|
||||
check_body([H|T],[H|TOut]):-
|
||||
check_body(T,TOut).
|
||||
|
||||
|
||||
/* predicates for processing the clauses read from the file */
|
||||
/* process_clauses(Terms,Clauses)
|
||||
processes Terms to produce Clauses
|
||||
Terms is a list contatining elements of the form
|
||||
((H:-B),V)
|
||||
Clauses is a list containing elements of the form
|
||||
r(V,HL,BL)
|
||||
where HL is the list of disjuncts in H and BL is the list
|
||||
of literals in B
|
||||
*/
|
||||
process_clauses([(end_of_file,[])],[]).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,HL,B)|T1]):-
|
||||
H=(_;_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,HL,B)|T1]):-
|
||||
H=(_:_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([((H:-B),V)|T],[r(V,[H:1],B)|T1]):-!,
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,HL,true)|T1]):-
|
||||
H=(_;_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,HL,true)|T1]):-
|
||||
H=(_:_),!,
|
||||
list2or(HL1,H),
|
||||
process_head(HL1,0,HL),
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_clauses([(H,V)|T],[r(V,[H:1],true)|T1]):-
|
||||
process_clauses(T,T1).
|
||||
|
||||
process_head([H:PH],P,[H:PH1|Null]):-
|
||||
PH1 is PH,
|
||||
PNull is 1-P-PH1,
|
||||
setting(epsilon,Eps),
|
||||
EpsNeg is - Eps,
|
||||
PNull > EpsNeg,
|
||||
(PNull>Eps->
|
||||
Null=['':PNull]
|
||||
;
|
||||
Null=[]
|
||||
).
|
||||
|
||||
process_head([H:PH|T],P,[H:PH1|NT]):-
|
||||
PH1 is PH,
|
||||
P1 is P+PH1,
|
||||
process_head(T,P1,NT).
|
||||
|
||||
|
||||
/* predicates for reading in the program clauses */
|
||||
/* read_clauses(S,Clauses)
|
||||
read Clauses from stream S
|
||||
*/
|
||||
read_clauses(S,Clauses):-
|
||||
(setting(ground_body,true)->
|
||||
read_clauses_ground_body(S,Clauses)
|
||||
;
|
||||
read_clauses_exist_body(S,Clauses)
|
||||
).
|
||||
|
||||
|
||||
read_clauses_ground_body(S,[(Cl,V)|Out]):-
|
||||
read_term(S,Cl,[variable_names(V)]),
|
||||
(Cl=end_of_file->
|
||||
Out=[]
|
||||
;
|
||||
read_clauses_ground_body(S,Out)
|
||||
).
|
||||
|
||||
|
||||
read_clauses_exist_body(S,[(Cl,V)|Out]):-
|
||||
read_term(S,Cl,[variable_names(VN)]),
|
||||
extract_vars_cl(Cl,VN,V),
|
||||
(Cl=end_of_file->
|
||||
Out=[]
|
||||
;
|
||||
read_clauses_exist_body(S,Out)
|
||||
).
|
||||
|
||||
|
||||
/* extract_vars_cl(Clause,VariableNames,Couples)
|
||||
extract from Clause couples of the form VariableName=Variable
|
||||
*/
|
||||
extract_vars_cl(end_of_file,[]).
|
||||
|
||||
extract_vars_cl(Cl,VN,Couples):-
|
||||
(Cl=(H:-_B)->
|
||||
true
|
||||
;
|
||||
H=Cl
|
||||
),
|
||||
extract_vars(H,[],V),
|
||||
pair(VN,V,Couples).
|
||||
|
||||
|
||||
pair(_VN,[],[]).
|
||||
|
||||
pair([VN= _V|TVN],[V|TV],[VN=V|T]):-
|
||||
pair(TVN,TV,T).
|
||||
|
||||
|
||||
extract_vars(Var,V0,V):-
|
||||
var(Var),!,
|
||||
(member_eq(Var,V0)->
|
||||
V=V0
|
||||
;
|
||||
append(V0,[Var],V)
|
||||
).
|
||||
|
||||
extract_vars(Term,V0,V):-
|
||||
Term=..[_F|Args],
|
||||
extract_vars_list(Args,V0,V).
|
||||
|
||||
|
||||
extract_vars_list([],V,V).
|
||||
|
||||
extract_vars_list([Term|T],V0,V):-
|
||||
extract_vars(Term,V0,V1),
|
||||
extract_vars_list(T,V1,V).
|
||||
|
||||
member_eq(A,[H|_T]):-
|
||||
A==H,!.
|
||||
|
||||
member_eq(A,[_H|T]):-
|
||||
member_eq(A,T).
|
||||
|
||||
/* auxiliary predicates */
|
||||
list2or([X],X):-
|
||||
X\=;(_,_),!.
|
||||
|
||||
list2or([H|T],(H ; Ta)):-!,
|
||||
list2or(T,Ta).
|
||||
|
||||
|
||||
list2and([],true):-!.
|
||||
|
||||
list2and([X],X):-
|
||||
X\=(_,_),!.
|
||||
|
||||
list2and([H|T],(H,Ta)):-!,
|
||||
list2and(T,Ta).
|
||||
|
||||
|
||||
builtin(_A is _B).
|
||||
builtin(_A > _B).
|
||||
builtin(_A < _B).
|
||||
builtin(_A >= _B).
|
||||
builtin(_A =< _B).
|
||||
builtin(_A =:= _B).
|
||||
builtin(_A =\= _B).
|
||||
builtin(true).
|
||||
builtin(false).
|
||||
builtin(_A = _B).
|
||||
builtin(_A==_B).
|
||||
builtin(_A\=_B).
|
||||
builtin(_A\==_B).
|
||||
|
||||
|
||||
bg(member(_El,_L)).
|
||||
bg(average(_L,_Av)).
|
||||
bg(max_list(_L,_Max)).
|
||||
bg(min_list(_L,_Max)).
|
||||
|
||||
|
||||
average(L,Av):-
|
||||
sum_list(L,Sum),
|
||||
length(L,N),
|
||||
Av is Sum/N.
|
||||
|
||||
/* set(Par,Value) can be used to set the value of a parameter */
|
||||
set(Parameter,Value):-
|
||||
retract(setting(Parameter,_)),
|
||||
assert(setting(Parameter,Value)).
|
||||
2158
packages/cplint/slg.pl
Normal file
2158
packages/cplint/slg.pl
Normal file
File diff suppressed because it is too large
Load Diff
124
packages/cplint/testcpl.pl
Normal file
124
packages/cplint/testcpl.pl
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for cpld.pl
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
|
||||
:-use_module(library(cpl)).
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting cpl.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
test_files(F,ground_body(false)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
format("~n~a.cpl~n",[H]),
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([
|
||||
exapprox,exrange,threesideddice,mendels,
|
||||
coin2,ex,throws,trigger,win,hiv,light,
|
||||
invalid]).
|
||||
|
||||
test((s([p],P),close_to(P,0.5)),invalid,_).
|
||||
test((s([q],P),close_to(P,0.5)),invalid,_).
|
||||
test((s([p,q],P),close_to(P,0)),invalid,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([win(white)],P),close_to(P,0.5)),win,_).
|
||||
test((s([win(black)],P),close_to(P,0.5)),win,_).
|
||||
test((s([win(black),win(white)],P),close_to(P,0)),win,_).
|
||||
|
||||
test((s([hiv(a)],P),close_to(P,0.154)),hiv,_).
|
||||
test((s([hiv(b)],P),close_to(P,0.154)),hiv,_).
|
||||
test((s([hiv(b),hiv(a)],P),close_to(P,0.118)),hiv,_).
|
||||
test((s([\+ hiv(b),\+ hiv(a)],P),close_to(P,0.81)),hiv,_).
|
||||
test((s([ hiv(b),\+ hiv(a)],P),close_to(P,0.036)),hiv,_).
|
||||
test((s([\+ hiv(b),hiv(a)],P),close_to(P,0.036)),hiv,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
136
packages/cplint/testlpad.pl
Normal file
136
packages/cplint/testlpad.pl
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpad.pl
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
|
||||
:-use_module(library(lpad)).
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting lpad.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(F,ground_body(false)),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
format("~n~a.cpl~n",[H]),
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([
|
||||
exapprox,exrange,threesideddice,mendels,
|
||||
coin2,ex,throws,trigger,win,hiv,light,
|
||||
invalid,exist,exist1]).
|
||||
|
||||
test((s([a],P),close_to(P,0.18)),exist,ground_body(false)).
|
||||
test((s([a],P),close_to(P,0.19)),exist,ground_body(true)).
|
||||
|
||||
test((s([a],P),close_to(P,0.276)),exist1,ground_body(false)).
|
||||
test((s([a],P),close_to(P,0.3115)),exist1,ground_body(true)).
|
||||
|
||||
test((s([p],P),close_to(P,0.5)),invalid,_).
|
||||
test((s([q],P),close_to(P,0.5)),invalid,_).
|
||||
test((s([p,q],P),close_to(P,0)),invalid,_).
|
||||
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([win(white)],P),close_to(P,0.5)),win,_).
|
||||
test((s([win(black)],P),close_to(P,0.5)),win,_).
|
||||
test((s([win(black),win(white)],P),close_to(P,0)),win,_).
|
||||
|
||||
test((s([hiv(a)],P),close_to(P,0.154)),hiv,_).
|
||||
test((s([hiv(b)],P),close_to(P,0.154)),hiv,_).
|
||||
test((s([hiv(b),hiv(a)],P),close_to(P,0.118)),hiv,_).
|
||||
test((s([\+ hiv(b),\+ hiv(a)],P),close_to(P,0.81)),hiv,_).
|
||||
test((s([ hiv(b),\+ hiv(a)],P),close_to(P,0.036)),hiv,_).
|
||||
test((s([\+ hiv(b),hiv(a)],P),close_to(P,0.036)),hiv,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
212
packages/cplint/testlpadclpbn.pl
Normal file
212
packages/cplint/testlpadclpbn.pl
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is grounded
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
:-use_module(library(lpadclpbn)).
|
||||
|
||||
epsilon(0.001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting lpadclpbn.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
test_files(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([exapprox,exrange,
|
||||
threesideddice,
|
||||
mendel,coin2,ex,trigger,throws,light]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
215
packages/cplint/testlpadsld_gbfalse.pl
Normal file
215
packages/cplint/testlpadsld_gbfalse.pl
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is an existential event
|
||||
(not grounded)
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
:-use_module(library(lpadsld)).
|
||||
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting lpadsld.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(F,ground_body(false)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([paper_ref_not,paper_ref,female,exapprox,exrange,threesideddice,
|
||||
mendel,student,school_simple,school,coin2,ex,trigger,throws,light]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
246
packages/cplint/testlpadsld_gbtrue.pl
Normal file
246
packages/cplint/testlpadsld_gbtrue.pl
Normal file
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is grounded
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
:-use_module(library(lpadsld)).
|
||||
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
ti:-
|
||||
format("~nTesting iterative deepening lpadsld.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_filesi(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
ti:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
t:-
|
||||
format("~nTesting lpadsld.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
test_filesi([],_GB).
|
||||
|
||||
test_filesi([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_alli(H,L),
|
||||
test_filesi(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
test_alli(_F,[]).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(s(Q,P),close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
si(Q,PL,PU,T),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([paper_ref_not,paper_ref,female,exapprox,exrange,threesideddice,
|
||||
mendel,student,school_simple,school,coin2,ex,trigger,throws,light]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
236
packages/cplint/testlpadsldit.pl
Normal file
236
packages/cplint/testlpadsldit.pl
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is grounded
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
:-source.
|
||||
:-use_module(library(lpadsld)).
|
||||
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
t:-
|
||||
format("~nTesting iterative deepening lpadsld.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,true),
|
||||
set(depth_bound,1),
|
||||
set(min_error,0.05),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_filesi(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_filesi([],_GB).
|
||||
|
||||
test_filesi([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_alli(H,L),
|
||||
test_filesi(T,GB).
|
||||
|
||||
test_alli(_F,[]).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(s(Q,_P),close_to('P',P)),!,
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
si(Q,PL,PU,_Time),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
P>=PL-1e-7,P=<PU+1e-7,
|
||||
test_alli(F,T).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(sc(Q,E,_P),close_to('P',P)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
sci(Q,E,PL,PU,_Time),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
P>=PL-1e-10,P=<PU+1e-10,
|
||||
test_alli(F,T).
|
||||
|
||||
|
||||
files([
|
||||
exapprox,
|
||||
exrange,
|
||||
threesideddice,
|
||||
%mendel,
|
||||
coin2,ex,trigger,throws,light
|
||||
]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
test((s([on(3,1)],P),close_to(P,0.0987654320987654)),threesideddice,_).
|
||||
test((s([on(4,1)],P),close_to(P,0.0658436213991769)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((sc([on(4,1)],[on(1,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
|
||||
test((sc([on(5,1)],[on(2,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
|
||||
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
236
packages/cplint/testlpadslditc.pl
Normal file
236
packages/cplint/testlpadslditc.pl
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is grounded
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
:-source.
|
||||
:-use_module(library(lpadsld)).
|
||||
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
t:-
|
||||
format("~nTesting iterative deepening lpadsld.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,true),
|
||||
set(depth_bound,7),
|
||||
set(min_error,0.05),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_filesi(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_filesi([],_GB).
|
||||
|
||||
test_filesi([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_alli(H,L),
|
||||
test_filesi(T,GB).
|
||||
|
||||
test_alli(_F,[]).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(s(Q,_P),close_to('P',P)),!,
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
sic(Q,PL,PU,_Time),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
P>=PL-1e-7,P=<PU+1e-7,
|
||||
test_alli(F,T).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(sc(Q,E,_P),close_to('P',P)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
scic(Q,E,PL,PU,_Time),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
P>=PL-1e-10,P=<PU+1e-10,
|
||||
test_alli(F,T).
|
||||
|
||||
|
||||
files([
|
||||
exapprox,
|
||||
exrange,
|
||||
threesideddice,
|
||||
mendel,
|
||||
coin2,ex,trigger,throws,light
|
||||
]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
test((s([on(3,1)],P),close_to(P,0.0987654320987654)),threesideddice,_).
|
||||
test((s([on(4,1)],P),close_to(P,0.0658436213991769)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((sc([on(4,1)],[on(1,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
|
||||
test((sc([on(5,1)],[on(2,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
|
||||
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
234
packages/cplint/testlpadslditr.pl
Normal file
234
packages/cplint/testlpadslditr.pl
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is grounded
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
:-source.
|
||||
:-use_module(library(lpadsld)).
|
||||
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
t:-
|
||||
format("~nTesting iterative deepening lpadsld.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,true),
|
||||
set(depth_bound,1),
|
||||
set(min_error,0.05),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_filesi(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_filesi([],_GB).
|
||||
|
||||
test_filesi([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_alli(H,L),
|
||||
test_filesi(T,GB).
|
||||
|
||||
test_alli(_F,[]).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(s(Q,_P),close_to('P',P)),!,
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
sir(Q,PL,PU,_Time),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
P>=PL-1e-7,P=<PU+1e-7,
|
||||
test_alli(F,T).
|
||||
|
||||
test_alli(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(sc(Q,E,_P),close_to('P',P)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
scir(Q,E,PL,PU,_Time),!,
|
||||
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
|
||||
P>=PL-1e-10,P=<PU+1e-10,
|
||||
test_alli(F,T).
|
||||
|
||||
|
||||
files([
|
||||
%exapprox,exrange,
|
||||
threesideddice,
|
||||
mendel,
|
||||
coin2,ex,trigger,throws,light]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
test((s([on(3,1)],P),close_to(P,0.0987654320987654)),threesideddice,_).
|
||||
test((s([on(4,1)],P),close_to(P,0.0658436213991769)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((sc([on(4,1)],[on(1,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
|
||||
test((sc([on(5,1)],[on(2,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
|
||||
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
222
packages/cplint/testlpadvel.pl
Normal file
222
packages/cplint/testlpadvel.pl
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for lpadsld.pl, case where the body is grounded
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
%:-use_module(library(lpadvel)).
|
||||
:-use_module(lpadvelor).
|
||||
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
t:-
|
||||
format("~nTesting lpadvel.yap~n~n",[]),
|
||||
t(max_card),!,
|
||||
t(top_sort),!,
|
||||
t(min_def),
|
||||
format("All orders successful~n",[]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
t(Order):-
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
format("~nOrder=~p~n",[Order]),
|
||||
set(order,Order),
|
||||
test_files(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([exapprox,exrange,
|
||||
threesideddice,
|
||||
mendel,coin2,ex,trigger,throws,light]).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
|
||||
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
|
||||
|
||||
|
||||
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
|
||||
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
|
||||
|
||||
|
||||
test((s([female(f)],P),close_to(P,0.6)),female,_).
|
||||
test((s([male(f)],P),close_to(P,0.4)),female,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
|
||||
|
||||
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
|
||||
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
|
||||
|
||||
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
|
||||
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
|
||||
|
||||
|
||||
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
|
||||
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
|
||||
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
|
||||
|
||||
|
||||
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
|
||||
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
|
||||
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
|
||||
|
||||
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
|
||||
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
|
||||
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
|
||||
|
||||
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
|
||||
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
|
||||
|
||||
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
|
||||
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
|
||||
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
|
||||
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
|
||||
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
|
||||
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
|
||||
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
|
||||
|
||||
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
|
||||
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
|
||||
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
|
||||
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
|
||||
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
|
||||
|
||||
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
|
||||
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
|
||||
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
|
||||
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
|
||||
|
||||
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
|
||||
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
|
||||
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
|
||||
|
||||
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
|
||||
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
|
||||
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
|
||||
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
|
||||
|
||||
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
|
||||
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
|
||||
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
|
||||
|
||||
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
|
||||
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
|
||||
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
|
||||
|
||||
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
|
||||
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
|
||||
127
packages/cplint/testsemcpl.pl
Normal file
127
packages/cplint/testsemcpl.pl
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
Test file for semcpl.pl
|
||||
|
||||
Use
|
||||
:-t.
|
||||
to execute the test
|
||||
|
||||
*/
|
||||
|
||||
:-use_module(library(semcpl)).
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting semcpl.yap~n~n",[]),
|
||||
files(F),
|
||||
statistics(runtime,[_,_]),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(F,ground_body(false)),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(F,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
format("~n~a.cpl~n",[H]),
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
|
||||
files([
|
||||
exapprox,exrange,threesideddice,mendels,
|
||||
coin2,ex,throws,trigger,win,hiv,light,
|
||||
invalid]).
|
||||
|
||||
test((s([p],P),close_to(P,0)),invalid,_).
|
||||
test((s([q],P),close_to(P,0)),invalid,_).
|
||||
test((s([p,q],P),close_to(P,0)),invalid,_).
|
||||
|
||||
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
|
||||
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
|
||||
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
|
||||
|
||||
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
|
||||
|
||||
test((s([win(white)],P),close_to(P,0.5)),win,_).
|
||||
test((s([win(black)],P),close_to(P,0.5)),win,_).
|
||||
test((s([win(black),win(white)],P),close_to(P,0)),win,_).
|
||||
|
||||
test((s([hiv(a)],P),close_to(P,0.154)),hiv,_).
|
||||
test((s([hiv(b)],P),close_to(P,0.154)),hiv,_).
|
||||
test((s([hiv(b),hiv(a)],P),close_to(P,0.118)),hiv,_).
|
||||
test((s([\+ hiv(b),\+ hiv(a)],P),close_to(P,0.81)),hiv,_).
|
||||
test((s([ hiv(b),\+ hiv(a)],P),close_to(P,0.036)),hiv,_).
|
||||
test((s([\+ hiv(b),hiv(a)],P),close_to(P,0.036)),hiv,_).
|
||||
|
||||
test((s([push,replace],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light],P),close_to(P,0.5)),light,_).
|
||||
test((s([push,light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light,replace],P),close_to(P,0)),light,_).
|
||||
test((s([light],P),close_to(P,0.5)),light,_).
|
||||
test((s([replace],P),close_to(P,0.5)),light,_).
|
||||
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.5)),mendels,ground_body(false)).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.5)),mendels,ground_body(false)).
|
||||
test((s([cg(s,2,p)],P),close_to(P,1.0)),mendels,ground_body(false)).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0)),mendels,ground_body(false)).
|
||||
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
120
packages/cplint/testsemlpad.pl
Normal file
120
packages/cplint/testsemlpad.pl
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
list of tests for semlpad.pl
|
||||
|
||||
*/
|
||||
:-use_module(library(semlpad)).
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting semlpad.yap~n~n",[]),
|
||||
files_modes(FM),
|
||||
files_variables(FV),
|
||||
statistics(runtime,[_,_]),
|
||||
format("~nGrounding using modes~n~n",[]),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(FM,ground_body(false)),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(FM,ground_body(true)),
|
||||
format("~nGrounding using variables~n~n",[]),
|
||||
set(grounding,variables),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(FV,ground_body(false)),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(FV,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
format("~n~a.cpl~n",[H]),
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
files_modes([
|
||||
exapprox,
|
||||
exrange,
|
||||
threesideddice,
|
||||
%mendels, %ok only with grounding=variables
|
||||
coin2,
|
||||
ex,exist,exist1
|
||||
]).
|
||||
|
||||
files_variables([
|
||||
exapprox,
|
||||
exrange,
|
||||
%threesideddice, removed because of a strange bug in yap, in debug it does not fail
|
||||
mendels,
|
||||
coin2,
|
||||
ex
|
||||
]).
|
||||
|
||||
|
||||
test((s([a],P),close_to(P,0.18)),exist,ground_body(false)).
|
||||
test((s([a],P),close_to(P,0.19)),exist,ground_body(true)).
|
||||
|
||||
test((s([a],P),close_to(P,0.276)),exist1,ground_body(false)).
|
||||
test((s([a],P),close_to(P,0.3115)),exist1,ground_body(true)).
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.5)),mendels,ground_body(false)).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.5)),mendels,ground_body(false)).
|
||||
test((s([cg(s,2,p)],P),close_to(P,1.0)),mendels,ground_body(false)).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0)),mendels,ground_body(false)).
|
||||
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
128
packages/cplint/testsemlpadsld.pl
Normal file
128
packages/cplint/testsemlpadsld.pl
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
LPAD and CP-Logic reasoning suite
|
||||
Copyright (c) 2007, Fabrizio Riguzzi
|
||||
|
||||
list of tests for semlpadsld.pl
|
||||
|
||||
*/
|
||||
:-use_module(library(semlpadsld)).
|
||||
|
||||
epsilon(0.000001).
|
||||
|
||||
close_to(V,T):-
|
||||
epsilon(E),
|
||||
TLow is T-E,
|
||||
THigh is T+E,
|
||||
TLow<V,
|
||||
V<THigh.
|
||||
|
||||
|
||||
t:-
|
||||
format("~nTesting semlpadsld.yap~n~n",[]),
|
||||
files_modes(FM),
|
||||
files_variables(FV),
|
||||
statistics(runtime,[_,_]),
|
||||
format("~nGrounding using modes~n~n",[]),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(FM,ground_body(false)),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(FM,ground_body(true)),
|
||||
format("~nGrounding using variables~n~n",[]),
|
||||
set(grounding,variables),
|
||||
set(ground_body,false),
|
||||
format("~nNon ground body~n~n",[]),
|
||||
test_files(FV,ground_body(false)),
|
||||
set(ground_body,true),
|
||||
format("~nGround body~n~n",[]),
|
||||
test_files(FV,ground_body(true)),
|
||||
statistics(runtime,[_,T]),
|
||||
T1 is T /1000,
|
||||
format("Test successful, time ~f secs.~n",[T1]).
|
||||
|
||||
t:-
|
||||
format("Test unsuccessful.~n",[]).
|
||||
|
||||
test_files([],_GB).
|
||||
|
||||
test_files([H|T],GB):-
|
||||
format("~n~a.cpl~n",[H]),
|
||||
library_directory(LD),
|
||||
atom_concat(LD,'/cplint/examples/',ExDir),
|
||||
atom_concat(ExDir,H,NH),
|
||||
p(NH),!,
|
||||
findall(A,test(A,H,GB),L),
|
||||
test_all(H,L),
|
||||
test_files(T,GB).
|
||||
|
||||
test_all(_F,[]).
|
||||
|
||||
test_all(F,[H|T]):-
|
||||
copy_term(H,NH),
|
||||
NH=(_Query,close_to('P',_Prob)),
|
||||
format("~a ~p.~n",[F,NH]),
|
||||
call(H),!,
|
||||
test_all(F,T).
|
||||
|
||||
files_modes([
|
||||
exapprox,
|
||||
exrange,
|
||||
threesideddice,
|
||||
%mendels,
|
||||
school_simple,
|
||||
coin2,
|
||||
ex]).
|
||||
|
||||
|
||||
files_variables([
|
||||
exapprox,
|
||||
exrange,
|
||||
threesideddice,
|
||||
mendels,
|
||||
%school_simple,
|
||||
coin2,
|
||||
ex]).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
|
||||
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
|
||||
|
||||
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
|
||||
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
|
||||
|
||||
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
|
||||
|
||||
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
|
||||
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
|
||||
|
||||
|
||||
test((s([cg(s,1,p)],P),close_to(P,0.5)),mendels,ground_body(false)).
|
||||
test((s([cg(s,1,w)],P),close_to(P,0.5)),mendels,ground_body(false)).
|
||||
test((s([cg(s,2,p)],P),close_to(P,1.0)),mendels,ground_body(false)).
|
||||
test((s([cg(s,2,w)],P),close_to(P,0)),mendels,ground_body(false)).
|
||||
|
||||
|
||||
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,ground_body(false)).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,ground_body(false)).
|
||||
|
||||
/*test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
|
||||
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).
|
||||
*/
|
||||
|
||||
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
|
||||
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
|
||||
|
||||
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
|
||||
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
|
||||
|
||||
test((s([a],P),close_to(P,0.226)),ex,_).
|
||||
|
||||
Reference in New Issue
Block a user