\doxysection{RRRAgent.\+hpp}
\hypertarget{RRRAgent_8hpp_source}{}\label{RRRAgent_8hpp_source}\index{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/RL/RRRAgent.hpp@{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/RL/RRRAgent.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#ifndef\ GYM\_PCB\_RRRAGENT\_H}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#define\ GYM\_PCB\_RRRAGENT\_H}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}RL/Action.hpp"{}}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ "{}RL/Agent.hpp"{}}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ "{}RL/Reward.hpp"{}}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include\ "{}Track.hpp"{}}}
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <random>}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{keyword}{class\ }RRRAgent\ :\ \textcolor{keyword}{public}\ Agent}
\DoxyCodeLine{00012\ \{}
\DoxyCodeLine{00013\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00014\ \ \ \ \ RRRAgent();}
\DoxyCodeLine{00015\ \ \ \ \ \string~RRRAgent();}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ \ \ \ \ \textcolor{keywordtype}{bool}\ \_run()\ \textcolor{keyword}{override};}
\DoxyCodeLine{00018\ \ \ \ \ PyObject\ *get\_state(PyObject\ *)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00020\ \ \ \ \ \textcolor{keywordtype}{void}\ setMinIterations(uint);}
\DoxyCodeLine{00021\ \ \ \ \ \textcolor{keywordtype}{void}\ setMaxIterations(uint);}
\DoxyCodeLine{00022\ \ \ \ \ \textcolor{keywordtype}{void}\ setMaxIterationsStagnant(uint);}
\DoxyCodeLine{00023\ \ \ \ \ \textcolor{keywordtype}{void}\ setNumTidyIterations(uint);}
\DoxyCodeLine{00024\ \ \ \ \ \textcolor{keywordtype}{void}\ setCheckStagnationBeforeSuccess(\textcolor{keywordtype}{bool});}
\DoxyCodeLine{00025\ \ \ \ \ \textcolor{keywordtype}{void}\ setHistoryCostDecay(\textcolor{keywordtype}{float});}
\DoxyCodeLine{00026\ \ \ \ \ \textcolor{keywordtype}{void}\ setHistoryCostIncrement(\textcolor{keywordtype}{float});}
\DoxyCodeLine{00027\ \ \ \ \ \textcolor{keywordtype}{void}\ setHistoryCostMax(\textcolor{keywordtype}{float});}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordtype}{void}\ setRandomizeOrder(\textcolor{keywordtype}{bool});}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00030\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00031\ \ \ \ \ uint\ mMinIterations\{1\};}
\DoxyCodeLine{00032\ \ \ \ \ uint\ mMaxIterations\{256\};}
\DoxyCodeLine{00033\ \ \ \ \ uint\ mMaxIterationsStagnant\{1\};}
\DoxyCodeLine{00034\ \ \ \ \ uint\ mNumTidyIterations\{2\};}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keywordtype}{bool}\ mCheckStagnationBeforeSuccess\{\textcolor{keyword}{false}\};}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keywordtype}{bool}\ mRandomizeOrder\{\textcolor{keyword}{true}\};}
\DoxyCodeLine{00037\ \ \ \ \ \textcolor{keywordtype}{bool}\ mPostrouteStage\{\textcolor{keyword}{false}\};}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{keywordtype}{float}\ mHistoryCostDecay\{1.0f\};}
\DoxyCodeLine{00039\ \ \ \ \ \textcolor{keywordtype}{float}\ mHistoryCostIncrement\{0.125f\};}
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keywordtype}{float}\ mHistoryCostMax\{std::numeric\_limits<float>::infinity()\};}
\DoxyCodeLine{00041\ \ \ \ \ std::vector<uint>\ mConnectionOrder;}
\DoxyCodeLine{00042\ \ \ \ \ std::mt19937\ RNG\{unsigned(std::chrono::system\_clock::now().time\_since\_epoch().count())\};}
\DoxyCodeLine{00043\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{keywordtype}{bool}\ init();}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keywordtype}{void}\ initParameters();}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keywordtype}{bool}\ routeHistoryAll();}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keywordtype}{bool}\ rerouteHistoryOneByOne();}
\DoxyCodeLine{00048\ \ \ \ \ \textcolor{keywordtype}{void}\ unrouteHistoryAll();}
\DoxyCodeLine{00049\ \ \ \ \ \mbox{\hyperlink{structAction_1_1Result}{Action::Result}}\ routeProperlyAll();}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keywordtype}{void}\ unrouteAll();}
\DoxyCodeLine{00051\ \ \ \ \ \mbox{\hyperlink{structAction_1_1Result}{Action::Result}}\ postroute();}
\DoxyCodeLine{00052\ \ \ \ \ \mbox{\hyperlink{structAction_1_1Result}{Action::Result}}\ checkRouting();}
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{keywordtype}{void}\ saveTracks(std::vector<Track>\&);}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keywordtype}{void}\ restoreTracks(std::vector<Track>\&);}
\DoxyCodeLine{00055\ \ \ \ \ uint\ mIterationsStagnant;}
\DoxyCodeLine{00056\ \ \ \ \ \mbox{\hyperlink{structAction_1_1Result}{Action::Result}}\ mScore;}
\DoxyCodeLine{00057\ \ \ \ \ \mbox{\hyperlink{structAction_1_1Result}{Action::Result}}\ mScoreMax;}
\DoxyCodeLine{00058\ \ \ \ \ std::vector<Track>\ mScoreMaxTracks;}
\DoxyCodeLine{00059\ \ \ \ \ std::vector<Track>\ mSavedTracks;}
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keywordtype}{bool}\ mErrorState;}
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00062\ \ \ \ \ uint\ rasterize(\textcolor{keyword}{const}\ \mbox{\hyperlink{classConnection}{Connection}}\&,\ int8\_t\ value,\ \textcolor{keywordtype}{bool}\ updateHistoryCost)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keywordtype}{void}\ decayHistoryCosts(\textcolor{keywordtype}{float});}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00065\ \ \ \ \ \textcolor{keywordtype}{void}\ updateSpacings(\textcolor{keyword}{const}\ \mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keywordtype}{bool}\ routeHistory(\mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00068\ \ \ \ \ \textcolor{keywordtype}{void}\ unrouteHistory(\mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keywordtype}{bool}\ rerouteHistory(\mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00070\ \ \ \ \ \textcolor{keywordtype}{bool}\ route(\mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00071\ \ \ \ \ \textcolor{keywordtype}{void}\ unroute(\mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{keywordtype}{bool}\ reroute(\mbox{\hyperlink{classConnection}{Connection}}\&);}
\DoxyCodeLine{00073\ \ \ \ \ \textcolor{keywordtype}{void}\ restoreTrack(uint\ i,\ \mbox{\hyperlink{classTrack}{Track}}\&);}
\DoxyCodeLine{00074\ \};}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setMinIterations(uint\ n)}
\DoxyCodeLine{00077\ \{}
\DoxyCodeLine{00078\ \ \ \ \ mMinIterations\ =\ n;}
\DoxyCodeLine{00079\ \}}
\DoxyCodeLine{00080\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setMaxIterations(uint\ n)}
\DoxyCodeLine{00081\ \{}
\DoxyCodeLine{00082\ \ \ \ \ mMaxIterations\ =\ n;}
\DoxyCodeLine{00083\ \}}
\DoxyCodeLine{00084\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setMaxIterationsStagnant(uint\ n)}
\DoxyCodeLine{00085\ \{}
\DoxyCodeLine{00086\ \ \ \ \ mMaxIterationsStagnant\ =\ n;}
\DoxyCodeLine{00087\ \}}
\DoxyCodeLine{00088\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setNumTidyIterations(uint\ n)}
\DoxyCodeLine{00089\ \{}
\DoxyCodeLine{00090\ \ \ \ \ mNumTidyIterations\ =\ n;}
\DoxyCodeLine{00091\ \}}
\DoxyCodeLine{00092\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setCheckStagnationBeforeSuccess(\textcolor{keywordtype}{bool}\ b)}
\DoxyCodeLine{00093\ \{}
\DoxyCodeLine{00094\ \ \ \ \ mCheckStagnationBeforeSuccess\ =\ b;}
\DoxyCodeLine{00095\ \}}
\DoxyCodeLine{00096\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setHistoryCostIncrement(\textcolor{keywordtype}{float}\ v)}
\DoxyCodeLine{00097\ \{}
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordflow}{if}\ (v\ <\ 0.0f)}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::runtime\_error(\textcolor{stringliteral}{"{}history\ cost\ increment\ must\ be\ positive"{}});}
\DoxyCodeLine{00100\ \ \ \ \ mHistoryCostIncrement\ =\ v;}
\DoxyCodeLine{00101\ \}}
\DoxyCodeLine{00102\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setHistoryCostDecay(\textcolor{keywordtype}{float}\ v)}
\DoxyCodeLine{00103\ \{}
\DoxyCodeLine{00104\ \ \ \ \ \textcolor{keywordflow}{if}\ (v\ <\ 0.0f\ ||\ v\ >\ 1.0f)}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::runtime\_error(\textcolor{stringliteral}{"{}must\ have\ 0\ <=\ history\ cost\ decay\ <=\ 1"{}});}
\DoxyCodeLine{00106\ \ \ \ \ mHistoryCostDecay\ =\ v;}
\DoxyCodeLine{00107\ \}}
\DoxyCodeLine{00108\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setHistoryCostMax(\textcolor{keywordtype}{float}\ v)}
\DoxyCodeLine{00109\ \{}
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keywordflow}{if}\ (v\ <\ 0.0f)}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::runtime\_error(\textcolor{stringliteral}{"{}history\ cost\ maximum\ must\ be\ positive"{}});}
\DoxyCodeLine{00112\ \ \ \ \ mHistoryCostMax\ =\ v;}
\DoxyCodeLine{00113\ \}}
\DoxyCodeLine{00114\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ RRRAgent::setRandomizeOrder(\textcolor{keywordtype}{bool}\ b)}
\DoxyCodeLine{00115\ \{}
\DoxyCodeLine{00116\ \ \ \ \ mRandomizeOrder\ =\ b;}
\DoxyCodeLine{00117\ \}}
\DoxyCodeLine{00118\ }
\DoxyCodeLine{00119\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ GYM\_PCB\_RRRAGENT\_H}}

\end{DoxyCode}
