How does `random_variable `random_value` work in SWI-Prolog's labeling/2?

南楼画角 提交于 2019-12-13 03:01:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!