Commit a46d6f9f by pangchong

fix(utils): 解决DTD约束生成中的自相矛盾问题

- 添加判断跳过出现在后段的元素约束生成
- 防止出现相互冲突的先后顺序约束
- 修复因矛盾约束导致的排列验证失败
- 优化DTD约束逻辑的准确性和健壮性
parent e18a5ac0
......@@ -357,7 +357,10 @@ function buildSequenceConstraints(model: DtdContentModel): Array<[string, string
const after = getLeafNames(m.children[j])
for (const a of before) {
for (const b of after) {
if (a !== b && !constraints.some(([x, y]) => x === a && y === b)) {
// 跳过自相矛盾的约束:若 a 同时出现在 after 段(即 a 可在后段再次出现),
// 说明 a 与 b 之间无严格先后顺序,不应生成约束,否则会导致
// (a→b) 和 (b→a) 同时存在,使任何排列都无法通过验证。
if (a !== b && !after.includes(a) && !constraints.some(([x, y]) => x === a && y === b)) {
constraints.push([a, b])
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment