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


Python Sliding.hash_to_board方法代码示例

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


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

示例1: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """ YOUR CODE HERE """
    return_list = [value]
    children = Sliding.children(HEIGHT, WIDTH, Sliding.hash_to_board(WIDTH, HEIGHT, value[0]))
    for child in children:
        return_list.append((Sliding.board_to_hash(WIDTH, HEIGHT, child), value[1]+1))
    return return_list
开发者ID:rtadinada,项目名称:cs61c-proj2-1,代码行数:9,代码来源:SlidingBfsSpark.py

示例2: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """ YOUR CODE HERE """
    result = []
    if value[1] == level - 1:
        result = Sliding.children(WIDTH, HEIGHT, Sliding.hash_to_board(WIDTH, HEIGHT, value[0]))
        for i in range(0, len(result)):
            result[i] = (Sliding.board_to_hash(WIDTH, HEIGHT, result[i]), level)
    result.append(value)
    return result
开发者ID:podfog,项目名称:SchoolWork,代码行数:11,代码来源:SlidingBfsSpark.py

示例3: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value): #value is the (puzzle, level) tuple
    """ YOUR CODE HERE """ 
    lst = [(value)]
    if value[1] == level: 
        children = Sliding.children(WIDTH,HEIGHT,Sliding.hash_to_board(WIDTH, HEIGHT, value[0])) 
        for child in children:
            lst.append((Sliding.board_to_hash(WIDTH, HEIGHT, child),level+1))    
        return lst
    return lst
开发者ID:shauryakalsi,项目名称:CS61C,代码行数:11,代码来源:SlidingBfsSpark.py

示例4: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """ YOUR CODE HERE """
    if (value[1] != (level - 1)):
   	    return [value]
    else:
    	children = Sliding.children(WIDTH, HEIGHT, Sliding.hash_to_board(WIDTH,HEIGHT,value[0]))    
        childList = [value]
        for child in children:
        	childList.append((Sliding.board_to_hash(WIDTH,HEIGHT,child), level))
        return childList
开发者ID:Jananiravichandran,项目名称:cs61c,代码行数:12,代码来源:SlidingBfsSpark.py

示例5: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """ YOUR CODE HERE """
    mapVal = []
    mapVal.append((value[0], value[1]))
    if value[1] == level:
        pos = Sliding.hash_to_board(WIDTH, HEIGHT, value[0])
        for cpos in Sliding.children(WIDTH, HEIGHT, pos):
            cpos2 = Sliding.board_to_hash(WIDTH, HEIGHT, cpos)
            mapVal.append((cpos2,level+1))
    return mapVal
开发者ID:aparsrinara,项目名称:slidingBlockPuzzle,代码行数:12,代码来源:SlidingBfsSpark.py

示例6: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    items = []
    if value[1] < level: 
        items.append((value[0],value[1]))
    if value[1] == level-1:
        children_board = Sliding.hash_to_board(WIDTH, HEIGHT, value[0])
        children = Sliding.children(WIDTH, HEIGHT, children_board)
        for child in children:
            items.append((Sliding.board_to_hash(WIDTH, HEIGHT, child), value[1] + 1))
    return items
开发者ID:poywoo,项目名称:61cproj2-2,代码行数:12,代码来源:SlidingBfsSpark.py

示例7: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """ YOUR CODE HERE """
    prev = [(value[0], value[1])]
    if value[1] == level:
        #convert from int to board
        # do I save it, not sure? ask Manny , using hashID since it was declared down?
        hashID = Sliding.board_to_hash(WIDTH, HEIGHT, prev[0][0]) #value[0]
        currBoard = Sliding.hash_to_board(WIDTH, HEIGHT, hashID) # ask manny if this is the correct to call this method
        # also what would number be?
        children = Sliding.children(WIDTH, HEIGHT, currBoard) # not sure value[0], currBoard
        #nextID = Sliding.board_to_hash(WIDTH, HEIGHT, children)
        curr = []
        for i in range(0, len(children)):
            curr.append((children[i], level+1))
        return prev + curr
    #nextID = Sliding.board_to_hash(WIDTH, HEIGHT, children[0]) #children[0]
    return prev
开发者ID:warlck,项目名称:cs61c,代码行数:19,代码来源:SlidingBfsSpark.py

示例8: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """
    Takes in a key, value pair of (board state, level), creates
    all of the children of that board state if is on the same level as the
    global level, and returns them in a list.
    """
    """ YOUR CODE HERE """
    child_list = []
    #Check if we are at the right level, so then we can make children of only those boards
    if value[1] == level:
        temp = Sliding.hash_to_board(WIDTH, HEIGHT, value[0])
        iter_list = Sliding.children(WIDTH, HEIGHT, temp)
        for child in iter_list:
            child_list += [(Sliding.board_to_hash(WIDTH,HEIGHT, child), level + 1)]
    #Spark map only lets us return a list if we want multiple things.
    #Unlike Hadoop I believe which allows us to emit
    return child_list
开发者ID:rtadinada,项目名称:GamesmanSpark,代码行数:19,代码来源:SlidingBfsSpark.py

示例9: solve_sliding_puzzle

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def solve_sliding_puzzle(master, output, height, width):
    """
    Solves a sliding puzzle of the provided height and width.
     master: specifies master url for the spark context
     output: function that accepts string to write to the output file
     height: height of puzzle
     width: width of puzzle
    """
    # Set up the spark context. Use this to create your RDD
    sc = SparkContext(master, "python")

    # Global constants that will be shared across all map and reduce instances.
    # You can also reference these in any helper functions you write.
    global HEIGHT, WIDTH, level

    # Initialize global constants
    HEIGHT=height
    WIDTH=width
    level = 0 # this "constant" will change, but it remains constant for every MapReduce job

    # The solution configuration for this sliding puzzle. You will begin exploring the tree from this node
    sol = Sliding.solution(WIDTH, HEIGHT)


    """ YOUR MAP REDUCE PROCESSING CODE HERE """
    myRdd = sc.parallelize([(sol, level)]) # myRdd = [(('A', 'B', 'C', '-'), 0)]
    myRdd = myRdd.flatMap(bfs_flat_map).reduceByKey(bfs_reduce)
    prev_num = 0
    pos_num = myRdd.count()

    while prev_num != pos_num:
        level+=1
        prev_num = pos_num
        myRdd = myRdd.flatMap(bfs_flat_map)
        if level%4==0:
            myRdd = myRdd.partitionBy(16)
        myRdd = myRdd.reduceByKey(bfs_reduce)
        pos_num = myRdd.count()

    """ YOUR OUTPUT CODE HERE """
    # myRdd = myRdd.map(lambda a: (a[1], a[0])).sortByKey().collect() # myRdd becomes a list
    # for each in myRdd:
    #     output(str(each[0]) + " " + str(each[1]))
    myRdd = myRdd.map(lambda a: (Sliding.hash_to_board(WIDTH, HEIGHT, a[1]), a[0])).sortByKey()
    sc.stop()
开发者ID:SanityL,项目名称:Projects,代码行数:47,代码来源:SlidingBfsSpark.py

示例10: bfs_flat_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_flat_map(value):
    """ YOUR CODE HERE """
    # childrenLst=[]    
    # childrenLst.append(value)
    # for child in Sliding.children(WIDTH,HEIGHT,Sliding.hash_to_board(WIDTH, HEIGHT, value[0])):
    #     pair=[]
    #     pair.append(Sliding.board_to_hash(WIDTH, HEIGHT, child))
    #     pair.append(level)     
    #     childrenLst.append(tuple(pair))
       
    # return childrenLst

    childrenLst = []
    childrenLst.append((value[0], value[1]))
    if(value[1] == level - 1):
        for child in Sliding.children(WIDTH, HEIGHT, Sliding.hash_to_board(WIDTH,HEIGHT, value[0])):
            childrenLst.append((Sliding.board_to_hash(WIDTH,HEIGHT,child), value[1]+1))
    return childrenLst 
开发者ID:VictoriaSnow,项目名称:CS-Projects,代码行数:20,代码来源:SlidingBfsSpark.py

示例11: bfs_map

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def bfs_map(value):
    """
    value: Taken an element from RDD
    bfs_map function only applies children() to each element at the last level in RDD;
    return :If an element is not at the last level, then it will be put
    in an empty list and return;
    return :If an element is at the last level, then its children and 
    the element will be put into an empty list and return;
    """
    lst = []
    lst.append(value)
    value = (Sliding.hash_to_board(WIDTH,HEIGHT,value[0]), value[1])
    if (value[1] < level):
        return lst
    children = Sliding.children(WIDTH, HEIGHT, value[0])
    for each in children:
        lst.append(((Sliding.board_to_hash(WIDTH, HEIGHT, tuple(each))), value[1]+1))
    return lst
开发者ID:ShihengJiang666,项目名称:proj2-2CodeToRunOnAmazonServer,代码行数:20,代码来源:SlidingBfsSpark.py

示例12: solve_puzzle

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def solve_puzzle(master, output, height, width, slaves):
    global HEIGHT, WIDTH, level
    HEIGHT=height
    WIDTH=width
    level = 0

    sc = SparkContext(master, "python")

    sol = Sliding.solution(WIDTH, HEIGHT)
    
    frontierRDD = sc.parallelize([(Sliding.board_to_hash(WIDTH, HEIGHT, sol), 0)])
    boardsRDD = sc.parallelize([(Sliding.board_to_hash(WIDTH, HEIGHT, sol), 0)])
    #while frontierRDD.count() != 0:
    while True:
        level += 1
            
        # get all frontier nodes as a flattened list of ONLY (key), NOT (key, value)
        frontierRDD = frontierRDD.flatMap(lambda v: Sliding.children(WIDTH, HEIGHT, Sliding.hash_to_board(WIDTH, HEIGHT, v[0])))
            
        # add new (chilq, level) pairs to all boards
        boardsRDD = boardsRDD + frontierRDD.map(lambda v: (Sliding.board_to_hash(WIDTH, HEIGHT, v), level))
        #boardsRDD = boardsRDD.partitionBy(8, partitionFunc)
            
        # only keep board seen at lowest level
        boardsRDD = boardsRDD.reduceByKey(lambda v1, v2: min(v1, v2))

        # frontier is only the boards that have the current level
        frontierRDD = boardsRDD.filter(lambda v: v[1] == level)

        # magic voodoo that it doesn't work without
        boardsRDD = boardsRDD.partitionBy(slaves, lambda v: v)
        frontierRDD = frontierRDD.partitionBy(slaves, lambda v: v)
        if level % 4 == 0 and frontierRDD.count() == 0:
            break

    boardsRDD.coalesce(slaves).saveAsTextFile(output)
    sc.stop()
开发者ID:logicx24,项目名称:proj2-2,代码行数:39,代码来源:SlidingBfsSpark.py

示例13: get_board

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def get_board(state):
    """Abstraction for obtaining the board of a
    state representation
    """
    return Sliding.hash_to_board(WIDTH, HEIGHT, state[0])
开发者ID:hansongcal,项目名称:CS61C,代码行数:7,代码来源:SlidingBfsSpark.py

示例14: hash_to_board

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
	def hash_to_board(state):
		return Sliding.hash_to_board(width, height, state)
开发者ID:neoluc,项目名称:spark-n-puzzle-solver,代码行数:4,代码来源:SlidingBfsSpark.py

示例15: revert_back

# 需要导入模块: import Sliding [as 别名]
# 或者: from Sliding import hash_to_board [as 别名]
def revert_back(value):
    return str(value[1]) + " " + str(Sliding.hash_to_board(WIDTH, HEIGHT, value[0]))
开发者ID:ShihengJiang666,项目名称:proj2-2CodeToRunOnAmazonServer,代码行数:4,代码来源:SlidingBfsSpark.py


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