InRangeAllNto1VarRel.cpp
Go to the documentation of this file.
00001 #include "InRangeAllNto1VarRel.h"
00002 
00003 
00004 
00005 InRangeAllNto1VarRel::InRangeAllNto1VarRel(SharedPointer<BooleanVariable> resultVar, SharedPointer<Map2DPosVar> mapDestVar, double range)
00006 {
00007         this->resultVar = resultVar;
00008         this->mapDestVar = mapDestVar;
00009         this->range = range;
00010         this->addSourceVar(mapDestVar);
00011         this->setDestVariable(resultVar);
00012 }
00013 
00014 InRangeAllNto1VarRel::~InRangeAllNto1VarRel(void)
00015 {
00016 }
00017 void InRangeAllNto1VarRel::addSrcVar(SharedPointer<Map2DPosVar> srcVar)
00018 {
00019     mapSrcVars.push_back(srcVar);
00020     this->addSourceVar(srcVar);
00021 }
00022 
00023 vector<SharedPointer<RelEntry> > InRangeAllNto1VarRel::getProb(map<string, SharedPointer<IVariableValue> > sourceVals)
00024 {
00025         //string action = sourceVals[destVar->getVariableName()];
00026         
00027         bool inRange = true;
00028         SharedPointer<Map2DPosValue> destVarPos = dynamic_pointer_cast<Map2DPosValue>(sourceVals[mapDestVar->getVariableName()]);
00029         for(int i = 0 ; i < mapSrcVars.size() ; i ++ )
00030         {
00031                 SharedPointer<Map2DPosVar> srcVar = mapSrcVars[i];
00032                 
00033                 SharedPointer<Map2DPosValue> srcVarPos = dynamic_pointer_cast<Map2DPosValue>(sourceVals[srcVar->getVariableName()]);
00034                 double dist = srcVarPos->distanceTo(destVarPos);
00035                 if(dist > range)
00036                 {
00037                         inRange = false;
00038                         break;
00039                 }
00040         }
00041 
00042         
00043 
00044         vector<SharedPointer<RelEntry> > result;
00045         {
00046                 SharedPointer<IVariableValue> resultValue;
00047                 if(inRange)
00048                 {
00049                          resultValue = resultVar->getTrueValue();
00050                 }
00051                 else
00052                 {
00053                         resultValue = resultVar->getFalseValue();
00054                 }
00055                 
00056                 SharedPointer<RelEntry> newEntry (new RelEntry());
00057                 /*for(int i = 0 ; i < srcVars.size(); i++)
00058                 {
00059                         SharedPointer<IVariable>& sourceVar = srcVars[i];
00060                         newEntry->sourceValues[sourceVar->getVariableName()] = sourceVals[sourceVar->getVariableName()];
00061                 }*/
00062                 newEntry->destValues[this->getDestVariable()->getVariableName()] = resultValue;
00063                 newEntry->prob = 1; // noisy value
00064                 result.push_back(newEntry);
00065         }
00066         return result;
00067 }


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29