zoukankan      html  css  js  c++  java
  • behavior planning——10 behaior planning pseudocode

    One way to implement a transition function is by generating rough trajectories for each accessible "next state" and then finding the best. To "find the best" we generally use cost functions. We can then figure out how costly each rough trajectory is and then select the state with the lowest cost trajectory.

    We'll discuss this in more detail later, but first read carefully through the pseudocode below to get a better sense for how a transition function might work.

    def transition_function(predictions, current_fsm_state, current_pose, cost_functions, weights):
        # only consider states which can be reached from current FSM state.
        possible_successor_states = successor_states(current_fsm_state)
    
        # keep track of the total cost of each state.
        costs = []
        for state in possible_successor_states:
            # generate a rough idea of what trajectory we would
            # follow IF we chose this state.
            trajectory_for_state = generate_trajectory(state, current_pose, predictions)
    
            # calculate the "cost" associated with that trajectory.
            cost_for_state = 0
            for i in range(len(cost_functions)) :
                # apply each cost function to the generated trajectory
                cost_function = cost_functions[i]
                cost_for_cost_function = cost_function(trajectory_for_state, predictions)
    
                # multiply the cost by the associated weight
                weight = weights[i]
                cost_for_state += weight * cost_for_cost_function
             costs.append({'state' : state, 'cost' : cost_for_state})
    
        # Find the minimum cost state.
        best_next_state = None
        min_cost = 9999999
        for i in range(len(possible_successor_states)):
            state = possible_successor_states[i]
            cost  = costs[i]
            if cost < min_cost:
                min_cost = cost
                best_next_state = state 
    
        return best_next_state

    Obviously we are glossing over some important details here. Namely: what are these cost functions and how do we create them? We'll talk about that next!

  • 相关阅读:
    JS面向对象的程序设计
    dede 调用自定义图片时新增了很多html结构的解决方法
    dedecms arclist 栏目文章列表调用标签
    POJ 3145 Harmony Forever
    URAL K-based Numbers(1-3)
    POj 3420
    Ural 1004 FLOYD最小环问题
    noip2016提高组总结
    POJ 2566 Bound Found
    POJ 1639度限制生成树
  • 原文地址:https://www.cnblogs.com/fuhang/p/8983828.html
Copyright © 2011-2022 走看看