问题
I've seen it's possible to label cplfd variables using a random method by adding the following options to labeling/2
:
labeling([random_variable(N),random_value(M)],List).
Where M
and N
are supposed to be integers, I think. However I am not able to find any information about those options in SWI-Prolog's documentation page. How can they be used?
回答1:
In the CLP(FD) library there's this:
selection(random_variable(Seed)) :-
must_be(integer, Seed),
set_random(seed(Seed)).
% TODO: random_variable and random_value currently both set the seed,
% so exchanging the options can yield different results.
order(random_value(Seed)) :-
must_be(integer, Seed),
set_random(seed(Seed)).
select_var(random_variable(_), Vars0, Var, Vars) :-
length(Vars0, L),
I is random(L),
nth0(I, Vars0, Var),
delete_eq(Vars0, Var, Vars).
So the options would only set the seed for randomly generated numbers, although it is not clear what's the purpose of having different values for random_value(N) and random_variable(M).
来源:https://stackoverflow.com/questions/21018846/how-does-random-variable-random-value-work-in-swi-prologs-labeling-2