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

# /Users/fpy/titan-1-5-MBARI/Mers/Solvers/SAT/GATSAT/NUGatsatFactory.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 //
    00010
    00011 #include "NUGatsatFactory.h"
    00012
    00013 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00014 #include <Mers/Models/Base/BaseModelVariable.h>
    00015 #include <Mers/Models/Base/BaseModelDomain.h>
    00016 #include <Mers/Models/Base/BaseModelSentence.h>
    00017
    00019
    00020 using namespace Mers::Solvers::SAT::GATSAT;
    00021 using Mers::Models::Base::BaseModelVariableArray;
    00022 using Mers::Models::Base::BaseModelVariable;
    00023 using Mers::Models::Base::BaseModelDomain;
    00024 using Mers::Models::Base::BaseModelSentence;
    00025 using Mers::Utils::Containers::IntegerArray;
    00026 using Mers::Utils::Exceptions::RuntimeException;
    00027 using std::vector;
    00028
    00030
    00031 void NUGatsatFactory::setProbabilities(const IntegerArray &valueMap,
    00032         const vector<double> & searchVarProbs)
    00033 {
    00034         // Copy our new probability data.
    00035         m_ValueMap = valueMap;
    00036         m_SearchVarProbs = searchVarProbs;
    00037 }
    00038
    00040
    00041 GATSAT * NUGatsatFactory::createGatsat(
    00042         const BaseModelVariableArray & searchVars,
    00043         const BaseModelVariableArray & allVars,
    00044         const BaseModelSentence & theory)
    00045         const throw(RuntimeException)
    00046 {
    00047         // This is true if we generated the data, at which point we should
    00048         // clear it again to avoid errors.
    00049         bool createdData = false;
    00050
    00051         // Our data handle for the next step.
    00052         const IntegerArray * cValueMap = &m_ValueMap;
    00053         const vector<double> * cSearchVarProbs = &m_SearchVarProbs;
    00054
    00055         // See if we have valid probability data.
    00056         if(m_ValueMap.size() < searchVars.size()) {
    00057                 // We're creating data.
    00058                 createdData = true;
    00059
    00060                 // generate new uniform data.
    00061                 IntegerArray * valueMap = new IntegerArray();
    00062                 vector<double> * searchVarProbs = new vector<double>();
    00063
    00064                 // Keep a reference to this data.
    00065                 cValueMap = valueMap;
    00066                 cSearchVarProbs = searchVarProbs;
    00067
    00068                 // Create some uniform probability data.
    00069                 for(unsigned int i = 0; i < searchVars.size(); ++i) {
    00070                         // Get our variable and domain.
    00071                         const BaseModelVariable &var = *(searchVars[i]);
    00072                         const BaseModelDomain &dom = *(var.getDomain());
    00073
    00074                         // Create room for an entry for this variable, if necessary.
    00075                         if(valueMap->size() <= var.getUID())
    00076                                 valueMap->resize(var.getUID() + 1);
    00077
    00078                         // Create an entry for this variable.
    00079                         (*valueMap)[var.getUID()] = searchVarProbs->size();
    00080
    00081                         // Create an entry for each value for this variable.
    00082                         for(unsigned int j = 0; j < dom.size(); ++j) {
    00083                                 // Add our uniform cost, one for each value.
    00084                                 searchVarProbs->push_back(1.0);
    00085                         }
    00086                 }
    00087         }
    00088
    00089         // Use our probabiltiy data.
    00090         GATSAT * ret = createGatsat(searchVars, allVars, theory,
    00091                 *cValueMap, *cSearchVarProbs);
    00092
    00093         // If we created data, clean it up.
    00094         if(createdData) {
    00095                 delete cValueMap;
    00096                 delete cSearchVarProbs;
    00097         }
    00098
    00099         // Return our result.
    00100         return ret;
    00101 }
    00102