AIToolbox
A library that offers tools for AI problem solving.
|
Go to the documentation of this file. 1 #ifndef AI_TOOLBOX_MDP_LINEAR_PROGRAMMING_HEADER_FILE
2 #define AI_TOOLBOX_MDP_LINEAR_PROGRAMMING_HEADER_FILE
36 std::tuple<double, ValueFunction, QFunction>
operator()(
const M & m);
42 const size_t S = model.getS();
43 const size_t A = model.getA();
69 for (
size_t s = 0; s < S; ++s) {
73 for (
size_t a = 0; a < A; ++a) {
75 if constexpr(IsModelEigen<M>) {
76 lp.
row = -model.getDiscount() * model.getTransitionFunction(a).row(s);
77 rhs = model.getRewardFunction()(s, a);
82 for (
size_t s1 = 0; s1 < S; ++s1) {
83 lp.
row[s1] = -model.getDiscount() * model.getTransitionProbability(s, a, s1);
84 rhs += model.getTransitionProbability(s, a, s1) * model.getExpectedReward(s, a, s1);
94 auto values = lp.
solve(S);
97 throw std::runtime_error(
"Could not solve the LP for this MDP");
101 const auto & ir = [&]{
102 if constexpr (IsModelEigen<M>)
return model.getRewardFunction();
109 v.
values = std::move(*values);
111 for (
size_t s = 0; s < S; ++s)
112 q.row(s).maxCoeff(&v.
actions[s]);
114 return std::make_tuple(lp.
getPrecision(), std::move(v), std::move(q));