gpt4 book ai didi

prolog - 如何将域变量添加到 global_cardinality?

转载 作者:行者123 更新时间:2023-12-01 06:15:06 24 4
gpt4 key购买 nike

我正在尝试向我的程序和 manual of SICStus Prolog 添加约束 global_cardinality写成:

global_cardinality(+Xs,+Vals)

global_cardinality(+Xs,+Vals,+Options)

where Xs = [X1,...,Xd] is a list of integers or domain variables, and Vals = [K1-V1,...,Kn-Vn] is a list of pairs where each key Ki is a unique integer and Vi is a domain variable or an integer. True if every element of Xs is equal to some key and for each pair Ki-Vi, exactly Vi elements of Xs are equal to Ki.

现在我可以写:

global_cardinality([A,B,C], [1-2, 2-1]).

表示数字 1 将被使用两次。数字 2 将只使用一次。

但我想说的是,数字1将被使用:一次,两次或三次

根据手册,我需要一个域变量,但正确的语法是什么?

最佳答案

?- X in 1..3, global_cardinality([A,B,C], [1-X, 2-1]).

关于prolog - 如何将域变量添加到 global_cardinality?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16399792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com