3 Constraint programming in a nutshell

3.1 Equivalence of CSPs

  1. Q: 解释词语:solved, false constraint.
    A: \(C = D_1\times\cdots\times D_k\)就是(某个)约束\(C\)的solved.(约束和定义域相同了)
    所有约束(不能有\(\perp\))solved时,如果任何\(D_i\)都不是空集,则称CSP is solved.
    注:根据变换后\(D_i\)是否都是单元素集,我们一次solve可能得到单个解或多个解。
    false constriant \(\perp\)表示(可能是某个“分支”或“总体”)无解了。具体的表现形式可能是任何无法成立的“约束”,如\(1=0\).
    注:对于边界情况(0个变量),我们承认两种特殊的约束,即true constraint和false constraint.
  2. Q: projection 和 equivalent w.r.t. \(X\)有何联系?
    A: \(\mathcal P_1\) and \(\mathcal P_2\) are equivalent w.r.t. \(X\) iff
    \(\{d[X]|d \quad\text{is a solution to }\quad \mathcal P_1\}=\{d[X]|d \quad\text{is a solution to }\quad \mathcal P_2\}\)
    \(d[X]\)表示元组\(d\)序列(不是集合)\(X\)上的投影。
    注:这里的“投影”是只要存在一个相应的\(d\),投影集中就出现相应的元素,而多个不同的\(d\)的投影结果也可能相同。这和三维图形投影到二维平面完全可以类比。
    注:把上式右边改成多个集合的(不必无交)并,就是更加广义的“The union of ... is equivalent w.r.t. \(X\) to ...”

3.2 Basic framework for constraint programming

  1. Q: 请将Generic procedure SOLVE改写成不需使用循环的形式。
    A:
SOLVE:
	PREPROCESS
	CONSTRAINT_PROPAGATION
	IF HAPPY OR ATOMIC THEN RETURN // returns the solution relating to HAPPY or ATOMIC
	SPLIT
	PROCEED_BY_CASES // in fact returns the solution by implementing recursion

用类似python的语法可以更加明确表示如下

def solve(csp):
	csp = preprocess(csp)
	csp = constraint_propagation(csp)
	if happy or atomic:
		return trivially_solve(csp)
	else:
		return recursively_solve(split(csp))

甚至可以这样:

def solve(csp):
	# The csp is preprocessed and propagated
	if happy or atomic:
		return trivially_solve(csp)
	else:
		# always preprocesses and propagates the csp after splitting it
		return recursively_solve(split(csp))
  1. Q: HAPPY标准中,"solved form"一般在什么情况下出现?举一例。
    "domains are reduced to sizes smaller than \(\epsilon\)"呢?
    A:
    有无穷多解(且无法简单用有限个笛卡尔积表示解,只能通过某种固定步骤“生成”一系列解。这种固定步骤、模式就是所谓"form")。
    针对定义域为实数的情况。
  2. Q: 为什么要引入非平凡的ATOMIC标准?
    A: 例如:暴力解法具有较小的常数,在问题规模很小的时候,效率高。类比快速排序分到小规模后用插入排序。
  3. Q: split a constraint和split a domain有何异同?
    A: 提示:设
    \(x_0\)在定义域\(D_0\)中”
    “元组满足约束\(C_0\)
    “除\(x_0\)外其余\(x_i\)在各自定义域\(D_i\)中,且元组满足除\(C_0\)外其它约束”
    为命题\(p,q,r\),则
    split a constraint: \(p\wedge q\wedge r\equiv p\wedge (q_1\vee q_2)\wedge r \equiv (p\wedge q_1\wedge r)\vee(p\wedge q_2\wedge r)\).
    split a domain: \(p\wedge q\wedge r\equiv(p_1\vee p_2)\wedge q\wedge r \equiv (p_1\wedge q\wedge r)\vee(p_2\wedge q\wedge r)\).
    其实把定义域限制看成特殊的约束的话,两种split没有本质区别。
  4. Q: 简要举例说明如何通过引入新变量减少split的使用,及这么做的意义。
    A: 对于有限个命题形式的析取,有时可以表达成:某个表达式的值为新的辅助变量\(z\),而\(z\)的定义域是有限集。这有时可以避免组合爆炸。例如\(|x-y|=1\)可以表达为\(x-y=z,z\in\{1,-1\}\).
  5. Q: backtracking和一般意义的深度优先搜索有何联系和区别?树的非叶子节点和叶子节点分别是什么?
    A: backtracking的树是求解中动态生成的,不是预先给定的。
    叶子节点:solved or failed CSPs.
    非叶子节点:CSPs.
    注:这里没有涉及会回溯多层的intelligent backtracking.
  6. Q: 在结合heuristic function的分支限界法中,如何理解“the heuristic function overestimates the objective function.”?
    A: 其字面意思\(h(\psi)\ge obj(\psi)\). 注意优化目标是最大化obj.
    要认识到其目的是帮助剪枝
    \(h\)要求节点的祖先相比节点自身,overestimate更多,也是为了保证剪枝。这样一来,如果看到某个较靠近根的节点的函数值就已经小于目前最优值,也就没必要进一步深入其子节点了,可以直接剪枝!
    注:当heuristic function无法给出任何有用信息时,可以指定其值为\(+\infty\). 可以称为trivial overestimation,无法引起剪枝。

