【问题标题】:How to create non-numeric constraints in Mozart/Oz?如何在 Mozart/Oz 中创建非数字约束?
【发布时间】:2011-07-07 11:30:42
【问题描述】:

我想实现一个变量域为非数字的 CSP(类似于 [lisa ann mary joanna] )。有没有办法在 Mozart/Oz 中实现这一点?

【问题讨论】:

    标签: constraints constraint-programming oz mozart


    【解决方案1】:

    在 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 对未知数量的值执行此操作。

    【讨论】:

    • 感谢您的回答。内容丰富且乐于助人。我想坚持约束编程范式,以便利用传播器以及能够将一般约束与一阶逻辑规则混合。我想我将使用字典以便在我的 csp 中使用我的常量作为整数值。
    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 2012-04-26
    • 2021-12-04
    • 2015-05-13
    • 2015-05-24
    • 2012-12-28
    • 2019-06-04
    • 2014-05-05
    相关资源
    最近更新 更多