`random_variable `random_value` 如何在 SWI-Prolog 的标签/2 中工作? [英] How does `random_variable `random_value` work in SWI-Prolog's labeling/2?

查看:41
本文介绍了`random_variable `random_value` 如何在 SWI-Prolog 的标签/2 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到可以通过向 labeling/2 添加以下选项来使用随机方法标记 cplfd 变量:

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). 

我认为 MN 应该是整数.但是,我无法在 SWI-Prolog 的文档页面中找到有关这些选项的任何信息.如何使用它们?

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?

推荐答案

在 CLP(FD) 库中有这个:

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).

因此,这些选项只会为随机生成的数字设置种子,尽管尚不清楚为 random_value(N)random_variable(M) 设置不同值的目的是什么强>.

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).

这篇关于`random_variable `random_value` 如何在 SWI-Prolog 的标签/2 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