Constraint Propagation

  1. Q: Constraint Propagation和Split有何共同点?
    A: Constraint Propagation中的reduction过程可以看成Split之后立即丢掉不要的部分。
    Constraint Propagation和Split都是“动态”进行的。例如把某个变量的定义域缩小之后,在这么做之后的新问题上考虑,可能又能进一步缩小别的变量的定义域,不断进行多次。
    注:因此上节题0.的伪码中的CONSTRAINT_PROPAGATION实际上内部有“循环”结构。
  2. Q: 如何理解“Sometimes a rather misleading terminology of redundant constraints is used.”?
    A: 首先,从字面来看,由已有的约束推导(derive)出的,隐含(imply)的约束并没有带来任何实质上的进一步限制。去掉它不影响CSP的解。所以字面来看“redundant”这个称呼合理。
    然而,在实际求解中,引入的“多余”的约束可能会帮助计算,甚至直接推导出某变量的唯一取值,或直接推导出failed结果等等,所以是有用的,并不真的是“多余”的。例如\(x<y,y<z,z<x\)推出\(x<z\),进而\(\perp\).
    当然:

It should be stressed here that not all implied constraints are useful.

  1. Q: resolution rule与肯定前件(Modus Ponens)有何关系?
    A: 提示:一般意义的resolution rule为:
    \(\frac{a_1\vee\cdots \vee a_i\vee c,b_1\vee \cdots\vee b_i\vee \sim c}{a_1\vee \cdots \vee a_i\vee b_1\vee\cdots\vee b_i}\).
    这里的","表示两个命题形式都成立(合取)。
    也可以写作\(\frac{(\sim a_1\wedge\cdots\wedge\sim a_i)\to c,c\to(b_1\vee \cdots\vee b_i)}{(\sim a_1\wedge\cdots\wedge\sim a_i)\to(b_1\vee \cdots\vee b_i)}\).
    Modus Ponens可以写作
    \(\frac{p,p\to q}{q}\)也就是\(\frac{\sim p\vee q,p(\vee 0)}{q(\vee0)}\).

This rule is a cornerstone of the automated theorem proving.

  1. Q: 如何理解"local consistency"的"local"一词?以arc consistency为例。
    A:

In constraint satisfaction, local consistency conditions are properties of constraint satisfaction problems related to the consistency of subsets of variables or constraints.

