kar*_*thi 4 java nlp ontology sat-solvers sat4j
我是一个全新的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 )
)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题,使用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
Run Code Online (Sandbox Code Playgroud)
然后,以下是将问题转换为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)
Run Code Online (Sandbox Code Playgroud)
这是你的示例问题,格式化应该由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
Run Code Online (Sandbox Code Playgroud)
我让你在这个小例子上运行SAT4J,
它会给你解决方案SATISFIABLExor 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.
Run Code Online (Sandbox Code Playgroud)
我希望这个循序渐进的例子能帮助很少的人.
您查看过他们网站上的SAT4J Howto吗?它包含一个指向Postscript 文档的链接,该文档详细介绍了 CNF 格式的语义。该格式似乎支持您在示例中使用的所有运算符(“<->”除外),但这可能是这个特定“非官方”文档中的遗漏。