PCB Environment: /home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/RL/Action.hpp Source File

PCB Environment 2

Loading...
Searching...
No Matches
Action.hpp
1
2#ifndef GYM_PCB_RL_ACTION_H
3#define GYM_PCB_RL_ACTION_H
4
5#include "Defs.hpp"
6#include "RL/Reward.hpp"
7#include <string>
8
9class Agent;
10class NavGrid;
11
13 class Action
14{
15public:
16 using Index = uint16_t;
17 constexpr static const Index IndexNone = std::numeric_limits<Index>::max();
18
19 using CacheRef = uint32_t;
20
21 struct Result {
22 Result() { }
23 Result(Reward r, bool ok, bool t = false) : R(r), Success(ok), Termination(t) { }
24 bool operator<(const Result&) const;
25 bool operator>(const Result &that) const { return that < *this; }
26 bool operator==(const Result&) const;
27 std::string str() const;
28 Reward R;
29 RouterResult Router;
30 bool Success{true}; // Don't change the defaults!
31 bool Termination{false};
32 };
33public:
34 Action(const std::string &name, uint index = std::numeric_limits<Index>::max()) : mName(name), mIndex(index) { }
35 virtual ~Action() { }
36
37 const std::string& name() const { return mName; }
38 Index index() const { return mIndex; }
39 bool legal() const { return mLegal; }
40
41 virtual Result performAs(Agent& context, PyObject *arg = 0) { return Result(); }
42
43 virtual void clearCache(CacheRef = 0) { }
44 virtual Result performAs(Agent& context, PyObject *arg, CacheRef) { return performAs(context); }
45
46 virtual Result undoAs(Agent&);
47 Action *getUndo() const { return mUndo; }
48
49 void setUndo(Action *A) { mUndo = A; }
50 void setIndex(Index a) { mIndex = a; }
51 void setLegal(bool b) { mLegal = b; }
52
53 void setActionCountIncrement(uint n) { mActionCountIncrement = n; }
54
55 virtual PyObject *getPy() const;
56protected:
57 Action *mUndo{0};
58 uint mActionCountIncrement{1};
59private:
60 const std::string mName;
61 Index mIndex{std::numeric_limits<Index>::max()};
62 bool mLegal;
63};
64inline bool Action::Result::operator<(const Action::Result &that) const
65{
66 return (Success < that.Success) || (Success == that.Success && R < that.R);
67}
68
69#endif // GYM_PCB_RL_ACTION_H
Action
NOTE: Actions always set the Agent's least recently used connction (getConnectionLRU()) which is some...
Definition Action.hpp:14
Agent
Definition Agent.hpp:31
NavGrid
The grid-representation of the board.
Definition NavGrid.hpp:61
Action::Result
Definition Action.hpp:21
RouterResult
Definition Reward.hpp:15