From 87abcd6a5252ff809d6b598677006786046df754 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Fri, 5 Mar 2021 18:16:38 +0100 Subject: [PATCH 1/3] adapt comment to Scryer Prolog --- src/lib/clpb.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/clpb.pl b/src/lib/clpb.pl index 75a38282..add580ff 100644 --- a/src/lib/clpb.pl +++ b/src/lib/clpb.pl @@ -1517,8 +1517,8 @@ pairs_([], _) --> []. pairs_([B|Bs], A) --> [A-B], pairs_(Bs, A). /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Set the Prolog flag clpb_residuals to bdd to obtain the BDD nodes - as residuals. Note that they cannot be used as regular goals. + Assert clpb:clpb_residuals(bdd) to obtain the BDD nodes as + residuals. Note that they cannot be used as regular goals. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ nodes([]) --> []. From 0fb74b56b378b3518bb1201099c3953ad677a8d2 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Fri, 5 Mar 2021 18:35:19 +0100 Subject: [PATCH 2/3] FIXED: CLP(B): weighted_maximum/3 with repeated variables Many thanks to @jburse for reporting this issue: https://github.com/triska/clpz/issues/15 Example: ?- sat(~(Y*X)), sat(Z=:=Y), weighted_maximum([7,2,5],[X,Y,Z],W). W = 7, Y = 0, X = 1, Z = 0 ; W = 7, Y = 1, X = 0, Z = 1 ; false. --- src/lib/clpb.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/clpb.pl b/src/lib/clpb.pl index add580ff..f41e2100 100644 --- a/src/lib/clpb.pl +++ b/src/lib/clpb.pl @@ -1276,13 +1276,18 @@ weighted_maximum(Ws, Vars, Max) :- maplist(var_with_index, Vars, IVs), pairs_keys_values(Pairs0, IVs, Ws), keysort(Pairs0, Pairs1), - pairs_keys_values(Pairs1, IVs1, WeightsIndexOrder), + % sum linear combinations of repeated variables + group_pairs_by_key(Pairs1, Groups), + maplist(group_sumweights_pair, Groups, Pairs2), + pairs_keys_values(Pairs2, IVs1, WeightsIndexOrder), pairs_values(IVs1, VarsIndexOrder), % Pairs is a list of Var-Weight terms, in index order of Vars pairs_keys_values(Pairs, VarsIndexOrder, WeightsIndexOrder), bdd_maximum(BDD, Pairs, Max), max_labeling(BDD, Pairs). +group_sumweights_pair((I-V)-Ws, (I-V)-W) :- sum_list(Ws, W). + max_labeling(1, Pairs) :- max_upto(Pairs, _, _). max_labeling(node(_,Var,Low,High,Aux), Pairs0) :- max_upto(Pairs0, Var, Pairs), From 842176a595c4fa151f5fe9ec41826dbae52c0390 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Fri, 5 Mar 2021 18:36:00 +0100 Subject: [PATCH 3/3] is is --> is --- src/lib/format.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/format.pl b/src/lib/format.pl index 823c700c..d873f2cc 100644 --- a/src/lib/format.pl +++ b/src/lib/format.pl @@ -153,7 +153,7 @@ element_gluevar(glue(_,V), N, N) --> [V]. available space is distributed. newline is used if ~n occurs in a format string. - It is is used because a newline character does not + It is used because a newline character does not consume whitespace in the sense of format strings. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */