- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/CCATransition.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "CCATransition.h"
    00015
    00016 #include <cstdio>
    00017 #include <cassert>
    00018
    00019 #include "CCAAutomaton.h"
    00020 #include "CCAModel.h"
    00021
    00023
    00024 using namespace Mers::Models::CCA;
    00025 using std::ostream;
    00026
    00028 // Constructors, Copy Constructors, & Destructors
    00030
    00031 CCATransition::CCATransition()
    00032 : BaseModelObject(BaseModelObject::oCCATransition),
    00033 _guard(true, CCAClause::CONJUNCTIVE)
    00034 {
    00035         _from_state_p   = NULL;
    00036         _to_state_p             = NULL;
    00037         _probability    = 0.0;
    00038 }
    00039
    00040 CCATransition::CCATransition(const CCAState &from_state,
    00041                                            const CCAState &to_state,
    00042                                            const CCAClause &guard,
    00043                                            double probability_)
    00044 : BaseModelObject(BaseModelObject::oCCATransition),
    00045 _guard(true, CCAClause::CONJUNCTIVE)
    00046 {
    00047         if (from_state.automaton_p()    == to_state.automaton_p()) {
    00048                 _from_state_p   = &from_state;
    00049                 _to_state_p             = &to_state;
    00050                 _guard                  = guard;
    00051                 _probability    = probability_;
    00052         } else {
    00053                 _from_state_p   = NULL;
    00054                 _to_state_p             = NULL;
    00055                 _guard.setClauseType(CCAClause::CONJUNCTIVE);
    00056                 _probability    = 0.0;
    00057         }
    00058 }
    00059
    00060 CCATransition::CCATransition(const CCATransition &other)
    00061 : BaseModelObject(other),
    00062 _guard(true, CCAClause::CONJUNCTIVE)
    00063 {
    00064         copy(other);
    00065 }
    00066
    00067 CCATransition::~CCATransition() {
    00068         destroy();
    00069 }
    00070
    00072 // Public Function Members
    00074
    00075 const CCAAutomaton * CCATransition::automaton_p() const
    00076 {
    00077         if (_from_state_p != NULL && _to_state_p != NULL) {
    00078                 if (_from_state_p->automaton_p() == _to_state_p->automaton_p()) {
    00079                         return _from_state_p->automaton_p();
    00080                 }
    00081         }
    00082         return NULL;
    00083 }
    00084
    00085 const CCAAutomata * CCATransition::ccAutomata_p() const
    00086 {
    00087         if (_from_state_p != NULL && _to_state_p != NULL) {
    00088                 if (_from_state_p->ccAutomata_p() == _to_state_p->ccAutomata_p()) {
    00089                         return _from_state_p->ccAutomata_p();
    00090                 }
    00091         }
    00092         return NULL;
    00093 }
    00094
    00095 const CCAModel * CCATransition::model_p() const
    00096 {
    00097         if (_from_state_p != NULL && _to_state_p != NULL) {
    00098                 if (_from_state_p->model_p() == _to_state_p->model_p()) {
    00099                         return _from_state_p->model_p();
    00100                 }
    00101         }
    00102         return NULL;
    00103 }
    00104
    00105 bool CCATransition::set_from_state_p(const CCAState &_state)
    00106 {
    00107         _from_state_p = &_state;
    00108         return true;
    00109 }
    00110
    00111 const CCAState * CCATransition::from_state_p() const
    00112 {
    00113         return _from_state_p;
    00114 }
    00115
    00116 bool CCATransition::set_to_state_p(const CCAState &_state)
    00117 {
    00118         _to_state_p = &_state;
    00119         return true;
    00120 }
    00121
    00122 const CCAState * CCATransition::to_state_p() const
    00123 {
    00124         return _to_state_p;
    00125 }
    00126
    00127 bool CCATransition::set_guard(const CCAClause &guard)
    00128 {
    00129         _guard = guard;
    00130         return true;
    00131 }
    00132
    00133 const CCAClause * CCATransition::guard_p() const
    00134 {
    00135         return &_guard;
    00136 }
    00137
    00138 double CCATransition::probability() const
    00139 {
    00140         return _probability;
    00141 }
    00142
    00144
    00145 void CCATransition::setUID(unsigned int newUID)
    00146 {
    00147         uid = newUID;
    00148 }
    00149
    00151
    00152 unsigned int CCATransition::getUID()    const
    00153 {
    00154         return uid;
    00155 }
    00156
    00158
    00159 #ifndef EMBEDDED
    00160
    00161 void CCATransition::print(ostream &out) const
    00162 {
    00163         if (this != NULL) {
    00164                 out << from_state_p()->name() << " --> " << to_state_p()->name()
    00165                         << ": " << *guard_p() << " Probability(" << probability() << ")";
    00166         } else {
    00167                 out << "Error streaming NULL transition!";
    00168         }
    00169 }
    00170
    00171 #endif
    00172
    00174 // Public Operators
    00176
    00177 const CCATransition &CCATransition::operator =(const CCATransition &other)
    00178 {
    00179         if(this != &other) {
    00180                 destroy();
    00181                 copy(other);
    00182         }
    00183         return *this;
    00184 }
    00185
    00186 bool CCATransition::operator ==(const CCATransition &other) const
    00187 {
    00188         if (_from_state_p       == other._from_state_p  &&
    00189                 _to_state_p             == other._to_state_p    &&
    00190                 _guard                  == other._guard                 &&
    00191                 _probability    == other._probability) {
    00192                 return true;
    00193         } else {
    00194                 return false;
    00195         }
    00196 }
    00197
    00198 bool CCATransition::operator !=(const CCATransition &other) const
    00199 {
    00200         return !operator ==(other);
    00201 }
    00202
    00204 // Private Function Members
    00206
    00207 void CCATransition::destroy()
    00208 {
    00209         _from_state_p   = NULL;
    00210         _to_state_p             = NULL;
    00211         _guard.clear();
    00212         _probability    = 0.0;
    00213 }
    00214
    00216
    00217 void CCATransition::copy(const CCATransition &other)
    00218 {
    00219         _from_state_p   = other._from_state_p;
    00220         _to_state_p             = other._to_state_p;
    00221         _guard                  = other._guard;
    00222         _probability    = other._probability;
    00223 }
    00224
    00226