44 #include <ilqgames/cost/route_progress_cost.h> 45 #include <ilqgames/geometry/polyline2.h> 46 #include <ilqgames/utils/types.h> 53 float RouteProgressCost::Evaluate(Time t,
const VectorXf& input)
const {
54 CHECK_LT(xidx_, input.size());
55 CHECK_LT(yidx_, input.size());
57 const float desired_route_pos =
58 initial_route_pos_ + (t - initial_time_) * nominal_speed_;
59 const Point2 desired = polyline_.PointAt(desired_route_pos,
nullptr,
nullptr);
61 const float dx = input(xidx_) - desired.x();
62 const float dy = input(yidx_) - desired.y();
63 return 0.5 * weight_ * (dx * dx + dy * dy);
66 void RouteProgressCost::Quadraticize(Time t,
const VectorXf& input,
67 MatrixXf* hess, VectorXf* grad)
const {
68 CHECK_LT(xidx_, input.size());
69 CHECK_LT(yidx_, input.size());
73 CHECK_EQ(input.size(), hess->rows());
74 CHECK_EQ(input.size(), hess->cols());
75 CHECK_EQ(input.size(), grad->size());
78 const Point2 current_position(input(xidx_), input(yidx_));
79 const float desired_route_pos =
80 initial_route_pos_ + (t - initial_time_) * nominal_speed_;
83 const Point2 route_point =
84 polyline_.PointAt(desired_route_pos,
nullptr,
nullptr, &is_endpoint);
87 const float diff_x = current_position.x() - route_point.x();
88 const float diff_y = current_position.y() - route_point.y();
89 const float dx = weight_ * diff_x;
90 const float dy = weight_ * diff_y;
91 const float ddx = weight_;
92 const float ddy = weight_;
93 const float dxdy = 0.0;
98 (*hess)(xidx_, xidx_) += ddx;
99 (*hess)(yidx_, yidx_) += ddy;
100 (*hess)(xidx_, yidx_) += dxdy;
101 (*hess)(yidx_, xidx_) += dxdy;