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

时间:2011-03-02 17:47:45

标签: constraints constraint-programming oz mozart

我想实现一个CSP,变量'domain是非数字的(类似于[lisa ann mary joanna])。有没有办法在莫扎特/奥兹实现这一目标?

1 个答案:

答案 0 :(得分:2)

有可能在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]"

使用Combinators可以使用非静态已知数量的值来执行此操作。

相关问题