Exemple #1
0
 def applyAmbiguities(cls, originalRule, ambiguitiesByOriginalForm, model):
     """ generated source for method applyAmbiguities """
     rules = Lists.newArrayList(originalRule)
     # Each literal can potentially multiply the number of rules we have, so
     # we apply each literal separately to the entire list of rules so far.
     for literal in Iterables.concat(ImmutableSet.of(originalRule.getHead()), originalRule.getBody()):
         for rule in rules:
             Preconditions.checkArgument(originalRule.arity() == rule.arity())
             newRules.addAll(applyAmbiguitiesForLiteral(literal, rule, ambiguitiesByOriginalForm, model))
         rules = newRules
     return rules
Exemple #2
0
 def mergeStrata(cls, toMerge, toAdd, strataDependencyGraph):
     """ generated source for method mergeStrata """
     newStratum = ImmutableSet.copyOf(Iterables.concat(toMerge))
     for oldStratum in toMerge:
         toAdd.remove(oldStratum)
     toAdd.add(newStratum)
     # Change the keys
     for oldStratum in toMerge:
         strataDependencyGraph.putAll(newStratum, parents)
         strataDependencyGraph.removeAll(oldStratum)
     # Change the values
     for entry in ImmutableList.copyOf(strataDependencyGraph.entries()):
         if toMerge.contains(entry.getValue()):
             strataDependencyGraph.remove(entry.getKey(), entry.getValue())
             strataDependencyGraph.put(entry.getKey(), newStratum)
 def removeUnreachableBasesAndInputs(cls, pn, basesTrueByInit):
     """ generated source for method removeUnreachableBasesAndInputs """
     reachability = Maps.newHashMap()
     numTrueInputs = HashMultiset.create()
     numFalseInputs = HashMultiset.create()
     toAdd = Stack()
     legalsToInputs = Maps.newHashMap()
     for legalProp in Iterables.concat(pn.getLegalPropositions().values()):
         if inputProp != None:
             legalsToInputs.put(legalProp, inputProp)
     for c in pn.getComponents():
         ConcurrencyUtils.checkForInterruption()
         if isinstance(c, (Constant, )):
             if c.getValue():
                 toAdd.add(Pair.of(c, cls.Type.TRUE))
             else:
                 toAdd.add(Pair.of(c, cls.Type.FALSE))
     for p in pn.getInputPropositions().values():
         toAdd.add(Pair.of(p, cls.Type.FALSE))
     for baseProp in pn.getBasePropositions().values():
         if basesTrueByInit.contains(baseProp):
             toAdd.add(Pair.of(baseProp, cls.Type.TRUE))
         else:
             toAdd.add(Pair.of(baseProp, cls.Type.FALSE))
     initProposition = pn.getInitProposition()
     toAdd.add(Pair.of(initProposition, cls.Type.BOTH))
     while not toAdd.isEmpty():
         ConcurrencyUtils.checkForInterruption()
         if oldType == None:
             oldType = cls.Type.NEITHER
         if isinstance(curComp, (Proposition, )):
             typeToAdd = newInputType
         elif isinstance(curComp, (Transition, )):
             typeToAdd = newInputType
         elif isinstance(curComp, (Constant, )):
             typeToAdd = newInputType
         elif isinstance(curComp, (Not, )):
             typeToAdd = newInputType.opposite()
         elif isinstance(curComp, (And, )):
             if newInputType.hasTrue:
                 numTrueInputs.add(curComp)
                 if numTrueInputs.count(curComp) == curComp.getInputs().size():
                     typeToAdd = cls.Type.TRUE
             if newInputType.hasFalse:
                 typeToAdd = typeToAdd.with_(cls.Type.FALSE)
         elif isinstance(curComp, (Or, )):
             if newInputType.hasFalse:
                 numFalseInputs.add(curComp)
                 if numFalseInputs.count(curComp) == curComp.getInputs().size():
                     typeToAdd = cls.Type.FALSE
             if newInputType.hasTrue:
                 typeToAdd = typeToAdd.with_(cls.Type.TRUE)
         else:
             raise RuntimeException("Unhandled component type " + curComp.__class__)
         if oldType.includes(typeToAdd):
             continue 
         reachability.put(curComp, typeToAdd.with_(oldType))
         typeToAdd = typeToAdd.minus(oldType)
         if typeToAdd == cls.Type.NEITHER:
             raise RuntimeException("Something's messed up here")
         for output in curComp.getOutputs():
             toAdd.add(Pair.of(output, typeToAdd))
         if legalsToInputs.containsKey(curComp):
             if inputProp == None:
                 raise IllegalStateException()
             toAdd.add(Pair.of(inputProp, typeToAdd))
     trueConst = Constant(True)
     falseConst = Constant(False)
     pn.addComponent(trueConst)
     pn.addComponent(falseConst)
     for entry in reachability.entrySet():
         if type_ == cls.Type.TRUE or type_ == cls.Type.FALSE:
             if isinstance(c, (Constant, )):
                 continue 
             for input in c.getInputs():
                 input.removeOutput(c)
             c.removeAllInputs()
             if type_ == cls.Type.TRUE ^ (isinstance(c, (Not, ))):
                 c.addInput(trueConst)
                 trueConst.addOutput(c)
             else:
                 c.addInput(falseConst)
                 falseConst.addOutput(c)
     cls.optimizeAwayTrueAndFalse(pn, trueConst, falseConst)
Exemple #4
0
 def getSentences(cls, rule, includeHead):
     """ generated source for method getSentences """
     if includeHead == cls.VarDomainOpts.INCLUDE_HEAD:
         return Iterables.concat(ImmutableList.of(rule.getHead()), rule.getBody())
     else:
         return rule.getBody()