zoukankan      html  css  js  c++  java
  • behavior planning——13. implement a cost function in C++

    In the previous quizzes, you designed a cost function to choose a lane when trying to reach a goal in highway driving:

    cost=1eΔd​​​​/​Δs

    Here, Δ was the lateral distance between the goal lane and the final chosen lane, and Δ was the longitudinal distance from the vehicle to the goal.

    In this quiz, we'd like you to implement the cost function in C++, but with one important change. The finite state machine we use for vehicle behavior also includes states for planning a lane change right or left (PLCR or PLCL), and the cost function should incorporate this information. We will provide the following four inputs to the function:

    • Intended lane: the intended lane for the given behavior. For PLCR, PLCL, LCR, and LCL, this would be the one lane over from the current lane.
    • Final lane: the immediate resulting lane of the given behavior. For LCR and LCL, this would be one lane over.
    • The Δdistance to the goal.
    • The goal lane.

    Your task in the implementation will be to modify Δd in the equation above so that it satisifes:

    • Δis smaller as both intended lane and final lane are closer to the goal lane.
    • The cost function provides different costs for each possible behavior: KL, PLCR/PLCL, LCR/LCL.
    • The values produced by the cost function are in the range 0 to 1.

    You can implement your solution in cost.cpp below.

     cost.cpp

    float goal_distance_cost(int goal_lane, int intended_lane, int final_lane, float distance_to_goal) {
        /*
        The cost increases with both the distance of intended lane from the goal
        and the distance of the final lane from the goal. The cost of being out of the 
        goal lane also becomes larger as vehicle approaches the goal.
        */
        int delta_d = 2.0*goal_lane - intended_lane - final_lane;
        float cost = 1 - exp(-(abs(delta_d) / distance_to_goal));
        return cost;
    }
  • 相关阅读:
    MySQL-Linux升级MySQL
    查看linux 版本
    mysql 密码找回方法
    CentOS7.6利用systemctl添加自定义系统服务
    centos7.6下定时监测MySQL进程终止后自动重启的方法
    Linux实操篇-Linux磁盘分区、挂载
    阿里云centos7.6下MongoDB安装和配置
    Linux中文件权限 chmod、u+x、u、r、w、x分别代表什么
    ABP 发布以后nlog4.NET写入不到日志文件里
    Android studio gradle 下载很缓慢的解决方法,gradle版本不对
  • 原文地址:https://www.cnblogs.com/fuhang/p/8984638.html
Copyright © 2011-2022 走看看