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


Python Stats.stat_node_ignoring方法代码示例

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


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

示例1: __init__

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import stat_node_ignoring [as 别名]

#.........这里部分代码省略.........
                return None
            fringe.print_contents()

            currNode = fringe.pop()
            if (problem.is_goal(currNode)):
                return self.path(root, currNode)
            successors = self.expand(problem, currNode)
            if problem.maximum_depth > 0 and len([x for x in successors if x.depth > problem.maximum_depth]) > 0:
                return None
            fringe.extend(successors)

    def graphsearch(self, problem, strategy):
        """
        Searches for a solution to the given problem using the graphsearch
        algorithm and a given search strategy.
        """
        root = Node(problem.start_state, None, Action(0, None))
        self.stats.stat_node_creation(root)
        fringe = Fringe(strategy)
        fringe.insert(root)
        closed = set([])
        while True:
            if fringe == []:
                return None
            fringe.print_contents()

            currNode = fringe.pop()

            if (problem.is_goal(currNode)):
                return self.path(root, currNode)

            if not currNode.state in closed:
                closed.add(currNode.state)

                successors = self.expand(problem, currNode)
                accepted_successors = [item for item in successors if not item.state in closed]
                rejected_successors = [item for item in successors if item.state in closed]
                self.stats.stat_node_deletion(rejected_successors)

                if problem.maximum_depth > 0 and len([x for x in accepted_successors if x.depth > problem.maximum_depth]) > 0:
                    return None
                fringe.extend(accepted_successors)
            else:
                self.stats.stat_node_ignoring(currNode)

    def RBFS(self, problem):
        """
        Searches for a solution to the given problem using the RBFS algorithm.
        """
        def recursion(problem, cNode, cLimit):
            if problem.is_goal(cNode):
                return ([cNode], 0)

            successors = self.expand(problem, cNode)
            if successors == []:
                return (None, INFINITY)
            for node in successors:
                node.f = max(cNode.f, problem.f(node))

            while True:
                successors.sort(key=lambda x: x.f)
                best = successors[0]
                if best.f > cLimit:
                    self.stats.stat_node_deletion(successors)
                    return (None, best.f)
                limit = min(cLimit, successors[1].f) if len(successors) > 1 else cLimit
                rnl, rlim = recursion(problem, best, limit)
                if rnl != None:
                    rnl.insert(0, cNode)
                    return (rnl, 0)
                best.f = rlim

        root = Node(problem.start_state, None, Action(0, None))
        self.stats.stat_node_creation(root)
        return recursion(problem, root, INFINITY)[0][1:]

    def iterative_deepening(self, problem, max_depth=1):
        """
        Searches for a solution to the given problem using the Iterative
        Deepening search algorithm.
        """
        if max_depth > problem.maximum_depth:
            return None
        created_nodes_start = self.stats.created_nodes
        root = Node(problem.start_state, None, Action(0, None))
        fringe = Fringe(SearchStrategy.DEPTH_FIRST)
        fringe.insert(root)
        while True:
            if fringe.empty():
                break
            fringe.print_contents()

            currNode = fringe.pop()
            if (problem.is_goal(currNode)):
                return self.path(root, currNode)
            if currNode.depth <= max_depth:
                fringe.extend(self.expand(problem, currNode))
        self.stats.deleted_nodes += self.stats.created_nodes - created_nodes_start
        self.stats.calc_memory_usage()
        return self.iterative_deepening(problem, max_depth+1)
开发者ID:janstrohbeck,项目名称:problemsolver,代码行数:104,代码来源:problemsolver.py


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