12 #ifndef FAUDES_HYB_HGENERATOR_H
13 #define FAUDES_HYB_HGENERATOR_H
235 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
621 virtual bool Valid(
void)
const;
684 #define THIS TlhaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
685 #define BASE TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
686 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
691 FD_DG(
"lhaGenerator(" <<
this <<
")::lhaGenerator()");
696 FD_DG(
"lhaGenerator(" <<
this <<
")::lhaGenerator(rOtherGen)");
701 FD_DG(
"lhaGenerator(" <<
this <<
")::lhaGenerator(rOtherGen) with csymtab");
705 TEMP THIS::TlhaGenerator(
const std::string& rFileName) :
BASE(rFileName) {
706 FD_DG(
"lhaGenerator(" <<
this <<
")::lhaGenerator(" << rFileName <<
")");
715 res->EventSymbolTablep(BASE::mpEventSymbolTable);
716 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
730 TEMP int THIS::Dimension(
void)
const {
731 return BASE::pGlobalAttribute->mStateSpace.Dimension();
736 return BASE::pGlobalAttribute->mStateSpace;
747 BASE::pGlobalAttribute->mStateSpace=states;
752 if(!BASE::ExistsState(stateindex)) {
753 std::stringstream errstr;
754 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
755 throw Exception(
"lhaGenerator::Invariant", errstr.str(), 90);
757 return BASE::pStates->Attribute(stateindex).mInvariant;
762 if(!BASE::ExistsState(stateindex)) {
763 std::stringstream errstr;
764 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
765 throw Exception(
"lhaGenerator::Invariant", errstr.str(), 90);
767 return &BASE::pStates->Attributep(stateindex)->mInvariant;
772 if(!BASE::ExistsState(stateindex)) {
773 std::stringstream errstr;
774 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
775 throw Exception(
"lhaGenerator::Invariant", errstr.str(), 90);
777 if(Dimension()!=rInvariant.
Dimension()) {
778 std::stringstream errstr;
779 errstr <<
"dimension mismatch for state index " << stateindex;
780 throw Exception(
"lhaGenerator::Invariant", errstr.str(), 700);
782 BASE::pStates->Attributep(stateindex)->mInvariant=rInvariant;
787 Idx idx=BASE::StateIndex(statename);
788 return Invariant(idx);
792 TEMP void THIS::Invariant(
const std::string& statename,
const Polyhedron& rInvariant) {
793 Idx idx=BASE::StateIndex(statename);
794 Invariant(idx,rInvariant);
801 if(!BASE::ExistsState(stateindex)) {
802 std::stringstream errstr;
803 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
804 throw Exception(
"lhaGenerator::InitialConstraint", errstr.str(), 90);
806 const Polyhedron& iconstraint = BASE::pStates->Attributep(stateindex)->mInitialConstraint;
807 if(iconstraint.
Dimension()==0)
const_cast< Polyhedron&
>(iconstraint).Dimension(Dimension());
813 if(!BASE::ExistsState(stateindex)) {
814 std::stringstream errstr;
815 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
816 throw Exception(
"lhaGenerator::InitialConstraint", errstr.str(), 90);
818 Polyhedron& iconstraint = BASE::pStates->Attributep(stateindex)->mInitialConstraint;
825 if(!BASE::ExistsState(stateindex)) {
826 std::stringstream errstr;
827 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
828 throw Exception(
"lhaGenerator::InitialConstraint", errstr.str(), 90);
830 if(Dimension()!=rInitialConstraint.
Dimension()) {
831 std::stringstream errstr;
832 errstr <<
"dimension mismatch for state index " << stateindex;
833 throw Exception(
"lhaGenerator::InitialConstraint", errstr.str(), 700);
835 BASE::pStates->Attributep(stateindex)->mInitialConstraint=rInitialConstraint;
839 TEMP const Polyhedron& THIS::InitialConstraint(
const std::string& statename)
const {
840 Idx idx=BASE::StateIndex(statename);
841 return InitialConstraint(idx);
845 TEMP void THIS::InitialConstraint(
const std::string& statename,
const Polyhedron& rInitialConstraint) {
846 Idx idx=BASE::StateIndex(statename);
847 InitialConstraint(idx,rInitialConstraint);
852 if(!BASE::ExistsState(stateindex)) {
853 std::stringstream errstr;
854 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
855 throw Exception(
"lhaGenerator::Rate", errstr.str(), 90);
857 return BASE::pStates->Attribute(stateindex).mRate;
862 if(!BASE::ExistsState(stateindex)) {
863 std::stringstream errstr;
864 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
865 throw Exception(
"lhaGenerator::Rate", errstr.str(), 90);
867 return &BASE::pStates->Attributep(stateindex)->mRate;
872 if(!BASE::ExistsState(stateindex)) {
873 std::stringstream errstr;
874 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
875 throw Exception(
"lhaGenerator::Rate", errstr.str(), 90);
878 std::stringstream errstr;
879 errstr <<
"dimension mismatch for state index " << stateindex;
880 throw Exception(
"lhaGenerator::Rate", errstr.str(), 700);
882 BASE::pStates->Attributep(stateindex)->mRate=rRate;
887 Idx idx=BASE::StateIndex(statename);
893 Idx idx=BASE::StateIndex(statename);
901 if(!BASE::ExistsTransition(trans)) {
902 std::stringstream errstr;
903 errstr <<
"transition " << trans.
Str() <<
" not found in TransRel" << std::endl;
904 throw Exception(
"lhaGenerator::Guard", errstr.str(), 90);
906 const Polyhedron& guard = BASE::pTransRel->Attributep(trans)->mGuard;
907 if(guard.
Size()==0)
const_cast< Polyhedron&
>(guard).Dimension(Dimension());
913 if(!BASE::ExistsTransition(trans)) {
914 std::stringstream errstr;
915 errstr <<
"transition " << trans.
Str() <<
" not found in TransRel" << std::endl;
916 throw Exception(
"lhaGenerator::Guard", errstr.str(), 90);
918 Polyhedron& guard = BASE::pTransRel->Attributep(trans)->mGuard;
919 if(guard.
Size()==0)
const_cast< Polyhedron&
>(guard).Dimension(Dimension());
925 if(!BASE::ExistsTransition(trans)) {
926 std::stringstream errstr;
927 errstr <<
"transition " << trans.
Str() <<
" not found in TransRel" << std::endl;
928 throw Exception(
"lhaGenerator::Guard", errstr.str(), 90);
931 std::stringstream errstr;
932 errstr <<
"dimension mismatch for guard at transition " << trans.
Str();
933 throw Exception(
"lhaGenerator::Guard", errstr.str(), 700);
935 BASE::pTransRel->Attributep(trans)->mGuard=rGuard;
941 if(!BASE::ExistsTransition(trans)) {
942 std::stringstream errstr;
943 errstr <<
"transition " << trans.
Str() <<
" not found in TransRel" << std::endl;
944 throw Exception(
"lhaGenerator::Reset", errstr.str(), 90);
946 const LinearRelation& reset = BASE::pTransRel->Attributep(trans)->mReset;
953 if(!BASE::ExistsTransition(trans)) {
954 std::stringstream errstr;
955 errstr <<
"transition " << trans.
Str() <<
" not found in TransRel" << std::endl;
956 throw Exception(
"lhaGenerator::Reset", errstr.str(), 90);
958 LinearRelation& reset = BASE::pTransRel->Attributep(trans)->mReset;
965 if(!BASE::ExistsState(trans)) {
966 std::stringstream errstr;
967 errstr <<
"transition " << trans.
Str() <<
" not found in TransRel" << std::endl;
968 throw Exception(
"lhaGenerator::Reset", errstr.str(), 90);
971 std::stringstream errstr;
972 errstr <<
"dimension mismatch for guard at transition " << trans.
Str();
973 throw Exception(
"lhaGenerator::Reset", errstr.str(), 700);
975 BASE::pTransRel->Attributep(trans)->mReset=rReset;
981 TEMP bool THIS::Valid(
void)
const {
982 FD_DG(
"lhaGenerator(" <<
this <<
")::Valid()");
984 if(!BASE::Valid())
return false;
986 StateSet::Iterator sit;
987 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
988 if(Invariant(*sit).Dimension()!=Dimension())
return false;
991 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
992 if(Guard(*tit).Dimension()!=Dimension())
return false;
993 if(Reset(*tit).Dimension()!=Dimension())
return false;
1001 TEMP bool THIS::UpdateAttributes(
void) {
1002 FD_DG(
"lhaGenerator(" <<
this <<
")::UpdateAttributes()");
1009 FD_DG(
"lhaGenerator(" <<
this <<
")::DoRead(...)");
1010 std::cout <<
"lhaGenerator(" <<
this <<
")::DoRead(...)";
1012 BASE::DoRead(rTr,rLabel,pContext);
1014 StateSet::Iterator sit;
1015 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1016 if(Invariant(*sit).Dimension()==0) Invariantp(*sit)->Dimension(Dimension());
1017 if(Invariant(*sit).Dimension()!=Dimension()) {
1018 std::stringstream errstr;
1019 errstr <<
"dimension mismatch for invariant at state index " << *sit;
1020 throw Exception(
"lhaGenerator::DoRead", errstr.str(), 700);
1022 if(InitialConstraint(*sit).Dimension()==0) InitialConstraintp(*sit)->Dimension(Dimension());
1023 if(InitialConstraint(*sit).Dimension()!=Dimension()) {
1024 std::stringstream errstr;
1025 errstr <<
"dimension mismatch for initial constraint at state index " << *sit;
1026 throw Exception(
"lhaGenerator::DoRead", errstr.str(), 700);
1028 if(Rate(*sit).Dimension()==0) Ratep(*sit)->Dimension(Dimension());
1029 if(Rate(*sit).Dimension()!=Dimension()) {
1030 std::stringstream errstr;
1031 errstr <<
"dimension mismatch for rate at state index " << *sit;
1032 throw Exception(
"lhaGenerator::DoRead", errstr.str(), 700);
1036 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1037 if(Guard(*tit).Dimension()==0) Guardp(*tit)->Dimension(Dimension());
1038 if(Guard(*tit).Dimension()!=Dimension()) {
1039 std::stringstream errstr;
1040 errstr <<
"dimension mismatch for guard transition index " << tit->Str();
1041 throw Exception(
"lhaGenerator::DoRead", errstr.str(), 700);
1043 if(Reset(*tit).Dimension()==0) Resetp(*tit)->Dimension(Dimension());
1044 if(Reset(*tit).Dimension()!=Dimension()) {
1045 std::stringstream errstr;
1046 errstr <<
"dimension mismatch for reset transition index " << tit->Str();
1047 throw Exception(
"lhaGenerator::DoRead", errstr.str(), 700);
1054 this->DoXWrite(rTw,rLabel,pContext);
#define FD_DG(message)
Debug: optional report on generator operations.
bool Identity(void) const
Test for data format.
int Dimension(void) const
Get dimension.
Idx Size(void) const
Get size.
int Dimension(void) const
Get dimension.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Generator with specified attribute types.
virtual TaGenerator & Assign(const Type &rSrc)
Copy from other faudes Type (try to cast to agenerator or pass to base)
Set of indices with attributes.
Set of Transitions with attributes.
Generator with linear hybrid automata extensions.
virtual bool UpdateAttributes(void)
Updates internal attributes.
virtual bool Valid(void) const
Check if generator is valid.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read generator object from TokenReader, see Type::Read for public wrappers.
const Polyhedron & Rate(Idx idx) const
Get rate of state by index.
TlhaGenerator * Copy(void) const
Construct copy on heap.
const Polyhedron & InitialConstraint(Idx idx) const
Get initial constraint of state by index.
Polyhedron * Guardp(const Transition &rTrans)
Get guard of a transition.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write generator object to TokenWriter, see Type::Write for public wrappers.
int Dimension(void) const
Get dimension of continuous statespace.
virtual const Type * Cast(const Type *pOther) const
Type test.
const Polyhedron & StateSpace(void) const
Get continuous statespace.
TlhaGenerator * New(void) const
Construct on heap.
Polyhedron * InitialConstraintp(Idx idx)
Get initial constraint of state by index.
const Polyhedron & Guard(const Transition &rTrans) const
Get guard of a transition.
TlhaGenerator(void)
Constructor.
Polyhedron * Ratep(Idx idx)
Get rate of state by index.
const Polyhedron & Invariant(Idx idx) const
Get invariant of state by index.
const LinearRelation & Reset(const Transition &rTrans) const
Get reset of a transition.
LinearRelation * Resetp(const Transition &rTrans)
Get reset of a transition.
virtual TlhaGenerator & operator=(const TlhaGenerator &rOtherGen)
Assignment operator (uses copy) Note: you must reimplement this operator in derived classes in order ...
Polyhedron * Invariantp(Idx idx)
Get invariant of state by index.
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Triple (X1,Ev,X2) to represent current state, event and next state.
std::string Str(void) const
Pretty print to string.
Base class of all libFAUDES objects that participate in the run-time interface.
Base class of all FAUDES generators.
Includes all libFAUDES headers, no plugins.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
TaIndexSet< AttributeLhaState > LhaStateSet
TaTransSet< AttributeLhaTrans > LhaTransSet
TlhaGenerator< AttributeLhaGlobal, AttributeLhaState, AttributeCFlags, AttributeLhaTrans > LinearHybridAutomaton
Convenience typedef for std lhaGenerator.