Closed ibrahim-mo closed 7 years ago
Thanks for reporting this. I'm wondering if this is just timing out in the classroom. We will check on it.
Would you mind posting or linking your solution?
Hmm, that is not what happens when I paste the suggested solution. Would you mind trying again and also posting your solution?
I found a bug in my solution and I fixed it, but by then Udacity has posted a new solution which works too. Please mark this issue as resolved.
Thanks, Ibrahim
Thanks for letting us know. I’m glad it worked out!
I will be able reopen this issue later. In the meantime, let’s troubleshoot. The quiz solution is working from my accounts so we need to see if we can reproduce the error from your account. Would you mind doing the following?
Hi, I am experiencing a similar problem with the grader in this particular quiz. My code runs properly in my local machine and it also works when I test it on the platform. When I try to submit, however, I receive a "Try again" message followed by the error message I will add below.
Interestingly, even if I copy and paste the proposed solution, the same error happens.
File "", line 10, in
IndexError: list index out of range
Environment: {'executor_result': {u'vm_time': 2.4359679222106934, u'stdout': u'', u'vm_creation_time': 0.000102996826171875, u'test_results': [], u'stderr': u"vehicle.o: In function Vehicle::choose_next_state(std::map<int, std::vector<Vehicle, std::allocator<Vehicle> >, std::less<int>, std::allocator<std::pair<int const, std::vector<Vehicle, std::allocator<Vehicle> > > > >)':\nvehicle.cpp:(.text+0x5bc): undefined reference tocalculate_cost(Vehicle const&, std::map >, std::less, std::allocator > > > > const&, std::vector > const&)'\ncollect2: error: ld returned 1 exit status\n", u'exec_server_time': 2.4484999179840088, u'exec_status': u'ok'}, 'grade_result': {'comment': 'Thank you for your submission!', 'feedback': '', 'completed': None, 'test_results': [], 'bin_codes': [], 'correct': False}, 'executor_status': u'ok'}
Submission: {'_operation': 'REGRADE', u'main.cpp': u'#include "road.h"\n#include "vehicle.h"\n#include \n#include \n#include \n#include \n\nusing namespace std;\n\n//impacts default behavior for most states\nint SPEED_LIMIT = 10;\n\n//all traffic in lane (besides ego) follow these speeds\nvector LANE_SPEEDS = {6,7,8,9}; \n\n//Number of available "cells" which should have traffic\ndouble TRAFFIC_DENSITY = 0.15;\n\n// At each timestep, ego can set acceleration to value between \n// -MAX_ACCEL and MAX_ACCEL\nint MAX_ACCEL = 2;\n\n// s value and lane number of goal.\nvector GOAL = {300, 0};\n\n// These affect the visualization\nint FRAMES_PER_SECOND = 4;\nint AMOUNT_OF_ROAD_VISIBLE = 40;\n\nint main() {\n \n\tRoad road = Road(SPEED_LIMIT, TRAFFIC_DENSITY, LANE_SPEEDS);\n\n\troad.update_width = AMOUNT_OF_ROAD_VISIBLE;\n\n\troad.populate_traffic();\n\n\tint goal_s = GOAL[0];\n\tint goal_lane = GOAL[1];\n\n\t//configuration data: speed limit, num_lanes, goal_s, goal_lane, max_acceleration\n\n\tint num_lanes = LANE_SPEEDS.size();\n\tvector ego_config = {SPEED_LIMIT,num_lanes,goal_s,goal_lane,MAX_ACCEL};\n\t \n\troad.add_ego(2,0, ego_config);\n\tint timestep = 0;\n\t\n\twhile (road.get_ego().s <= GOAL[0]) {\n\t\ttimestep++;\n\t\tif (timestep > 100) {\n\t\t\tbreak;\n\t\t}\n\t\troad.advance();\n\t\troad.display(timestep);\n\t\t//time.sleep(float(1.0) / FRAMES_PER_SECOND);\n\t}\n\tVehicle ego = road.get_ego();\n\tif (ego.lane == GOAL[1])\n\t{\n\t\tcout << "You got to the goal in " << timestep << " seconds!" << endl;\n\t\tif(timestep > 35)\n\t {\n\t cout << "But it took too long to reach the goal. Go faster!" << endl;\n\t }\n\t}\n\telse\n\t{\n\t\tcout << "You missed the goal. You are in lane " << ego.lane << " instead of " << GOAL[1] << "." << endl;\n\t}\n\n\treturn 0;\n}', u'vehicle.cpp': u'#include \n#include \n#include "vehicle.h"\n#include \n#include \n#include \n#include \n#include "cost.h"\n\n/\n Initializes Vehicle\n /\n\nVehicle::Vehicle(){}\n\nVehicle::Vehicle(int lane, float s, float v, float a, string state) {\n\n this->lane = lane;\n this->s = s;\n this->v = v;\n this->a = a;\n this->state = state;\n max_acceleration = -1;\n\n}\n\nVehicle::~Vehicle() {}\n\n\nvector Vehicle::choose_next_state(map> predictions) {\n /\n\n Here you can implement the transition_function code from the Behavior Planning Pseudocode\n classroom concept.\n\n INPUT: A predictions map. This is a map using vehicle id as keys with predicted\n vehicle trajectories as values. A trajectory is a vector of Vehicle objects. The first\n item in the trajectory represents the vehicle at the current timestep. The second item in\n the trajectory represents the vehicle one timestep in the future.\n OUTPUT: The the best (lowest cost) trajectory for the ego vehicle corresponding to the next ego vehicle state.\n\n Functions that will be useful:\n 1. successor_states() - Uses the current state to return a vector of possible successor states for the finite\n state machine.\n 2. generate_trajectory(string state, map> predictions) - Returns a vector of Vehicle objects\n representing a vehicle trajectory, given a state and predictions. Note that trajectory vectors\n might have size 0 if no possible trajectory exists for the state.\n 3. calculate_cost(Vehicle vehicle, map> predictions, vector trajectory) - Included from\n cost.cpp, computes the cost for a trajectory.\n /\n\n //TODO: Your solution here.\n vector possible_successor_states = successor_states();\n\n // Keep track of the total cost of each state\n vector costs;\n vector> final_trajectories;\n\n for(int i = 0; i < possible_successor_states.size(); i++) {\n // Generate the trajectory we would follow if we choose this state\n vector trajectory_for_state = generate_trajectory(possible_successor_states[i], predictions);\n\n if (trajectory_for_state.size() != 0) {\n // Calculate the cost of that trajectory\n float cost = calculate_cost(this, predictions, trajectory_for_state);\n costs.push_back(cost);\n final_trajectories.push_back(trajectory_for_state);\n }\n\n }\n\n // Find the minimum cost state\n vector::iterator best_cost = min_element(begin(costs), end(costs));\n int best_idx = distance(begin(costs), best_cost);\n\n\n //TODO: Change return value here:\n // return generate_trajectory("KL", predictions);\n return final_trajectories[best_idx];\n}\n\nvector Vehicle::successor_states() {\n /\n Provides the possible next states given the current state for the FSM\n discussed in the course, with the exception that lane changes happen\n instantaneously, so LCL and LCR can only transition back to KL.\n /\n vector states;\n states.push_back("KL");\n string state = this->state;\n if(state.compare("KL") == 0) {\n states.push_back("PLCL");\n states.push_back("PLCR");\n } else if (state.compare("PLCL") == 0) {\n if (lane != lanes_available - 1) {\n states.push_back("PLCL");\n states.push_back("LCL");\n }\n } else if (state.compare("PLCR") == 0) {\n if (lane != 0) {\n states.push_back("PLCR");\n states.push_back("LCR");\n }\n }\n //If state is "LCL" or "LCR", then just return "KL"\n return states;\n}\n\nvector Vehicle::generate_trajectory(string state, map> predictions) {\n /\n Given a possible next state, generate the appropriate trajectory to realize the next state.\n /\n vector trajectory;\n if (state.compare("CS") == 0) {\n trajectory = constant_speed_trajectory();\n } else if (state.compare("KL") == 0) {\n trajectory = keep_lane_trajectory(predictions);\n } else if (state.compare("LCL") == 0 || state.compare("LCR") == 0) {\n trajectory = lane_change_trajectory(state, predictions);\n } else if (state.compare("PLCL") == 0 || state.compare("PLCR") == 0) {\n trajectory = prep_lane_change_trajectory(state, predictions);\n }\n return trajectory;\n}\n\nvector Vehicle::get_kinematics(map> predictions, int lane) {\n /\n Gets next timestep kinematics (position, velocity, acceleration)\n for a given lane. Tries to choose the maximum velocity and acceleration,\n given other vehicle positions and accel/velocity constraints.\n /\n float max_velocity_accel_limit = this->max_acceleration + this->v;\n float new_position;\n float new_velocity;\n float new_accel;\n Vehicle vehicle_ahead;\n Vehicle vehicle_behind;\n\n if (get_vehicle_ahead(predictions, lane, vehicle_ahead)) {\n\n if (get_vehicle_behind(predictions, lane, vehicle_behind)) {\n new_velocity = vehicle_ahead.v; //must travel at the speed of traffic, regardless of preferred buffer\n } else {\n float max_velocity_in_front = (vehicle_ahead.s - this->s - this->preferred_buffer) + vehicle_ahead.v - 0.5 (this->a);\n new_velocity = min(min(max_velocity_in_front, max_velocity_accel_limit), this->target_speed);\n }\n } else {\n new_velocity = min(max_velocity_accel_limit, this->target_speed);\n }\n\n new_accel = new_velocity - this->v; //Equation: (v_1 - v_0)/t = acceleration\n new_position = this->s + new_velocity + new_accel / 2.0;\n return{new_position, new_velocity, new_accel};\n\n}\n\nvector Vehicle::constant_speed_trajectory() {\n /\n Generate a constant speed trajectory.\n /\n float next_pos = position_at(1);\n vector trajectory = {Vehicle(this->lane, this->s, this->v, this->a, this->state),\n Vehicle(this->lane, next_pos, this->v, 0, this->state)};\n return trajectory;\n}\n\nvector Vehicle::keep_lane_trajectory(map> predictions) {\n /\n Generate a keep lane trajectory.\n /\n vector trajectory = {Vehicle(lane, this->s, this->v, this->a, state)};\n vector kinematics = get_kinematics(predictions, this->lane);\n float new_s = kinematics[0];\n float new_v = kinematics[1];\n float new_a = kinematics[2];\n trajectory.push_back(Vehicle(this->lane, new_s, new_v, new_a, "KL"));\n return trajectory;\n}\n\nvector Vehicle::prep_lane_change_trajectory(string state, map> predictions) {\n /\n Generate a trajectory preparing for a lane change.\n /\n float new_s;\n float new_v;\n float new_a;\n Vehicle vehicle_behind;\n int new_lane = this->lane + lane_direction[state];\n vector trajectory = {Vehicle(this->lane, this->s, this->v, this->a, this->state)};\n vector curr_lane_new_kinematics = get_kinematics(predictions, this->lane);\n\n if (get_vehicle_behind(predictions, this->lane, vehicle_behind)) {\n //Keep speed of current lane so as not to collide with car behind.\n new_s = curr_lane_new_kinematics[0];\n new_v = curr_lane_new_kinematics[1];\n new_a = curr_lane_new_kinematics[2];\n\n } else {\n vector best_kinematics;\n vector next_lane_new_kinematics = get_kinematics(predictions, new_lane);\n //Choose kinematics with lowest velocity.\n if (next_lane_new_kinematics[1] < curr_lane_new_kinematics[1]) {\n best_kinematics = next_lane_new_kinematics;\n } else {\n best_kinematics = curr_lane_new_kinematics;\n }\n new_s = best_kinematics[0];\n new_v = best_kinematics[1];\n new_a = best_kinematics[2];\n }\n\n trajectory.push_back(Vehicle(this->lane, new_s, new_v, new_a, state));\n return trajectory;\n}\n\nvector Vehicle::lane_change_trajectory(string state, map> predictions) {\n /\n Generate a lane change trajectory.\n /\n int new_lane = this->lane + lane_direction[state];\n vector trajectory;\n Vehicle next_lane_vehicle;\n //Check if a lane change is possible (check if another vehicle occupies that spot).\n for (map>::iterator it = predictions.begin(); it != predictions.end(); ++it) {\n next_lane_vehicle = it->second[0];\n if (next_lane_vehicle.s == this->s && next_lane_vehicle.lane == new_lane) {\n //If lane change is not possible, return empty trajectory.\n return trajectory;\n }\n }\n trajectory.push_back(Vehicle(this->lane, this->s, this->v, this->a, this->state));\n vector kinematics = get_kinematics(predictions, new_lane);\n trajectory.push_back(Vehicle(new_lane, kinematics[0], kinematics[1], kinematics[2], state));\n return trajectory;\n}\n\nvoid Vehicle::increment(int dt = 1) {\n\tthis->s = position_at(dt);\n}\n\nfloat Vehicle::position_at(int t) {\n return this->s + this->vt + this->att/2.0;\n}\n\nbool Vehicle::get_vehicle_behind(map> predictions, int lane, Vehicle & rVehicle) {\n /\n Returns a true if a vehicle is found behind the current vehicle, false otherwise. The passed reference\n rVehicle is updated if a vehicle is found.\n /\n int max_s = -1;\n bool found_vehicle = false;\n Vehicle temp_vehicle;\n for (map>::iterator it = predictions.begin(); it != predictions.end(); ++it) {\n temp_vehicle = it->second[0];\n if (temp_vehicle.lane == this->lane && temp_vehicle.s < this->s && temp_vehicle.s > max_s) {\n max_s = temp_vehicle.s;\n rVehicle = temp_vehicle;\n found_vehicle = true;\n }\n }\n return found_vehicle;\n}\n\nbool Vehicle::get_vehicle_ahead(map> predictions, int lane, Vehicle & rVehicle) {\n /\n Returns a true if a vehicle is found ahead of the current vehicle, false otherwise. The passed reference\n rVehicle is updated if a vehicle is found.\n /\n int min_s = this->goal_s;\n bool found_vehicle = false;\n Vehicle temp_vehicle;\n for (map>::iterator it = predictions.begin(); it != predictions.end(); ++it) {\n temp_vehicle = it->second[0];\n if (temp_vehicle.lane == this->lane && temp_vehicle.s > this->s && temp_vehicle.s < min_s) {\n min_s = temp_vehicle.s;\n rVehicle = temp_vehicle;\n found_vehicle = true;\n }\n }\n return found_vehicle;\n}\n\nvector Vehicle::generate_predictions(int horizon) {\n /\n Generates predictions for non-ego vehicles to be used\n in trajectory generation for the ego vehicle.\n /\n\tvector predictions;\n for(int i = 0; i < horizon; i++) {\n float next_s = position_at(i);\n float next_v = 0;\n if (i < horizon-1) {\n next_v = position_at(i+1) - s;\n }\n predictions.push_back(Vehicle(this->lane, next_s, next_v, 0));\n \t}\n return predictions;\n\n}\n\nvoid Vehicle::realize_next_state(vector trajectory) {\n /\n Sets state and kinematics for ego vehicle using the last state of the trajectory.\n /\n Vehicle next_state = trajectory[1];\n this->state = next_state.state;\n this->lane = next_state.lane;\n this->s = next_state.s;\n this->v = next_state.v;\n this->a = next_state.a;\n}\n\nvoid Vehicle::configure(vector road_data) {\n /\n Called by simulator before simulation begins. Sets various\n parameters which will impact the ego vehicle.\n /\n target_speed = road_data[0];\n lanes_available = road_data[1];\n goal_s = road_data[2];\n goal_lane = road_data[3];\n max_acceleration = road_data[4];\n}\n', u'road.h': u'#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include "vehicle.h"\n\nusing namespace std;\n\nclass Road {\npublic:\n\n\tint update_width = 70;\n\n \tstring ego_rep = " ";\n\n \tint ego_key = -1;\n\n \tint num_lanes;\n\n vector lane_speeds;\n\n int speed_limit;\n\n double density;\n\n int camera_center;\n\n map vehicles;\n\n int vehicles_added = 0;\n\n /\n \t Constructor\n \t/\n \tRoad(int speed_limit, double traffic_density, vector lane_speeds);\n\n \t/\n \t Destructor\n \t/\n \tvirtual ~Road();\n\n \tVehicle get_ego();\n\n \tvoid populate_traffic();\n\n \tvoid advance();\n\n \tvoid display(int timestep);\n\n \tvoid add_ego(int lane_num, int s, vector config_data);\n\n \tvoid cull();\n\n};\n', u'cost.h': u'#ifndef COST_H\n#define COST_H\n#include "vehicle.h"\n\nusing namespace std;\n\nfloat calculate_cost(const Vehicle & vehicle, const map> & predictions, const vector & trajectory);\n\nfloat goal_distance_cost(const Vehicle & vehicle, const vector & trajectory, const map> & predictions, map & data);\n\nfloat inefficiency_cost(const Vehicle & vehicle, const vector & trajectory, const map> & predictions, map & data);\n\nfloat lane_speed(const map> & predictions, int lane);\n\nmap get_helper_data(const Vehicle & vehicle, const vector & trajectory, const map> & predictions);\n\n#endif', u'road.cpp': u'#include \n#include "road.h"\n#include "vehicle.h"\n#include \n#include \n#include \n#include \n\n\n/\n Initializes Road\n /\nRoad::Road(int speed_limit, double traffic_density, vector lane_speeds) {\n\n this->num_lanes = lane_speeds.size();\n this->lane_speeds = lane_speeds;\n this->speed_limit = speed_limit;\n this->density = traffic_density;\n this->camera_center = this->update_width/2;\n\n}\n\nRoad::~Road() {}\n\nVehicle Road::get_ego() {\n\t\n\treturn this->vehicles.find(this->ego_key)->second;\n}\n\nvoid Road::populate_traffic() {\n\t\n\tint start_s = max(this->camera_center - (this->update_width/2), 0);\n\tfor (int l = 0; l < this->num_lanes; l++)\n\t{\n\t\tint lane_speed = this->lane_speeds[l];\n\t\tbool vehicle_just_added = false;\n\t\tfor(int s = start_s; s < start_s+this->update_width; s++)\n\t\t{\n\t\t\t\n\t\t\tif(vehicle_just_added)\n\t\t\t{\n\t\t\t\tvehicle_just_added = false;\n\t\t\t}\n\t\t\tif(((double) rand() / (RAND_MAX)) < this->density)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tVehicle vehicle = Vehicle(l,s,lane_speed,0);\n\t\t\t\tvehicle.state = "CS";\n\t\t\t\tthis->vehicles_added += 1;\n\t\t\t\tthis->vehicles.insert(std::pair(vehicles_added,vehicle));\n\t\t\t\tvehicle_just_added = true;\n\t\t\t}\n\t\t}\n\t}\n\t\n}\n\nvoid Road::advance() {\n\t\n\tmap > predictions;\n\n\tmap::iterator it = this->vehicles.begin();\n while(it != this->vehicles.end())\n {\n int v_id = it->first;\n vector preds = it->second.generate_predictions();\n predictions[v_id] = preds;\n it++;\n }\n\tit = this->vehicles.begin();\n\twhile(it != this->vehicles.end())\n {\n \tint v_id = it->first;\n if(v_id == ego_key)\n { \n \tvector trajectory = it->second.choose_next_state(predictions);\n \tit->second.realize_next_state(trajectory);\n }\n else {\n it->second.increment(1);\n }\n it++;\n }\n \n}\n\n\nvoid Road::add_ego(int lane_num, int s, vector config_data) {\n\t\n\tmap::iterator it = this->vehicles.begin();\n while(it != this->vehicles.end())\n {\n \tint v_id = it->first;\n Vehicle v = it->second;\n if(v.lane == lane_num && v.s == s)\n {\n \tthis->vehicles.erase(v_id);\n }\n it++;\n }\n Vehicle ego = Vehicle(lane_num, s, this->lane_speeds[lane_num], 0);\n ego.configure(config_data);\n ego.state = "KL";\n this->vehicles.insert(std::pair(ego_key,ego));\n \n}\n\nvoid Road::display(int timestep) {\n\n Vehicle ego = this->vehicles.find(this->ego_key)->second;\n int s = ego.s;\n string state = ego.state;\n\n this->camera_center = max(s, this->update_width/2);\n int s_min = max(this->camera_center - this->update_width/2, 0);\n int s_max = s_min + this->update_width;\n\n vector > road;\n\n for(int i = 0; i < this->update_width; i++)\n {\n vector road_lane;\n for(int ln = 0; ln < this->num_lanes; ln++)\n {\n road_lane.push_back(" ");\n }\n road.push_back(road_lane);\n\n }\n\n map::iterator it = this->vehicles.begin();\n while(it != this->vehicles.end())\n {\n\n int v_id = it->first;\n Vehicle v = it->second;\n\n if(s_min <= v.s && v.s < s_max)\n {\n string marker = "";\n if(v_id == this->ego_key)\n {\n marker = this->ego_rep;\n }\n else\n {\n \n stringstream oss;\n stringstream buffer;\n buffer << " ";\n oss << v_id;\n for(int buffer_i = oss.str().length(); buffer_i < 3; buffer_i++)\n {\n buffer << "0";\n \n }\n buffer << oss.str() << " ";\n marker = buffer.str();\n }\n road[int(v.s - s_min)][int(v.lane)] = marker;\n }\n it++;\n }\n ostringstream oss;\n oss << "+Meters ======================+ step: " << timestep << endl;\n int i = s_min;\n for(int lj = 0; lj < road.size(); lj++)\n {\n if(i%20 ==0)\n {\n stringstream buffer;\n stringstream dis;\n dis << i;\n for(int buffer_i = dis.str().length(); buffer_i < 3; buffer_i++)\n {\n buffer << "0";\n }\n \n oss << buffer.str() << dis.str() << " - ";\n }\n else\n {\n oss << " ";\n } \n i++;\n for(int li = 0; li < road[0].size(); li++)\n {\n oss << "|" << road[lj][li];\n }\n oss << "|";\n oss << "\n";\n }\n \n cout << oss.str();\n\n}\n\n\n', u'cost.cpp': u'#include "cost.h"\n#include "vehicle.h"\n#include \n#include \n#include \n#include \n\n\n//TODO: change weights for cost functions.\nconst float REACH_GOAL = 0.9;\nconst float EFFICIENCY = 0.1;\n\n/\nHere we have provided two possible suggestions for cost functions, but feel free to use your own!\nThe weighted cost over all cost functions is computed in calculate_cost. The data from get_helper_data\nwill be very useful in your implementation of the cost functions below. Please see get_helper_data\nfor details on how the helper data is computed.\n/\n\n\nfloat goal_distance_cost(const Vehicle & vehicle, const vector & trajectory, const map> & predictions, map & data) {\n /\n Cost increases based on distance of intended lane (for planning a lane change) and final lane of trajectory.\n Cost of being out of goal lane also becomes larger as vehicle approaches goal distance. This function is\n very similar to what you have already implemented in the "Implement a Cost Function in C++" quiz.\n /\n float cost;\n float distance = data["distance_to_goal"];\n if (distance > 0) {\n cost = 1 - 2exp(-(abs(2.0vehicle.goal_lane - data["intended_lane"] - data["final_lane"]) / distance));\n } else {\n cost = 1;\n }\n return cost;\n}\n\nfloat inefficiency_cost(const Vehicle & vehicle, const vector & trajectory, const map> & predictions, map & data) {\n /\n Cost becomes higher for trajectories with intended lane and final lane that have traffic slower than vehicle\'s target speed.\n You can use the lane_speed(const map> & predictions, int lane) function to determine the speed\n for a lane. This function is very similar to what you have already implemented in the "Implement a Second Cost Function in C++" quiz.\n /\n float proposed_speed_intended = lane_speed(predictions, data["intended_lane"]);\n //If no vehicle is in the proposed lane, we can travel at target speed.\n if (proposed_speed_intended < 0) {\n proposed_speed_intended = vehicle.target_speed;\n }\n\n float proposed_speed_final = lane_speed(predictions, data["final_lane"]);\n if (proposed_speed_final < 0) {\n proposed_speed_final = vehicle.target_speed;\n }\n\n float cost = (2.0vehicle.target_speed - proposed_speed_intended - proposed_speed_final)/vehicle.target_speed;\n\n return cost;\n}\n\nfloat lane_speed(const map> & predictions, int lane) {\n /\n All non ego vehicles in a lane have the same speed, so to get the speed limit for a lane,\n we can just find one vehicle in that lane.\n /\n for (map>::const_iterator it = predictions.begin(); it != predictions.end(); ++it) {\n int key = it->first;\n Vehicle vehicle = it->second[0];\n if (vehicle.lane == lane && key != -1) {\n return vehicle.v;\n }\n }\n //Found no vehicle in the lane\n return -1.0;\n}\n\nfloat calculate_cost(const Vehicle & vehicle, const map> & predictions, const vector & trajectory) {\n /\n Sum weighted cost functions to get total cost for trajectory.\n /\n map trajectory_data = get_helper_data(vehicle, trajectory, predictions);\n float cost = 0.0;\n\n //Add additional cost functions here.\n vector< function &, const map> &, map &)>> cf_list = {goal_distance_cost, inefficiency_cost};\n vector weight_list = {REACH_GOAL, EFFICIENCY};\n\n for (int i = 0; i < cf_list.size(); i++) {\n float new_cost = weight_list[i]cf_listi;\n cost += new_cost;\n }\n\n return cost;\n\n}\n\nmap get_helper_data(const Vehicle & vehicle, const vector & trajectory, const map> & predictions) {\n /\n Generate helper data to use in cost functions:\n intended_lane: +/- 1 from the current lane if the vehicle is planning or executing a lane change.\n final_lane: The lane of the vehicle at the end of the trajectory. The lane is unchanged for KL and PLCL/PLCR trajectories.\n distance_to_goal: The s distance of the vehicle to the goal.\n\n Note that intended_lane and final_lane are both included to help differentiate between planning and executing\n a lane change in the cost functions.\n /\n map trajectory_data;\n Vehicle trajectory_last = trajectory[1];\n float intended_lane;\n\n if (trajectory_last.state.compare("PLCL") == 0) {\n intended_lane = trajectory_last.lane + 1;\n } else if (trajectory_last.state.compare("PLCR") == 0) {\n intended_lane = trajectory_last.lane - 1;\n } else {\n intended_lane = trajectory_last.lane;\n }\n\n float distance_to_goal = vehicle.goal_s - trajectory_last.s;\n float final_lane = trajectory_last.lane;\n trajectory_data["intended_lane"] = intended_lane;\n trajectory_data["final_lane"] = final_lane;\n trajectory_data["distance_to_goal"] = distance_to_goal;\n return trajectory_data;\n}\n', u'vehicle.h': u'#ifndef VEHICLE_H\n#define VEHICLE_H\n#include \n#include \n#include \n#include \n#include \n\nusing namespace std;\n\nclass Vehicle {\npublic:\n\n map lane_direction = {{"PLCL", 1}, {"LCL", 1}, {"LCR", -1}, {"PLCR", -1}};\n\n struct collider{\n\n bool collision ; // is there a collision?\n int time; // time collision happens\n\n };\n\n int L = 1;\n\n int preferred_buffer = 6; // impacts "keep lane" behavior.\n\n int lane;\n\n int s;\n\n float v;\n\n float a;\n\n float target_speed;\n\n int lanes_available;\n\n float max_acceleration;\n\n int goal_lane;\n\n int goal_s;\n\n string state;\n\n /\n Constructor\n /\n Vehicle();\n Vehicle(int lane, float s, float v, float a, string state="CS");\n\n /*\n Destructor\n */\n virtual ~Vehicle();\n\n vector choose_next_state(map> predictions);\n\n vector successor_states();\n\n vector generate_trajectory(string state, map> predictions);\n\n vector get_kinematics(map> predictions, int lane);\n\n vector constant_speed_trajectory();\n\n vector keep_lane_trajectory(map> predictions);\n\n vector lane_change_trajectory(string state, map> predictions);\n\n vector prep_lane_change_trajectory(string state, map> predictions);\n\n void increment(int dt);\n\n float position_at(int t);\n\n bool get_vehicle_behind(map> predictions, int lane, Vehicle & rVehicle);\n\n bool get_vehicle_ahead(map> predictions, int lane, Vehicle & rVehicle);\n\n vector generate_predictions(int horizon=2);\n\n void realize_next_state(vector trajectory);\n\n void configure(vector road_data);\n\n};\n\n#endif'}
I am also experiencing the exact same issue as camigord with both my solution and the proposed solution.
I am experiencing the same issue as camigord and sclegg99
Thanks for letting us know about this. I'm not sure what happened but it should work now (fixed some items in the grader).
My C++ solution passes on my machine, with the message 'You got to the goal in 31 seconds!'. However, when I click 'SUBMIT ANSWER' on the exercise, it gives a 'Try again' error with the message 'You didn't make it to the goal in time.'!
Other issues: