如何在 Mozart/Oz 中创建非数字约束?

发布于 2024-10-20 12:40:44 字数 77 浏览 6 评论 0原文

我想实现一个变量域为非数字的 CSP(类似于 [lisa ann mary joanna] )。在《莫扎特/奥兹国》中有没有办法实现这一点?

I want to implement a CSP with the variables' domain being non-numeric (something like [lisa ann mary joanna] ). Is there a way to achieve this in Mozart/Oz?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2024-10-27 12:40:44

在 C++ 中实现语言扩展之类的东西也许是可能的,但在语言本身内,这是不可能的。

唯一内置的约束类型是有限域约束(非负整数)、有限集约束(非负整数集合域上的约束)和记录约束。

也许您可以使用整数常量来模拟您的问题,例如,

declare
  %% 4 constants
  Lisa = 1
  Ann = 2
  Mary = 3
  Joanna = 4

  %% N will be the constrained variable
  N
in
  N::[Lisa Ann Mary Joanna]
  {Show N}   %% displays N{1#4}, i.e. N is between 1 and 4

  N \=: Mary %% tell: N is not Mary
  {Show N}   %% displays N{1 2 4}, i.e. N is one of 1,2,4

如果您不想使用有限域,则可以使用更一般的逻辑编程思想。您可以为变量的不同可能值创建选择点,例如:

declare

  proc {Script A}
     A =
     choice
        lisa
     [] ann
     [] mary
     [] joanna
     end
  end

  {Show {SearchOne Script}}  %% displays "[lisa]"
  {Show {SearchAll Script}}  %% displays "[lisa ann mary joanna]"

也可以使用非静态已知数量的值来执行此操作 组合器

It might be possible to implement such a thing as a language extension in C++, but within the language itself, it is not possible.

The only built-in types of constraints are finite domain constraints (non-negative integers), finite set constraints (constraints on the domain of sets of non-negative ints) and record constraints.

Maybe you can use integer constants to model your problem, e.g.

declare
  %% 4 constants
  Lisa = 1
  Ann = 2
  Mary = 3
  Joanna = 4

  %% N will be the constrained variable
  N
in
  N::[Lisa Ann Mary Joanna]
  {Show N}   %% displays N{1#4}, i.e. N is between 1 and 4

  N \=: Mary %% tell: N is not Mary
  {Show N}   %% displays N{1 2 4}, i.e. N is one of 1,2,4

If you don't want to work with finite domains, there is the more general idea of logic programming. You can create choice points for different possible values of a variable, e.g.:

declare

  proc {Script A}
     A =
     choice
        lisa
     [] ann
     [] mary
     [] joanna
     end
  end

  {Show {SearchOne Script}}  %% displays "[lisa]"
  {Show {SearchAll Script}}  %% displays "[lisa ann mary joanna]"

It is also possible to do that with a not statically known number of values, using Combinators.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文