Skip to content

Commit

Permalink
introduce and use weighted_maybe/2
Browse files Browse the repository at this point in the history
This is until library(random) provides this functionality,
and a good name is found for it. See mthom#2670.
  • Loading branch information
triska committed Dec 8, 2024
1 parent dba9c9a commit f28aec5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/clpb.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1550,11 +1550,15 @@
{ node_var_low_high(Node, Var, Low, High),
bdd_count(Node, VNum, Total),
bdd_count(Low, VNum, LCount) },
( { maybe(LCount, Total) } ->
( { weighted_maybe(LCount, Total) } ->
[Var=0], random_bindings(VNum, Low)
; [Var=1], random_bindings(VNum, High)
).

weighted_maybe(K, N) :-
random_integer(0, N, X),
X < K.

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Find solutions with maximum weight.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
Expand Down

0 comments on commit f28aec5

Please sign in to comment.