提示:例如\(\langle x<y,y<z,x<z;x\in[0,5],y\in[0,7],z\in[3,8]\rangle\)在考察\((x,y,z)\in [0,5]\times\{0\}\times[3,8]\)时(对于一个变量\(y\)的一个取值\(0\)),对于一条约束\(x<y\)不一致。回忆:arc consistency是“三个一”,即选择一个变量,选择其一个值,选择一条约束。
注:所以说,对每一条约束都local consistent不一定整体consistent.
注:解数独题时不断缩小各个格子中数字的定义域,就常用到arc consistency.

  1. Q: propagate字面有增长,增殖之意,那么constraint propagation是说问题变复杂了吗?
    A: 通过合理的方式增加约束,实际上是让问题变简单(例如缩减定义域等)。

To summarise, each constraint propagation algorithm reduces a given CSP to an equivalent one that satisfies some local consistency notion. Which local consistency notion is reached depends on the type of the CSPs considered and on the form of rules used.

当然,中文将propagate翻译为传播。

3.3 Example: Boolean constraints

  1. Q: 在\(\frac{x\in\{0,1\}}{x\in\{0\}|x\in\{1\}}\)中,如何理解“As already noted there this rule is parametrized by a variable, the choice of which is of relevance here, and by a value, the choice of which is of no relevance here. We use this rule in combination with the heuristic...”?
    A: 选取0还是选取1是对称的,但选取哪个\(x\)可能在实际执行中对效率产生决定性影响。根据经验,我们采用一定的启发式方法,即选择出现在最多约束中的变量。其实这和人类在进行分类讨论时的选择十分一致。
  2. Q: 形式上的表达式\(x\wedge y = z,z=1\to x=1,y=1\)就告诉我们\(\frac{\langle x\wedge y = z;x\in D_x,y\in D_y, z\in\{1\}\rangle}{\langle ;x\in\{1\},y\in \{1\},z\in\{1\}\rangle}\)嘛?
    A: 否,因为\(D_x=\{0\}\)时,上述规则将导致错误结果。(回忆我们传播约束的目的:除了找解,还有可能直接排除一些情况,直接得出一些\(\perp\). 此处的传播在\(D_x=\{0\}\)时就能直接产生inconsistency,排除!)
  3. Q: 作为人类专家,你怎么得到“six rules for the constraint \(x\wedge y=z\)”呢?
    A: 相当于手动搜索出决策树。
    例如:
    如果\(z=1\),则直接\(x=1,y=1\).
    否则讨论,若\(x=1\),则\(y=0\).
    否则讨论,若\(y=1\),则\(x=0\).
    否则,该条约束无价值。
    当然,实际设计“树”时可以利用各类技术,设法减少节点个数,使得树更平衡,等等,以提升性能。

3.4 Example: polynomial constraints on integer intervals

  1. Q: 用一句话概括预处理时,书中两条transformation rule.
    A: 把复杂度高的公式拆成数个复杂度低的公式并对每个子公式换新变量名。
  2. Q: 举例说明“整数区间的四则运算”(interval arithmetic)不一定得到整数区间。
    A: 比如区间乘区间显然得不到质数(233)
    再比如区间除以一个数没问题,但除以一个有\(n\)个整数的区间有可能得到\(n\)部分分立的结果。
  3. Q: 如何理解\(int([-3..5]/[-1..2])=\mathcal Z\)
    A: 首先\(int(\cdot)\)含义类似于“凸包”,即是区间且包含一切可能结果(当然在结果是\(\mathcal Z\)时输出就是\(\mathcal Z\)),其次注意根据interval arithmetic定义,0除以0得到一切数。
  4. Q: 如何理解启发式规则"choose the variable with the smallest interval domain."?
    A: 直观上,尽快分割直至某个变量取值固定为一个值,方便讨论。
  5. Q: 为什么书中定义的heuristic function \(h(\mathcal P):=max(obj^+(D_1,\cdots,D_n))\)是合理的?
    A: 提示:因为\(obj^+\)保持集合的包含关系(书中称为monotonic),则容易验证满足heuristic function定义中涉及overestimate的相关性质。