Directory: | ./ |
---|---|
File: | src/core/solvers/ipopt.cpp |
Date: | 2025-01-30 11:01:55 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 21 | 38 | 55.3% |
Branches: | 20 | 66 | 30.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2022-2023, IRI: CSIC-UPC, Heriot-Watt University | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include "crocoddyl/core/solvers/ipopt.hpp" | ||
10 | |||
11 | namespace crocoddyl { | ||
12 | |||
13 | 6 | SolverIpopt::SolverIpopt(std::shared_ptr<crocoddyl::ShootingProblem> problem) | |
14 | : SolverAbstract(problem), | ||
15 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 | ipopt_iface_(new IpoptInterface(problem)), |
16 |
4/8✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
|
12 | ipopt_app_(IpoptApplicationFactory()) { |
17 |
3/6✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
|
6 | ipopt_app_->Options()->SetNumericValue("tol", th_stop_); |
18 |
4/8✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
|
6 | ipopt_app_->Options()->SetStringValue("mu_strategy", "adaptive"); |
19 | |||
20 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | ipopt_status_ = ipopt_app_->Initialize(); |
21 | |||
22 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (ipopt_status_ != Ipopt::Solve_Succeeded) { |
23 | ✗ | std::cerr << "Error during IPOPT initialization!" << std::endl; | |
24 | } | ||
25 | 6 | } | |
26 | |||
27 | 5 | bool SolverIpopt::solve(const std::vector<Eigen::VectorXd>& init_xs, | |
28 | const std::vector<Eigen::VectorXd>& init_us, | ||
29 | const std::size_t maxiter, const bool is_feasible, | ||
30 | const double /*reg_init*/) { | ||
31 | 5 | setCandidate(init_xs, init_us, is_feasible); | |
32 | 5 | ipopt_iface_->set_xs(xs_); | |
33 | 5 | ipopt_iface_->set_us(us_); | |
34 | |||
35 |
2/4✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
|
5 | ipopt_app_->Options()->SetIntegerValue("max_iter", |
36 | static_cast<Ipopt::Index>(maxiter)); | ||
37 |
1/2✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
|
5 | ipopt_status_ = ipopt_app_->OptimizeTNLP(ipopt_iface_); |
38 | |||
39 | 5 | std::copy(ipopt_iface_->get_xs().begin(), ipopt_iface_->get_xs().end(), | |
40 | xs_.begin()); | ||
41 | 5 | std::copy(ipopt_iface_->get_us().begin(), ipopt_iface_->get_us().end(), | |
42 | us_.begin()); | ||
43 | 5 | cost_ = ipopt_iface_->get_cost(); | |
44 |
1/2✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | iter_ = ipopt_app_->Statistics()->IterationCount(); |
45 | |||
46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | return ipopt_status_ == Ipopt::Solve_Succeeded || |
47 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
5 | ipopt_status_ == Ipopt::Solved_To_Acceptable_Level; |
48 | } | ||
49 | |||
50 | ✗ | void SolverIpopt::resizeData() { | |
51 | ✗ | SolverAbstract::resizeData(); | |
52 | ✗ | ipopt_iface_->resizeData(); | |
53 | } | ||
54 | |||
55 | 16 | SolverIpopt::~SolverIpopt() {} | |
56 | |||
57 | ✗ | void SolverIpopt::computeDirection(const bool) {} | |
58 | |||
59 | ✗ | double SolverIpopt::tryStep(const double) { return 0.; } | |
60 | |||
61 | ✗ | double SolverIpopt::stoppingCriteria() { return 0.; } | |
62 | |||
63 | ✗ | const Eigen::Vector2d& SolverIpopt::expectedImprovement() { return d_; } | |
64 | |||
65 | ✗ | void SolverIpopt::setStringIpoptOption(const std::string& tag, | |
66 | const std::string& value) { | ||
67 | ✗ | ipopt_app_->Options()->SetStringValue(tag, value); | |
68 | } | ||
69 | |||
70 | ✗ | void SolverIpopt::setNumericIpoptOption(const std::string& tag, | |
71 | Ipopt::Number value) { | ||
72 | ✗ | ipopt_app_->Options()->SetNumericValue(tag, value); | |
73 | } | ||
74 | |||
75 | ✗ | void SolverIpopt::set_th_stop(const double th_stop) { | |
76 | ✗ | if (th_stop <= 0.) { | |
77 | ✗ | throw_pretty("Invalid argument: " << "th_stop value has to higher than 0."); | |
78 | } | ||
79 | ✗ | th_stop_ = th_stop; | |
80 | ✗ | ipopt_app_->Options()->SetNumericValue("tol", th_stop_); | |
81 | } | ||
82 | |||
83 | } // namespace crocoddyl | ||
84 |