简体   繁体   English

解析时选项类型的实例是什么?

[英]What is an instance of Option Type at parsing time?

About option types , the specification of Minizinc (sec. 6.6.3) says: 关于选项类型 ,Minizinc的规范 (第6.6.3节)说:

Overview. 概述。 Option types defined using the opt type constructor, define types that may or may not be there. 使用opt类型构造函数定义的选项类型定义可能存在或可能不存在的类型。 They are similar to Maybe types of Haskell implicity adding a new value <> to the type. 它们类似于Haskell的Maybe类型,即为该类型隐式添加一个新值<>

[...] [...]

Initialisation. 初始化。 An opt type variable does not need to be initialised at instance-time. opt类型变量不需要在实例时初始化。 An uninitialised opt type variable is automatically initialised to <> . 未初始化的opt类型变量会自动初始化为<>

I would like to parse and process the following constraint with two opt types: 我想使用两种opt类型来解析和处理以下约束

predicate alternative(var opt int: s0, var int: d0,
                      array[int] of var opt int: s,
                      array[int] of var int: d);

However, I am not sure about what should I expect as values for arguments s0 and s when parsing this constraint. 但是,我不确定解析此约束时作为参数s0s值应该期望什么。

Can I simply ignore the presence of the opt modifier and assume the constraint signature to be equal to the following one? 我可以简单地忽略opt修饰符的存在,并假设约束签名等于下一个吗?

predicate alternative(var int: s0, var int: d0,
                      array[int] of var int: s,
                      array[int] of var int: d);

If not, how should I handle it? 如果没有,我应该如何处理?

In MiniZinc variable option types are handled as variables that might not exist. 在MiniZinc中,变量选项类型被视为可能不存在的变量。 Within the compiler these variables are transformed these variables are interpreted and rewritten in such a way that the FlatZinc output only contains actual variables. 在编译器中,将对这些变量进行转换,并以FlatZinc输出仅包含实际变量的方式来解释和重写这些变量。 Usually this means that an boolean variable is added for every variable that is true if-and-only-if the variable "exists". 通常,这意味着为每个变量添加一个布尔变量,如果且仅当变量“存在”时才为true。

For the library writers, there is the option to rewrite it in such a way that your solver will be able to handle best. 对于库编写者,可以选择用一种方式重写它,以使您的求解程序能够最好地处理。 In the standard library alternative is defined as: 在标准库中, alternative定义为:

predicate alternative(var opt int: s0, var int: d0,
                  array[int] of var opt int: s,
                  array[int] of var int: d) =
          assert(index_set(s) = index_set(d),
                 "alternative: index sets of third and fourth argument must be identical",
          sum(i in index_set(s))(bool2int(occurs(s[i]))) <= 1 /\
          span(s0,d0,s,d)
      );

Notice that the occurs intrinsic is used to test if a variable exists. 注意, occurs内在函数用于测试变量是否存在。 More intrinsics for variable types can be found in the MiniZinc library: http://www.minizinc.org/doc-lib/doc-optiontypes.html . 在MiniZinc库中可以找到有关变量类型的更多内在函数: http : //www.minizinc.org/doc-lib/doc-optiontypes.html If necessary, you can also use a let-expression to create extra variable and then map the predicate to an solver intrinsic predicate. 如有必要,您还可以使用let表达式创建额外的变量,然后将该谓词映射到求解器固有谓词。

Even if there is no better decomposition of the optional type predicate for your solver, it can still be worthwhile to implement the predicate without option types. 即使您的求解程序没有更好地分解可选类型谓词,但仍然可以在没有选项类型的情况下实现谓词。 Because of MiniZinc's overloading, that implementation will be used whenever the predicate is called with arrays of non-option variable types. 由于MiniZinc的重载,每当用非选项变量类型的数组调用谓词时,都将使用该实现。 (Note though that the alternative predicate is specifically meant for "optional tasks" and is unlikely to be called that way). (尽管请注意, alternative谓词专门用于“可选任务”,不太可能那样称呼)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将代理分配给具有固定开始时间和结束时间的任务的 CP/MILP 问题名称是什么? - What is the CP/MILP problem name for the assignment of agents to tasks with fixed start time and end time? 您可以在序言中的累积谓词的[limit(x)]选项中使用变量吗? - Can you use a variable in the [limit (x)] option of the cumulative predicate in prolog? 如何在Docplex中实现时间限制 - How to implement time limit in Docplex 带时间窗minizinc示例的车辆路线 - Vehicle routing with time windows minizinc example 不同起点站和终点站时间窗的车辆路径问题 - Vehicle routing problem with time windows at different start and end depot 使用间隔进行调度时如何获取CP中的当前时间 - How to get current time in CP when using Intervals for scheduling OR-Tools 带休息和时间间隔的护士排班问题 - OR-Tools Nurse scheduling problem with breaks and time intervals OR-tools:在累积约束中建立时间相关的能力 - OR-tools: Build time-dependent capacity in cumulative constraint 使用容量和时间 window 约束与提货和交货问题 - Using capacity and time window constraints with pick up and delivery problem 在约束求解中,SMT求解器比CSP求解器有什么优势? - What's the advantage of SMT-solver over CSP-solver in constraint solving?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM