コード例 #1
0
 def restrictDomainsToUsefulValues(cls, oldModel):
     """ generated source for method restrictDomainsToUsefulValues """
     #  Start with everything from the current domain model.
     neededAndPossibleConstantsByForm = Maps.newHashMap()
     for form in oldModel.getSentenceForms():
         neededAndPossibleConstantsByForm.put(form, HashMultimap.create())
         addDomain(neededAndPossibleConstantsByForm.get(form), oldModel.getDomain(form), form)
     # 
     # 		 * To minimize the contents of the domains, we repeatedly go through two processes to reduce
     # 		 * the domain:
     # 		 *
     # 		 * 1) We remove unneeded constants from the domain. These are constants which (in their
     # 		 *    position) do not contribute to any sentences with a GDL keyword as its name; that
     # 		 *    is, it never matters whether a sentence with that constant in that position is
     # 		 *    true or false.
     # 		 * 2) We remove impossible constants from the domain. These are constants which cannot
     # 		 *    end up in their position via any rule or sentence in the game description, given
     # 		 *    the current domain.
     # 		 *
     # 		 * Constants removed because of one type of pass or the other may cause other constants
     # 		 * in other sentence forms to become unneeded or impossible, so we make multiple passes
     # 		 * until everything is stable.
     # 		 
     somethingChanged = True
     while somethingChanged:
         somethingChanged = removeUnneededConstants(neededAndPossibleConstantsByForm, oldModel)
         somethingChanged |= removeImpossibleConstants(neededAndPossibleConstantsByForm, oldModel)
     return toSentenceDomainModel(neededAndPossibleConstantsByForm, oldModel)
コード例 #2
0
 def getDependencyGraph(cls, sentenceForms, rulesByForm):
     """ generated source for method getDependencyGraph """
     dependencyGraph = HashMultimap.create()
     for entry in rulesByForm.entries():
         for bodyLiteral in rule.getBody():
             dependencyGraph.putAll(head, getSentenceFormsInBody(bodyLiteral, sentenceForms))
     return ImmutableSetMultimap.copyOf(dependencyGraph)
コード例 #3
0
 def copyOf(cls, other):
     """ generated source for method copyOf """
     if isinstance(other, (ImmutableConstantChecker, )):
         return other
     model = other.getSentenceFormModel()
     sentencesByForm = HashMultimap.create()
     for form in other.getConstantSentenceForms():
         sentencesByForm.putAll(form, other.getTrueSentences(form))
     return ImmutableConstantChecker(ImmutableSentenceFormModel.copyOf(model), ImmutableSetMultimap.copyOf(sentencesByForm))
コード例 #4
0
 def removeUnneededConstants(cls, curDomains, model):
     """ generated source for method removeUnneededConstants """
     newNeededConstantsByForm = Maps.newHashMap()
     for form in curDomains.keySet():
         newNeededConstantsByForm.put(form, HashMultimap.create())
     populateInitialNeededConstants(newNeededConstantsByForm, curDomains, model)
     somethingChanged = True
     while somethingChanged:
         somethingChanged = propagateNeededConstants(newNeededConstantsByForm, curDomains, model)
     return retainNewDomains(curDomains, newNeededConstantsByForm)
コード例 #5
0
 def augmentGraphWithLanguageRules(cls, dependencyGraph, sentenceForms):
     """ generated source for method augmentGraphWithLanguageRules """
     newGraph = HashMultimap.create()
     newGraph.putAll(dependencyGraph)
     for form in sentenceForms:
         if form.__name__ == GdlPool.TRUE:
             if sentenceForms.contains(nextForm):
                 newGraph.put(form, nextForm)
         elif form.__name__ == GdlPool.DOES:
             if sentenceForms.contains(legalForm):
                 newGraph.put(form, legalForm)
     return newGraph
コード例 #6
0
ファイル: DependencyGraphsTest.py プロジェクト: hobson/ggpy
 def testSafeToposort(self):
     """ generated source for method testSafeToposort """
     allElements = Sets.newHashSet(1, 2, 3, 4, 5, 6, 7, 8)
     graph = HashMultimap.create()
     graph.put(2, 1)
     graph.put(3, 2)
     graph.put(4, 2)
     graph.put(5, 3)
     graph.put(5, 4)
     graph.put(3, 4)
     graph.put(4, 3)
     graph.put(4, 6)
     graph.put(6, 7)
     graph.put(7, 8)
     graph.put(8, 3)
     print DependencyGraphs.toposortSafe(allElements, graph)
コード例 #7
0
ファイル: GdlSentenceSet.py プロジェクト: hobson/ggpy
 def __init__(self):
     """ generated source for method __init__ """
     self.sentences = HashMultimap.create()
     self.functionInfoMap = Maps.newHashMap()
コード例 #8
0
ファイル: DependencyGraphs.py プロジェクト: hobson/ggpy
 def reverseGraph(cls, graph):
     """ generated source for method reverseGraph """
     return Multimaps.invertFrom(graph, HashMultimap.create())
コード例 #9
0
ファイル: DependencyGraphs.py プロジェクト: hobson/ggpy
 def createStrataDependencyGraph(cls, dependencyGraph):
     """ generated source for method createStrataDependencyGraph """
     strataDependencyGraph = HashMultimap.create()
     for entry in dependencyGraph.entries():
         strataDependencyGraph.put(ImmutableSet.of(entry.getKey()), ImmutableSet.of(entry.getValue()))
     return strataDependencyGraph
コード例 #10
0
ファイル: ConstantCheckerFactory.py プロジェクト: hobson/ggpy
 def createWithProver(cls, model):
     """ generated source for method createWithProver """
     sentencesByForm = HashMultimap.create()
     addSentencesTrueByRules(sentencesByForm, model)
     return ImmutableConstantChecker.create(model, sentencesByForm)