CN103020714B - Solution method for cognitive description program based on generation-verification - Google Patents
Solution method for cognitive description program based on generation-verification Download PDFInfo
- Publication number
- CN103020714B CN103020714B CN201210529095.7A CN201210529095A CN103020714B CN 103020714 B CN103020714 B CN 103020714B CN 201210529095 A CN201210529095 A CN 201210529095A CN 103020714 B CN103020714 B CN 103020714B
- Authority
- CN
- China
- Prior art keywords
- program
- subjective
- word
- rule
- predicate
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 230000001149 cognitive effect Effects 0.000 title claims abstract description 118
- 238000000034 method Methods 0.000 title claims abstract description 46
- 238000012795 verification Methods 0.000 title claims abstract description 17
- 238000005516 engineering process Methods 0.000 claims abstract description 10
- 238000004458 analytical method Methods 0.000 claims abstract description 5
- 230000001419 dependent effect Effects 0.000 claims description 14
- 238000012804 iterative process Methods 0.000 claims description 9
- 230000001131 transforming effect Effects 0.000 claims 1
- 238000010586 diagram Methods 0.000 abstract description 4
- 230000019771 cognition Effects 0.000 description 5
- 238000012360 testing method Methods 0.000 description 5
- 238000006243 chemical reaction Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000013522 software testing Methods 0.000 description 2
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 230000007812 deficiency Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000003745 diagnosis Methods 0.000 description 1
- 238000007726 management method Methods 0.000 description 1
- 230000008450 motivation Effects 0.000 description 1
- 230000003121 nonmonotonic effect Effects 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000010200 validation analysis Methods 0.000 description 1
Landscapes
- Stored Programmes (AREA)
Abstract
本发明公开了一种基于生成-验证的认知描述程序的求解方法,当输入一个认知描述程序:首先,在词法、语法正确性分析和安全检查基础上,构建认知描述程序的谓词依赖图,据此对程序分块并生成块的拓扑排序,然后,使用正向推理技术,依据拓扑排序,依次实例化程序块,最终生成实例化的认知描述程序。其次,对实例化的认知描述程序求其恒真恒假字集,用于删除冗余规则和冗余字,以简化程序。然后,根据谓词依赖图确定主观字之间的依赖关系,依据主观字之间的依赖关系启发式生成程序的可能解。此后,通过验证主观字取值是否正确,确定这个可能解是否是认知描述程序的解。整个求解方法采用回溯过程生成所有可能解,并验证得到程序所有解。
The invention discloses a method for solving a cognitive description program based on generation-verification. When a cognitive description program is input: firstly, on the basis of lexical and grammatical correctness analysis and security check, the predicate dependency of the cognitive description program is constructed. According to the diagram, the program is divided into blocks and the topological sorting of the blocks is generated. Then, the forward reasoning technology is used to instantiate the program blocks in turn according to the topological sorting, and finally an instantiated cognitive description program is generated. Secondly, the set of constant true and false characters is obtained for the instantiated cognitive description program, which is used to delete redundant rules and redundant words to simplify the program. Then, the dependency relationship between subjective words is determined according to the predicate dependency graph, and possible solutions of the program are heuristically generated according to the dependency relationship between subjective words. Afterwards, by verifying whether the value of the subjective word is correct, it is determined whether this possible solution is the solution of the cognitive description program. The entire solution method uses a backtracking process to generate all possible solutions, and verifies that all solutions of the program are obtained.
Description
技术领域technical field
本发明涉及一种基于生成-验证的认知描述程序的求解方法,该方法基于非单调逻辑推理理论,采用程序谓词依赖图以及启发式搜索技术,包括实例化,程序简化,生成可能解、通过测试确定最终解四个步骤。属于逻辑程序设计、知识表示和推理领域。The invention relates to a method for solving a cognitive description program based on generation-verification. The method is based on non-monotone logic reasoning theory, adopts program predicate dependency graph and heuristic search technology, including instantiation, program simplification, generation of possible solutions, and The test determines the final solution in four steps. In the fields of logic programming, knowledge representation, and reasoning.
背景技术Background technique
回答集程序(answer set program)具有较强的非单调推理能力,并且接近自然语言,因此成为规划、诊断、知识管理、基于知识的问答、约束求解等领域一种重要的知识表示和推理的工具。随着Smodels、DLV、Clasp等高效的回答集程序推理机的出现,回答集程序的应用前景越来越广泛。但是人们发现回答集程序在不完整信息的表示及推理方面存在缺陷,因此Michael Gelfond于1991年提出了一种扩展的回答集程序——认知描述程序(Epistemic Specifications)。认知描述程序作为回答集程序的一种扩展,由一些规则组成,其中规则的形式如下:The answer set program (answer set program) has strong non-monotonic reasoning ability and is close to natural language, so it has become an important tool for knowledge representation and reasoning in the fields of planning, diagnosis, knowledge management, knowledge-based question answering, and constraint solving. . With the emergence of efficient answer set program reasoning machines such as Smodels, DLV, and Clasp, the application prospects of answer set programs are becoming more and more extensive. However, people found that the answer set program has defects in the representation and reasoning of incomplete information, so Michael Gelfond proposed an extended answer set program - Epistemic Specifications in 1991. As an extension of the answer set program, the cognitive description program consists of some rules, where the rules are in the following form:
l1or...or lk←gk+1,...,gm,not lm+1,...,not ln通过添加认知运算符K,能够在信念集不唯一的情况下,直观简洁地表示基于不完全信息的认知推理知识,而这种情况下,采用传统回答集程序无法正确表示和推理,M.Gelfond用下例直观地表达了提出认知描述程序的动机。l 1 or...or l k ←g k+1 ,...,g m ,not l m+1 ,...,not l n By adding cognitive operator K, it can be used in belief sets that are not unique In this case, the cognitive reasoning knowledge based on incomplete information can be expressed intuitively and concisely. In this case, the traditional answer set program cannot be used to correctly represent and reason. motivation.
例:某学校使用下面四条规则去决定学生是否有资格获取奖学金。a)学分高的学生可以获取奖学金、b)学分中等的但是是少数民族的学生可以获取奖学金、c)学分低的学生不可以获取奖学金、d)根据上面三条规则不可以决定是否有资格获取奖学金的同学,学院需要进行面试来确定其是否有资格获取奖学金。如果给定这样一个不完整信息“Mike的学分可能为高也可能为中”。显然,依据上述四条规则,Mike是需要去面试的,因为不能确定Mike一定有资格获取奖学金和一定没有资格获取奖学金。而这个问题使用回答集程序构建一个查询系统来查询Mike是否要去面试,将不能得出正确的结论,但是使用认知描述程序却可以得到正确的结论。Example: A school uses the following four rules to determine a student's eligibility for a scholarship. a) Students with high credits can get scholarships, b) students with medium credits but ethnic minorities can get scholarships, c) students with low credits cannot get scholarships, d) it is not possible to decide whether they are eligible for scholarships according to the above three rules students, the college needs to conduct an interview to determine their eligibility for scholarships. If such an incomplete information is given, "Mike's credits may be high or medium". Obviously, according to the above four rules, Mike needs to go for an interview, because it is not sure whether Mike is eligible for the scholarship or not. For this question, using the answer set program to build a query system to query whether Mike is going to interview will not be able to draw a correct conclusion, but using the cognitive description program can get a correct conclusion.
M.Truszczynski于2010年进一步完善了认知描述程序,他提出了一种认知描述程序的新形式,并且证明了这种新的形式与M.Gelfond于1991年所定义的语法与语义吻合。通过新的形式,M.Truszczynski分析了该语言实现的复杂度以及使用有向图的方法去构建认知描述程序推理机。然而,该语言的语义在某些特殊程序中,存在得到不正确解的缺陷。M.Gelfond于2011年修正了认知描述程序的语义,进一步完善了认知描述程序。语义的定义如下:M. Truszczynski further improved the cognitive description program in 2010. He proposed a new form of cognitive description program and proved that this new form is consistent with the syntax and semantics defined by M.Gelfond in 1991. Through the new form, M. Truszczynski analyzed the complexity of the language implementation and used the directed graph method to build a cognitive description program reasoning machine. However, the semantics of the language has the disadvantage of obtaining incorrect solutions in some special programs. M.Gelfond revised the semantics of the cognitive description program in 2011, and further improved the cognitive description program. The semantics are defined as follows:
假定S为认知描述程序中客观字的集合的集合,根据S约去认知描述程序中的K和-K,使得认知描述程序变为普通的逻辑程序,如果普通逻辑程序的解和S相等,则S为该认知描述程序的解。Assume that S is a set of objective words in the cognitive description program, and K and -K in the cognitive description program are removed according to S, so that the cognitive description program becomes an ordinary logic program. If the solution of the ordinary logic program and S are equal, then S is the solution of the cognition description program.
由于语义的修改,从而更好地符合自然语言,并且确保了认知描述程序的正确性。至此认识描述程序的语义更加完善,为进一步应用于多Agent,软件测试,基于知识的问答系统等领域打下了理论基础。Due to the modification of the semantics, it better conforms to the natural language and ensures the correctness of the cognitive description program. So far, the semantics of cognition and description programs are more complete, which lays a theoretical foundation for further application in multi-agent, software testing, knowledge-based question answering systems and other fields.
此外,鉴于认识逻辑的广泛应用和需求,作为认识逻辑语言子集的认知描述程序被认为将会有效地应用于基于多Agent推理系统,问答系统,软件测试及决策系统等领域。然而,迄今为止,还未出现该程序的推理机,认知描述程序推理机的设计与实现能够使得该语言得到实际应用,认知描述程序求解是复杂度的问题,但是此求解方法效率较低且复杂。In addition, in view of the wide application and demand of cognitive logic, the cognitive description program, which is a subset of cognitive logic language, is considered to be effective in the fields of multi-agent-based reasoning systems, question-answering systems, software testing and decision-making systems. However, so far, no inference engine for this program has appeared. The design and implementation of an inference engine for a cognitive description program can enable the language to be used in practice. The solution to a cognitive description program is a complexity problem, but this solution method is inefficient and complicated.
发明内容Contents of the invention
发明目的:针对现有技术中存在的问题与不足,本发明提供一种基于生成一验证的认知描述程序的求解方法,设计求解方法并提出和采用高效的优化方法是该发明的关键。本发明采用程序谓词依赖图以及启发式生成一验证技术实现认知描述程序的求解,包括实例化,程序简化,生成可能解、通过测试确定最终解四个步骤。通过程序依赖图减少实例化过程中的迭代次数,利用求解恒真恒假字集简化了输入程序,通过启发式搜索方法减少了搜索空间,提高推理机的效率,使得该语言能够应用到实际问题求解中,这在大规模的问题求解中尤为重要。Purpose of the invention: Aiming at the problems and deficiencies in the prior art, the present invention provides a solution method based on a generation-verification cognitive description program. Designing a solution method and proposing and adopting an efficient optimization method are the keys of the invention. The invention adopts the program predicate dependency graph and the heuristic generation-verification technology to realize the solution of the cognitive description program, including four steps of instantiation, program simplification, generation of possible solutions, and determination of the final solution through testing. The number of iterations in the instantiation process is reduced through the program dependency graph, the input program is simplified by solving the constant true and false character set, the search space is reduced through the heuristic search method, and the efficiency of the reasoning machine is improved, so that the language can be applied to practical problems This is especially important in large-scale problem solving.
技术方案:一种基于生成一验证的认知描述程序的求解方法,其步骤包括:Technical solution: a solution method based on a generation-verification cognitive description program, the steps of which include:
步骤1:对词法和语法正确,规则安全的认知描述程序构建谓词依赖图,步骤包括:Step 1: Construct a predicate dependency graph for a lexically and grammatically correct, rule-safe cognitive description program. The steps include:
11)通过Lex和Yacc生成推理机的词法和语法分析模块,检查输入程序是否为语法正确的认知描述程序;11) Generate the lexical and grammatical analysis modules of the inference engine through Lex and Yacc, and check whether the input program is a grammatically correct cognitive description program;
12)规则的安全性检查12) Security check of rules
对于一条规则,如果出现在规则头部的变量都出现在正主观字或客观字中,则该规则是安全的,否则它是不安全的;For a rule, if the variables appearing in the head of the rule all appear in the positive subject word or the objective word, the rule is safe, otherwise it is not safe;
13)构建谓词依赖图13) Build a predicate dependency graph
i)如果一个谓词p是程序中某一规则头部字的谓词,而另一个谓词q存在于该规则的规则体中客观字或正主观字中,那么就建立p到q的强依赖边;i) If a predicate p is the predicate of the head word of a certain rule in the program, and another predicate q exists in the objective word or positive subjective word in the rule body of the rule, then a strong dependency edge from p to q is established;
ii)如果一个谓词谓词p是程序中某一规则头部字的谓词,而另一个谓词q存在于该规则的规则体中弱否定字或负主观字中,那么就建立p到q的弱依赖边;ii) If a predicate predicate p is the predicate of a certain rule header word in the program, and another predicate q exists in the weak negative word or negative subjective word in the rule body of the rule, then a weak dependency of p to q is established side;
步骤2:利用步骤l生成的谓词谓词依赖图,对程序进行实例化,步骤包括:Step 2: Use the predicate-predicate dependency graph generated in step 1 to instantiate the program, and the steps include:
21)程序分块:21) Program block:
根据步骤1生成的谓词谓词依赖图,依次找出图中的所有强连通子图,每个强连通子图确定程序的一个分块;According to the predicate-predicate dependency graph generated in step 1, find all strongly connected subgraphs in the graph in turn, and each strongly connected subgraph determines a block of the program;
22)拓扑排序:22) Topological sorting:
根据以下规则确定程序块之间的拓扑排序;The topological sorting between program blocks is determined according to the following rules;
i)如果强连通子图A到强连通子图B存在一条强依赖边,则强连通子图A确定的块先于强连通子图B确定的块;i) If there is a strongly dependent edge from strongly connected subgraph A to strongly connected subgraph B, the block determined by strongly connected subgraph A is prior to the block determined by strongly connected subgraph B;
ii)如果强连通子图A与强连通子图B不存在任何强依赖边,且强连通子图A存在一条弱依赖边到强连通子图B,则强连通子图A确定的块先于强连通子图B确定的块;ii) If there is no strongly dependent edge between strongly connected subgraph A and strongly connected subgraph B, and there is a weakly dependent edge from strongly connected subgraph A to strongly connected subgraph B, then the block determined by strongly connected subgraph A precedes The blocks determined by the strongly connected subgraph B;
23)分步实例化:23) Step-by-step instantiation:
基于正向推理技术,依次对各个程序块进行实例化;Based on forward reasoning technology, each program block is instantiated in turn;
步骤3:简化程序,在保证解不变的情况下,删除冗余规则并消去其余规则规则体中的冗余字步骤包括:Step 3: Simplify the program. Under the condition that the solution remains unchanged, delete the redundant rules and eliminate the redundant words in the rest of the rules. The steps include:
31)求恒真恒假字集31) Seek the set of constant true and false characters
求取实例化的认知描述程序的所有恒真恒假字集。这是一个迭代的过程,直至恒真和恒假字集不再增加为止;Get all the constant true and false character sets of the instantiated cognitive description program. This is an iterative process until the constant true and constant false word sets no longer increase;
32)删除冗余规则和字32) Delete redundant rules and words
根据恒真恒假字集,删除冗余规则并消去其余规则规则体中的冗余字,从而简化认知描述程,简化推理复杂性;According to the set of constant true and false characters, delete redundant rules and eliminate redundant characters in the rule bodies of other rules, thereby simplifying the cognitive description process and simplifying the complexity of reasoning;
步骤4:猜测主观字的取值,生成程序可能解:Step 4: Guess the value of the subjective word and generate a possible solution for the program:
41)确定主观字间依赖关系41) Determine the subjective inter-word dependency
根据步骤1生成的谓词依赖图,确定所有主观字之间的依赖关系。即如果从主观字A的谓词到主观字B的谓词,存在一条由强依赖边组成的路径,则主观字B依赖于主观字A;According to the predicate dependency graph generated in step 1, the dependencies among all subjective words are determined. That is, if there is a path consisting of strongly dependent edges from the predicate of subjective word A to the predicate of subjective word B, then subjective word B depends on subjective word A;
42)生成可能解42) Generate possible solutions
采用启发式方法,依据主观字之间的依赖关系,猜测所有主观字的取值。从而转化认知描述程序为回答集逻辑程序,并生成回答集逻辑程序的全部回答集组成的一个认知描述程序的可能解。Using the heuristic method, guess the values of all the subjective words according to the dependencies between the subjective words. Therefore, the cognitive description program is transformed into an answer set logic program, and a possible solution of a cognitive description program composed of all answer sets of the answer set logic program is generated.
步骤5:用可能解检验主观字的猜测值,如果该可能解满足所有主观字的猜测值,则该可能解就是认知描述程序的一个解;Step 5: Check the guess value of the subjective word with the possible solution, if the possible solution satisfies the guess value of all the subjective words, then the possible solution is a solution of the cognitive description program;
采用回溯过程猜测所有主观字的取值,生成程序所有的解。Use the backtracking process to guess the values of all subjective words and generate all the solutions of the program.
所述的步骤1中,对包含了主观字的逻辑程序规则,依照规则头中的变量是否出现在规则体的正主观字和客观字中判定规则的安全性,判定条件是:对于一条规则,如果出现在规则头部的变量都出现在正主观字或客观字中,则该规则是安全的,否则它是不安全的。一个认知描述程序是安全的当且仅当程序中的所有规则都是安全的。In the step 1, for the logic program rule that contains the subjective word, the security of the rule is judged according to whether the variable in the rule header appears in the positive subjective word and the objective word of the rule body, and the judgment condition is: for a rule, A rule is safe if the variables that appear in the head of the rule all appear in either the positive or the objective word, otherwise it is unsafe. A cognitive description program is safe if and only if all the rules in the program are safe.
利用恒真恒假字集简化认知描述程序,简化规则如下:对于一条规则r,Use the constant true and constant false character set to simplify the cognitive description procedure, the simplification rules are as follows: for a rule r,
i)当规则体中的正主观字Ka存在于恒真字集中,则从该规则规则体中删掉Ka;i) When the positive and subjective character Ka in the rule body exists in the constant true character set, then delete Ka from the rule body;
ii)当规则体中的客观字l存在于恒真字集中,则从该规则规则体中删掉l;ii) When the objective word l in the rule body exists in the constant true word set, then delete l from the rule body;
iii)当规则体中的负主观字-Ka存在于恒假字集中,则从该规则规则体中删掉-Ka;iii) When the negative subjective word-Ka in the rule body exists in the constant false character set, then delete-Ka from the rule body;
iv)当规则体中的弱否定字not l存在于恒假字集中,则从该规则规则体中删掉not l;iv) When the weak negative character not l in the rule body exists in the constant false word set, then delete not l from the rule body;
v)当规则体中的正主观字Ka存在于恒假字集中,去除该规则;v) When the positive and subjective character Ka in the rule body exists in the constant false character set, remove the rule;
vi)当规则体中的客观字l存在于恒假字集中,去除该规则;vi) When the objective word l in the rule body exists in the set of constant false characters, remove the rule;
vii)当规则体中的负主观字-Ka存在于恒真字集中,去除该规则;vii) When the negative subjective word-Ka in the rule body exists in the constant true character set, remove the rule;
viii)当规则体中的弱否定字not l存在于恒真字集中,去除该规则。viii) When the weak negative word not l in the rule body exists in the constant true word set, remove the rule.
所述步骤4中,将主观字之间的依赖关系作为启发信息,搜索主观字取值空间,用每一个搜索到的主观字可能的取值把认知描述程序转换为一个回答集程序,求取该回答集程序的所有回答集并组成认知描述程序的一个可能解。采用启发信息猜测主观字取值的策略具体如下:In the step 4, the dependency relationship between the subjective words is used as the heuristic information, the value space of the subjective words is searched, and the cognitive description program is converted into an answer set program with the possible values of each searched subjective word, and the result is obtained. Take all the answer sets of the answer set program and form a possible solution of the cognitive description program. The strategy of using heuristic information to guess the value of subjective words is as follows:
i)依照主观字依赖关系的先后次序,i) According to the sequence of subjective word dependencies,
ii)后续主观字的值由它所依赖的主观字的值决定,即如果主观字A依赖于主观字B,当主观字B取值为真,则主观字A的取值也为真。当主观字B取值为假,则主观字A取值也为假。ii) The value of the subsequent subjective word is determined by the value of the subjective word it depends on, that is, if the subjective word A depends on the subjective word B, when the value of the subjective word B is true, the value of the subjective word A is also true. When the value of the subjective word B is false, the value of the subjective word A is also false.
iii)对不依赖于任何其他主观字的主观字,赋予一个真值。iii) Assign a truth value to a subjective word that does not depend on any other subjective word.
有益效果:本发明主要有以下优点:Beneficial effect: the present invention mainly has the following advantages:
(1)通过定义了认知描述程序的安全规则,使得认知描述程序的语义更加完善,使得用户使用认知描述程序时可以使用变量,并且含有变量的规则都是有意义及实例化后的规则数目有限;(1) By defining the security rules of the cognitive description program, the semantics of the cognitive description program is improved, so that users can use variables when using the cognitive description program, and the rules containing variables are meaningful and instantiated limited number of rules;
(2)通过定义了认知描述程序的程序谓词依赖图,使得对认知描述程序可以分块及块之间拓扑排序。再次采用正向推理技术依次实例化各程序块,从而减少了实例化的迭代次数,提高了认知描述程序的实例化效率。此外分块还使得认知描述程序并行实例化成为了可能,对于没有依赖关系的块之间,可以使用并行技术对其实例化,提高认知描述程序实例化的效率;(2) By defining the program predicate dependency graph of the cognitive description program, the cognitive description program can be divided into blocks and topologically sorted between blocks. The forward reasoning technique is used again to instantiate each program block sequentially, thereby reducing the number of instantiation iterations and improving the instantiation efficiency of the cognitive description program. In addition, block also makes it possible to instantiate cognitive description programs in parallel. For blocks without dependencies, parallel technology can be used to instantiate them, improving the efficiency of instantiation of cognitive description programs;
(3)通过求出程序的恒真恒假字集,删除冗余规则并消去其余规则规则体中的冗余字,从而简化了认知描述程序,提高了推理机求解的效率;(3) By finding out the constant true and constant false word set of the program, deleting redundant rules and eliminating redundant words in the rule body of other rules, thereby simplifying the cognitive description program and improving the efficiency of the inference engine;
(4)本发明首先利用恒真和恒假字集去除了部分可以约简的主观字,对于余下的主观字的采用启发式生成-验证的方法。然后根据转换规则将认知描述程序转换为回答集程序,最后求出认知描述程序的所有解。本发明中,只需猜测余下的主观字,不需要对所有的主观字进行猜测,极大地提高了推理机的效率;(4) The present invention first utilizes the constant true and constant false character sets to remove some subjective characters that can be reduced, and adopts a heuristic generation-verification method for the remaining subjective characters. Then convert the cognition description program into answer set program according to the conversion rules, and finally obtain all the solutions of the cognition description program. In the present invention, it is only necessary to guess the rest of the subjective words, and it is not necessary to guess all the subjective words, which greatly improves the efficiency of the reasoning machine;
(5)本发明提出了基于启发式的搜索的技术,对于所有主观字,首先利用程序谓词依赖图确定其依赖关系,然后依次猜测主观字。减少了一些不必要的猜测,减少生成测试中生成的次数,极大地提高了生成测试的效率。(5) The present invention proposes a heuristic-based search technology. For all subjective words, firstly use the program predicate dependency graph to determine their dependencies, and then guess the subjective words in turn. Reduce some unnecessary guesses, reduce the number of times generated in the generated test, and greatly improve the efficiency of generated tests.
附图说明Description of drawings
图1为本发明实施例的系统原理图;Fig. 1 is the system schematic diagram of the embodiment of the present invention;
图2为本发明实施例中示例程序1的程序谓词依赖图;Fig. 2 is a program predicate dependency graph of example program 1 in the embodiment of the present invention;
图3是本发明实施例中推理机实例化的流程图;Fig. 3 is the flowchart of instantiation of reasoning engine in the embodiment of the present invention;
图4是本发明实施例中推理机求解的流程图;Fig. 4 is the flow chart that reasoning machine solves in the embodiment of the present invention;
图5是本发明实施例中求解恒真恒假字集的过程图;Fig. 5 is the process figure of solving constant true and false character set in the embodiment of the present invention;
图6是本发明实施例中启发式生成-验证的过程图。Fig. 6 is a process diagram of heuristic generation-verification in the embodiment of the present invention.
具体实施方式Detailed ways
下面结合具体实施例,进一步阐明本发明,应理解这些实施例仅用于说明本发明而不用于限制本发明的范围,在阅读了本发明之后,本领域技术人员对本发明的各种等价形式的修改均落于本申请所附权利要求所限定的范围。Below in conjunction with specific embodiment, further illustrate the present invention, should be understood that these embodiments are only used to illustrate the present invention and are not intended to limit the scope of the present invention, after having read the present invention, those skilled in the art will understand various equivalent forms of the present invention All modifications fall within the scope defined by the appended claims of the present application.
下面将从体系结构和方法流程两个方面来介绍本发明的技术方案。The technical solution of the present invention will be introduced below from two aspects of system structure and method flow.
1)体系结构:图1给出了一种认知描述程序推理机的实现的体系结构。下面给出几个主要部分的具体说明。1) Architecture: Figure 1 shows the architecture of a cognitive description program inference engine. The specific description of several main parts is given below.
语法分析器parser
语法分析器检查输入认知描述程序的语法的正确性和认知描述程序是否为安全的认知描述程序,当用户输入程序语法不正确或者不是安全的认知描述程序,则给出程序的出错位置。The grammatical analyzer checks the correctness of the syntax of the input cognitive description program and whether the cognitive description program is a safe cognitive description program. When the user input program syntax is incorrect or is not a safe cognitive description program, an error will be given Location.
语法分析器模块的输入为用户输入的认知描述程序,输出为语法正确且安全的认知描述程序或者为错误的认知描述程序和错误报告。The input of the grammatical analyzer module is the cognitive description program input by the user, and the output is a grammatically correct and safe cognitive description program or a wrong cognitive description program and an error report.
构建程序谓词依赖图Build program predicate dependency graph
程序P的谓词依赖图由顶点和有向边构成,即Dep(P)=(V,E)。其中顶点的集合V由程序P中所有谓词的名构成。边的集合E由程序中的规则生成。The predicate dependency graph of program P consists of vertices and directed edges, that is, Dep(P)=(V,E). The set V of vertices consists of the names of all predicates in program P. The edge set E is generated by the rules in the program.
i)如果一个谓词p是程序中某一规则的头部字的谓词,而另一个谓词q存在于该规则的规则体中客观字或正主观字中,那么就建立p到q的强依赖边。i) If a predicate p is the predicate of the head word of a certain rule in the program, and another predicate q exists in the objective word or positive subjective word in the rule body of the rule, then a strong dependency edge from p to q is established .
ii)如果一个谓词谓词p是程序中某一规则的头部字的谓词,而另一个谓词q存在于该规则的规则体中弱否定字或负主观字中,那么就建立p到q的弱依赖边。ii) If a predicate predicate p is the predicate of the head word of a rule in the program, and another predicate q exists in the weak negative word or negative subjective word in the rule body of the rule, then a weak link from p to q is established dependent side.
图2下面示例认知描述程序1的程序谓词依赖图。Figure 2 shows the program predicate dependency graph of Cognitive Description Program 1 below.
学生(张三).Student (Zhang San).
优秀(X)or 中等(X)←学生(X),not 老师(X).Excellent(X)or Medium(X)←Student(X),not Teacher(X).
奖学金(X)←K 优秀(X).Scholarship (X)←K Excellent (X).
免学费(X)←K 奖学金(X)Tuition Free (X)←K Scholarship (X)
程序1program 1
构建程序谓词依赖图模块的输入为语法正确且安全的认知描述程序,根据谓词依赖图的定义构建输入程序的程序谓词依赖图,输出为程序谓词依赖图。The input of the program predicate dependency graph module is a grammatically correct and safe cognitive description program, and the program predicate dependency graph of the input program is constructed according to the definition of the predicate dependency graph, and the output is a program predicate dependency graph.
程序分块及排序Program Partitioning and Sorting
根据程序谓词依赖图,依次找出图中的所有强连通子图,根据强连通子图确定各个程序块。然后利用谓词依赖图,确定各个程序块的依赖关系。According to the predicate dependency graph of the program, all strongly connected subgraphs in the graph are found in turn, and each program block is determined according to the strongly connected subgraph. Then use the predicate dependency graph to determine the dependencies of each program block.
程序分块及排序模块的输入为程序谓词依赖图和认知描述程序,输出为有序的模块化的认知描述程序。The input of the program chunking and sorting module is the program predicate dependency graph and the cognitive description program, and the output is an ordered and modular cognitive description program.
程序实例化program instantiation
程序实例化即使用常量替换程序中的所有变量。基于正向推理技术,首先获取所有已实例化的谓词,依据分块排序模块的输出使用已实例化的谓词集合依次实例化各个程序块。对于任一程序块,实例化该程序块和产生新的谓词是一个迭代的过程,直至该程序块不再产生新的谓词。当所有程序块全部实例化,程序实例化模块终止运行,并输出实例化的认知描述。Program instantiation means replacing all variables in the program with constants. Based on the forward reasoning technique, all instantiated predicates are obtained first, and each program block is instantiated sequentially using the instantiated predicate set according to the output of the block sorting module. For any program block, instantiating the program block and generating new predicates is an iterative process until the program block no longer generates new predicates. When all the program blocks are fully instantiated, the program instantiation module stops running and outputs instantiated cognitive descriptions.
程序实例化模块的输入为有序的模块化的认知描述程序,输出则为实例化后的认知描述程序。The input of the program instantiation module is an ordered and modular cognitive description program, and the output is the instantiated cognitive description program.
求解恒真恒假集(如图4所示),简化程序Solve the constant true and constant false set (as shown in Figure 4), simplify the program
恒真和恒假集由两种字的集合组成,即SM(P)=(LFP,MFS)。其中LFP由一定成立的字构成,MFS由一定不成立的字所构成。根据恒真恒假字集,删除冗余规则并消去其余规则规则体中的冗余字,从而简化认知描述程,简化推理复杂性。The constant true and constant false sets consist of two sets of words, SM(P)=(LFP,MFS). Among them, LFP is composed of words that must be established, and MFS is composed of words that must not be established. According to the set of constant true and false characters, redundant rules are deleted and redundant characters in the rule bodies of other rules are eliminated, so as to simplify the process of cognitive description and the complexity of reasoning.
求解恒真恒假模块输入为实例化后的认知描述程序,求解当前程序的恒真恒假集,然后根据这两个集合去简化程序。该过程是一个迭代的过程,直至恒真恒假集不在增加和程序不能简化为止。该模块的输出为简化后的认知描述程序和恒真恒假集。The input of solving constant true and constant false module is the instantiated cognitive description program, which solves the constant true and constant false set of the current program, and then simplifies the program according to these two sets. This process is an iterative process until the constant true and constant false sets are no longer increasing and the program cannot be simplified. The output of this module is the simplified cognitive description program and constant true and false sets.
启发式搜索(如图6所示)Heuristic search (as shown in Figure 6)
生成验证是人工智能中的一项成熟技术,本发明提出了一种启发式生成验证方法,来求解认知描述程序的解。首先根据构建的程序谓词依赖图,确定认知描述程序中所有主观字(Subjective Literal)的依赖关系,其中主观字即含有认知运算符的字K l或者-K l。依次猜测主观字的取值,然后根据猜测的主观字取值将认知描述程序变为普通回答集程序,求出回答集程序的所有回答集,并将所有的回答集作为认知描述程序的一个可能的解,通过验证主观字确定是否为程序的解。通过采用回溯过程猜测主观字的可能取值,直至完成所有的猜测,求解认知描述程序的全部解。Generation verification is a mature technology in artificial intelligence. The invention proposes a heuristic generation verification method to solve the solution of cognitive description program. Firstly, according to the built program predicate dependency graph, determine the dependencies of all the subjective literals (Subjective Literal) in the cognitive description program, where the subjective literals are the words K l or -K l that contain cognitive operators. Guess the value of the subjective word in turn, then change the cognitive description program into a common answer set program according to the guessed subjective word value, find all the answer sets of the answer set program, and use all the answer sets as the cognitive description program A possible solution, by verifying the subjective word to determine whether it is the solution of the program. By using the backtracking process to guess the possible values of the subjective words until all the guesses are completed, all the solutions of the cognitive description program are solved.
启发式生成验证模块的输入认知描述程序和稳定模型,其输出为认知描述程序的所有的解。The input cognitive description program and stable model of the verification module are generated heuristically, and its output is all solutions of the cognitive description program.
2)方法流程:本发明提出了一种基于生成-验证的认知描述程序推理机实现方法,包括实例化,程序简化,生成可能解、通过测试确定最终解四个步骤。当输入一个认知描述程序,首先,在词法、语法正确性检查基础上,构建认知描述程序的谓词依赖图,据此对程序分块并生成块的拓扑排序,然后,使用前向推理技术,依据拓扑排序,依次对程序进行安全规则检查并实施实例化,最终生成实例化的认知描述程序。其次,对实例化的认知描述程序求解其恒真和恒假字集,简化程序。该过程是一个迭代的过程,依据不动点定理保证了迭代可终止。然后,根据谓词依赖图确定主观字之间的依赖关系,依此猜测主观字的取值,从而转化认知描述程序为回答集逻辑程序,并求解该程序的全部回答集。至此,所求回答集就是所输入的认知描述程序的一个可能解。此后,通过验证主观字取值是否正确,确定这个可能解是否是认知描述程序的解。通过采用回溯过程猜测主观字的可能取值,直至完成所有的猜测,求解认知描述程序的全部解。该方法的步骤包括:2) Method flow: The present invention proposes a generation-verification-based cognitive description program inference engine implementation method, including four steps of instantiation, program simplification, generation of possible solutions, and determination of the final solution through testing. When inputting a cognitive description program, first, on the basis of lexical and grammatical correctness checks, construct a predicate dependency graph of the cognitive description program, and then divide the program into blocks and generate a topological sort of blocks, and then use forward reasoning technology , according to the topological sorting, check the safety rules of the program in turn and implement instantiation, and finally generate the instantiated cognitive description program. Secondly, solve the set of constant true and constant false characters for the instantiated cognitive description program to simplify the program. This process is an iterative process, and the iteration can be terminated according to the fixed point theorem. Then, according to the predicate dependency graph, the dependency relationship between the subjective words is determined, and the value of the subjective words is guessed accordingly, so that the cognitive description program is transformed into an answer set logic program, and all answer sets of the program are solved. So far, the answer set sought is a possible solution of the input cognitive description program. Afterwards, by verifying whether the value of the subjective word is correct, it is determined whether this possible solution is the solution of the cognitive description program. By using the backtracking process to guess the possible values of the subjective words until all the guesses are completed, all the solutions of the cognitive description program are solved. The steps of the method include:
步骤1:对词法和语法正确,规则安全的认知描述程序构建谓词依赖图,步骤包括:Step 1: Construct a predicate dependency graph for a lexically and grammatically correct, rule-safe cognitive description program. The steps include:
11)检查输入程序是否为语法正确的认知描述程序。这一步中通过Lex和Yacc生成推理机的词法和语法分析模块,当语法错误时,给出出错的位置,否则将进入规则的安全性检查。11) Check whether the input program is a grammatically correct cognitive description program. In this step, Lex and Yacc are used to generate the lexical and grammatical analysis modules of the inference engine. When the grammar is wrong, the location of the error is given, otherwise it will enter the security check of the rules.
12)规则的安全性检查12) Security check of rules
如果一条规则中,出现在规则头部的变量都出现在正主观字或客观字中,则该规则是安全的,否则它是不安全的。该模块检查程序中所有含有变量的规则,当出现不安全的规则,程序出错并给出错误位置。If in a rule, the variables that appear in the head of the rule all appear in the positive subject word or the objective word, then the rule is safe, otherwise it is not safe. This module checks all the rules that contain variables in the program. When an unsafe rule appears, the program makes an error and gives the error location.
13)构建谓词依赖图13) Build a predicate dependency graph
i)如果一个谓词p是程序中某一规则的头部字的谓词,而另一个谓词q存在于该规则的规则体中客观字或正主观字中,那么就建立p到q的强依赖边。i) If a predicate p is the predicate of the head word of a certain rule in the program, and another predicate q exists in the objective word or positive subjective word in the rule body of the rule, then a strong dependency edge from p to q is established .
ii)如果一个谓词谓词p是程序中某一规则的头部字的谓词,而另一个谓词q存在于该规则的规则体中弱否定字或负主观字中,那么就建立p到q的弱依赖边。ii) If a predicate predicate p is the predicate of the head word of a rule in the program, and another predicate q exists in the weak negative word or negative subjective word in the rule body of the rule, then a weak link from p to q is established dependent side.
程序根据上述两条规则,构建认知描述程序的程序谓词依赖图。According to the above two rules, the program constructs the program predicate dependency graph of cognitive description program.
步骤2:利用步骤1中谓词依赖图,对程序进行分块实例化,步骤包括:Step 2: Use the predicate dependency graph in step 1 to instantiate the program in blocks. The steps include:
21)程序分块:21) Program block:
根据步骤1中的谓词依赖图,依次找出图中的所有强连通子图,根据强连通子图将原程序分成各个程序块。According to the predicate dependency graph in step 1, find all strongly connected subgraphs in the graph in turn, and divide the original program into various program blocks according to the strongly connected subgraphs.
22)拓扑排序:22) Topological sorting:
依赖关系由下面两条规则确定:Dependencies are determined by the following two rules:
i)如果强连通子图A到强连通子图B存在一条强依赖边,则强连通子图A确定的块先于强连通子图B确定的块。i) If there is a strongly dependent edge from strongly connected subgraph A to strongly connected subgraph B, the block determined by strongly connected subgraph A is prior to the block determined by strongly connected subgraph B.
ii)如果强连通子图A与强连通子图B不存在任何强依赖边,且强连通子图A存在一条弱依赖边到强连通子图B,则强连通子图A确定的块先于强连通子图B确定的块。ii) If there is no strongly dependent edge between strongly connected subgraph A and strongly connected subgraph B, and there is a weakly dependent edge from strongly connected subgraph A to strongly connected subgraph B, then the block determined by strongly connected subgraph A precedes The block determined by the strongly connected subgraph B.
23)分步实例化:23) Step-by-step instantiation:
基于正向推理技术,依次对各个程序块进行实例化,并输出实例化后的认知描述程序。首先获取程序中所有已实例化的字,加至集合S,即遍历认知描述程序中的所有规则,将不含变量的规则头部(head)的字加至集合S。依次实例化所有的程序块,将S和程序块中的每条规则体比较,如果该规则可以被S实例化,即该规则体中含有变量的字在S中存在,则用可替换的字生成一条不含变量的规则,并将新规则的头部中的字加至集合S中。这是一个迭代的过程,直到S中不产生新的已实例化的字为止。Based on the forward reasoning technology, each program block is instantiated in turn, and the instantiated cognitive description program is output. Firstly, all the instantiated words in the program are obtained and added to the set S, that is, all the rules in the cognitive description program are traversed, and the words in the head of the rules without variables are added to the set S. Instantiate all the program blocks in turn, compare S with each rule body in the program block, if the rule can be instantiated by S, that is, the word containing the variable in the rule body exists in S, then use the replaceable word Generate a rule without variables, and add the words in the head of the new rule to the set S. This is an iterative process until no new instantiated words are generated in S.
程序实例化的算法见算法1。See Algorithm 1 for the algorithm of program instantiation.
步骤3:简化程序,在保证解不变的情况下,减少程序的规则数目,减少规则体中字的数目。Step 3: Simplify the program, reduce the number of rules of the program and the number of words in the rule body while ensuring the solution remains unchanged.
根据实例化后认知描述程序,求取程序中所有的恒真和真假字集和简化认知描述程序。这是一个迭代的过程,直至恒真和恒假字集不在增加为止。首先将认知描述程序中的所有事实加到LFP,将仅在规则体中出现的字加至MFS。再次使用恒真恒假字简化认知描述程序,简化规则如下:对于一条规则r,According to the cognitive description program after instantiation, all the constant true and true and false character sets and the simplified cognitive description program in the program are obtained. This is an iterative process until the constant true and constant false word sets are no longer increasing. First add all the facts in the Cognitive Description Program to the LFP, and add the words that only appear in the rule body to the MFS. The cognitive description procedure is simplified again by using the constant true and false characters, and the simplification rules are as follows: for a rule r,
i)当规则体中的正主观字Ka存在于恒真字集中,则从该规则规则体中删掉Ka;i) When the positive and subjective character Ka in the rule body exists in the constant true character set, then delete Ka from the rule body;
ii)当规则体中的客观字l存在于恒真字集中,则从该规则规则体中删掉l;ii) When the objective word l in the rule body exists in the constant true word set, then delete l from the rule body;
iii)当规则体中的负主观字-Ka存在于恒假字集中,则从该规则规则体中删掉-Ka;iii) When the negative subjective word-Ka in the rule body exists in the constant false character set, then delete-Ka from the rule body;
iv)当规则体中的弱否定字not l存在于恒假字集中,则从该规则规则体中删掉not l;iv) When the weak negative character not l in the rule body exists in the constant false word set, then delete not l from the rule body;
v)当规则体中的正主观字Ka存在于恒假字集中,去除该规则;v) When the positive and subjective character Ka in the rule body exists in the constant false character set, remove the rule;
vi)当规则体中的客观字l存在于恒假字集中,去除该规则;vi) When the objective word l in the rule body exists in the set of constant false characters, remove the rule;
vii)当规则体中的负主观字-Ka存在于恒真字集中,去除该规则;vii) When the negative subjective word-Ka in the rule body exists in the constant true character set, remove the rule;
viii)当规则体中的弱否定字not l存在于恒真字集中,去除该规则;viii) When the weak negative word not l in the rule body exists in the constant true word set, remove the rule;
再次更新恒真恒假集,并用更新后的字集去简化认知描述程序。这也是一个迭代的过程,直至LFP和MFS不再增加为止,算法见算法2。Update the constant true and constant false set again, and use the updated word set to simplify the cognitive description procedure. This is also an iterative process until the LFP and MFS no longer increase. See Algorithm 2 for the algorithm.
步骤4:猜测主观字的取值,生成程序可能解:Step 4: Guess the value of the subjective word and generate a possible solution for the program:
41)确定主观字间依赖关系41) Determine the subjective inter-word dependency
根据步骤1生成的谓词依赖图,确定所有主观字之间的依赖关系。即如果从主观字A的谓词到主观字B的谓词,存在一条由强依赖边组成的路径,则主观字B依赖于主观字A。According to the predicate dependency graph generated in step 1, the dependencies among all subjective words are determined. That is, if there is a path consisting of strongly dependent edges from the predicate of subjective word A to the predicate of subjective word B, then subjective word B depends on subjective word A.
42)生成可能解42) Generate possible solutions
采用启发式方法,依据主观字之间的依赖关系,猜测所有主观字的取值。从而转化认知描述程序为回答集逻辑程序,其转化规则如下:Using the heuristic method, guess the values of all the subjective words according to the dependencies between the subjective words. Thus, the cognitive description program is converted into an answer set logic program, and the conversion rules are as follows:
●当规则体中包含真值为假的主观字,去除该规则●When the rule body contains a subjective word whose true value is false, remove the rule
●当K l的真值为真,用l替换K l●When the truth value of K l is true, replace K l with l
●当-K l的真值为真,从规则体中去除-K l● When the truth value of -K l is true, remove -K l from the rule body
使用上面三条规则以及猜测的真值将认知描述程序变为普通回答集程序,并将稳定模型中的LFP中的字作为事实,将MFS中的字作为约束,一起交由回答集程序的推理机求解所有回答集,所有的回答集组成认知描述程序一个可能解。Use the above three rules and the guessed truth value to turn the cognitive description program into an ordinary answer set program, and use the words in the LFP in the stable model as facts, and the words in the MFS as constraints, and hand them over to the reasoning of the answer set program The computer solves all the answer sets, and all the answer sets form a possible solution of the cognitive description program.
步骤5:用可能解检验主观字的猜测值,如果该可能解满足所有主观字的猜测值,则该可能解就是认知描述程序的一个解。验证使用的规则如下:Step 5: Check the guessed value of the subjective word with the possible solution, if the possible solution satisfies all the guessed values of the subjective word, then the possible solution is a solution of the cognitive description program. The rules used for validation are as follows:
●-K l的真值为假或K l的真值为真,则所有的回答集中都需包含l,并且回答集不能为空●-The true value of K l is false or the true value of K l is true, then all answer sets must contain l, and the answer set cannot be empty
●-K l的真值为真或K l的真值为假,则至少存在一个回答集中不包含l,并且回答集可以为空- If the true value of K l is true or the true value of K l is false, then there is at least one answer set that does not contain l, and the answer set can be empty
根据以上两条规则验证所有主观字的猜测的真值,验证的成功的可能解则为认知描述程序的一个解。回溯地猜测所有主观字直至所有猜测完所有主观字的可能取值,生成程序所有的解。其算法见算法3。According to the above two rules, verify the truth value of all guesses of subjective words, and the successful possible solution of the verification is a solution of the cognitive description program. Guess all subjective words retroactively until all possible values of all subjective words are guessed, and all solutions of the program are generated. See Algorithm 3 for its algorithm.
假定有如下输入的认知描述程序:Assume a cognitive description program with the following inputs:
学生(张三). 1Student (Zhang San).
中等(X)or优秀(X)←学生(X),not 老师(X). 2Medium (X) or excellent (X) ← student (X), not teacher (X). 2
奖学金(X)←K 优秀(X). 3Scholarship (X)←K Excellent (X).
免学费(X)←K 奖学金(X) 4Tuition Free (X)←K Scholarship (X) 4
程序1program 1
我们按照如下步骤对输入程序进行求解:We solve the input program as follows:
(1)语法分析及安全规则检查:首先检查每条规则的语法以及认知描述程序所包含的规则是否为安全规则。对于程序1,我们可知,4条规则全部为合法规则,规则中所有体(body)都由主观字、客观字或弱否定字组成,没有非法字符,规则中的头部均由客观字组成,并且对于一条规则,如果出现在规则头部的变量都出现在正主观字或客观字中。所以程序1是语法正确并且安全的。(1) Grammatical analysis and security rule checking: first check the grammar of each rule and whether the rules included in the cognitive description program are security rules. For program 1, we know that all four rules are legal rules, all bodies in the rules are composed of subjective words, objective words or weak negative words, there are no illegal characters, and the heads in the rules are all composed of objective words. And for a rule, if the variables appearing in the head of the rule all appear in the positive subjective word or the objective word. So Program 1 is syntactically correct and safe.
(2)构建谓词依赖图,分块及排序:根据输入的程序1,遍历所有规则,根据上述谓词依赖图的定义,生成如图2所示的程序谓词依赖图,即存在学生到优秀和中等的两条强依赖的边,两条老师到优秀和中等的弱依赖的边,一条优秀到奖学金的强依赖边,一条奖学金到免学费的强依赖边。然后使用寻找强连通子图的算法,找出图2中所有的强连通子图,即为程序的各个子程序块。图中所有的四条规则将形成四个程序块,其中程序块1为规则1,程序块2为规则2,程序块3为规则3,程序块4为规则4。其拓扑排序为1-2-3-4。(2) Build the predicate dependency graph, block and sort: According to the input program 1, traverse all the rules, according to the definition of the above predicate dependency graph, generate the program predicate dependency graph as shown in Figure 2, that is, there are students to excellent and medium There are two sides of strong dependence, two sides of weak dependence from teachers to excellent and medium, one side of strong dependence from excellent to scholarship, and one side of strong dependence from scholarship to tuition exemption. Then use the algorithm for finding strongly connected subgraphs to find out all strongly connected subgraphs in Figure 2, which are the subroutine blocks of the program. All four rules in the diagram will form four blocks, where block 1 is rule 1, block 2 is rule 2, block 3 is rule 3, and block 4 is rule 4. Its topological sort is 1-2-3-4.
(3)程序实例化(根据图3):首先找出程序中已实例化的字,并加至集合S,即S={学生(张三)}。由于程序块已经实例化,因此程序首先迭代地使用S实例化程序块2,直至集合S不再增加为止。显然,一次迭代后,程序块2实例化结束,中等(张三)和优秀(张三)将加至集合S中,并产生一条新的实例化后的规则,优秀(张三)or 中等(张三)←学生(张三),not 老师(张三).。接着程序将使用S继续实例化程序块3,当程序块3实例化结束后,奖学金(张三)加至集合S,并且增加新的规则,奖学金(张三)←K 优秀(张三)。然后,程序将实例化程序块4。将增加新的规则免学费(张三)←K 奖学金(张三).。集合S中将包含以下实例化后的字,{学生(张三),优秀(张三),中等(张三),奖学金(张三),免学费(张三)}。实例化后的程序如下所示:(3) Program instantiation (according to Figure 3): first find out the instantiated words in the program, and add them to the set S, that is, S={student (Zhang San)}. Since the block has already been instantiated, the program first iteratively uses S to instantiate block 2 until the set S no longer increases. Obviously, after one iteration, the instantiation of program block 2 ends, the medium (Zhang San) and excellent (Zhang San) will be added to the set S, and a new instantiated rule will be generated, excellent (Zhang San) or medium ( Zhang San) ← student (Zhang San), not teacher (Zhang San).. Then the program will use S to continue to instantiate program block 3. When program block 3 is instantiated, the scholarship (Zhang San) is added to the set S, and a new rule is added, scholarship (Zhang San) ← K excellent (Zhang San). The program will then instantiate block 4. A new rule will be added: Tuition Free (Zhang San) ← K Scholarship (Zhang San). The set S will contain the following instantiated words, {student (Zhang San), excellent (Zhang San), medium (Zhang San), scholarship (Zhang San), tuition-free (Zhang San)}. The instantiated program is as follows:
学生(张三). 1Student (Zhang San). 1
优秀(张三)or 中等(张三)←学生(张三),not 老师(张三).2Excellent (Zhang San) or medium (Zhang San)←student (Zhang San), not teacher (Zhang San).2
奖学金(张三)←K 优秀(张三).3Scholarship (Zhang San)←K Excellent (Zhang San).3
免学费(张三)←K 奖学金(张三)4 Tuition Free (Zhang San)←K Scholarship (Zhang San) 4
程序2Procedure 2
(4)求解恒真恒假字集(根据图5),简化程序:(4) solve constant true constant false word set (according to Fig. 5), simplify program:
根据实例化后的程序(即程序2),程序将按照上述所介绍的方法求解程序的恒真恒假字集和简化程序。这是一个迭代的过程,直至恒真恒假字集不再增加和程序不能简化为止。程序将得到恒真恒假字集{{男人(张三).},{老师(张三)}}。然后使用恒真恒假字集简化程序,简化后的程序如下所示:According to the instantiated program (that is, program 2), the program will solve the program's constant true and false character set and simplify the program according to the method introduced above. This is an iterative process until the set of constant true and false characters no longer increases and the program cannot be simplified. The program will get the constant true and false character set {{man (Zhang San).}, {teacher (Zhang San)}}. Then use the constant true and false character set to simplify the program, the simplified program is as follows:
学生(张三). 1Student (Zhang San).
优秀(张三)or 中等(张三). 2Excellent (Zhang San) or medium (Zhang San). 2
奖学金(张三)←K 优秀(张三). 3Scholarship (Zhang San)←K Excellent (Zhang San). 3
免学费(张三)←K 奖学金(张三) 4Free Tuition (Zhang San)←K Scholarship (Zhang San) 4
程序3program 3
再次求解恒真恒假字集和简化程序。显然稳定模型已达到稳定,恒真恒假字集和程序不能简化,因此程序将进入下一步骤。Solve the constant true and false character set and simplify the program again. Obviously the stable model has reached stability, the constant true constant false character set and the program cannot be simplified, so the program will enter the next step.
(5)猜测主观字的取值,生成程序可能解:(5) Guess the value of the subjective word and generate a possible solution for the program:
程序首先根据谓词依赖图,确定认知描述程序的主观字的依赖关系。显然可知K免学费(张三)(假定为主观字2)的依赖于K优秀(张三)(假定为主观字1)。因此指派K优秀(张三)一个真值,即主观字1。假设主观字1指派真值为假,求取程序的恒真恒假字集和简化程序。显然可知,主观字2的真值也为假,规则2将从程序去去除,则规则3也必须从规则中去除,于是程序转化为回答集程序,且其为如下形式:The program first determines the dependency relationship of the subjective words of the cognition description program according to the predicate dependency graph. Obviously, it can be seen that K's tuition-free (Zhang San) (assumed to be subjective character 2) depends on K's excellent (Zhang San) (assumed to be subjective character 1). Therefore assign K excellent (Zhang San) a truth value, namely the subjective word 1. Assuming that the subjective word 1 assigns the true value to be false, obtain the constant true and constant false character set of the program and simplify the program. Obviously, the truth value of subjective word 2 is also false, rule 2 will be removed from the program, and rule 3 must also be removed from the rule, so the program is transformed into an answer set program, and it is in the following form:
学生(张三). 1Student (Zhang San).
中等(张三)or 优秀(张三). 2Moderate (Zhang San) or Excellent (Zhang San). 2
程序4program 4
将上述程序,恒真字集作为事实,恒假字集作为约束一并送入回答集程序推理机。将得到一个解{{学生(张三),中等(张三)},{学生(张三),优秀(张三)}}。验证主观字1和主观字2,则可发现满足两个主观字,此为认知描述程序的一个解。The above program, the constant true character set as the fact, and the constant false character set as the constraints are sent to the answer set program reasoning machine. Will get a solution {{student (Zhang San), medium (Zhang San)}, {student (Zhang San), excellent (Zhang San)}}. Verifying the subjective word 1 and the subjective word 2, it can be found that the two subjective words are satisfied, which is a solution of the cognitive description program.
(6)根据回答集验证主观字的猜测,如果满足所有主观字的猜测,则所有回答集组成一个认知描述程序的解。回溯地猜测所有主观字直至所有猜测完所有主观字的可能取值,生成程序所有的解。继续假设主观字1指派真值为真,则可知主观字2的真值也为真,于是程序转化为回答集程序,且其为如下形式:(6) Verify the guess of the subjective word according to the answer set, if all the guesses of the subjective word are satisfied, then all the answer sets form a solution of a cognitive description program. Guess all subjective words retroactively until all possible values of all subjective words are guessed, and all solutions of the program are generated. Continue to assume that the truth value assigned by subjective word 1 is true, then it can be seen that the truth value of subjective word 2 is also true, so the program is transformed into an answer set program, and it is in the following form:
学生(张三). 1Student (Zhang San).
中等(张三)or 优秀(张三). 2Moderate (Zhang San) or excellent (Zhang San). 2
奖学金(张三)←优秀(张三). 3Scholarship (Zhang San) ← Excellent (Zhang San). 3
免学费(张三)←奖学金(张三) 4Tuition free (Zhang San) ← scholarship (Zhang San) 4
程序5program 5
将上述程序,恒真字集作为事实,恒假字集作为约束一并送入回答集程序推理机。将得到一个解{{学生(张三),中等(张三)},{学生(张三),优秀(张三),奖学金(张三),免学费(张三)}}。验证所有的主观字,发现猜测的真值均不能满足,于是该可能解不是程序的一个解。至此,程序猜测了所有主观字可能的取值。因此,程序得到了一个啮一的解:{{学生(张三),中等(张三)},{学生(张三),优秀(张三)}}。The above program, the constant true character set as the fact, and the constant false character set as the constraints are sent to the answer set program reasoning machine. Will get a solution {{student (Zhang San), medium (Zhang San)}, {student (Zhang San), excellent (Zhang San), scholarship (Zhang San), tuition-free (Zhang San)}}. After verifying all the subjective words, it is found that none of the guessed truth values can be satisfied, so this possible solution is not a solution of the program. So far, the program has guessed the possible values of all subjective words. Therefore, the program obtains a single solution: {{student (Zhang San), medium (Zhang San)}, {student (Zhang San), excellent (Zhang San)}}.
Claims (4)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210529095.7A CN103020714B (en) | 2012-12-10 | 2012-12-10 | Solution method for cognitive description program based on generation-verification |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210529095.7A CN103020714B (en) | 2012-12-10 | 2012-12-10 | Solution method for cognitive description program based on generation-verification |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103020714A CN103020714A (en) | 2013-04-03 |
CN103020714B true CN103020714B (en) | 2015-04-15 |
Family
ID=47969300
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201210529095.7A Active CN103020714B (en) | 2012-12-10 | 2012-12-10 | Solution method for cognitive description program based on generation-verification |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103020714B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104007981B (en) * | 2014-06-13 | 2017-04-12 | 河海大学常州校区 | Human-computer interaction interface design method based on error-cognition mapping model |
CN107092515B (en) * | 2017-03-16 | 2020-09-11 | 东南大学 | A LPMLN reasoning method and system based on answer set logic program |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101512505A (en) * | 2006-09-11 | 2009-08-19 | 微软公司 | Security language translations with logic resolution |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110244434A1 (en) * | 2006-01-27 | 2011-10-06 | University Of Utah Research Foundation | System and Method of Analyzing Freeform Mathematical Responses |
-
2012
- 2012-12-10 CN CN201210529095.7A patent/CN103020714B/en active Active
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101512505A (en) * | 2006-09-11 | 2009-08-19 | 微软公司 | Security language translations with logic resolution |
Non-Patent Citations (3)
Title |
---|
A modal logic for authorization specification and reasoning;Yun Bai;《2009 IEEE International Conference on Intelligent Computing and Intelligent Systems (ICIS 2009)》;20091122;第264-268页 * |
ESParser: An Epistemic Specification Grounder;Rongcun Cui等;《2012 International Conference on Computer Science and Service System (CSSS)》;20120813;第1823-1827页 * |
一种求解认知难题的模型检测方法;骆翔宇;《计算机学报》;20100315;第33卷(第3期);第406-414页 * |
Also Published As
Publication number | Publication date |
---|---|
CN103020714A (en) | 2013-04-03 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Dal Lago et al. | Probabilistic operational semantics for the lambda calculus | |
Müller et al. | The third international verification of neural networks competition (vnn-comp 2022): summary and results | |
de Moura et al. | A Tutorial on Satisfiability Modulo Theories: (Invited Tutorial) | |
Plotnikov et al. | NESTML: a modeling language for spiking neurons | |
Kobayashi et al. | On the relationship between higher-order recursion schemes and higher-order fixpoint logic | |
Lu et al. | Program classification using gated graph attention neural network for online programming service | |
Liu | Testing-based formal verification for theorems and its application in software specification verification | |
He et al. | Hoare logic-based genetic programming | |
CN103020714B (en) | Solution method for cognitive description program based on generation-verification | |
CN118349669A (en) | Referee document abstract generation method and system based on structural feature fusion prompt | |
Lagniez et al. | On checking Kripke models for modal logic K | |
Dixit | Answering Queries Over Inconsistent Databases Using SAT Solvers | |
Arthan et al. | A Hoare logic for linear systems | |
Saleh et al. | Static Detection of Implementation Errors Using Formal Code Specification | |
Doré et al. | The Elfe System-Verifying mathematical proofs of undergraduate students | |
Gordon | Background reading on hoare logic | |
de Boer et al. | Automated verification of recursive programs with pointers | |
Lund et al. | On Verified Automated Reasoning in Propositional Logic: Teaching Sequent Calculus to Computer Science Students | |
Doré et al. | ELFE–An interactive theorem prover for undergraduate students | |
Song et al. | Geometry problem solving based on counter-factual evolutionary reasoning | |
Newcomb et al. | Model checking data-independent systems with arrays | |
Kiesl | Structural reasoning methods for satisfiability solving and beyond | |
Shterionov | Design and development of probabilistic inference pipelines | |
Hozzová | Inductive Reasoning in Superposition | |
Deng et al. | Spy Inside: Scalable Verification of Dependable Transformers for Event Time Series Systems |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |