Loading...
Please wait, while we are loading the content...
AI Algorithms, Data Structures, and Idioms in Prolog, Lisp, and Java for Artificial Intelligence: Structures and Strategies for Complex Problem Solving
| Content Provider | Semantic Scholar |
|---|---|
| Author | Luger, George F. Stubblefield, William A. |
| Copyright Year | 2008 |
| Abstract | SolutionNode defines the basic functionality for every node of the graph, including the abstract method nextSolution(). AbstractSolutionNode and its descendants will implement the ability to search the and/or graph, to save the state of the search, and to resume on subsequent calls to nextSolution(). Luger_all_wcopyright_COsfixed.pd351 351 5/15/2008 6:37:00 PM 336 Part IV: Programming in Java The class RuleSet maintains the logic base, a list of rules. The intention is that all nodes will use the same instance of RuleSet, with each instance of AbstractSolutionNode maintaining a reference to a particular rule in the set to enable the continuation pattern. Figure 24.8. An example search space and construction of the proof tree. Figure 24.9. The class structure for implementing continuations. The descendants of AbstractSolutionNode maintain references to their children. SimpleSentenceSolutionNode represents a simple sentence as a goal, and maintains a reference to its child: the head of a rule. AndSolutionNode represents an and node, and keeps a Luger_all_wcopyright_COsfixed.pd352 352 5/15/2008 6:37:09 PM Chapter 24 A Logic-Based Reasoning System 337 reference to the first branch of the and node (the relationship labeled headSolutionNode) and the subsequent branches in the and node (the relationship labeled tailSolutionNode). We begin implementation with the RuleSet class: public class RuleSet { private Rule[] rules; public RuleSet(Rule... rules) { this.rules = rules; } public Rule getRuleStandardizedApart(int i) { Rule rule = (Rule)rules[i]. standardizeVariablesApart( new Hashtable()); return rule; } public Rule getRule(int i) { return rules[i]; } public int getRuleCount() { return rules.length; } } This definition is simple: it maintains an array of rules and allows them to be retrieved by number. The only unusual element is the method getRuleStandardizedApart(int i). This is necessary because the scope of logical variables is the single predicate sentence containing it in a single reasoning step. If we use the same rule again in the search, which is fairly common, we will need to assign new bindings to the variables. A simple way to insure this is to replace the variables in the rule with new copies having the same name. This operation, called “standardizing variables apart” must be defined for all expressions in the rule set. To support this, we will add a new method signature to the interface PCExpression. This interface now becomes: public interface PCExpression { public PCExpression standardizeVariablesApart( Luger_all_wcopyright_COsfixed.pd353 353 5/15/2008 6:37:10 PM 338 Part IV: Programming in Java Hashtable newVars); public PCExpression replaceVariables(SubstitutionSet s); } The intention here is that the method will be recursive, with each type of PCExpression giving it its own appropriate definition. In the method signature, the hash table of pairs of variables keeps track of the substitutions made so far, since a variable may occur multiple times in an expression, and will need to use the same replacement. Defining this requires changes to the following classes. AbstractOperator will define it for all n-ary operators: public abstract class AbstractOperator implements Goal, Cloneable { // variables and methods as already defined public PCExpression standardizeVariablesApart( HashtablewVars) throws CloneNotSupportedException { ArrayList newOperands = new ArrayList(); for(int i = 0; i < operandCount(); i++) newOperands.add((Goal)getOperand(i). standardizeVariablesApart(newVars)); AbstractOperator copy = (AbstractOperator) this.clone(); copy.setOperands(newOperands); return copy; } } We will also define the method for existing classes SimpleSentence, Constant, and Variable. The definition for Constant is straightforward: each constant returns itself. public class Constant implements Unifiable { // variables and methods as previously defined public PCExpression standardizeVariablesApart( Hashtable newVars) { return this; } } Luger_all_wcopyright_COsfixed.pd354 354 5/15/2008 6:37:10 PM Chapter 24 A Logic-Based Reasoning System 339 The definition for Variable is also straightforward, and makes use of the copy constructor defined earlier. public class Variable implements Unifiable { // variables and methods already defined. public PCExpression standardizeVariablesApart( Hashtable newVars) { Variable newVar = newVars.get(this); // Check if the expression already has // a substitute variable. if(newVar == null) // if not create one. { newVar = new Variable(this); newVars.put(this, newVar); } return newVar; } SimpleSentence defines the method recursively: public class SimpleSentence implements Unifiable, Goal, Cloneable { // variables and methods already defined. public PCExpression standardizeVariablesApart( Hashtable newVars) throws CloneNotSupportedException { Unifiable[] newTerms = new Unifiable[terms.length]; //create an array for new terms. for(int i = 0; i < length(); i++){ newTerms[i] = (Unifiable)terms[i]. standardizeVariablesApart( newVars); // Standardize apart each term. // Only variables will be affected. |
| Starting Page | 464 |
| Ending Page | 464 |
| Page Count | 1 |
| File Format | PDF HTM / HTML |
| Alternate Webpage(s) | http://wps.aw.com/wps/media/objects/5771/5909832/PDF/Luger_0136070477_1.pdf |
| Alternate Webpage(s) | http://www.cse.sc.edu/~mgv/csce580sp14/Luger_0136070477_1.pdf |
| Alternate Webpage(s) | https://rebo.pw/zyreb.pdf |
| Alternate Webpage(s) | http://www.cse.sc.edu/~mgv/csce580f12/Luger_0136070477_1.pdf |
| Alternate Webpage(s) | https://cse.sc.edu/~mgv/csce580f12/Luger_0136070477_1.pdf |
| Language | English |
| Access Restriction | Open |
| Content Type | Text |
| Resource Type | Article |