n most situations, a single cost function will not be sufficient to produce complex vehicle behavior. In this quiz, we'd like you to implement one more cost function in C++. We will use these two C++ cost functions later in the lesson. The goal with this quiz is to create a cost function that would make the vehicle drive in the fastest possible lane, given several behavior options. We will provide the following four inputs to the function:

  • Target speed: Currently set as 10 (unitless), the speed at which you would like the vehicle to travel.
  • 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.
  • A vector of lane speeds, based on traffic in that lane: {6, 7, 8, 9}.

Your task in the implementation will be to create a cost function that satisifes:

  • The cost decreases as both intended lane and final lane are higher speed lanes.
  • 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 inefficiency_cost (int target_speed, int intended_lane,int final_lane, vector<int> lane_speeds)
{
float speed_intended=lane_speeds[intended_lane];
float speed_final=lane_speeds[final_lane];
float cost=(2.0*target_speed-speed_intended-speed_final)/target_speed;
return cost;
}

behavior planning——14.implement a cost function in C++的更多相关文章

  1. 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 i ...

  2. behavior planning——11 create a cost function speed penalty

    A  key part of getting transitions to happen when we want  them to is the design of reasonable cost ...

  3. behavior planning——15.cost function design weightTweaking

    Designing cost functions is difficult and getting them all to cooperate to produce reasionable vehic ...

  4. behavior planning——12.example cost funtion -lane change penalty

      In the image above, the blue self driving car (bottom left) is trying to get to the goal (gold sta ...

  5. machine learning(11) -- classification: advanced optimization 去求cost function最小值的方法

    其它的比gradient descent快, 在某些场合得到广泛应用的求cost function的最小值的方法 when have a large machine learning problem, ...

  6. behavior planning——10 behaior planning pseudocode

    One way to implement a transition function is by generating rough trajectories for each accessible & ...

  7. loss function与cost function

    实际上,代价函数(cost function)和损失函数(loss function 亦称为 error function)是同义的.它们都是事先定义一个假设函数(hypothesis),通过训练集由 ...

  8. 【caffe】loss function、cost function和error

    @tags: caffe 机器学习 在机器学习(暂时限定有监督学习)中,常见的算法大都可以划分为两个部分来理解它 一个是它的Hypothesis function,也就是你用一个函数f,来拟合任意一个 ...

  9. 逻辑回归损失函数(cost function)

    逻辑回归模型预估的是样本属于某个分类的概率,其损失函数(Cost Function)可以像线型回归那样,以均方差来表示:也可以用对数.概率等方法.损失函数本质上是衡量”模型预估值“到“实际值”的距离, ...

随机推荐

  1. Redis分布式锁的实现及注意事项

    一.前言 分布式锁一般有三种实现方式: 1. 数据库乐观锁: 2. 基于Redis的分布式锁: 3. 基于ZooKeeper的分布式锁. 本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上 ...

  2. PHP的注释规范

    <?php //注释规范 /** *函数的功能 *@param 参数类型 参数名1 参数解析 *@param 参数类型 参数名2 参数解析 *@return 返回值类型 返回值解析 *@auth ...

  3. (转载)http压缩 Content-Encoding: gzip

    (内容转自http://liuviphui.blog.163.com/blog/static/20227308420141843933379/) HTTP内容编码和HTTP压缩的区别 HTTP压缩,在 ...

  4. 统计Linux下的CPU状态信息

    def cpu(): all_cpus=[] with open('e:/cpu.txt') as f: core={} for line in f.readlines(): ab=line.spli ...

  5. [MySQL] TRUNCATE数据库所有表,打印所有TRUNCATE表语句

    将XXX替换成数据库名称,然后执行SQL,将执行结果拷贝出来执行就可以TRUNCATE数据库所有表了. select CONCAT('truncate table XXX.',TABLE_NAME,' ...

  6. oracle包头包体

    补充说明:包头和包体可以以java的接口来理解,包头像java的接口,包体像java接口的实现类. 一 包的组成 包头(package):包头部分申明包内数据类型,常量,变量,游标,子程序和异常错误处 ...

  7. Python 运算符首尾匹配

  8. NOIP模拟 7.04

    魔术球问题弱化版(ball.c/.cpp/.pas) [题目描述] 假设有 n 根柱子,现要按下述规则在这 n 根柱子中依次放入编号为 1,2,3,…的球. (1)每次只能在某根柱子的最上面放球. ( ...

  9. saltstack+python批量修改服务器密码

    saltstack安装:略过 python脚本修改密码: # -*- coding utf-8 -*- import socket import re import os import sys imp ...

  10. SSH免密码登录的方法

    在你的自己的机器下面使用ssh-keygen命令来实现创建公钥 将你~/.ssh目录中的id_rsa.pub这个文件拷贝到你要登录的服务器的~/.ssh目录中,然 后再运行以下命令来将公钥导入到~/. ...