| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2006-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef RAUTOMATON_H |
| 21 | #define RAUTOMATON_Hcxx . . $ `Kernel/RAutomaton.h:21:9`! |
| 22 | |
| 23 | #include <vector> |
| 24 | #include <iosfwd> |
| 25 | |
| 26 | #include "fpp_assert.h"cxx . . $ `<file>/Kernel/fpp_assert.h`/ |
| 27 | #include "tFastSet.h"cxx . . $ `<file>/Kernel/tFastSet.h`/ |
| 28 | |
| 29 | class TRolecxx . . $ TRole#; |
| 30 | |
| 31 | /// state of the role automaton |
| 32 | // TODO: think to use short |
| 33 | typedef unsigned int RAStatecxx . . $ RAState#; |
| 34 | |
| 35 | /// transition in the automaton for the role in RIQ-like languages |
| 36 | class RATransitioncxx . . $ RATransition# |
| 37 | { |
| 38 | protected: // typedefs |
| 39 | /// set or roles that labels transition |
| 40 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<const TRolecxx . . $ TRole#*> TLabelcxx . . $ RATransition#TLabel#; |
| 41 | |
| 42 | public: // typedefs |
| 43 | /// iterator over roles |
| 44 | typedef TLabelcxx . . $ RATransition#TLabel#::const_iteratorcxx . . $ std/vector#const_iterator# const_iteratorcxx . . $ RATransition#const_iterator#; |
| 45 | |
| 46 | protected: // members |
| 47 | /// set of roles that may affect the transition |
| 48 | TLabelcxx . . $ RATransition#TLabel# labelcxx . . $ RATransition#label.; |
| 49 | /// final state of the transition |
| 50 | RAStatecxx . . $ RAState# statecxx . . $ RATransition#state.; |
| 51 | |
| 52 | public: // interface |
| 53 | /// create a transition to given state |
| 54 | explicit RATransitioncxx . . $ RATransition#RATransition(cb2f890c2fdad230). ( RAStatecxx . . $ RAState# st ) : statecxx . . $ RATransition#state.(st) {} |
| 55 | /// create a transition with a given label R to given state ST |
| 56 | RATransitioncxx . . $ RATransition#RATransition(6d11a3757d356e3a). ( RAStatecxx . . $ RAState# st, const TRolecxx . . $ TRole#* R ) : statecxx . . $ RATransition#state.(st) { addcxx . . $ RATransition#add(67b1ad1f11addbc2).(R); } |
| 57 | /// copy c'tor |
| 58 | RATransitioncxx . . $ RATransition#RATransition(49cc212b42b37343). ( const RATransitioncxx . . $ RATransition#& ) = default; |
| 59 | /// move c'tor |
| 60 | RATransitioncxx . . $ RATransition#RATransition(265ed24da56d4f50). ( RATransitioncxx . . $ RATransition#&& ) = default; |
| 61 | /// assignment |
| 62 | RATransitioncxx . . $ RATransition#& operatorcxx . . $ RATransition#`operator=`(8639d81cfa4440e0). = ( const RATransitioncxx . . $ RATransition#& ) = default; |
| 63 | /// move assignment |
| 64 | RATransitioncxx . . $ RATransition#& operatorcxx . . $ RATransition#`operator=`(f647014f41384e2e). = ( RATransitioncxx . . $ RATransition#&& ) = default; |
| 65 | |
| 66 | /// check whether transition is applicable wrt role R |
| 67 | bool applicablecxx . . $ RATransition#applicable(81d69a9c8508a392). ( const TRolecxx . . $ TRole#* R ) const |
| 68 | { |
| 69 | return stdcxx . . $ std/::any_ofcxx . . $ std/any_of(f82cc6ce9cd000ea). ( labelcxx . . $ RATransition#label..cbegincxx . . $ std/vector#cbegin(359ca5030082c9f).(), labelcxx . . $ RATransition#label..cendcxx . . $ std/vector#cend(359ca5030082c9f).(), [=] (const TRolecxx . . $ TRole#* S) { return S == R; } ); |
| 70 | } |
| 71 | |
| 72 | // update the transition |
| 73 | |
| 74 | /// add role R to transition's label |
| 75 | void addcxx . . $ RATransition#add(67b1ad1f11addbc2). ( const TRolecxx . . $ TRole#* R ) { labelcxx . . $ RATransition#label..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(R); } |
| 76 | /// add role R to transition's label |
| 77 | void addIfNewcxx . . $ RATransition#addIfNew(67b1ad1f11addbc2). ( const TRolecxx . . $ TRole#* R ) { if ( !applicablecxx . . $ RATransition#applicable(81d69a9c8508a392).(R) ) addcxx . . $ RATransition#add(67b1ad1f11addbc2).(R); } |
| 78 | /// add label of transition TRANS to transition's label |
| 79 | void addcxx . . $ RATransition#add(49cc212b42b37343). ( const RATransitioncxx . . $ RATransition#& trans ) |
| 80 | { labelcxx . . $ RATransition#label..insertcxx . . $ std/vector#insert(134ef7853f0b3ebe). ( labelcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0)..endcxx . . $ std/vector#end(33b10a496a38335b).(), trans.labelcxx . . $ RATransition#label..cbegincxx . . $ std/vector#cbegin(359ca5030082c9f).(), trans.labelcxx . . $ RATransition#label..cendcxx . . $ std/vector#cend(359ca5030082c9f).() ); } |
| 81 | /// add label of transition TRANS to transition's label only if they are new |
| 82 | void addIfNewcxx . . $ RATransition#addIfNew(49cc212b42b37343). ( const RATransitioncxx . . $ RATransition#& trans ) |
| 83 | { |
| 84 | stdcxx . . $ std/::for_eachcxx . . $ std/for_each(88304b602929f6f4). ( trans.labelcxx . . $ RATransition#label..cbegincxx . . $ std/vector#cbegin(359ca5030082c9f).(), trans.labelcxx . . $ RATransition#label..cendcxx . . $ std/vector#cend(359ca5030082c9f).(), [=] (const TRolecxx . . $ TRole#* R) { addIfNewcxx . . $ RATransition#addIfNew(67b1ad1f11addbc2).(R); } ); |
| 85 | } |
| 86 | |
| 87 | // query the transition |
| 88 | |
| 89 | /// get the 1st role in (multi-)transition |
| 90 | const_iteratorcxx . . $ RATransition#const_iterator# begincxx . . $ RATransition#begin(506035cb53656567). ( void ) const { return labelcxx . . $ RATransition#label..begincxx . . $ std/vector#begin(359ca5030082c9f).(); } |
| 91 | /// get the last role in (multi-)transition |
| 92 | const_iteratorcxx . . $ RATransition#const_iterator# endcxx . . $ RATransition#end(506035cb53656567). ( void ) const { return labelcxx . . $ RATransition#label..endcxx . . $ std/vector#end(359ca5030082c9f).(); } |
| 93 | |
| 94 | /// give a final point of the transition |
| 95 | RAStatecxx . . $ RAState# finalcxx . . $ RATransition#final(ddd8539a2fcdd4ce). ( void ) const { return statecxx . . $ RATransition#state.; } |
| 96 | /// check whether transition is empty |
| 97 | bool emptycxx . . $ RATransition#empty(50ce9a9e25b4a850). ( void ) const { return labelcxx . . $ RATransition#label..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); } |
| 98 | /// check whether transition is TopRole one |
| 99 | bool isTopcxx . . $ RATransition#isTop(50ce9a9e25b4a850). ( void ) const; |
| 100 | /// print the transition starting from FROM |
| 101 | void Printcxx . . $ RATransition#Print(88043dd2772042aa). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o, RAStatecxx . . $ RAState# from ) const; |
| 102 | }; // RATransition |
| 103 | |
| 104 | /// class to represent transitions from a single state in an automaton |
| 105 | class RAStateTransitionscxx . . $ RAStateTransitions# |
| 106 | { |
| 107 | protected: // types |
| 108 | /// keep all the transitions |
| 109 | typedef stdcxx . . $ std/::vectorcxx . . $ std/vector#<RATransitioncxx . . $ RATransition#> RTBasecxx . . $ RAStateTransitions#RTBase#; |
| 110 | /// RW iterators |
| 111 | typedef RTBasecxx . . $ RAStateTransitions#RTBase#::iteratorcxx . . $ std/vector#iterator# iteratorcxx . . $ RAStateTransitions#iterator#; |
| 112 | |
| 113 | public: // type interface |
| 114 | /// RO iterators |
| 115 | typedef RTBasecxx . . $ RAStateTransitions#RTBase#::const_iteratorcxx . . $ std/vector#const_iterator# const_iteratorcxx . . $ RAStateTransitions#const_iterator#; |
| 116 | |
| 117 | protected: // members |
| 118 | /// all transitions |
| 119 | RTBasecxx . . $ RAStateTransitions#RTBase# Basecxx . . $ RAStateTransitions#Base.; |
| 120 | /// set of all roles that can be applied by one of the transitions |
| 121 | TFastSetcxx . . $ TFastSet#<unsigned int> ApplicableRolescxx . . $ RAStateTransitions#ApplicableRoles.; |
| 122 | /// state from which all the transition starts |
| 123 | RAStatecxx . . $ RAState# fromcxx . . $ RAStateTransitions#from.; |
| 124 | /// check whether there is an empty transition going from this state |
| 125 | bool EmptyTransitioncxx . . $ RAStateTransitions#EmptyTransition. = false; |
| 126 | /// true iff there is a top transition going from this state |
| 127 | bool TopTransitioncxx . . $ RAStateTransitions#TopTransition. = false; |
| 128 | /// flag whether the role is data or not (valid only for simple automata) |
| 129 | bool DataRolecxx . . $ RAStateTransitions#DataRole.; |
| 130 | |
| 131 | public: // interface |
| 132 | /// empty c'tor |
| 133 | RAStateTransitionscxx . . $ RAStateTransitions#RAStateTransitions(49f6e7a06ebc5aa8).()= default; |
| 134 | /// copy c'tor |
| 135 | RAStateTransitionscxx . . $ RAStateTransitions#RAStateTransitions(8c5c52e881c2873b). ( const RAStateTransitionscxx . . $ RAStateTransitions#& ) = default; |
| 136 | /// move c'tor |
| 137 | RAStateTransitionscxx . . $ RAStateTransitions#RAStateTransitions(2236e31168dc1964). ( RAStateTransitionscxx . . $ RAStateTransitions#&& ) = default; |
| 138 | /// assignment |
| 139 | RAStateTransitionscxx . . $ RAStateTransitions#& operatorcxx . . $ RAStateTransitions#`operator=`(92fc4ab46cf40c9f). = ( const RAStateTransitionscxx . . $ RAStateTransitions#& ) = default; |
| 140 | /// move assignment |
| 141 | RAStateTransitionscxx . . $ RAStateTransitions#& operatorcxx . . $ RAStateTransitions#`operator=`(1735ad94673d8402). = ( RAStateTransitionscxx . . $ RAStateTransitions#&& ) = default; |
| 142 | |
| 143 | /// set up state transitions: no more additions to the structure |
| 144 | void finalisecxx . . $ RAStateTransitions#finalise(552a8a0739473b9a). ( RAStatecxx . . $ RAState# state, size_tcxx . . $ size_t# nRoles, bool data ); |
| 145 | |
| 146 | /// add a transition from a given state |
| 147 | void addcxx . . $ RAStateTransitions#add(265ed24da56d4f50). ( RATransitioncxx . . $ RATransition#&& trans ) |
| 148 | { |
| 149 | if ( trans.emptycxx . . $ RATransition#empty(50ce9a9e25b4a850).() ) |
| 150 | EmptyTransitioncxx . . $ RAStateTransitions#EmptyTransition. = true; |
| 151 | if ( trans.isTopcxx . . $ RATransition#isTop(50ce9a9e25b4a850).() ) |
| 152 | TopTransitioncxx . . $ RAStateTransitions#TopTransition. = true; |
| 153 | Basecxx . . $ RAStateTransitions#Base..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(trans)); |
| 154 | } |
| 155 | /// copy information from TRANS to existing transition between the same states. @return false if no such transition found |
| 156 | bool addToExistingcxx . . $ RAStateTransitions#addToExisting(97732fae2d1abfaf). ( const RATransitioncxx . . $ RATransition#& trans ); |
| 157 | |
| 158 | /// @return true iff there are no transitions from this state |
| 159 | bool emptycxx . . $ RAStateTransitions#empty(50ce9a9e25b4a850). ( void ) const { return Basecxx . . $ RAStateTransitions#Base..emptycxx . . $ std/vector#empty(50ce9a9e25b4a850).(); } |
| 160 | /// @return true iff there is an empty transition from the state |
| 161 | bool hasEmptyTransitioncxx . . $ RAStateTransitions#hasEmptyTransition(50ce9a9e25b4a850). ( void ) const { return EmptyTransitioncxx . . $ RAStateTransitions#EmptyTransition.; } |
| 162 | /// @return true iff there is a top-role transition from the state |
| 163 | bool hasTopTransitioncxx . . $ RAStateTransitions#hasTopTransition(50ce9a9e25b4a850). ( void ) const { return TopTransitioncxx . . $ RAStateTransitions#TopTransition.; } |
| 164 | |
| 165 | // RO access |
| 166 | |
| 167 | /// RO begin |
| 168 | const_iteratorcxx . . $ RAStateTransitions#const_iterator# begincxx . . $ RAStateTransitions#begin(749dc97118b098e3). ( void ) const { return Basecxx . . $ RAStateTransitions#Base..begincxx . . $ std/vector#begin(359ca5030082c9f).(); } |
| 169 | /// RO end |
| 170 | const_iteratorcxx . . $ RAStateTransitions#const_iterator# endcxx . . $ RAStateTransitions#end(749dc97118b098e3). ( void ) const { return Basecxx . . $ RAStateTransitions#Base..endcxx . . $ std/vector#end(359ca5030082c9f).(); } |
| 171 | /// get FROM state |
| 172 | RAStatecxx . . $ RAState# getFromcxx . . $ RAStateTransitions#getFrom(ddd8539a2fcdd4ce). ( void ) const { return fromcxx . . $ RAStateTransitions#from.; } |
| 173 | /// check whether one of the transitions accept R; implementation is in tRole.h |
| 174 | bool recognisecxx . . $ RAStateTransitions#recognise(81d69a9c8508a392). ( const TRolecxx . . $ TRole#* R ) const; |
| 175 | /// @return true iff there is only one transition |
| 176 | bool isSingletoncxx . . $ RAStateTransitions#isSingleton(50ce9a9e25b4a850). ( void ) const { return Basecxx . . $ RAStateTransitions#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() == 1; } |
| 177 | /// @return final state of the 1st transition; used for singletons |
| 178 | RAStatecxx . . $ RAState# getTransitionEndcxx . . $ RAStateTransitions#getTransitionEnd(ddd8539a2fcdd4ce). ( void ) const { return Basecxx . . $ RAStateTransitions#Base..frontcxx . . $ std/vector#front(41f1d0357789174c).().finalcxx . . $ RATransition#final(ddd8539a2fcdd4ce).(); } |
| 179 | |
| 180 | /// print all the transitions starting from the state FROM |
| 181 | void Printcxx . . $ RAStateTransitions#Print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const |
| 182 | { |
| 183 | for ( auto& trans: Basecxx . . $ RAStateTransitions#Base. ) |
| 184 | trans.Printcxx . . $ RATransition#Print(88043dd2772042aa). ( o, fromcxx . . $ RAStateTransitions#from. ); |
| 185 | } |
| 186 | }; // RAStateTransitions |
| 187 | |
| 188 | /// automaton for the role in RIQ-like languages |
| 189 | class RoleAutomatoncxx . . $ RoleAutomaton# |
| 190 | { |
| 191 | protected: // members |
| 192 | /// all transitions of the automaton, grouped by a starting state |
| 193 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<RAStateTransitionscxx . . $ RAStateTransitions#> Basecxx . . $ RoleAutomaton#Base.; |
| 194 | /// maps original automata state into the new ones (used in copyRA) |
| 195 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int> mapcxx . . $ RoleAutomaton#map.; |
| 196 | /// initial state of the next automaton in chain |
| 197 | RAStatecxx . . $ RAState# iRAcxx . . $ RoleAutomaton#iRA. = 0; |
| 198 | /// flag whether automaton is input safe |
| 199 | bool ISafecxx . . $ RoleAutomaton#ISafe. = true; |
| 200 | /// flag whether automaton is output safe |
| 201 | bool OSafecxx . . $ RoleAutomaton#OSafe. = true; |
| 202 | /// flag for the automaton to be completed |
| 203 | bool Completecxx . . $ RoleAutomaton#Complete. = false; |
| 204 | |
| 205 | protected: // methods |
| 206 | /// make sure that STATE exists in the automaton (update ton's size) |
| 207 | void ensureStatecxx . . $ RoleAutomaton#ensureState(cb2f890c2fdad230). ( RAStatecxx . . $ RAState# state ) |
| 208 | { |
| 209 | if ( state >= Basecxx . . $ RoleAutomaton#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).() ) |
| 210 | Basecxx . . $ RoleAutomaton#Base..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(state+1); |
| 211 | } |
| 212 | |
| 213 | /// state that the automaton is i-unsafe |
| 214 | void setIUnsafecxx . . $ RoleAutomaton#setIUnsafe(49f6e7a06ebc5aa8). ( void ) { ISafecxx . . $ RoleAutomaton#ISafe. = false; } |
| 215 | /// state that the automaton is o-unsafe |
| 216 | void setOUnsafecxx . . $ RoleAutomaton#setOUnsafe(49f6e7a06ebc5aa8). ( void ) { OSafecxx . . $ RoleAutomaton#OSafe. = false; } |
| 217 | /// check whether transition between FROM and TO breaks safety |
| 218 | void checkTransitioncxx . . $ RoleAutomaton#checkTransition(b4d55b1286ff73e8). ( RAStatecxx . . $ RAState# from, RAStatecxx . . $ RAState# to ) |
| 219 | { |
| 220 | if ( from == finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce).() ) |
| 221 | setOUnsafecxx . . $ RoleAutomaton#setOUnsafe(49f6e7a06ebc5aa8).(); |
| 222 | if ( to == initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).() ) |
| 223 | setIUnsafecxx . . $ RoleAutomaton#setIUnsafe(49f6e7a06ebc5aa8).(); |
| 224 | } |
| 225 | |
| 226 | /// add TRANSition leading from a state FROM; all states are known to fit the ton |
| 227 | void addTransitioncxx . . $ RoleAutomaton#addTransition(ee5932827597e1f9). ( RAStatecxx . . $ RAState# from, RATransitioncxx . . $ RATransition#&& trans ) |
| 228 | { |
| 229 | checkTransitioncxx . . $ RoleAutomaton#checkTransition(b4d55b1286ff73e8). ( from, trans.finalcxx . . $ RATransition#final(ddd8539a2fcdd4ce).() ); |
| 230 | Basecxx . . $ RoleAutomaton#Base.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).from].addcxx . . $ RAStateTransitions#add(265ed24da56d4f50).(stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(trans)); |
| 231 | } |
| 232 | /// make the internal chain transition (between chainState and TO) |
| 233 | void nextChainTransitioncxx . . $ RoleAutomaton#nextChainTransition(cb2f890c2fdad230). ( RAStatecxx . . $ RAState# to ) |
| 234 | { |
| 235 | addTransitioncxx . . $ RoleAutomaton#addTransition(ee5932827597e1f9). ( iRAcxx . . $ RoleAutomaton#iRA., RATransitioncxx . . $ RATransition#RATransition(cb2f890c2fdad230).(to) ); |
| 236 | iRAcxx . . $ RoleAutomaton#iRA. = to; |
| 237 | } |
| 238 | |
| 239 | /// add copy of the RA to given one; use internal MAP to renumber the states |
| 240 | void addCopycxx . . $ RoleAutomaton#addCopy(12494a229a69a5c3). ( const RoleAutomatoncxx . . $ RoleAutomaton#& RA ); |
| 241 | /// init internal map according to RA size and final (FRA) states |
| 242 | void initMapcxx . . $ RoleAutomaton#initMap(34e6b58f48c1be0a). ( size_tcxx . . $ size_t# RASize, RAStatecxx . . $ RAState# fRA ); |
| 243 | |
| 244 | public: // interface |
| 245 | /// empty c'tor |
| 246 | RoleAutomatoncxx . . $ RoleAutomaton#RoleAutomaton(49f6e7a06ebc5aa8).() { ensureStatecxx . . $ RoleAutomaton#ensureState(cb2f890c2fdad230).(1); } |
| 247 | /// copy c'tor |
| 248 | RoleAutomatoncxx . . $ RoleAutomaton#RoleAutomaton(12494a229a69a5c3). ( const RoleAutomatoncxx . . $ RoleAutomaton#& ) = default; |
| 249 | /// move c'tor |
| 250 | RoleAutomatoncxx . . $ RoleAutomaton#RoleAutomaton(43a9a76aaad739a7). ( RoleAutomatoncxx . . $ RoleAutomaton#&& ) = default; |
| 251 | /// assignment |
| 252 | RoleAutomatoncxx . . $ RoleAutomaton#& operatorcxx . . $ RoleAutomaton#`operator=`(44ac9e27247554fe).= ( const RoleAutomatoncxx . . $ RoleAutomaton#& ) = default; |
| 253 | /// move assignment |
| 254 | RoleAutomatoncxx . . $ RoleAutomaton#& operatorcxx . . $ RoleAutomaton#`operator=`(5da0156bd8a5ae9c).= ( RoleAutomatoncxx . . $ RoleAutomaton#&& ) = default; |
| 255 | |
| 256 | // access to states |
| 257 | |
| 258 | /// get the initial state |
| 259 | RAStatecxx . . $ RAState# initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce). ( void ) const { return 0; } |
| 260 | /// get the final state |
| 261 | RAStatecxx . . $ RAState# finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce). ( void ) const { return 1; } |
| 262 | /// create new state |
| 263 | RAStatecxx . . $ RAState# newStatecxx . . $ RoleAutomaton#newState(db52760e79bf9054). ( void ) |
| 264 | { |
| 265 | RAStatecxx . . $ RAState# ret = (RAStatecxx . . $ RAState#) Basecxx . . $ RoleAutomaton#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); |
| 266 | ensureStatecxx . . $ RoleAutomaton#ensureState(cb2f890c2fdad230).(ret); |
| 267 | return ret; |
| 268 | } |
| 269 | |
| 270 | /// get access to the transitions starting from STATE |
| 271 | const RAStateTransitionscxx . . $ RAStateTransitions#& operatorcxx . . $ RoleAutomaton#`operator[]`(49d1c2a99a57610b). [] ( RAStatecxx . . $ RAState# state ) const { return Basecxx . . $ RoleAutomaton#Base.[cxx . . $ std/vector#`operator[]`(b61e45a10b63f40a).state]; } |
| 272 | /// set up all transitions passing number of roles |
| 273 | void setupcxx . . $ RoleAutomaton#setup(62a5225ebb2f873). ( size_tcxx . . $ size_t# nRoles, bool data ) |
| 274 | { |
| 275 | for ( RAStatecxx . . $ RAState# i = 0; i < Basecxx . . $ RoleAutomaton#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); ++i ) |
| 276 | Basecxx . . $ RoleAutomaton#Base.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i].finalisecxx . . $ RAStateTransitions#finalise(552a8a0739473b9a). ( i, nRoles, data ); |
| 277 | } |
| 278 | |
| 279 | // automaton's construction |
| 280 | |
| 281 | /// add TRANSition leading from a given STATE; check whether all states are correct |
| 282 | void addTransitionSafecxx . . $ RoleAutomaton#addTransitionSafe(ee5932827597e1f9). ( RAStatecxx . . $ RAState# state, RATransitioncxx . . $ RATransition#&& trans ) |
| 283 | { |
| 284 | ensureStatecxx . . $ RoleAutomaton#ensureState(cb2f890c2fdad230).(state); |
| 285 | ensureStatecxx . . $ RoleAutomaton#ensureState(cb2f890c2fdad230).(trans.finalcxx . . $ RATransition#final(ddd8539a2fcdd4ce).()); |
| 286 | addTransitioncxx . . $ RoleAutomaton#addTransition(ee5932827597e1f9). ( state, stdcxx . . $ std/::movecxx . . $ std/move(e7c6c0c8363dcc46).(trans) ); |
| 287 | } |
| 288 | |
| 289 | // chain automaton creation |
| 290 | |
| 291 | /// make the beginning of the chain |
| 292 | void initChaincxx . . $ RoleAutomaton#initChain(cb2f890c2fdad230). ( RAStatecxx . . $ RAState# from ) { iRAcxx . . $ RoleAutomaton#iRA. = from; } |
| 293 | /// add an Automaton to the chain that would start from the iRA; OSAFE shows the safety of a previous automaton in a chain |
| 294 | bool addToChaincxx . . $ RoleAutomaton#addToChain(43b07b70767d9338). ( const RoleAutomatoncxx . . $ RoleAutomaton#& RA, bool oSafe, RAStatecxx . . $ RAState# fRA ); |
| 295 | /// add an Automaton to the chain with a default final state |
| 296 | bool addToChaincxx . . $ RoleAutomaton#addToChain(cdf2e7af082d3283). ( const RoleAutomatoncxx . . $ RoleAutomaton#& RA, bool oSafe ) { return addToChaincxx . . $ RoleAutomaton#addToChain(43b07b70767d9338). ( RA, oSafe, (RAStatecxx . . $ RAState#) sizecxx . . $ RoleAutomaton#size(fe4d2d262d4164a8).()+1 ); } |
| 297 | |
| 298 | // i/o safety |
| 299 | |
| 300 | /// get the i-safe value |
| 301 | bool isISafecxx . . $ RoleAutomaton#isISafe(50ce9a9e25b4a850). ( void ) const { return ISafecxx . . $ RoleAutomaton#ISafe.; } |
| 302 | /// get the o-safe value |
| 303 | bool isOSafecxx . . $ RoleAutomaton#isOSafe(50ce9a9e25b4a850). ( void ) const { return OSafecxx . . $ RoleAutomaton#OSafe.; } |
| 304 | |
| 305 | // automaton completeness |
| 306 | |
| 307 | /// mark an automaton as completed |
| 308 | void setCompletedcxx . . $ RoleAutomaton#setCompleted(49f6e7a06ebc5aa8). ( void ) { Completecxx . . $ RoleAutomaton#Complete. = true; } |
| 309 | /// check whether automaton is completed |
| 310 | bool isCompletedcxx . . $ RoleAutomaton#isCompleted(50ce9a9e25b4a850). ( void ) const { return Completecxx . . $ RoleAutomaton#Complete.; } |
| 311 | |
| 312 | // get some stats |
| 313 | |
| 314 | /// return number of distinct states |
| 315 | size_tcxx . . $ size_t# sizecxx . . $ RoleAutomaton#size(fe4d2d262d4164a8). ( void ) const { return Basecxx . . $ RoleAutomaton#Base..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); } |
| 316 | /// @return true iff the automaton is simple |
| 317 | bool isSimplecxx . . $ RoleAutomaton#isSimple(50ce9a9e25b4a850). ( void ) const |
| 318 | { |
| 319 | fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`!(isCompleted()); |
| 320 | return sizecxx . . $ RoleAutomaton#size(fe4d2d262d4164a8).() == 2 && ISafecxx . . $ RoleAutomaton#ISafe. && OSafecxx . . $ RoleAutomaton#OSafe.; |
| 321 | } |
| 322 | |
| 323 | // add single RA |
| 324 | |
| 325 | /// add RA from a subrole to given one |
| 326 | void addRAcxx . . $ RoleAutomaton#addRA(12494a229a69a5c3). ( const RoleAutomatoncxx . . $ RoleAutomaton#& RA ) |
| 327 | { |
| 328 | fpp_assertcxx . . $ RoleAutomaton#isCompleted(50ce9a9e25b4a850).(!isCompleted()); |
| 329 | if ( RA.isSimplecxx . . $ RoleAutomaton#isSimple(50ce9a9e25b4a850).() ) |
| 330 | { |
| 331 | bool ok = Basecxx . . $ RoleAutomaton#Base.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).()].addToExistingcxx . . $ RAStateTransitions#addToExisting(97732fae2d1abfaf).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).RA[cxx . . $ RoleAutomaton#`operator[]`(49d1c2a99a57610b).initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).()].begincxx . . $ RAStateTransitions#begin(749dc97118b098e3).()); |
| 332 | fpp_assertcxx . . $ EFPPAssertion#(ok); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | initChaincxx . . $ RoleAutomaton#initChain(cb2f890c2fdad230).(initialcxx . . $ RoleAutomaton#initial(ddd8539a2fcdd4ce).()); |
| 337 | addToChaincxx . . $ RoleAutomaton#addToChain(43b07b70767d9338). ( RA, /*oSafe=*/false, finalcxx . . $ RoleAutomaton#final(ddd8539a2fcdd4ce).() ); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /// print an automaton |
| 342 | void Printcxx . . $ RoleAutomaton#Print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const |
| 343 | { |
| 344 | for ( auto& StateTransitions: Basecxx . . $ RoleAutomaton#Base. ) |
| 345 | StateTransitions.Printcxx . . $ RAStateTransitions#Print(490063bd7e6d8d5d).(o); |
| 346 | } |
| 347 | }; // RoleAutomaton |
| 348 | |
| 349 | #endif |
| 350 |