def getSuccessors(self, statement, i, goalCoHash = None): if statement.type(i) == "negation": if statement.type(i*2+1) == "conjunction" or statement.type(i*2+1) == "disjunction": thisType = statement.type(i*2+1) if thisType == "conjunction": otherType = "disjunction" else: otherType = "conjunction" np = statement.negatedChildTree(i*4+3) nq = statement.negatedChildTree(i*4+4) ns = Statement(dict(),statement.propMap) ns.insertProp(0, otherType) ns.graftInPlace(1,np) ns.graftInPlace(2,nq) successor = statement.graft(i,ns) successor.action = self.name successor.cost = self.cost + distance(str(statement), str(successor)) return successor elif statement.type(i) == "conjunction" or statement.type(i) == "disjunction": thisType = statement.type(i) if thisType == "conjunction": otherType = "disjunction" else: otherType = "conjunction" if self.dangerous: np = statement.negatedChildTree(i*2+1) nq = statement.negatedChildTree(i*2+2) ns = Statement(dict(),statement.propMap) ns.insertProp(0, "negation") ns.insertProp(1, otherType) ns.graftInPlace(3,np) ns.graftInPlace(4,nq) successor = statement.graft(i,ns) successor.action = self.name successor.cost = self.cost + distance(str(statement), str(successor)) return successor else: if statement.type(i*2+1) == "negation" and statement.type(i*2+2) == "negation": p = statement.childTree(i*4+3) q = statement.childTree(i*4+5) ns = Statement(dict(),statement.propMap) ns.insertProp(0, "negation") ns.insertProp(1, otherType) ns.graftInPlace(3,p) ns.graftInPlace(4,q) successor = statement.graft(i,ns) successor.action = self.name successor.cost = self.cost + distance(str(statement), str(successor)) return successor
def getSuccessors(self, statement, i, goalCoHash = None): if statement.type(i) == "implication": np = statement.negatedChildTree(i*2+1) q = statement.childTree(i*2+2) ns = Statement(dict(),statement.propMap) ns.insertProp(0, "disjunction") ns.graftInPlace(1,np) ns.graftInPlace(2,q) successor = statement.graft(i,ns) successor.action = self.name successor.cost = self.cost + distance(str(statement), str(successor)) return successor elif statement.type(i) == "disjunction": successors = [] if statement.type(i*2+1) == "negation": np = statement.negatedChildTree(2*i+1) q = statement.childTree(i*2+2) ns = Statement(dict(),statement.propMap) ns.insertProp(0, "implication") ns.graftInPlace(1,np) ns.graftInPlace(2,q) successor = statement.graft(i,ns) successor.action = self.name successor.cost = self.cost + distance(str(statement), str(successor)) successors.append(successor) if statement.type(i*2+2) == "negation": np = statement.negatedChildTree(2*i+2) q = statement.childTree(i*2+1) ns = Statement(dict(),statement.propMap) ns.insertProp(0, "implication") ns.graftInPlace(1,np) ns.graftInPlace(2,q) successor = statement.graft(i,ns) successor.action = self.name successor.cost = self.cost + distance(str(statement), str(successor)) successors.append(successor) if len(successors) == 1: return successors[0] elif len(successors) > 1: return successors else: return None