[ Advanced Control and Suspensions | Reference Manual | Alphabetic Index ]
Succeeds if Number is the number of goals delayed by the variable Var.
- Any term.
- Integer or a variable.
Unifies Number with the number of goals delayed by the variable Var. If
Var is instantiated, Number is unified with 1000000. If Var is not
instantiated and there are no goals delayed by it, Number is unified
with 0. This predicate does not construct the list of delayed goals and
hence it is faster than delayed_goals/2. Its purpose is to give each
variable a weight corresponding to the number of constraints imposed on
the variable to be able to select the most constrained one. It is
assumed that one million constraints cannot be placed on any variable.
Modes and Determinism
- delayed_goals_number(?, -) is det
% Make an intelligent permutation choosing
% the most constrained variable.
perm([Var|List], Values) :-
maxval(List, Var, C, Chosen, RestVar),
delete(Chosen, Values, RestVal),
maxval(L, Chosen, 1000000, Chosen, L) :- !.
maxval(, Chosen, _, Chosen, ).
maxval([X|L], SoFar, MaxVal, Chosen, [V|Rest]) :-
(C =< MaxVal -> V = X, Next = SoFar, Max = MaxVal ;
V = SoFar, Next = X, Max = C),
maxval(L, Next, Max, Chosen, Rest).
% the values are generated in the listed order
[eclipse]: perm([A, B, C], [1,2,3]).
A = 1
B = 2
C = 3 More? (;)
% B is more constrained than the others, and so
% its value will be generated first.
[eclipse]: B < 3, perm([A, B, C], [1,2,3]).
A = 2
B = 1
C = 3 More? (;)
X > 0, delayed_goals_number(X, 0).
delayed_goals / 1, delayed_goals / 2, subcall / 2