43 #include <ilqgames/dynamics/concatenated_dynamical_system.h> 44 #include <ilqgames/utils/linear_dynamics_approximation.h> 45 #include <ilqgames/utils/types.h> 47 #include <glog/logging.h> 51 ConcatenatedDynamicalSystem::ConcatenatedDynamicalSystem(
52 const SubsystemList& subsystems)
53 : MultiPlayerDynamicalSystem(std::accumulate(
54 subsystems.begin(), subsystems.end(), 0,
56 const std::shared_ptr<SinglePlayerDynamicalSystem>& subsystem) {
57 CHECK_NOTNULL(subsystem.get());
58 return total + subsystem->XDim();
60 subsystems_(subsystems) {
62 subsystem_start_dims_.push_back(0);
63 for (
const auto& subsystem : subsystems_) {
64 subsystem_start_dims_.push_back(subsystem_start_dims_.back() +
69 VectorXf ConcatenatedDynamicalSystem::Evaluate(
70 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const {
71 CHECK_EQ(us.size(), NumPlayers());
75 Dimension dims_so_far = 0;
76 for (
size_t ii = 0; ii < NumPlayers(); ii++) {
77 const auto& subsystem = subsystems_[ii];
78 xdot.segment(dims_so_far, subsystem->XDim()) = subsystem->Evaluate(
79 t, x.segment(dims_so_far, subsystem->XDim()), us[ii]);
80 dims_so_far += subsystem->XDim();
86 LinearDynamicsApproximation ConcatenatedDynamicalSystem::Linearize(
87 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const {
88 CHECK_EQ(us.size(), NumPlayers());
91 LinearDynamicsApproximation linearization(*
this);
93 Dimension dims_so_far = 0;
94 for (
size_t ii = 0; ii < NumPlayers(); ii++) {
95 const auto& subsystem = subsystems_[ii];
96 const Dimension xdim = subsystem->XDim();
97 const Dimension udim = subsystem->UDim();
99 t, x.segment(dims_so_far, xdim), us[ii],
100 linearization.A.block(dims_so_far, dims_so_far, xdim, xdim),
101 linearization.Bs[ii].block(dims_so_far, 0, xdim, udim));
103 dims_so_far += subsystem->XDim();
106 return linearization;
109 float ConcatenatedDynamicalSystem::DistanceBetween(
const VectorXf& x0,
110 const VectorXf& x1)
const {
112 return subsystems_[0]->DistanceBetween(x0.head(subsystems_[0]->XDim()),
113 x1.head(subsystems_[0]->XDim()));
130 std::vector<Dimension> ConcatenatedDynamicalSystem::PositionDimensions()
const {
131 std::vector<Dimension> dims;
133 for (
const auto& s : subsystems_) {
134 const std::vector<Dimension> sub_dims = s->PositionDimensions();
135 dims.insert(dims.end(), sub_dims.begin(), sub_dims.end());