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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/ModeEstimatorBase.h

    00001 //=============================================================================
    00002 // ModeEstimatorBase.h: interface for the ModeEstimatorBase class.
    00003 //
    00004 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00005 // All Rights Reserved          Massachusetts Institute of Technology
    00006 //
    00007 // This software is provided as is. Model-based Embedded and Robotic Systems
    00008 // (MERS) group does not assume any responsibility.
    00009 //
    00010 // Author:                      Oliver B. Martin
    00011 // Organization:        Model-based Embedded and Robotic Systems Group
    00012 //                                      Massachusetts Institute of Technology
    00013 //
    00014 // The ModeEstimator is an HHM estimation engine that generates estimates that
    00015 //  are consistent with the CCA model, commands, and observations. Estimates
    00016 //  are generated in best-first order (highest posterior probability first) by
    00017 //  using BFIG to find the most likely diagnoses. This implimentation of
    00018 //  ModeEstimator tracks the most likely trajectories using a compiled CCA model
    00019 //  consisting of dissents and compiled transitions.
    00020 //
    00021 //=============================================================================
    00022
    00023
    00024 #if !defined(_MODEESTIMATORBASE_H_)
    00025 #define _MODEESTIMATORBASE_H_
    00026
    00027 #if _MSC_VER > 1000
    00028 #pragma once
    00029 #endif // _MSC_VER > 1000
    00030
    00031
    00032 #include <vector>
    00033
    00034 #include <Mers/Models/Base/BaseModel.h>
    00035 #include <Mers/Utils/Lang/String.h>
    00036
    00037
    00038 namespace Mers {
    00039         namespace Models {
    00040                 namespace Base {
    00041                         class BaseModelVariable;
    00042                         class BaseModelVariableArray;
    00043                         class BaseModelAssignment;
    00044                         class BaseModelAssignmentArray;
    00045                 }
    00046         }
    00047         namespace Utils {
    00048                 namespace Containers {
    00049                         class DynamicArray;
    00050                         class IntegerArray;
    00051                         class intList;
    00052                 }
    00053         }
    00054         namespace Estimation {
    00055                 namespace Discrete {
    00056
    00057                         class Trigger;
    00058                         class Trajectories;
    00059                         class Dissent;
    00060                         class CompiledTransition;
    00061                         class Estimate;
    00062                         class EstimateHeap;
    00063                         class MEObjectiveFunction;
    00064
    00065                         // A short name for Mers::Models::Base
    00066                         namespace ns_BM = Mers::Models::Base;
    00067
    00076                         class ModeEstimatorBase
    00077                         {
    00078
    00082                                 friend std::ostream &  operator<<(std::ostream &, ModeEstimatorBase const &);
    00083
    00084                         public:
    00085                                 //-----------------------------------------
    00086                                 // Constructors
    00087                                 //-----------------------------------------
    00088
    00096                                 ModeEstimatorBase(const Mers::Models::Base::BaseModel &bm, std::vector<const Dissent *> dissents,
    00097                                         std::vector<const CompiledTransition *> compiledTransitions,
    00098                                         Trajectories * initialTrajectories);
    00099
    00100
    00101                                 //-----------------------------------------
    00102                                 // Destructors
    00103                                 //-----------------------------------------
    00104
    00108                                 virtual ~ModeEstimatorBase();
    00109
    00110
    00111                                 //-----------------------------------------
    00112                                 // Functions
    00113                                 //-----------------------------------------
    00114
    00121                                 bool                            observe(const Mers::Utils::Lang::String var, const Mers::Utils::Lang::String val);
    00122
    00129                                 bool                            observe(const unsigned int var, const unsigned int val);
    00130
    00139                                 bool                            command(const Mers::Utils::Lang::String var, const Mers::Utils::Lang::String val,
    00140                                                                                         unsigned int estNum = 0);
    00141
    00150                                 bool                            command(const unsigned int var, const unsigned int val, unsigned int estNum = 0);
    00151
    00160                                 bool                            setCurrentState(const Mers::Utils::Lang::String var, const Mers::Utils::Lang::String val);
    00161
    00170                                 bool                            setCurrentState(const unsigned int var, const unsigned int val);
    00171
    00181                                 bool                            addTrajectory(Estimate * est);
    00182
    00190                                 bool                            setTrajectory(Estimate * est);
    00191
    00196                                 double                          getUncertainty() const;
    00197
    00203                                 virtual const Estimate *        findModeEstimate(void);
    00204
    00213                                 Mers::Utils::Containers::intList const *                findModeEstimateIntList(bool full = true);
    00214
    00221                                 virtual const Estimate *        progressToEstimate(void);
    00222
    00227                                 const Trajectories *            getCurrentTrajectories(void) const;
    00228
    00236                                 const Trajectories *    findNextTrajectories(void);
    00237
    00243                                 virtual bool resetCommandsAndObservations(void);
    00244
    00245
    00252                                 void                            showAllVars(std::ostream &out) const;
    00253
    00260                                 void                            showStateVars(std::ostream &out) const;
    00261
    00268                                 void                            showCommandVars(std::ostream &out) const;
    00269
    00276                                 void                            showObservationVars(std::ostream &out) const;
    00277
    00282                                 void                            showDissents(std::ostream &out) const;
    00283
    00288                                 void                            showCompiledTransitions(std::ostream &out) const;
    00289
    00294                                 void                            showEnabled(std::ostream &out) const;
    00295
    00301                                 void                            showConflicts(std::ostream &out) const;
    00302
    00307                                 void                            showCurrentTrajectories(std::ostream &out) const;
    00308
    00315                                 void                            showNextTrajectories(std::ostream &out);
    00316
    00323                                 void                            setNumberTrajectories(unsigned int k);
    00324
    00330                                 virtual void            setDebug(const unsigned short db);
    00331
    00332
    00333                         protected:
    00334
    00339                                 virtual bool            generateTrajectories(void) = 0;
    00340
    00356                                 virtual bool            findNextBestStateAndPutInHeap(unsigned int generatorNum, const std::vector<double> & allProbs,
    00357                                                                                                                 Mers::Estimation::Discrete::EstimateHeap * nextTrajsEstHeap,
    00358                                                                                                                 bool willWarn = false);
    00359
    00360
    00373                                 virtual bool            calculateEstimateProbability(double & estProbability,
    00374                                                                                                 const Mers::Models::Base::BaseModelAssignmentArray * state,
    00375                                                                                                 unsigned int generatorNum, const std::vector<double> & allProbs) const;
    00376
    00387                                 virtual const Mers::Models::Base::BaseModelAssignmentArray *
    00388                                                                         generateBestSolution(unsigned int generatorNum, long int maximumVisitedNodeCount,
    00389                                                                                 long int maxQueueSize) = 0;
    00390
    00400                                 virtual bool            addEstimate(Mers::Estimation::Discrete::Estimate * theEst,
    00401                                                                                 Mers::Estimation::Discrete::EstimateHeap * nextTrajsEstHeap = NULL) = 0;
    00402
    00411                                 virtual bool            releaseMemoryAndNormalize(Mers::Estimation::Discrete::EstimateHeap * nextTrajsEstHeap);
    00412
    00420                                 virtual void            cleanAfterFailure(Mers::Estimation::Discrete::EstimateHeap * nextTrajsEstHeap = NULL);
    00421
    00422
    00432                                 virtual bool            addEstimateToCurrentTrajectories(Mers::Estimation::Discrete::Estimate * anEst,
    00433                                                                                                                                         bool createNewCurrentTrajectories = false);
    00434
    00435                         private:
    00436
    00445                                 virtual bool resetTrigger(const Trajectories * trajs);
    00446
    00454                                 virtual bool showVars(std::ostream &out, const Mers::Models::Base::BaseModelVariable::VariableType varType) const;
    00455
    00465                                 Mers::Utils::Containers::intList const *                estimateToIntList(Estimate const * nextEst, Estimate const * currEst = NULL)  const;
    00466
    00467
    00477                                 bool                            assign(const Mers::Utils::Lang::String var, const Mers::Utils::Lang::String val,
    00478                                                                                 const Mers::Models::Base::BaseModelVariable::VariableType varType,
    00479                                                                                 unsigned int estNum = 0);
    00480
    00490                                 bool                            assign(const unsigned int var, const unsigned int val,
    00491                                                                                 const Mers::Models::Base::BaseModelVariable::VariableType varType,
    00492                                                                                 unsigned int estNum = 0);
    00493
    00507                                 virtual bool assign(const ns_BM::BaseModelVariable * var,
    00508                                         const ns_BM::BaseModelValue * val,
    00509                                         unsigned int estNum = 0);
    00510
    00520                                 virtual bool            assign(Mers::Models::Base::BaseModelAssignment * bmAssign, unsigned int estNum = 0);
    00521
    00528                                 Trajectories *          createSeedTrajectory(const Mers::Models::Base::BaseModel & bm);
    00529
    00530                         protected:
    00531
    00532                                 //-----------------------------------------
    00533                                 // Data Members
    00534                                 //-----------------------------------------
    00535
    00538                                 const Mers::Models::Base::BaseModel &                   model;
    00539
    00541                                 Trigger *                                                                               compiledObjectTrigger;
    00542
    00544                                 Mers::Models::Base::BaseModelVariableArray *    decisionVariables;
    00546                                 Mers::Utils::Containers::IntegerArray *                 probabilityMap;
    00547
    00549                                 MEObjectiveFunction *                                                   objectiveFunction;
    00550
    00552                                 Trajectories *                                                                  currentTrajectories;
    00555                                 Trajectories *                                                                  nextTrajectories;
    00556
    00558                                 unsigned int                                                                    maxNumberEstimates;
    00559
    00561                                 unsigned short                                                                  debug;
    00562                         };
    00563                 }
    00564         }
    00565 }
    00566
    00567 #endif // !defined(_MODEESTIMATORBASE_H_)