44 #ifndef ILQGAMES_COST_PLAYER_COST_H 45 #define ILQGAMES_COST_PLAYER_COST_H 47 #include <ilqgames/constraint/constraint.h> 48 #include <ilqgames/cost/cost.h> 49 #include <ilqgames/utils/operating_point.h> 50 #include <ilqgames/utils/quadratic_cost_approximation.h> 51 #include <ilqgames/utils/types.h> 53 #include <unordered_map> 63 explicit PlayerCost(
const std::string& name =
"",
64 float state_regularization = 0.0,
65 float control_regularization = 0.0)
67 state_regularization_(state_regularization),
68 control_regularization_(control_regularization),
69 cost_structure_(CostStructure::SUM),
70 time_of_extreme_cost_(0) {}
73 void AddStateCost(
const std::shared_ptr<Cost>& cost);
74 void AddControlCost(PlayerIndex idx,
const std::shared_ptr<Cost>& cost);
79 void AddStateConstraint(
const std::shared_ptr<Constraint>& constraint);
80 void AddControlConstraint(PlayerIndex idx,
81 const std::shared_ptr<Constraint>& constraint);
86 float Evaluate(Time t,
const VectorXf& x,
87 const std::vector<VectorXf>& us)
const;
90 float EvaluateOffset(Time t, Time next_t,
const VectorXf& next_x,
91 const std::vector<VectorXf>& us)
const;
95 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const;
99 Time t,
const VectorXf& x,
const std::vector<VectorXf>& us)
const;
103 enum CostStructure { SUM, MAX, MIN };
104 void SetTimeAdditive() { cost_structure_ = SUM; }
105 void SetMaxOverTime() { cost_structure_ = MAX; }
106 void SetMinOverTime() { cost_structure_ = MIN; }
107 bool IsTimeAdditive()
const {
return cost_structure_ == SUM; }
108 bool IsMaxOverTime()
const {
return cost_structure_ == MAX; }
109 bool IsMinOverTime()
const {
return cost_structure_ == MIN; }
112 size_t TimeOfExtremeCost() {
return time_of_extreme_cost_; }
113 void SetTimeOfExtremeCost(
size_t kk) { time_of_extreme_cost_ = kk; }
116 const PtrVector<Cost>& StateCosts()
const {
return state_costs_; }
117 const PlayerPtrMultiMap<Cost>& ControlCosts()
const {
return control_costs_; }
118 const PtrVector<Constraint>& StateConstraints()
const {
119 return state_constraints_;
121 const PlayerPtrMultiMap<Constraint>& ControlConstraints()
const {
122 return control_constraints_;
124 bool IsConstrained()
const {
125 return !state_constraints_.empty() || !control_constraints_.empty();
130 const std::string name_;
133 PtrVector<Cost> state_costs_;
134 PlayerPtrMultiMap<Cost> control_costs_;
137 PtrVector<Constraint> state_constraints_;
138 PlayerPtrMultiMap<Constraint> control_constraints_;
141 const float state_regularization_;
142 const float control_regularization_;
146 CostStructure cost_structure_;
151 size_t time_of_extreme_cost_;