Skip to content

Commit b76f065

Browse files
Update extern/solver subproject commit hash and enhance executor functionality with new delay methods
1 parent 2f1015b commit b76f065

5 files changed

Lines changed: 29 additions & 18 deletions

File tree

extern/solver

include/plexa.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ namespace ratio::executor
6060
*
6161
* @param atoms The set of atoms which are not yet ready to start and the corresponding delay time.
6262
*/
63-
void dont_start_yet(const std::unordered_map<const riddle::atom_term *, utils::rational> &atoms) { dont_start.insert(atoms.cbegin(), atoms.cend()); }
63+
void dont_start_yet(const std::unordered_map<riddle::atom_term *, utils::rational> &atoms);
6464
/**
6565
* @brief Inserts the given atoms into the `dont_end` unordered map.
6666
*
6767
* This function inserts the given atoms into the `dont_end` set, which contains the atoms that are not yet ready to end. The solver will adapt the plan to delay the ending of these atoms.
6868
*
6969
* @param atoms The set of atoms which are not yet ready to end and the corresponding delay time.
7070
*/
71-
void dont_end_yet(const std::unordered_map<const riddle::atom_term *, utils::rational> &atoms) { dont_end.insert(atoms.cbegin(), atoms.cend()); }
71+
void dont_end_yet(const std::unordered_map<riddle::atom_term *, utils::rational> &atoms);
7272
/**
7373
* @brief Notifies the executor that the given atoms have failed.
7474
*
@@ -86,6 +86,8 @@ namespace ratio::executor
8686
private:
8787
virtual void adapt() = 0;
8888

89+
virtual void delay(riddle::arith_expr tp, const utils::rational &d) = 0;
90+
8991
private:
9092
/**
9193
* @brief Called when the state of the executor changes.
@@ -134,15 +136,13 @@ namespace ratio::executor
134136
protected:
135137
std::mutex mtx; // the mutex for the critical sections..
136138
private:
137-
std::atomic<bool> running = false; // the running state..
138-
executor_state state = executor_state::Reasoning; // the current state of the executor..
139-
std::unordered_set<const riddle::predicate *> executable_predicates; // the set of executable (impulses and intervals) predicates..
140-
const utils::rational units_per_tick; // the number of plan units for each tick..
141-
bool pending_requirements = false; // whether there are pending requirements to be solved or not..
142-
utils::rational current_time; // the current time in plan units..
143-
std::unordered_set<const riddle::atom_term *> executing; // the atoms that are currently executing..
144-
std::unordered_map<const riddle::atom_term *, utils::rational> dont_start; // the starting atoms which are not yet ready to start..
145-
std::unordered_map<const riddle::atom_term *, utils::rational> dont_end; // the ending atoms which are not yet ready to end..
146-
std::map<utils::inf_rational, std::pair<std::vector<riddle::atom_term *>, std::vector<riddle::atom_term *>>> pulses; // the pulses of the executor, with the starting and ending atoms..
139+
std::atomic<bool> running = false; // the running state..
140+
executor_state state = executor_state::Reasoning; // the current state of the executor..
141+
std::unordered_set<const riddle::predicate *> executable_predicates; // the set of executable (impulses and intervals) predicates..
142+
const utils::rational units_per_tick; // the number of plan units for each tick..
143+
bool pending_requirements = false; // whether there are pending requirements to be solved or not..
144+
utils::rational current_time; // the current time in plan units..
145+
std::unordered_set<const riddle::atom_term *> executing; // the atoms that are currently executing..
146+
std::map<utils::inf_rational, std::pair<std::unordered_set<riddle::atom_term *>, std::unordered_set<riddle::atom_term *>>> pulses; // the pulses of the executor, with the starting and ending atoms..
147147
};
148148
} // namespace ratio::executor

include/st/stexecutor.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace ratio::executor
1717
private:
1818
void adapt() override;
1919

20+
void delay(riddle::arith_expr tp, const utils::rational &d) override;
21+
2022
private:
2123
bool pending_requirements = false; // whether there are pending requirements to be solved or not..
2224
};

src/plexa.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace ratio::executor
4141
if (!running)
4242
return; // if not running, do nothing..
4343

44-
manage_tick:
4544
while (!pulses.empty() && pulses.cbegin()->first <= current_time)
4645
{
4746
if (!pulses.cbegin()->second.first.empty())
@@ -61,6 +60,13 @@ namespace ratio::executor
6160
}
6261
}
6362

63+
void plexa::dont_start_yet(const std::unordered_map<riddle::atom_term *, utils::rational> &atoms)
64+
{
65+
for (auto &[atm, d] : atoms)
66+
delay(std::dynamic_pointer_cast<riddle::arith_term>(atm->get_core().get_predicate(riddle::impulse_kw).is_assignable_from(atm->get_type()) ? atm->get("at") : atm->get("start")), d);
67+
}
68+
void plexa::dont_end_yet(const std::unordered_map<riddle::atom_term *, utils::rational> &atoms) { delay(std::dynamic_pointer_cast<riddle::arith_term>(atoms.begin()->first->get("end")), atoms.begin()->second); }
69+
6470
void plexa::build_timelines(const riddle::core &cr)
6571
{
6672
LOG_DEBUG("Building timelines");
@@ -77,18 +83,18 @@ namespace ratio::executor
7783
auto at = cr.arith_value(static_cast<riddle::arith_term &>(*atm->get("at")));
7884
if (at < current_time)
7985
continue; // this atom is already in the past..
80-
pulses[at].first.emplace_back(atm.get());
81-
pulses[at].second.emplace_back(atm.get());
86+
pulses[at].first.emplace(atm.get());
87+
pulses[at].second.emplace(atm.get());
8288
}
8389
else
8490
{
8591
auto end = cr.arith_value(static_cast<riddle::arith_term &>(*atm->get("end")));
8692
if (end < current_time)
8793
continue; // this atom is already in the past..
88-
pulses[end].second.emplace_back(atm.get());
94+
pulses[end].second.emplace(atm.get());
8995
auto start = cr.arith_value(static_cast<riddle::arith_term &>(*atm->get("start")));
9096
if (start >= current_time)
91-
pulses[start].first.emplace_back(atm.get());
97+
pulses[start].first.emplace(atm.get());
9298
}
9399
}
94100
}

src/st/stexecutor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "stexecutor.hpp"
2+
#include "la_theory.hpp"
23
#include "logging.hpp"
34

45
namespace ratio::executor
@@ -20,4 +21,6 @@ namespace ratio::executor
2021
}
2122

2223
void executor::adapt() { solve(); }
24+
25+
void executor::delay(riddle::arith_expr tp, const utils::rational &d) { get_linear_arithmetic_theory().new_lt(static_cast<riddle::arith_item &>(*tp).get_lin(), utils::lin(arith_value(*tp).get_rational() + d)); }
2326
} // namespace ratio::executor

0 commit comments

Comments
 (0)