1#ifndef PROBFD_OPEN_LISTS_KEY_BASED_OPEN_LIST_H
2#define PROBFD_OPEN_LISTS_KEY_BASED_OPEN_LIST_H
4#include "probfd/algorithms/open_list.h"
6#include "probfd/fdr_types.h"
16 StateID operator()(C& c)
const
19 const StateID res = *it;
20 c.erase(--(it.base()));
27 StateID operator()(C& c)
const
30 const StateID res = *it;
38 typename Pop = LifoPop,
39 typename Comparison =
typename std::less<Key>>
42 using Bucket = std::vector<StateID>;
44 using BucketMap = std::map<Key, Bucket, Comparison>;
45 using BucketRef =
typename BucketMap::iterator;
48 explicit KeyBasedOpenList(
const Comparison& comparison = Comparison())
50 , bucket_map_(comparison)
54 virtual ~KeyBasedOpenList() =
default;
56 virtual StateID pop()
override
58 BucketRef b = bucket_map_.begin();
59 const StateID res = bucket_pop(b);
60 if (bucket_empty(b)) {
67 virtual unsigned size()
const override {
return size_; }
69 virtual void clear()
override
75 virtual void push(StateID state_id)
override
77 Key k = get_key(state_id);
83 const ProbabilisticOperator* op,
84 const value_type::value_t& prob,
85 StateID state_id)
override
87 Key k = get_key(parent, op, prob, state_id);
92 virtual Key get_key(StateID state_id) = 0;
96 const ProbabilisticOperator*,
97 const value_type::value_t&,
100 return this->get_key(state_id);
104 void push(
const Key& key, StateID stateid)
106 BucketRef b = bucket(key);
107 bucket_push(b, stateid);
111 inline BucketRef bucket(
const Key& key)
113 return bucket_map_.emplace(key, Bucket()).first;
116 inline void remove(BucketRef ref) { bucket_map_.erase(ref); }
118 inline void bucket_push(BucketRef ref, StateID stateid)
120 ref->second.push_back(stateid);
123 inline StateID bucket_pop(BucketRef ref) {
return Pop()(ref->second); }
125 inline bool bucket_empty(BucketRef ref) {
return ref->second.empty(); }
129 BucketMap bucket_map_;
This namespace contains implementations of open lists.
Definition fifo_open_list.h:9
algorithms::OpenList< OperatorID > FDROpenList
Type alias for OpenLists for MDPs in FDR.
Definition fdr_types.h:26