加权 MaxSMT Z3
Weighted MaxSMT Z3
我正在阅读 Z3(Objective 函数)教程并遇到以下示例:
(declare-const a Bool)
(declare-const b Bool)
(declare-const c Bool)
(assert-soft a :weight 1 :id A)
(assert-soft b :weight 2 :id B)
(assert-soft c :weight 3 :id A)
(assert (= a c))
(assert (not (and a b)))
(check-sat)
(get-model)
我不明白 Z3 的输出:
A |-> 0
B |-> 2
sat
(model (define-fun c () Bool true)
(define-fun b () Bool false)
(define-fun a () Bool true) )
我的理解是 Weighted MaxSMT 试图最大化布尔表达式的加权和。因此,我们是否应该得到 A |->4 和 B|->0,因为 a 和 c 都为真而 b 为假。
在 assert-soft
调用中,权重是 "penalty" 如果您选择不满足该目标,您愿意累积的值。因此,在此作业中,Z3 选择 a
和 c
作为 true
,因此满足第一个和第三个 assert-soft
约束,因此不会对它们进行惩罚。这意味着 A |-> 0
,因为该组中的所有软约束都已满足。
当然,要使问题 sat
,选择 a
和 c
成为 true
需要 b
成为 false
,因此您对该失败的约束组产生了 2
的惩罚。
请注意,z3 必须满足所有常规 assert
约束。除此之外,它还尝试尽可能满足 assert-soft
约束中的 "many",从而最大限度地减少对那些不满足的约束的惩罚。
这篇 paper 对 Z3 的优化功能进行了出色的描述。
我正在阅读 Z3(Objective 函数)教程并遇到以下示例:
(declare-const a Bool)
(declare-const b Bool)
(declare-const c Bool)
(assert-soft a :weight 1 :id A)
(assert-soft b :weight 2 :id B)
(assert-soft c :weight 3 :id A)
(assert (= a c))
(assert (not (and a b)))
(check-sat)
(get-model)
我不明白 Z3 的输出:
A |-> 0
B |-> 2
sat
(model (define-fun c () Bool true)
(define-fun b () Bool false)
(define-fun a () Bool true) )
我的理解是 Weighted MaxSMT 试图最大化布尔表达式的加权和。因此,我们是否应该得到 A |->4 和 B|->0,因为 a 和 c 都为真而 b 为假。
在 assert-soft
调用中,权重是 "penalty" 如果您选择不满足该目标,您愿意累积的值。因此,在此作业中,Z3 选择 a
和 c
作为 true
,因此满足第一个和第三个 assert-soft
约束,因此不会对它们进行惩罚。这意味着 A |-> 0
,因为该组中的所有软约束都已满足。
当然,要使问题 sat
,选择 a
和 c
成为 true
需要 b
成为 false
,因此您对该失败的约束组产生了 2
的惩罚。
请注意,z3 必须满足所有常规 assert
约束。除此之外,它还尝试尽可能满足 assert-soft
约束中的 "many",从而最大限度地减少对那些不满足的约束的惩罚。
这篇 paper 对 Z3 的优化功能进行了出色的描述。