44 #include <ilqgames/cost/locally_convex_proximity_cost.h> 45 #include <ilqgames/utils/types.h> 47 #include <glog/logging.h> 51 float LocallyConvexProximityCost::Evaluate(
const VectorXf& input)
const {
52 const float dx = input(xidx1_) - input(xidx2_);
53 const float dy = input(yidx1_) - input(yidx2_);
55 if (dx * dx >= threshold_sq_ || dy * dy >= threshold_sq_)
return 0.0;
57 const float delta_x = threshold_ - std::abs(dx);
58 const float delta_y = threshold_ - std::abs(dy);
59 return 0.5 * weight_ * std::min(delta_x * delta_x, delta_y * delta_y);
62 void LocallyConvexProximityCost::Quadraticize(
const VectorXf& input,
64 VectorXf* grad)
const {
69 CHECK_EQ(input.size(), hess->rows());
70 CHECK_EQ(input.size(), hess->cols());
71 CHECK_EQ(input.size(), grad->size());
74 const float dx = input(xidx1_) - input(xidx2_);
75 const float dy = input(yidx1_) - input(yidx2_);
77 if (dx * dx >= threshold_sq_ || dy * dy >= threshold_sq_)
return;
80 const float delta_x = threshold_ - std::abs(dx);
81 const float delta_y = threshold_ - std::abs(dy);
83 const bool is_x_active = delta_x * delta_x < delta_y * delta_y;
86 const float dx1 = -weight_ * delta_x;
87 const float ddx1 = weight_;
89 (*grad)(xidx1_) += dx1;
90 (*grad)(xidx2_) -= dx1;
92 (*hess)(xidx1_, xidx1_) += ddx1;
93 (*hess)(xidx2_, xidx2_) += ddx1;
94 (*hess)(xidx1_, xidx2_) -= ddx1;
95 (*hess)(xidx2_, xidx1_) -= ddx1;
97 const float dy1 = -weight_ * delta_y;
98 const float ddy1 = weight_;
100 (*grad)(yidx1_) += dy1;
101 (*grad)(yidx2_) -= dy1;
103 (*hess)(yidx1_, yidx1_) += ddy1;
104 (*hess)(yidx2_, yidx2_) += ddy1;
105 (*hess)(yidx1_, yidx2_) -= ddy1;
106 (*hess)(yidx2_, yidx1_) -= ddy1;