43 #ifndef ILQGAMES_SOLVER_ILQ_SOLVER_H 44 #define ILQGAMES_SOLVER_ILQ_SOLVER_H 46 #include <ilqgames/cost/player_cost.h> 47 #include <ilqgames/dynamics/multi_player_dynamical_system.h> 48 #include <ilqgames/solver/game_solver.h> 49 #include <ilqgames/solver/lq_feedback_solver.h> 50 #include <ilqgames/solver/lq_solver.h> 51 #include <ilqgames/solver/solver_params.h> 52 #include <ilqgames/utils/linear_dynamics_approximation.h> 53 #include <ilqgames/utils/operating_point.h> 54 #include <ilqgames/utils/quadratic_cost_approximation.h> 55 #include <ilqgames/utils/solver_log.h> 56 #include <ilqgames/utils/strategy.h> 57 #include <ilqgames/utils/types.h> 59 #include <glog/logging.h> 69 ILQSolver(
const std::shared_ptr<Problem>& problem,
72 linearization_(time::kNumTimeSteps),
73 cost_quadraticization_(time::kNumTimeSteps),
74 last_merit_function_value_(constants::kInfinity),
75 expected_decrease_(constants::kInfinity) {
77 if (params_.open_loop)
85 if (problem_->Dynamics()->TreatAsLinear())
86 ComputeLinearization(&linearization_);
89 for (
auto& quads : cost_quadraticization_)
90 quads.resize(problem_->Dynamics()->NumPlayers(),
94 last_cost_quadraticization_ = cost_quadraticization_;
98 virtual std::shared_ptr<SolverLog> Solve(
99 bool* success =
nullptr,
100 Time max_runtime = std::numeric_limits<Time>::infinity());
104 std::vector<std::vector<QuadraticCostApproximation>>* Quadraticization() {
105 return &cost_quadraticization_;
108 std::vector<LinearDynamicsApproximation>* Linearization() {
109 return &linearization_;
115 bool ModifyLQStrategies(
const std::vector<VectorXf>& delta_xs,
116 const std::vector<std::vector<VectorXf>>& costates,
117 std::vector<Strategy>* strategies,
119 bool* has_converged);
123 float StateDistance(
const VectorXf& x1,
const VectorXf& x2,
124 const std::vector<Dimension>& dims)
const;
127 virtual bool HasConverged(
float current_merit_function_value)
const {
128 return (last_merit_function_value_ - current_merit_function_value) <
129 params_.convergence_tolerance;
134 std::vector<float>* total_costs)
const;
138 bool CheckArmijoCondition(
float current_merit_function_value,
139 float current_stepsize)
const;
151 float ExpectedDecrease(
152 const std::vector<Strategy>& strategies,
153 const std::vector<VectorXf>& delta_xs,
154 const std::vector<std::vector<VectorXf>>& costates)
const;
158 void CurrentOperatingPoint(
const OperatingPoint& last_operating_point,
159 const std::vector<Strategy>& current_strategies,
165 void ComputeLinearization(
167 std::vector<LinearDynamicsApproximation>* linearization);
168 void ComputeLinearization(
169 std::vector<LinearDynamicsApproximation>* linearization);
172 void ComputeCostQuadraticization(
174 std::vector<std::vector<QuadraticCostApproximation>>* q);
179 std::vector<LinearDynamicsApproximation> linearization_;
180 std::vector<std::vector<QuadraticCostApproximation>> cost_quadraticization_;
181 std::vector<std::vector<QuadraticCostApproximation>>
182 last_cost_quadraticization_;
185 std::unique_ptr<LQSolver> lq_solver_;
188 float last_merit_function_value_;
189 float expected_decrease_;