Beispiel #1
0
 def applyCondensation(cls, condensationSet, rule, sentenceNameSource):
     """ generated source for method applyCondensation """
     varsInCondensationSet = HashSet()
     for literal in condensationSet:
         varsInCondensationSet.addAll(GdlUtils.getVariables(literal))
     varsToKeep = HashSet()
     for literal in condensationSet:
         varsToKeep.addAll(GdlUtils.getVariables(literal))
     varsToKeep2 = HashSet()
     varsToKeep2.addAll(GdlUtils.getVariables(rule.getHead()))
     for literal in rule.getBody():
         if not condensationSet.contains(literal):
             varsToKeep2.addAll(GdlUtils.getVariables(literal))
     varsToKeep.retainAll(varsToKeep2)
     orderedVars = ArrayList(varsToKeep)
     condenserName = sentenceNameSource.getNameWithPrefix(rule.getHead().__name__)
     condenserHead = GdlSentence()
     if orderedVars.isEmpty():
         condenserHead = GdlPool.getProposition(condenserName)
     else:
         condenserHead = GdlPool.getRelation(condenserName, orderedVars)
     condenserBody = ArrayList(condensationSet)
     condenserRule = GdlPool.getRule(condenserHead, condenserBody)
     remainingLiterals = ArrayList()
     for literal in rule.getBody():
         if not condensationSet.contains(literal):
             remainingLiterals.add(literal)
     remainingLiterals.add(condenserHead)
     modifiedRule = GdlPool.getRule(rule.getHead(), remainingLiterals)
     newRules = ArrayList(2)
     newRules.add(condenserRule)
     newRules.add(modifiedRule)
     return newRules
Beispiel #2
0
 def updateDomains(self):
     """ generated source for method updateDomains """
     changedSomething = True
     while changedSomething:
         changedSomething = False
         for d in domains.values():
             for intSet in d.functionRefs:
                 for d2 in intSet:
                     if d2 != None:
                         if domain == None:
                             domain = HashSet(d2.values)
                         else:
                             domain.retainAll(d2.values)
                 if domain != None:
                     d.values.addAll(domain)
             if d.loc != None:
                 if name == "does":
                     newLoc.name = GdlPool.getConstant("legal")
                     newLoc.idx = d.loc.idx
                     if otherDom == None:
                         raise RuntimeException("Uh oh, missed a legal")
                     d.values.addAll(otherDom.values)
                 elif name == "true":
                     newLoc.name = GdlPool.getConstant("next")
                     newLoc.idx = d.loc.idx
                     if otherDom == None:
                         raise RuntimeException("Uh oh, missed a next")
                     d.values.addAll(otherDom.values)
             if len(d.values) != before:
                 changedSomething = True
Beispiel #3
0
 def getTurnsConjunctsArePossible(self, body):
     """ generated source for method getTurnsConjunctsArePossible """
     # We want to identify the conjuncts that are used by the
     # game flow.
     relevantLiterals = ArrayList()
     for literal in body:
         if isinstance(literal, (GdlSentence, )):
             if SentenceModelUtils.inSentenceFormGroup(sentence, self.formsControlledByFlow):
                 relevantLiterals.add(literal)
         elif isinstance(literal, (GdlNot, )):
             if SentenceModelUtils.inSentenceFormGroup(innerSentence, self.formsControlledByFlow):
                 relevantLiterals.add(literal)
     # If none are related to the game flow, then that's it. It can
     # happen on any turn.
     # if(relevantLiterals.isEmpty())
     # return getCompleteTurnSet();
     turnsPossible = HashSet(getCompleteTurnSet())
     # For each of the relevant literals, we need to see if there are assignments
     # such that
     for literal in relevantLiterals:
         if isinstance(literal, (GdlSentence, )):
             while t < self.getNumTurns():
                 if self.sentencesTrueByTurn.get(t).contains(literal):
                     turns.add(t)
                 else:
                     for s in sentencesTrueByTurn.get(t):
                         # Could be true if there's an assignment
                         if None != GdlUtils.getAssignmentMakingLeftIntoRight(literal, s):
                             turns.add(t)
                             break
                 t += 1
         elif isinstance(literal, (GdlNot, )):
             while t < self.getNumTurns():
                 if not self.sentencesTrueByTurn.get(t).contains(internal):
                     turns.add(t)
                 else:
                     for s in sentencesTrueByTurn.get(t):
                         if None != GdlUtils.getAssignmentMakingLeftIntoRight(internal, s):
                             turns.add(t)
                             break
                 t += 1
         # Accumulate turns
         # Note that all relevant conjuncts must be true, so this
         # is an intersection of when the individual conjuncts
         # could be true.
         turnsPossible.retainAll(turns)
     return turnsPossible