17 #define MAX_RUNTIME 120 86 template <
typename State,
typename Action,
typename Cost,
typename Conflict,
93 bool search(
const std::vector<State>& initialStates,
96 start.solution.resize(initialStates.size());
97 start.constraints.resize(initialStates.size());
101 for (
size_t i = 0; i < initialStates.size(); ++i) {
106 LowLevelEnvironment llenv(m_env, i, start.constraints[i]);
108 bool success = lowLevel.
search(initialStates[i], start.solution[i]);
113 start.cost += start.solution[i].cost;
117 typename boost::heap::d_ary_heap<HighLevelNode, boost::heap::arity<2>,
118 boost::heap::mutable_<true>>
121 auto handle = open.push(start);
122 (*handle).handle = handle;
124 std::chrono::high_resolution_clock::time_point
125 startTime = std::chrono::high_resolution_clock::now(),
129 while (!open.empty()) {
130 endTime = std::chrono::high_resolution_clock::now();
131 if (std::chrono::duration_cast<std::chrono::duration<double>>(endTime -
135 std::cout <<
"\033[1m\033[31m Plan out of runtime time! \033[0m\n";
139 HighLevelNode P = open.top();
148 solution = P.solution;
155 std::map<size_t, Constraints> constraints;
157 for (
const auto& c : constraints) {
161 HighLevelNode newNode = P;
166 assert(!newNode.constraints[i].overlap(c.second));
168 newNode.constraints[i].add(c.second);
170 newNode.cost -= newNode.solution[i].cost;
172 LowLevelEnvironment llenv(m_env, i, newNode.constraints[i]);
174 bool success = lowLevel.
search(initialStates[i], newNode.solution[i]);
176 newNode.cost += newNode.solution[i].cost;
180 auto handle = open.push(newNode);
181 (*handle).handle = handle;
192 struct HighLevelNode {
193 std::vector<PlanResult<State, Action, Cost>> solution;
194 std::vector<Constraints> constraints;
200 typename boost::heap::d_ary_heap<HighLevelNode, boost::heap::arity<2>,
201 boost::heap::mutable_<true>>::handle_type
204 bool operator<(
const HighLevelNode& n)
const {
206 return cost > n.cost;
210 friend std::ostream& operator<<(std::ostream& os,
const HighLevelNode& c) {
211 os <<
"id: " << c.id <<
" cost: " << c.cost << std::endl;
212 for (
size_t i = 0; i < c.solution.size(); ++i) {
213 os <<
"Agent: " << i << std::endl;
214 os <<
" States:" << std::endl;
215 for (
size_t t = 0; t < c.solution[i].states.size(); ++t) {
216 os <<
" " << c.solution[i].states[t].first << std::endl;
218 os <<
" Constraints:" << std::endl;
219 os << c.constraints[i];
220 os <<
" cost: " << c.solution[i].cost << std::endl;
226 struct LowLevelEnvironment {
227 LowLevelEnvironment(
Environment& env,
size_t agentIdx,
228 const Constraints& constraints)
233 m_env.setLowLevelContext(agentIdx, &constraints);
236 Cost admissibleHeuristic(
const State& s) {
237 return m_env.admissibleHeuristic(s);
241 const State& s, Cost g,
242 std::unordered_map<State, std::tuple<State, Action, Cost, Cost>,
243 std::hash<State>>& camefrom) {
244 return m_env.isSolution(s, g, camefrom);
247 void getNeighbors(
const State& s, Action act,
249 m_env.getNeighbors(s, act, neighbors);
252 State getGoal() {
return m_env.getGoal(); }
254 int calcIndex(
const State& s) {
return m_env.calcIndex(s); }
256 void onExpandNode(
const State& s, Cost fScore, Cost gScore) {
258 m_env.onExpandLowLevelNode(s, fScore, gScore);
261 void onDiscover(
const State& , Cost , Cost ) {
bool search(const State &startState, PlanResult< State, Action, Cost > &solution, Cost initialCost=0)
Definition: hybrid_astar.hpp:85
void onExpandHighLevelNode(int)
Definition: environment.hpp:172
bool getFirstConflict(const std::vector< PlanResult< State, Action, double >> &solution, Conflict &result)
High Level Environment functions.
Definition: environment.hpp:133
Spatiotemporal Hybrid A* Algorithm.
Definition: hybrid_astar.hpp:80
bool search(const std::vector< State > &initialStates, std::vector< PlanResult< State, Action, Cost >> &solution)
Definition: cl_cbs.hpp:93
~CL_CBS()
Definition: cl_cbs.hpp:91
Environment class.
Definition: environment.hpp:97
Represents state transations.
Definition: neighbor.hpp:24
Definition: cl_cbs.hpp:19
void createConstraintsFromConflict(const Conflict &conflict, std::map< size_t, Constraints > &constraints)
Definition: environment.hpp:160
Represents the path for an agent.
Definition: planresult.hpp:28
Car-Like Conflict-Based Search(CL-CBS) algorithm to solve the Multi-Agent Path Finding for Car-Like r...
Definition: cl_cbs.hpp:88
CL_CBS(Environment &environment)
Definition: cl_cbs.hpp:90
#define MAX_RUNTIME
Definition: cl_cbs.hpp:17