gpt4 book ai didi

java - SAT4J 求解器的输入 CNF

转载 作者:搜寻专家 更新时间:2023-11-01 01:57:54 25 4
gpt4 key购买 nike

我是 sat4j 求解器的新手..

它说应该给一些cnf文件作为输入

是否有任何可能的方法将规则作为输入并确定它是否可满足?

我的规则是这样的:

Problem = ( 

( staff_1 <=> staff_2 ) AND
( doctor_1 <=> physician_2 )

) AND (

( staff_1 AND doctor_1 )

) AND (

NOT( ward_2 AND physician_2 ) AND
NOT( clinic_2 AND physician_2 ) AND
NOT( admission_record_2 AND physician_2 )

) AND (

NOT( hospital_2 AND physician_2 ) AND
NOT( department_2 AND physician_2 ) AND
NOT( staff_2 AND physician_2 )
)

有人可以帮助我如何使用 sat4j 求解器解决这个问题吗?

最佳答案

如果你想使用SAT4J,你需要转换你的问题CNF格式。

您首先需要将这些文本变量转换为整数。

1 = staff_1
2 = staff_2
3 = doctor_1
4 = physician_2
5 = ward_2
6 = clinic_2
7 = admission_record_2
8 = hospital_2
9 = department_2

然后,将您的问题转换为 CNF 格式需要了解以下规则和语法。

Syntax: 
OR = a space
AND = a newline
NOT = -

Rules from De Morgan's laws:
A <=> B = (A => B) AND (B => A)
A => B = NOT(A) OR B
NOT(A AND B) = NOT(A) OR NOT(B)
NOT(A OR B) = NOT(A) AND NOT(B)

这是您的示例问题,其格式应由 SAT4J 读取。

(请参阅 DIMACS 以了解有关此格式的更多信息)。

 c you can put comment here. 
c Formatted by StackOverFlow.
p cnf 9 12
-1 2 0
-2 1 0
-3 4 0
-4 3 0
1 0
3 0
-5 -4 0
-6 -4 0
-7 -4 0
-8 -4 0
-9 -4 0
-2 -4 0

我让你在这个小例子上运行 SAT4J,

它会给你解决方案SATISFIABLE xor UNSATISFIABLE

使用 SAT4J 必须做的小总结:

 * Transform your `text_n` into a number.
* Use the rule that I gave you to transform your problem into CNF.
* Write the definition of your problem `p cnf nbVariables nbClauses`
* Write everything in a FILE and run SAT4J on this file.

我希望这个循序渐进的示例对少数人有所帮助。

关于java - SAT4J 求解器的输入 CNF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3943646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com