当前位置: 首页>>代码示例>>Python>>正文


Python HashSet.removeAll方法代码示例

本文整理汇总了Python中java.util.HashSet.removeAll方法的典型用法代码示例。如果您正苦于以下问题:Python HashSet.removeAll方法的具体用法?Python HashSet.removeAll怎么用?Python HashSet.removeAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.HashSet的用法示例。


在下文中一共展示了HashSet.removeAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GameFlow

# 需要导入模块: from java.util import HashSet [as 别名]
# 或者: from java.util.HashSet import removeAll [as 别名]
class GameFlow(object):
    """ generated source for class GameFlow """
    INIT = GdlPool.getConstant("init")
    TRUE = GdlPool.getConstant("true")
    NEXT = GdlPool.getConstant("next")
    turnAfterLast = int()

    # We end with a loop
    sentencesTrueByTurn = ArrayList()

    # The non-constant ones
    formsControlledByFlow = Set()
    constantForms = Set()
    constantChecker = ConstantChecker()

    def __init__(self, description):
        """ generated source for method __init__ """
        description = GdlCleaner.run(description)
        description = DeORer.run(description)
        description = VariableConstrainer.replaceFunctionValuedVariables(description)
        # First we use a sentence model to get the relevant sentence forms
        model = SentenceDomainModelFactory.createWithCartesianDomains(description)
        self.formsControlledByFlow = HashSet()
        self.formsControlledByFlow.addAll(model.getIndependentSentenceForms())
        self.formsControlledByFlow.removeAll(model.getConstantSentenceForms())
        self.constantForms = model.getConstantSentenceForms()
        self.constantChecker = ConstantCheckerFactory.createWithForwardChaining(model)
        # Figure out which of these sentences are true at each stage
        solveTurns(model)

    def solveTurns(self, model):
        """ generated source for method solveTurns """
        # Before we can do anything else, we need a topological ordering on our forms
        ordering = getTopologicalOrdering(model.getIndependentSentenceForms(), model.getDependencyGraph())
        ordering.retainAll(self.formsControlledByFlow)
        # Let's add function info to the consideration...
        functionInfoMap = HashMap()
        for form in constantForms:
            functionInfoMap.put(form, FunctionInfoImpl.create(form, self.constantChecker))
        # First we set the "true" values, then we get the forms controlled by the flow...
        # Use "init" values
        trueFlowSentences = HashSet()
        for form in constantForms:
            if form.__name__ == self.INIT:
                for initSentence in constantChecker.getTrueSentences(form):
                    trueFlowSentences.add(trueSentence)
        # Go through ordering, adding to trueFlowSentences
        addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap)
        self.sentencesTrueByTurn.add(trueFlowSentences)
        while True:
            # Now we use the "next" values from the previous turn
            trueFlowSentences = HashSet()
            for sentence in sentencesPreviouslyTrue:
                if sentence.__name__ == self.NEXT:
                    trueFlowSentences.add(trueSentence)
            addSentenceForms(ordering, trueFlowSentences, model, functionInfoMap)
            # Test if this turn's flow is the same as an earlier one
            while i < len(self.sentencesTrueByTurn):
                if prevSet == trueFlowSentences:
                    # Complete the loop
                    self.turnAfterLast = i
                    break
                i += 1
            self.sentencesTrueByTurn.add(trueFlowSentences)

    @SuppressWarnings("unchecked")
    def addSentenceForms(self, ordering, trueFlowSentences, model, functionInfoMap):
        """ generated source for method addSentenceForms """
        for curForm in ordering:
            # Check against trueFlowSentences, add to trueFlowSentences
            # or check against constantForms if necessary
            # Use basic Assignments class, of course
            for alwaysTrueSentences in model.getSentencesListedAsTrue(curForm):
                trueFlowSentences.add(alwaysTrueSentences)
            for rule in model.getRules(curForm):
                while asnItr.hasNext():
                    if trueFlowSentences.contains(transformedHead):
                        asnItr.changeOneInNext(varsInHead, assignment)
                    # Go through the conjuncts
                    for literal in rule.getBody():
                        if isinstance(literal, (GdlSentence, )):
                            if curForm.matches(literal):
                                raise RuntimeException("Haven't implemented recursion in the game flow")
                            if self.constantForms.contains(conjForm):
                                if not self.constantChecker.isTrueConstant(transformed):
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                            else:
                                if not trueFlowSentences.contains(transformed):
                                    # False sentence
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                        elif isinstance(literal, (GdlNot, )):
                            if self.constantForms.contains(conjForm):
                                if self.constantChecker.isTrueConstant(transformed):
                                    isGoodAssignment = False
                                    asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment)
                            else:
                                if trueFlowSentences.contains(transformed):
                                    # False sentence
#.........这里部分代码省略.........
开发者ID:hobson,项目名称:ggpy,代码行数:103,代码来源:GameFlow.py


注:本文中的java.util.HashSet.removeAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。