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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/Dissent.cpp

    00001 //==============================================================================
    00002 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00003 // All Rights Reserved          Massachusetts Institute of Technology
    00004 //
    00005 // This software is provided as is. Model-based Embedded and Robotic Systems
    00006 // (MERS) group does not assume any responsibility.
    00007 //==============================================================================
    00008
    00009 #include "Dissent.h"
    00010
    00011 #ifdef _MSC_VER
    00012 #pragma warning( disable : 4786 )
    00013 #endif
    00014
    00015 #include <iostream>
    00016 #include <Mers/Models/Base/BaseModelVariable.h>
    00017 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00018
    00019
    00020 using namespace Mers::Estimation::Discrete;
    00021 using Mers::Models::Base::BaseModelVariable;
    00022 using Mers::Models::Base::BaseModelAssignmentArray;
    00023 using std::ostream;
    00024 using std::cerr;
    00025 using std::endl;
    00026
    00027
    00028         //-----------------------------------------------
    00029         //      CONSTRUCTOR
    00030         //-----------------------------------------------
    00031
    00032
    00033 Dissent::Dissent(const BaseModelAssignmentArray * imp, const BaseModelAssignmentArray * con)
    00034 : dissentImplicant(imp), conflict(con), debug(0)
    00035 {
    00036         // Check to make sure all assigments have the correct variable types.
    00037
    00038         BaseModelAssignmentArray::ConstantIterator bmaaItr;
    00039
    00040         for(bmaaItr = imp->begin(); bmaaItr != imp->end(); bmaaItr++)
    00041         {
    00042                 const BaseModelVariable var = *bmaaItr->getVariable();
    00043                 if(var.getVariableType() != BaseModelVariable::OBSERVABLE && var.getVariableType() != BaseModelVariable::Observable)
    00044                         cerr << "Invalid Variable Type! Dissent implicants should be Observables." << endl;
    00045         }
    00046
    00047         for(bmaaItr = con->begin(); bmaaItr != con->end(); bmaaItr++)
    00048         {
    00049                 const BaseModelVariable var = *bmaaItr->getVariable();
    00050                 if(var.getVariableType() != BaseModelVariable::STATE && var.getVariableType() != BaseModelVariable::State)
    00051                         cerr << "Invalid Variable Type! Dissent conflicts should be States." << endl;
    00052         }
    00053 }
    00054
    00055
    00056         //-----------------------------------------------
    00057         //      COPY CONSTRUCTOR
    00058         //-----------------------------------------------
    00059
    00060
    00061 Dissent::Dissent(Dissent const & originalDissent)
    00062 : dissentImplicant(originalDissent.dissentImplicant), conflict(originalDissent.conflict),
    00063   debug(originalDissent.debug)
    00064 {}
    00065
    00066
    00067 Dissent::Dissent(Dissent const * originalDissent)
    00068 : dissentImplicant(originalDissent->dissentImplicant), conflict(originalDissent->conflict),
    00069   debug(originalDissent->debug)
    00070 {}
    00071
    00072         //-----------------------------------------------
    00073         //      DESTRUCTOR
    00074         //-----------------------------------------------
    00075
    00076
    00077 Dissent::~Dissent()
    00078 {
    00079         // Dissents assume ownership over the assignment arrays so they are deleted
    00080         //  along with the dissent
    00081         delete dissentImplicant;
    00082         delete conflict;
    00083 }
    00084
    00085
    00086
    00087         //-----------------------------------------------
    00088         //      PUBLIC METHODS
    00089         //-----------------------------------------------
    00090
    00091
    00092 const BaseModelAssignmentArray *
    00093 Dissent::getConflict(void) const
    00094 {
    00095         return conflict;
    00096 }
    00097
    00098
    00099 const unsigned int
    00100 Dissent::getAntecedentLength(void) const
    00101 //  This includes all observation assigments
    00102 {
    00103         return dissentImplicant->getLength();
    00104 }
    00105
    00106
    00107 const unsigned int
    00108 Dissent::getAntecedentVariableUID(unsigned int vectorPos) const
    00109 {
    00110         return (*dissentImplicant)[vectorPos]->getVariable()->getUID();
    00111 }
    00112
    00113 const unsigned short
    00114 Dissent::getAntecedentValueUID(unsigned int vectorPos) const
    00115 {
    00116         return (*dissentImplicant)[vectorPos]->getValue()->getUID();
    00117 }
    00118
    00119
    00120 void
    00121 Dissent::setDebug(const unsigned short debugVal)
    00122 // Sets debug to debugVal
    00123 {
    00124         debug = debugVal;
    00125         return;
    00126 }
    00127
    00128
    00129
    00130 ostream&
    00131 Mers::Estimation::Discrete::operator<<(ostream& os, Dissent const & dis)
    00132 {
    00133         BaseModelAssignmentArray::ConstantIterator impItr;
    00134         BaseModelAssignmentArray::ConstantIterator conItr;
    00135
    00136         os << "{";
    00137         for(impItr = dis.dissentImplicant->begin(); impItr != dis.dissentImplicant->end(); impItr++)
    00138                 os << *impItr;
    00139         os << "} => {";
    00140         for(conItr = dis.conflict->begin(); conItr != dis.conflict->end(); conItr++)
    00141                 os << *conItr;
    00142         os << "}";
    00143
    00144         return os;
    00145 }
    00146         //-----------------------------------------------
    00147         //      PRIVATE METHODS
    00148         //-----------------------------------------------
    00149