STAMINA/STORM 0.1
Infinite state-space truncator which generates a probability within a window
ControlThread.h
1
10#ifndef STAMINA_BUILDER_THREADS_CONTROLTHREAD_H
11#define STAMINA_BUILDER_THREADS_CONTROLTHREAD_H
12
13#include "BaseThread.h"
14
15#include "storm/storage/BitVectorHashMap.h"
16
17#include <deque>
18
19namespace stamina {
20 namespace builder {
21 namespace threads {
22 // The thread index of no exploration thread
23 const uint8_t NO_THREAD = 0;
24
25 // Forward-declare the exploration thread
26 template <typename StateType, typename RewardModelType, typename ValueType>
27 class ExplorationThread;
28
29 template <typename StateType, typename RewardModelType, typename ValueType>
30 class ControlThread : public BaseThread<StateType, RewardModelType, ValueType> {
31 public:
33 StateAndThreadIndex(StateType state, uint8_t thread) : state(state), thread(thread) {
34 // Intentionally left empty
35 }
36 StateType state; // State Index
37 uint8_t thread; // Thread index
38 // Cast to StateType
39 operator StateType() const {
40 return state;
41 }
42 };
44 public:
45 int size();
49 void emplace_back(StateType from, StateType to, double rate);
50 bool empty();
51 void lockThread();
52 void unlockThread();
53 private:
54 std::deque<typename StaminaModelBuilder<ValueType, RewardModelType, StateType>::TransitionInfo> queue;
55 std::shared_mutex lock;
56 };
57
68 , uint8_t numberExplorationThreads
69// , storm::storage::sparse::StateStorage<uint8_t>& stateThreadMap // State storage owned by parents
70 );
87 std::pair<uint8_t, StateType> requestOwnership(CompressedState & state, uint8_t threadIndex, StateType requestedId = 0);
96 uint8_t whoOwns(CompressedState & state);
104 StateType whatIsIndex(CompressedState & state);
120 uint8_t thread
121 , StateType from
122 , StateType to
123 , double rate
124 );
135 StateAndProbability stateAndProbability
136 , double threadIndex
137 );
146 virtual void mainLoop() override;
147 storm::storage::sparse::StateStorage<StateAndThreadIndex>& getStateStorage();
148 void terminate();
149 private:
150 std::vector<LockableDeque> transitionQueues;
151 std::shared_mutex ownershipMutex;
152 const uint8_t numberExplorationThreads;
153 storm::storage::sparse::StateStorage<uint8_t>& stateThreadMap;
154 const std::vector<ExplorationThread<StateType, RewardModelType, ValueType>> explorationThreads;
155 };
156
157 } // namespace threads
158 } // namespace builder
159} // namespace stamina
160
161#endif // STAMINA_BUILDER_THREADS_CONTROLTHREAD_H
Definition: BaseThread.h:28
void emplace_back(StateType from, StateType to, double rate)
Definition: ControlThread.h:30
StateType whatIsIndex(CompressedState &state)
Definition: ControlThread.cpp:60
virtual void mainLoop() override
Definition: ControlThread.cpp:90
ControlThread(StaminaModelBuilder< ValueType, RewardModelType, StateType > *parent, uint8_t numberExplorationThreads)
Definition: ControlThread.cpp:8
void requestCrossExplorationFromThread(StateAndProbability stateAndProbability, double threadIndex)
Definition: ControlThread.cpp:81
std::pair< uint8_t, StateType > requestOwnership(CompressedState &state, uint8_t threadIndex, StateType requestedId=0)
Definition: ControlThread.cpp:19
void requestInsertTransition(uint8_t thread, StateType from, StateType to, double rate)
Definition: ControlThread.cpp:70
uint8_t whoOwns(CompressedState &state)
Definition: ControlThread.cpp:50
Definition: ExplicitTruncatedModelBuilder.cpp:40