| 420 | |
| 421 | template <typename T, typename U, typename V> |
| 422 | T gap_step_assign_bounded_variables ( |
| 423 | const double eps, |
| 424 | T vect, |
| 425 | const T& x, |
| 426 | const T& gradient, |
| 427 | const U& x_lower, |
| 428 | const V& x_upper |
| 429 | ) |
| 430 | { |
| 431 | for (long i = 0; i < gradient.size(); ++i) |
| 432 | { |
| 433 | const double tol = eps*std::abs(x(i)); |
| 434 | // If x(i) is an active bound constraint then we should set its search |
| 435 | // direction such that a single step along the direction either does nothing or |
| 436 | // closes the gap of size tol before hitting the bound exactly. |
| 437 | if (x_lower(i)+tol >= x(i) && gradient(i) > 0) |
| 438 | vect(i) = x_lower(i)-x(i); |
| 439 | else if (x_upper(i)-tol <= x(i) && gradient(i) < 0) |
| 440 | vect(i) = x_upper(i)-x(i); |
| 441 | } |
| 442 | return vect; |
| 443 | } |
| 444 | |
| 445 | // ---------------------------------------------------------------------------------------- |
| 446 |
no test coverage detected