00001 00012 #ifndef SIMILARATTRIBUTECONNECTIONPREDICATE_H 00013 #define SIMILARATTRIBUTECONNECTIONPREDICATE_H 00014 00015 #include <ConnectionDecisionPredicateSpecialization.h> 00016 #include <string> 00017 00019 00021 class SimilarAttributeConnectionPredicate : public AugmentedConnectionDecisionPredicate 00022 { 00023 public: 00024 SimilarAttributeConnectionPredicate(string attr, double C=1.0, double tol=0.0) 00025 : attr(attr), C(C), tol(tol), unirnd(0.0, 1.0) 00026 { 00027 }; 00028 00030 00033 virtual bool decide(size_t src, size_t dst, RandomEngine *rnd) 00034 { 00035 const SimObjectAttributes & dst_attr = m_destinationPopulation->getAttributes(dst); 00036 const SimObjectAttributes & src_attr = m_sourcePopulation->getAttributes(src); 00037 00038 bool connect=false; 00039 try{ 00040 connect = fabs(dst_attr.getDouble(attr) - src_attr.getDouble(attr)) <= tol; 00041 } 00042 catch (PCSIM::Exception e) 00043 { 00044 // TODO: e.g. throw exception 00045 } 00046 00047 return connect && (unirnd(*rnd) < C); 00048 }; 00049 00050 private: 00051 string attr; 00052 double C; 00053 double tol; 00054 00055 UniformDistribution unirnd; 00056 }; 00057 00058 #endif