Merge branch 'master' of yap.dcc.fc.up.pt:yap-6

This commit is contained in:
Vítor Santos Costa 2010-10-08 12:22:06 +01:00
commit 6811ded37b
27 changed files with 671 additions and 217 deletions

View File

@ -1677,7 +1677,8 @@ Yap_absmi(int inp)
/* ensure_space */
BOp(ensure_space, Osbpi);
{
Int sz = PREG->u.Osbpi.i;
Int sz = PREG->u.Osbpi.i;
UInt arity = PREG->u.Osbpi.p->ArityOfPE;
PREG = NEXTOP(PREG,Osbpi);
if (Unsigned(H) + sz > Unsigned(YREG)-CreepFlag) {
YENV[E_CP] = (CELL) CPREG;
@ -1689,7 +1690,7 @@ Yap_absmi(int inp)
if (ASP > (CELL *)PROTECT_FROZEN_B(B))
ASP = (CELL *)PROTECT_FROZEN_B(B);
saveregs();
if (!Yap_gcl(sz, PREG->u.Osbpi.p->ArityOfPE, YENV, PREG)) {
if (!Yap_gcl(sz, arity, YENV, PREG)) {
Yap_Error(OUT_OF_STACK_ERROR,TermNil,Yap_ErrorMessage);
setregs();
FAIL();

View File

@ -301,7 +301,7 @@ eval1(Int fi, Term t) {
out = asin(dbl);
#if HAVE_ISNAN
if (isnan(out)) {
return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "atanh(%f)", dbl);
return Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "asin(%f)", dbl);
}
#endif
RFLOAT(out);
@ -314,7 +314,7 @@ eval1(Int fi, Term t) {
out = acos(dbl);
#if HAVE_ISNAN
if (isnan(out)) {
return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "atanh(%f)", dbl);
return Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "acos(%f)", dbl);
}
#endif
RFLOAT(out);

View File

@ -111,7 +111,7 @@ p_div2(Term t1, Term t2) {
{
Int i1 = IntegerOfTerm(t1);
Int i2 = IntegerOfTerm(t2);
Int res;
Int res, mod;
if (i2 == 0) goto zero_divisor;
if (i1 == Int_MIN && i2 == -1) {
@ -122,7 +122,10 @@ p_div2(Term t1, Term t2) {
"// /2 with %d and %d", i1, i2);
#endif
}
res = (i1 - i1%i2) / i2;
mod = i1%i2;
if (mod && (mod ^ i2) < 0)
mod += i2;
res = (i1 - mod) / i2;
RINT(res);
}
case (CELL)double_e:

View File

@ -2651,7 +2651,7 @@ Note also that you can use chains of commit operators like:
Note that @code{(->)/2} does not affect the scope of cuts in its
arguments.
@item +@var{Conditon} *-> +@var{Action} ; +@var{Else}
@item +@var{Condition} *-> +@var{Action} ; +@var{Else}
@findex ->*/2
@snindex ->*/2
@cnindex ->*/2
@ -3593,13 +3593,13 @@ the call.
@item digit
@var{Char} is a digit.
@item digit(@var{Weigth})
@item digit(@var{Weight})
@var{Char} is a digit with value
@var{Weigth}. I.e. @code{char_type(X, digit(6))} yields @code{X =
@var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X =
'6'}. Useful for parsing numbers.
@item xdigit(@var{Weigth})
@var{Char} is a hexa-decimal digit with value @var{Weigth}. I.e. char_type(a, xdigit(X) yields X = '10'. Useful for parsing numbers.
@item xdigit(@var{Weight})
@var{Char} is a hexa-decimal digit with value @var{Weight}. I.e. char_type(a, xdigit(X) yields X = '10'. Useful for parsing numbers.
@item graph
@var{Char} produces a visible mark on a page when printed. Note that the space is not included!
@ -3816,7 +3816,7 @@ of length @var{S}.
@node Arithmetic, I/O, Comparing Terms, Top
@section Arithmetic
YAP now supposets several different numeric types:
YAP now supports several different numeric types:
@table @code
@item integers
@ -4712,9 +4712,9 @@ Unify @var{LinePosition} with the position on current text stream
@cnindex stream_position/2
Unify @var{StreamPosition} with the packaged information of position on
current stream @var{Stream}. Use @code{stream_position_data/3} to
retrieve information on charater or line count.
retrieve information on character or line count.
@item stream_position_data(+@var{Field},+@var{StreamPsition},-@var{Info})
@item stream_position_data(+@var{Field},+@var{StreamPosition},-@var{Info})
@findex stream_position_data/3
@syindex stream_position_data/3
@cnindex stream_position_data/3
@ -8036,7 +8036,7 @@ profiling information. Profiling data can be read through the
@item prompt_alternatives_on(atom, changeable)
@findex prompt_alternatives_on (yap_flag/2 option)
SWI-Compatible opttion, determines prompting for alternatives in the Prolog toplevel. Default is @t{groundness}, YAP prompts for alternatives if and only if the query contains variables. The alternative, default in SWI-Prolog is @t{determinism} which implies the system prompts for alternatives if the goal succeeded while leaving choicepoints.
SWI-Compatible option, determines prompting for alternatives in the Prolog toplevel. Default is @t{groundness}, YAP prompts for alternatives if and only if the query contains variables. The alternative, default in SWI-Prolog is @t{determinism} which implies the system prompts for alternatives if the goal succeeded while leaving choicepoints.
@item redefine_warnings
@ -8620,7 +8620,7 @@ The predicates are:
No
@end example
Notice that @var{Goal} is copied repeatetly, which may cause
Notice that @var{Goal} is copied repeatedly, which may cause
problems if attributed variables are involved.
@item [det]free_variables(:Generator, +@var{Template}, +VarList0, -VarList)
@ -9169,7 +9169,7 @@ need not be ordered.
This package provides a set of useful predicates to manipulate
sequences of characters codes, usually first read in as a line. It is
avalailable by loading the library @code{library(lineutils)}.
available by loading the library @code{library(lineutils)}.
@table @code

View File

@ -50,6 +50,7 @@ PROBLOG_PROGRAMS= \
$(srcdir)/problog/variable_elimination.yap \
$(srcdir)/problog/print_learning.yap \
$(srcdir)/problog/utils_learning.yap \
$(srcdir)/problog/version_control.yap \
$(srcdir)/problog/variables.yap
PROBLOG_EXAMPLES = \

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-29 13:03:26 +0200 (Wed, 29 Sep 2010) $
% $Revision: 4843 $
% $Date: 2010-10-06 12:56:13 +0200 (Wed, 06 Oct 2010) $
% $Revision: 4877 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -249,6 +249,7 @@
non_ground_fact/1,
export_facts/1,
problog_help/0,
problog_version/0,
show_inference/0,
problog_dir/1,
set_problog_flag/2,
@ -313,6 +314,7 @@
% problog related modules
:- use_module('problog/variables').
:- use_module('problog/extlists').
:- use_module('problog/gflags', [flag_store/2]).
:- use_module('problog/flags').
:- use_module('problog/print').
:- use_module('problog/os').
@ -504,14 +506,6 @@ init_global_params :-
problog_define_flag(mc_logfile, problog_flag_validate_file, 'logfile for montecarlo', 'log.txt', mcmc, flags:working_file_handler),
check_existance('problogbdd').
check_existance(FileName):-
convert_filename_to_problog_path(FileName, Path),
catch(file_exists(Path), _, fail).
check_existance(FileName):-
problog_path(PD),
write(user_error, 'WARNING: Can not find file: '), write(user_error, FileName),
write(user_error, ', please place file in problog path: '), write(user_error, PD), nl(user_error).
% parameter initialization to be called after returning to user's directory:
:- initialization(init_global_params).
@ -2208,16 +2202,27 @@ problog_max_id(Goal, Prob, Clauses) :-
% version with _save at the end renames files for problogbdd to keep them
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problog_kbest_save(Goal, K, Prob, Status, BDDFile, ParamFile) :-
problog_kbest(Goal, K, Prob, Status),
( Status=ok ->
problog_flag(bdd_file,InternBDDFlag),
problog_flag(bdd_par_file,InternParFlag),
convert_filename_to_working_path(InternBDDFlag, InternBDD),
convert_filename_to_working_path(InternParFlag, InternPar),
rename_file(InternBDD,BDDFile),
rename_file(InternPar,ParamFile)
;
true).
problog_flag(dir, InternWorkingDir),
problog_flag(bdd_file, InternBDDFlag),
problog_flag(bdd_par_file, InternParFlag),
split_path_file(BDDFile, WorkingDir, BDDFileName),
split_path_file(ParamFile, _WorkingDir, ParamFileName),
flag_store(dir, WorkingDir),
flag_store(bdd_file, BDDFileName),
flag_store(bdd_par_file, ParamFileName),
problog_kbest(Goal, K, Prob, Status),
flag_store(dir, InternWorkingDir),
flag_store(bdd_file, InternBDDFlag),
flag_store(bdd_par_file, InternParFlag).
% ( Status=ok ->
% problog_flag(bdd_file,InternBDDFlag),
% problog_flag(bdd_par_file,InternParFlag),
% convert_filename_to_working_path(InternBDDFlag, InternBDD),
% convert_filename_to_working_path(InternParFlag, InternPar),
% rename_file(InternBDD,BDDFile),
% rename_file(InternPar,ParamFile)
% ;
% true).
problog_kbest(Goal, K, Prob, Status) :-
problog_flag(first_threshold,InitT),
@ -2357,23 +2362,34 @@ problog_exact(Goal,Prob,Status) :-
problog_control(off, exact).
problog_exact_save(Goal,Prob,Status,BDDFile,ParamFile) :-
problog_control(on, exact),
problog_flag(dir, InternWorkingDir),
problog_flag(bdd_file, InternBDDFlag),
problog_flag(bdd_par_file, InternParFlag),
split_path_file(BDDFile, WorkingDir, BDDFileName),
split_path_file(ParamFile, _WorkingDir, ParamFileName),
flag_store(dir, WorkingDir),
flag_store(bdd_file, BDDFileName),
flag_store(bdd_par_file, ParamFileName),
problog_control(on, exact),
problog_low(Goal,0,Prob,Status),
problog_control(off, exact),
(
Status==ok
->
(
problog_flag(bdd_file,InternBDDFlag),
problog_flag(bdd_par_file,InternParFlag),
problog_flag(dir,DirFlag),
atomic_concat([DirFlag,InternBDDFlag],InternBDD),
atomic_concat([DirFlag,InternParFlag],InternPar),
rename_file(InternBDD,BDDFile),
rename_file(InternPar,ParamFile)
);
true
).
flag_store(dir, InternWorkingDir),
flag_store(bdd_file, InternBDDFlag),
flag_store(bdd_par_file, InternParFlag).
% (
% Status==ok
% ->
% (
% problog_flag(bdd_file,InternBDDFlag),
% problog_flag(bdd_par_file,InternParFlag),
% problog_flag(dir,DirFlag),
% atomic_concat([DirFlag,InternBDDFlag],InternBDD),
% atomic_concat([DirFlag,InternParFlag],InternPar),
% rename_file(InternBDD,BDDFile),
% rename_file(InternPar,ParamFile)
% );
% true
% ).
problog_collect_trie(Goal):-
problog_call(Goal),
@ -3116,4 +3132,3 @@ user:term_expansion(Term,ExpandedTerm) :-
prolog_load_context(module,Mod),
problog:term_expansion_intern(Term,Mod,ExpandedTerm).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
% $Date: 2010-09-30 13:50:45 +0200 (Thu, 30 Sep 2010) $
% $Revision: 4857 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -217,7 +217,8 @@
logger_write_data/0,
logger_write_header/0,
logger_variable_is_set/1,
logger_add_to_variable/2]).
logger_add_to_variable/2,
logger_reset_all_variables/0]).
:- use_module(library(system),[datime/1,mktime/2]).
:- use_module(library(lists),[append/3,member/2]).
@ -480,9 +481,7 @@ logger_write_data :-
logger_write_data_intern(Variables,Handle),
close(Handle),
% reset variables
findall(_,(member((Name,_),Variables),atom_concat(logger_data_,Name,Key),bb_put(Key,null)),_),
findall(_,(member((Name,time),Variables),atom_concat(logger_start_time_,Name,Key2),bb_put(Key2,null)),_).
logger_reset_all_variables.
logger_write_data_intern([],_).
logger_write_data_intern([(Name,_Type)],Handle) :-
@ -511,6 +510,21 @@ variablevalue_with_nullcheck(Name,Result) :-
%=
%========================================================================
logger_reset_all_variables :-
bb_get(logger_variables,Variables),
% reset variables
findall(_,(member((Name,_),Variables),atom_concat(logger_data_,Name,Key),bb_put(Key,null)),_),
findall(_,(member((Name,time),Variables),atom_concat(logger_start_time_,Name,Key2),bb_put(Key2,null)),_).
%========================================================================
%=
%=
%=
%========================================================================
logger_write_header :-
bb_get(logger_filename,FName),
bb_get(logger_variables,Variables),

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
% $Date: 2010-10-06 12:56:13 +0200 (Wed, 06 Oct 2010) $
% $Revision: 4877 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -208,15 +208,19 @@
% Collected OS depended instructions
%%%%%%%%
:- module(os, [set_problog_path/1,
problog_path/1,
convert_filename_to_working_path/2,
convert_filename_to_problog_path/2,
concat_path_with_filename/3,
calc_md5/2]).
problog_path/1,
convert_filename_to_working_path/2,
convert_filename_to_problog_path/2,
concat_path_with_filename/3,
concat_path_with_filename2/3,
split_path_file/3,
check_existance/1,
calc_md5/2]).
% load library modules
:- use_module(library(system), [exec/3, file_exists/1]).
:- use_module(library(lists), [memberchk/2]).
% load our own modules
:- use_module(gflags, _, [flag_get/2]).
@ -237,20 +241,21 @@ convert_filename_to_problog_path(File_Name, Path):-
concat_path_with_filename(Dir, File_Name, Path).
concat_path_with_filename(Path, File_Name, Result):-
nonvar(File_Name),
nonvar(Path),
nonvar(File_Name),
nonvar(Path),
% make sure, that there is no path delimiter at the end
prolog_file_name(Path,Path_Absolute),
% make sure, that there is no path delimiter at the end
prolog_file_name(Path,Path_Absolute),
(
yap_flag(windows, true)
->
Path_Seperator = '\\';
Path_Seperator = '/'
),
path_seperator(Path_Seperator),
atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result).
atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result).
concat_path_with_filename2(Path, File_Name, Result):-
nonvar(File_Name),
nonvar(Path),
path_seperator(Path_Seperator),
(atomic_concat(Path_Absolute, Path_Seperator, Path) ; Path_Absolute = Path),
atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result).
%========================================================================
%= Calculate the MD5 checksum of +Filename by calling md5sum
@ -306,3 +311,25 @@ calc_md5_intern(Filename,Command,MD5) :-
bb_delete(calc_md5_temp, FinalList-[]),
bb_delete(calc_md5_temp2,_),
atom_codes(MD5,FinalList).
path_seperator('\\'):-
yap_flag(windows, true), !.
path_seperator('/').
split_path_file(PathFile, Path, File):-
path_seperator(PathSeperator),
atomic_concat(Path, File, PathFile),
name(PathSeperator, [PathSeperatorName]),
name(File, FileName),
\+ memberchk(PathSeperatorName, FileName),
!.
% (Path = '' ; atomic_concat(_, PathSeperator, Path)).
check_existance(FileName):-
convert_filename_to_problog_path(FileName, Path),
catch(file_exists(Path), _, fail).
check_existance(FileName):-
problog_path(PD),
write(user_error, 'WARNING: Can not find file: '), write(user_error, FileName),
write(user_error, ', please place file in problog path: '), write(user_error, PD), nl(user_error).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
% $Date: 2010-10-06 12:56:13 +0200 (Wed, 06 Oct 2010) $
% $Revision: 4877 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -222,14 +222,18 @@
show_inference/0,
problog_flags/0,
problog_flags/1,
problog_help/0]).
problog_help/0,
problog_version/0]).
% load library modules
:- use_module(library(lists), [member/2]).
:- use_module(library(system), [directory_files/2]).
% load our own modules
:- use_module(flags).
:- use_module(variables).
:- use_module(os, [check_existance/1, convert_filename_to_problog_path/2, concat_path_with_filename2/3]).
:- use_module(version_control, [get_version/3]).
% size, line_char, line_char_bold
@ -299,7 +303,7 @@ problog_help :-
format('~2nProbLog inference currently offers the following inference methods:~n',[]),
show_inference,
problog:problog_path(PD),
format('~nProblog directory: ~q~n',[PD]),
format('~nProbLog directory: ~q~n',[PD]),
format('~nThe following global parameters are available:~n',[]),
problog_flags,
print_sep_line,
@ -310,6 +314,35 @@ problog_help :-
nl,
flush_output.
problog_version :-
MainProblogFiles = ['problog.yap', 'problog_learning.yap', 'dtproblog.yap'],
nl,
print_group_line_bold('Version Information'),
print_version(MainProblogFiles, ''),
print_sep_line,
convert_filename_to_problog_path('problog', ProblogPath),
directory_files(ProblogPath, ProblogFiles),
sort(ProblogFiles, ProblogFilesS),
print_version(ProblogFilesS, 'problog'),
print_sep_line_bold.
print_version([], _Path).
print_version([H|T], Path):-
atom_concat(_, '.yap', H), !,
(Path == '' ->
FileName = H
;
concat_path_with_filename2(Path, H, FileName)
),
check_existance(FileName),
convert_filename_to_problog_path(FileName, FilePath),
get_version(FilePath, Version, Revision),
format('~w~35+ Last Modified at:~w~65+Revision:~w~n', [FileName, Version, Revision]),
print_version(T, Path).
print_version([_H|T], Path):-
print_version(T, Path).
show_inference :-
format('~n',[]),
print_sep_line,

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-28 21:04:43 +0200 (Tue, 28 Sep 2010) $
% $Revision: 4838 $
% $Date: 2010-10-06 12:56:13 +0200 (Wed, 06 Oct 2010) $
% $Revision: 4877 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -328,8 +328,9 @@ problog_table(Name/Arity, Module) :-
atom_concat(['problog_', Name, '_tabled'], ExactName),
% Monte carlo tabling
table(Module:MCName/Arity),
assertz(problog_tabled(Module:Name/Arity)),
catch((table(Module:MCName/Arity),
assertz(problog_tabled(Module:Name/Arity))), _,
(format(user_error, 'Warning: Tabling was not enabled over compilation, montecarlo tabling is disabled!~nPredicate: ~q~n', [Module:MCName/Arity]))),
findall(_,(
OriginalPred =.. [OriginalName|Args],

View File

@ -0,0 +1,241 @@
%%% -*- Mode: Prolog; -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-10-05 18:15:57 +0200 (Tue, 05 Oct 2010) $
% $Revision: 4876 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
%
% ProbLog was developed at Katholieke Universiteit Leuven
%
% Copyright 2008, 2009, 2010
% Katholieke Universiteit Leuven
%
% Main authors of this file:
% Theofrastos Mantadelis
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Figuring out the version of a problog file in a nasty way :-D
% This way SVN does the work of keeping the file date
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(version_control, [get_version/3]).
:- use_module(library(lists), [append/3, reverse/2]).
get_version(FilePath, Version, Revision):-
open(FilePath, read, SI),
repeat,
get_line(SI, Line),
(append(_, ['D','a','t','e',':'|Date], Line) ; at_end_of_stream(SI)),
!,
repeat,
get_line(SI, NLine),
(append(_, ['R','e','v','i','s','i','o','n',':'|Revision1], NLine) ; at_end_of_stream(SI)),
!,
close(SI),
append(ReadDate,['$'|_],Date),
append(Revision2,['$'|_],Revision1),
atomic_concat(ReadDate, Version),
atomic_concat(Revision2, Revision).
get_line(Stream, Line):-
get_line(Stream, LineR, []),
reverse(LineR, Line).
get_line(Stream, Line, Acc):-
get_char(Stream, Char),
((Char = '\n' ; at_end_of_stream(Stream)) ->
Line = Acc
;
get_line(Stream, Line, [Char|Acc])
).

View File

@ -3,6 +3,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing a probabilistic graph
% (running example from ProbLog presentations)
% $Id: graph.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog').

View File

@ -3,6 +3,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing a probabilistic graph using tabling
% (running example from ProbLog presentations)
% $Id: graph_tabled.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog').

View File

@ -3,13 +3,15 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing a probabilistic graph
% (running example from ProbLog presentations)
%
% $Id: learn_graph.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% example for parameter learning with LeProbLog
%
% training and test examples are included at the end of the file
%
% query ?- do_learning(20).
% will run 20 iterations of learning with default settings
% query ?- do_learning(20).
% will run 20 iterations of learning with default settings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog').
@ -23,10 +25,10 @@ path(X,Y) :- path(X,Y,[X],_).
path(X,X,A,A).
path(X,Y,A,R) :-
X\==Y,
edge(X,Z),
absent(Z,A),
path(Z,Y,[Z|A],R).
X\==Y,
edge(X,Z),
absent(Z,A),
path(Z,Y,[Z|A],R).
% using directed edges in both directions
edge(X,Y) :- dir_edge(Y,X).

View File

@ -2,12 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing an office window
%
% example for using hybrid ProbLog
%
% query ?- problog_exact(room_has_window, Prob, Status).
% Prob = 0.008527075,
% Status = ok ?
% $Id: office.pl 4876 2010-10-05 16:15:57Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog').
@ -25,3 +21,8 @@ room_has_window:-
room_has_window:-
in_corridor,corridor_has_window.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% query ?- problog_exact(room_has_window, Prob, Status).
% Prob = 0.01517076,
% Status = ok ?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -1,5 +1,11 @@
%%% -*- Mode: Prolog; -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing a viral marketing problem
% example for using decision theory ProbLog
% $Id: viralmarketing.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The viral marketing example consists of a social network of friend relations. You have to decide which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product.
:- use_module('../dtproblog').

View File

@ -1,5 +1,11 @@
%%% -*- Mode: Prolog; -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing a viral marketing problem
% example for using tabled decision theory ProbLog
% $Id: viralmarketing_tabled.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The viral marketing example consists of a social network of friend relations. You have to decido which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product.
:- use_module('../dtproblog').

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-09-29 18:43:14 +0200 (Wed, 29 Sep 2010) $
% $Revision: 4854 $
% $Date: 2010-10-05 16:52:13 +0200 (Tue, 05 Oct 2010) $
% $Revision: 4869 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
@ -206,7 +206,8 @@
:- module(learning,[do_learning/1,
do_learning/2
do_learning/2,
reset_learning/0
]).
% switch on all the checks to reduce bug searching time
@ -233,6 +234,9 @@
:- dynamic(query_probability_intern/2).
:- dynamic(query_gradient_intern/4).
:- dynamic(last_mse/1).
:- dynamic(query_is_similar/2).
:- dynamic(query_md5/2).
% used to identify queries which have identical proofs
:- dynamic(query_is_similar/2).
@ -360,7 +364,7 @@ check_examples :-
(current_predicate(user:example/4),user:example(ID,_,P,_), (\+ number(P); P>1 ; P<0))
->
(
format(user_error,'The training example ~q does not have a valid probaility value (~q).~n',[ID,P]),
format(user_error,'The training example ~q does not have a valid probability value (~q).~n',[ID,P]),
throw(error(examples))
); true
),
@ -369,7 +373,7 @@ check_examples :-
(current_predicate(user:test_example/4),user:test_example(ID,_,P,_), (\+ number(P); P>1 ; P<0))
->
(
format(user_error,'The test example ~q does not have a valid probaility value (~q).~n',[ID,P]),
format(user_error,'The test example ~q does not have a valid probability value (~q).~n',[ID,P]),
throw(error(examples))
); true
),
@ -409,6 +413,27 @@ check_examples :-
throw(error(examples))
); true
).
%========================================================================
%=
%========================================================================
reset_learning :-
retractall(current_iteration(_)),
retractall(learning_initialized),
retractall(values_correct),
retractall(current_iteration(_)),
retractall(example_count(_)),
retractall(query_probability_intern(_,_)),
retractall(query_gradient_intern(_,_,_)),
retractall(last_mse(_)),
retractall(query_is_similar(_,_)),
retractall(query_md5(_,_,_)),
set_problog_flag(alpha,auto),
set_problog_flag(learning_rate,examples),
logger_reset_all_variables.
%========================================================================
@ -763,9 +788,7 @@ update_values :-
( % go over all continuous facts
get_continuous_fact_parameters(ID,gaussian(Mu,Sigma)),
%SigmaL is log(Sigma),
SigmaL=Sigma,
format(Handle,'@x~q_*~n0~n0~n~10f;~10f~n',[ID,Mu,SigmaL]),
format(Handle,'@x~q_*~n0~n0~n~10f;~10f~n',[ID,Mu,Sigma]),
fail; % go to next continuous fact
true

View File

@ -7,6 +7,8 @@
* *
* Author: Theofrastos Mantadelis *
* File: general.c *
* $Date:: 2010-10-06 13:20:59 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4880 $ *
* *
********************************************************************************
* *
@ -189,6 +191,25 @@
/* Number Handling */
int getRealNumber(char *c, double *number) {
char *unparsed_string;
errno = 0;
*number = strtod(c, &unparsed_string);
return !(errno == ERANGE || unparsed_string == c || *unparsed_string != '\0');
}
int getIntNumber(char *c, int *number) {
char *unparsed_string;
errno = 0;
long int numberl = strtol(c, &unparsed_string, 10);
*number = (int) numberl;
return !(errno == ERANGE || unparsed_string == c || *unparsed_string != '\0' || numberl > INT_MAX || numberl < INT_MIN);
}
inline int getPosNumber(char *c, int *number) {
return (getIntNumber(c, number) && *number >= 0);
}
int IsRealNumber(char *c) {
int i, l;
l = strlen(c);

View File

@ -7,6 +7,8 @@
* *
* Author: Theofrastos Mantadelis *
* File: general.h *
* $Date:: 2010-10-06 13:20:59 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4880 $ *
* *
********************************************************************************
* *
@ -188,12 +190,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#define IsNumberDigit(c) ('0' <= c && c <= '9')
#define IsSignDigit(c) (c == '+' || c == '-')
#define isOperator(x) (x == '+' || x == '*' || x == '#' || x == '=')
#define freadline(fd) freadstr(fd, "\n");
int getRealNumber(char *c, double *number);
int getIntNumber(char *c, int *number);
inline int getPosNumber(char *c, int *number);
int IsRealNumber(char *c);
int IsPosNumber(const char *c);
int IsNumber(const char *c);

View File

@ -6,7 +6,9 @@
* Copyright Katholieke Universiteit Leuven 2008, 2009, 2010 *
* *
* Author: Theofrastos Mantadelis, Angelika Kimmig, Bernd Gutmann *
* File: ProblogBDD.c *
* File: problogbdd.c *
* $Date:: 2010-10-06 18:06:08 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4883 $ *
* *
********************************************************************************
* *
@ -345,6 +347,7 @@ int main(int argc, char **arg) {
MyManager.f = LOW(MyManager.manager);
MyManager.varmap = InitNamedVars(1, 0);
bdd = OnlineGenerateBDD(MyManager.manager, &MyManager.varmap);
bakbdd = bdd;
ivarcnt = GetVarCount(MyManager.manager);
} else if(params.independent_forest>0){
// the flag to create a forest of independent bdds is set
@ -1451,8 +1454,7 @@ int LoadVariableDataForForest(namedvars varmap, char *filename) {
if (hasvar >= 0) {
switch(idat) {
case 0:
if (IsRealNumber(dataread)) dvalue = atof(dataread);
else {
if (!getRealNumber(dataread, &dvalue)) {
fprintf(stderr, "Error at file: %s. Variable: %s can't have non real value: %s.\n", filename, varname, dataread);
fclose(data);
free(varname);
@ -1462,8 +1464,7 @@ int LoadVariableDataForForest(namedvars varmap, char *filename) {
idat++;
break;
case 1:
if (IsNumber(dataread)) ivalue = atoi(dataread);
else {
if (!getIntNumber(dataread, &ivalue)) {
fprintf(stderr, "Error at file: %s. Variable: %s can't have non integer value: %s.\n", filename, varname, dataread);
fclose(data);
free(varname);
@ -1675,9 +1676,8 @@ parameters loadparam(int argc, char **arg) {
}
break;
case 10:
if ((argc > i + 1) && (IsRealNumber(arg[i + 1]))) {
if ((argc > i + 1) && (getRealNumber(arg[i + 1], & params.sigmoid_slope))) {
i++;
params.sigmoid_slope = atof(arg[i]);
} else {
params.error[params.errorcnt] = i;
params.errorcnt++;

View File

@ -5,11 +5,10 @@
* *
* Copyright Katholieke Universiteit Leuven 2008, 2009, 2010 *
* *
* Author: Bernd Gutmann *
* File: problogmath.c *
* $Date:: 2010-08-25 15:23:30 +0200 (Wed, 25 Aug 2010) $ *
* $Revision:: 4683 $ *
* *
* Author: Bernd Gutmann *
* File: problogmath.c *
* $Date:: 2010-10-06 13:20:59 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4880 $ *
* *
********************************************************************************
* *
@ -266,6 +265,7 @@ double cumulative_normal_upper_dsigma(double high,double mu,double sigma) {
// it is used to parse in the parameters of continues variables from the input file
density_integral parse_density_integral_string(char *input, char *variablename) {
density_integral result;
double sigma;
int i;
char garbage[64], s1[64],s2[64],s3[64],s4[64];
@ -275,21 +275,18 @@ density_integral parse_density_integral_string(char *input, char *variablename)
exit(EXIT_FAILURE);
}
if (IsRealNumber(s1)) {
result.mu=atof(s1);
} else {
if (!getRealNumber(s1, &result.mu)) {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s1);
exit(EXIT_FAILURE);
}
if (IsRealNumber(s2)) {
result.log_sigma=atof(s2);
} else {
if (!getRealNumber(s2, &sigma) || sigma<=0.0) {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s2);
exit(EXIT_FAILURE);
}
result.log_sigma=log(sigma);
/* if (result.sigma<=0) { */
/* fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string",input); */
@ -322,17 +319,13 @@ density_integral parse_density_integral_string(char *input, char *variablename)
}
}
if (IsRealNumber(s3)) {
result.low=atof(s3);
} else {
if (!getRealNumber(s3, &result.low)) {
fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s1);
exit(EXIT_FAILURE);
}
if (IsRealNumber(s4)) {
result.high=atof(s4);
} else {
if (!getRealNumber(s4, &result.high)) {
fprintf(stderr, "Error ar parsing the string %s in the function parse_density_integral_string\n",input);
fprintf(stderr, "%s is not a number\n",s1);
exit(EXIT_FAILURE);
@ -349,6 +342,6 @@ density_integral parse_density_integral_string(char *input, char *variablename)
exit(EXIT_FAILURE);
}
return result;
}

View File

@ -7,9 +7,8 @@
* *
* Author: Bernd Gutmann *
* File: problogmath.h *
* $Date:: 2010-08-25 15:23:30 +0200 (Wed, 25 Aug 2010) $ *
* $Revision:: 4683 $ *
* *
* $Date:: 2010-10-06 13:20:59 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4880 $ *
* *
********************************************************************************
* *

View File

@ -7,6 +7,8 @@
* *
* Author: Theofrastos Mantadelis *
* File: simplecudd.c *
* $Date:: 2010-10-06 13:20:59 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4880 $ *
* *
********************************************************************************
* *
@ -378,6 +380,10 @@ int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd, char
DdNode *f[1];
int ret;
FILE *fd;
// Reordering until getting the optimal bdd //
/* Cudd_AutodynDisable(manager);
Cudd_ReduceHeap(manager, CUDD_REORDER_SIFT_CONVERGE, 1);*/
// better before making an ADD //
f[0] = Cudd_BddToAdd(manager, bdd);
fd = fopen(filename, "w");
if (fd == NULL) {
@ -690,8 +696,7 @@ int LoadVariableData(namedvars varmap, char *filename) {
if (hasvar >= 0) {
switch(idat) {
case 0:
if (IsRealNumber(dataread)) dvalue = atof(dataread);
else {
if (!getRealNumber(dataread, &dvalue)) {
fprintf(stderr, "Error at file: %s. Variable: %s can't have non real value: %s.\n", filename, varname, dataread);
fclose(data);
free(varname);
@ -701,8 +706,7 @@ int LoadVariableData(namedvars varmap, char *filename) {
idat++;
break;
case 1:
if (IsNumber(dataread)) ivalue = atoi(dataread);
else {
if (!getIntNumber(dataread, &ivalue)) {
fprintf(stderr, "Error at file: %s. Variable: %s can't have non integer value: %s.\n", filename, varname, dataread);
fclose(data);
free(varname);
@ -1706,34 +1710,55 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
inputline[icur] = '\0';
if ((icur > 0) && (inputline[0] == '@') && (inputline[2] == ',' || inputline[2] == '\0')) {
switch(inputline[1]) {
case '?':
printf("Available instructions:\n\t@c : current node\n\t@n,[BFS, DFS] : expand and go to next node\n\t@t,[BFS, DFS] : throw and go to next node\n");
printf("\t@h : high node of current\n\t@l : low node of current\n\t@v,[variable] : variable values\n\t@r restart traverse from parent node\n\t@e terminates\n");
break;
case 'r':
curnode = bdd;
iQsize = 0;
iRoot = 1;
free(Q);
Q = (DdNode **) malloc(sizeof(DdNode *) * iQsize);
Q2 = NULL;
ReInitHistory(his, varmap.varcnt);
break;
case 'c':
if (iRoot) {
iRoot = 0;
printf("bdd_temp_value('%s', %i).\n", GetNodeVarNameDisp(manager, varmap, curnode), 1);
printf("bdd_temp_value('%s', %i, %p).\n", GetNodeVarNameDisp(manager, varmap, curnode), 1, (void *) curnode);
} else {
printf("bdd_temp_value('%s', %i).\n", GetNodeVarNameDisp(manager, varmap, curnode), iQsize);
printf("bdd_temp_value('%s', %i, %p).\n", GetNodeVarNameDisp(manager, varmap, curnode), iQsize, (void *) curnode);
}
fflush(stdout);
break;
case 'n':
if (curnode != HIGH(manager) && curnode != LOW(manager) && (hnode = GetNode(his, varmap.varstart, curnode)) == NULL) {
//AddNode(his, varmap.varstart, curnode, 0.0, 0, NULL);
l_node = LowNodeOf(manager, curnode);
h_node = HighNodeOf(manager, curnode);
inQ = 0;
iQsize += 2;
Q = (DdNode **) realloc(Q, sizeof(DdNode *) * iQsize);
Q[iQsize - 2] = l_node;
Q[iQsize - 1] = h_node;
//AddNode(his, varmap.varstart, curnode, 0.0, 0, NULL);
/* inQ = 0;
for(i = 0; (i < iQsize / 2) && (inQ < 3); i++)
inQ = (Q[i] == l_node) || (Q[iQsize - i] == l_node) + 2 * (Q[i] == h_node) || (Q[iQsize - i] == h_node);
if ((inQ & 1) == 0) inQ = inQ + (GetNode(his, varmap.varstart, l_node) != NULL);
if ((inQ & 2) == 0) inQ = inQ + 2 * (GetNode(his, varmap.varstart, h_node) != NULL);
if ((inQ & 1) == 1) inQ = inQ - (l_node == HIGH(manager) || l_node == LOW(manager));
if ((inQ & 2) == 2) inQ = inQ - 2 * (h_node == HIGH(manager) || h_node == LOW(manager));
inQ = 0;
inQ = (Q[i] == l_node) || (Q[iQsize - i - 1] == l_node) + 2 * (Q[i] == h_node) || (Q[iQsize - i - 1] == h_node);
if ((l_node == HIGH(manager) || l_node == LOW(manager))) {
inQ = (inQ & 2);
} else {
if ((inQ & 1) == 0) inQ = inQ + (GetNode(his, varmap.varstart, l_node) != NULL);
}
if (h_node == HIGH(manager) || h_node == LOW(manager)) {
inQ = (inQ & 1);
} else {
if ((inQ & 2) == 0) inQ = inQ + 2 * (GetNode(his, varmap.varstart, h_node) != NULL);
}*/
/* if ((inQ & 1) == 1) inQ = inQ - (l_node == HIGH(manager) || l_node == LOW(manager));
if ((inQ & 2) == 2) inQ = inQ - 2 * (h_node == HIGH(manager) || h_node == LOW(manager));*/
/* inQ = 0;
switch(inQ) {
case 0:
iQsize += 2;
Q = (DdNode **) realloc(Q, sizeof(DdNode *) * iQsize);
Q[iQsize - 2] = l_node;
Q[iQsize - 1] = h_node;
break;
case 1:
iQsize++;
@ -1749,7 +1774,7 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
break;
default:
break;
}
}*/
}
if (inputline[2] == '\0' || strcmp(inputline + 3, "DFS") == 0) {
if (iQsize > 0) {
@ -1774,6 +1799,30 @@ void onlinetraverse(DdManager *manager, namedvars varmap, hisqueue *HisQueue, Dd
exit(-1);
}
break;
case 't':
if (inputline[2] == '\0' || strcmp(inputline + 3, "DFS") == 0) {
if (iQsize > 0) {
iQsize--;
curnode = Q[iQsize];
Q = (DdNode **) realloc(Q, sizeof(DdNode *) * iQsize);
}
} else if (strcmp(inputline + 3, "BFS") == 0) {
if (iQsize > 0) {
iQsize--;
curnode = Q[0];
Q2 = (DdNode **) malloc(sizeof(DdNode *) * iQsize);
for(i = 0; i < iQsize; i++)
Q2[i] = Q[i + 1];
free(Q);
Q = Q2;
}
} else {
fprintf(stderr, "Error: Could not find method: %s, Correct syntax @n,[DFS, BFS].\n", inputline + 3);
free(Q);
free(inputline);
exit(-1);
}
break;
case 'h':
printf("bdd_temp_value('%s').\n", GetNodeVarNameDisp(manager, varmap, HighNodeOf(manager, curnode)));
fflush(stdout);

View File

@ -7,6 +7,8 @@
* *
* Author: Theofrastos Mantadelis *
* File: simplecudd.h *
* $Date:: 2010-10-06 13:20:59 +0200 (Wed, 06 Oct 2010) $ *
* $Revision:: 4880 $ *
* *
********************************************************************************
* *

View File

@ -938,8 +938,8 @@ yap_flag(dialect,yap).
'$transl_to_arity'(X1,X) :- X1 < 0, !, X = unbounded.
'$transl_to_arity'(X,X).
'$transl_to_rounding_function'(0,down).
'$transl_to_rounding_function'(1,toward_zero).
'$transl_to_rounding_function'(0,toward_zero).
'$transl_to_rounding_function'(1,down).
'$transl_to_trl_types'(0,chars).
'$transl_to_trl_types'(1,codes).

View File

@ -19,34 +19,37 @@
'$check_op'(P,T,V,op(P,T,V)),
'$op'(P, T, V).
'$check_op'(P,T,V,G) :-
(
var(P) ->
'$do_error'(instantiation_error,G)
;
var(T) ->
'$do_error'(instantiation_error,G)
;
var(V) ->
'$do_error'(instantiation_error,G)
;
\+ integer(P) ->
'$do_error'(type_error(integer,P),G)
;
\+ atom(T) ->
'$do_error'(type_error(atom,T),G)
;
P < 0 ->
'$do_error'(domain_error(operator_priority,P),G)
;
P > 1200 ->
'$do_error'(domain_error(operator_priority,P),G)
;
\+ '$associativity'(T) ->
'$do_error'(domain_error(operator_specifier,T),G)
;
'$check_op_name'(V,G)
).
% just check the operator declarations for correctness.
'$check_op'(P,T,Op,G) :-
( var(P) ; var(T); var(Op)), !,
'$do_error'(instantiation_error,G).
'$check_op'(P,_,_,G) :-
\+ integer(P), !,
'$do_error'(type_error(integer,P),G).
'$check_op'(P,_,_,G) :-
P < 0, !,
'$do_error'(domain_error(operator_priority,P),G).
'$check_op'(P,_,_,G) :-
P > 1200, !,
'$do_error'(domain_error(operator_priority,P),G).
'$check_op'(_,T,_,G) :-
\+ atom(T), !,
'$do_error'(type_error(atom,P),G).
'$check_op'(_,T,_,G) :-
\+ '$associativity'(T), !,
'$do_error'(domain_error(operator_specifier,T),G).
'$check_op'(P,T,V,G) :-
'$check_module_for_op'(V, G, NV),
'$check_top_op'(P, T, NV, G).
'$check_top_op'(_, _, [], _).
'$check_top_op'(P, T, Op.NV, G) :- !,
'$check_ops'(P, T, Op.NV, G).
'$check_top_op'(P, T, V, G) :-
atom(V), !,
'$check_op_name'(P, T, V, G).
'$check_top_op'(P, T, V, G) :-
'$do_error'(type_error(atom,V),G).
'$associativity'(xfx).
'$associativity'(xfy).
@ -57,17 +60,43 @@
'$associativity'(fx).
'$associativity'(fy).
'$check_op_name'(V,G) :-
'$check_module_for_op'(MOp, G, _) :-
var(MOp), !,
'$do_error'(instantiation_error,G).
'$check_module_for_op'(M:V, G, _) :-
var(M), !,
'$do_error'(instantiation_error,G).
'$check_module_for_op'(M:V, G, NV) :-
atom(M), !,
'$check_module_for_op'(V, G, NV).
'$check_module_for_op'(M:V, G, _) :- !,
'$do_error'(type_error(atom,P),G).
'$check_module_for_op'(V, G, V).
'$check_ops'(P, T, [], G) :- !.
'$check_ops'(P, T, Op.NV, G) :- !,
(
var(NV)
->
'$do_error'(instantiation_error,G)
;
'$check_module_for_op'(Op, G, NOp),
'$check_op_name'(P, T, NOp, G),
'$check_ops'(P, T, NV, G)
).
'$check_ops'(P, T, Ops, G) :-
'$do_error'(type_error(list,Ops),G).
'$check_op_name'(_,_,V,G) :-
var(V), !,
'$do_error'(instantiation_error,G).
'$check_op_name'(',',G) :- !,
'$check_op_name'(_,_,',',G) :- !,
'$do_error'(permission_error(modify,operator,','),G).
'$check_op_name'('[]',G) :- !,
'$do_error'(permission_error(create,operator,'[]'),G).
'$check_op_name'('{}',G) :- !,
'$check_op_name'(_,_,'[]',G) :- !,
'$do_error'(permispsion_error(create,operator,'[]'),G).
'$check_op_name'(_,_,'{}',G) :- !,
'$do_error'(permission_error(create,operator,'{}'),G).
'$check_op_name'('|',G) :- !,
G = op(P, T, _),
'$check_op_name'(P,T,'|',G) :- !,
(
integer(P),
P < 1001
@ -75,35 +104,13 @@
Fix \== xfx, Fix \== xfy, Fix \== yfx, Fix \== yfy
),
'$do_error'(permission_error(create,operator,'|'),G).
'$check_op_name'(V,_) :-
'$check_op_name'(_,_,V,_) :-
atom(V), !.
'$check_op_name'(M:A, G) :-
(
var(M) ->
'$do_error'(instantiation_error,G)
;
var(A) ->
'$do_error'(instantiation_error,G)
;
atom(M) ->
'$check_op_name'(A, G)
;
'$do_error'(instantiation_error,G)
).
'$check_op_name'([A|As], G) :-
'$check_op_name'(A, G),
'$check_op_names'(As, G).
'$check_op_name'(_,_,A,G) :-
'$do_error'(type_error(atom,A),G).
'$check_op_names'([], _).
'$check_op_names'([A|As], G) :-
'$check_op_name'(A, G),
'$check_op_names'(As, G).
'$op'(P, T, M:[A|As]) :- !,
'$current_module'(M),
'$opl'(P, T, M, [A|As]).
'$op'(P, T, [A|As]) :- !,
'$op'(P, T, ML) :-
strip_module(ML, M, [A|As]), !,
'$opl'(P, T, M, [A|As]).
'$op'(P, T, A) :-
'$op2'(P,T,A).