[Avida-SVN] r1817 - branches/dkdev/source/main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Wed Jul 18 08:08:57 PDT 2007
Author: dknoester
Date: 2007-07-18 11:08:57 -0400 (Wed, 18 Jul 2007)
New Revision: 1817
Modified:
branches/dkdev/source/main/cPopulation.cc
Log:
Fixed bug in calculation of clustering coefficient.
Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc 2007-07-18 13:50:06 UTC (rev 1816)
+++ branches/dkdev/source/main/cPopulation.cc 2007-07-18 15:08:57 UTC (rev 1817)
@@ -1002,19 +1002,24 @@
for(; adjacent.first!=adjacent.second; ++adjacent.first) {
neighbors.insert(*adjacent.first);
}
- // Now, count the edges between vertices in the neighborhood.
- unsigned int neighborhood_edge_count=0;
- for(neighborhood::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) {
- typedef cDeme::Network::out_edge_iterator out_edge_iterator;
- std::pair<out_edge_iterator,out_edge_iterator> oe = out_edges(*i,network);
- for(; oe.first!=oe.second; ++oe.first) {
- if(neighbors.find(target(*oe.first,network))!=neighbors.end()) {
- ++neighborhood_edge_count;
+
+ if(neighbors.size() > 1) {
+ // Now, count the edges between vertices in the neighborhood.
+ unsigned int neighborhood_edge_count=0;
+ for(neighborhood::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) {
+ typedef cDeme::Network::out_edge_iterator out_edge_iterator;
+ std::pair<out_edge_iterator,out_edge_iterator> oe = out_edges(*i,network);
+ for(; oe.first!=oe.second; ++oe.first) {
+ if(neighbors.find(target(*oe.first,network))!=neighbors.end()) {
+ ++neighborhood_edge_count;
+ }
}
}
+ neighborhood_edge_count /= 2;
+ cluster_coeffs.push_back((double)neighborhood_edge_count / (neighbors.size()*(neighbors.size()-1)/2));
+ } else {
+ cluster_coeffs.push_back(1.0);
}
- neighborhood_edge_count /= 2;
- cluster_coeffs.push_back((double)neighborhood_edge_count / (neighbors.size()*(neighbors.size()-1)/2));
}
// Clustering coefficient:
More information about the Avida-cvs
mailing list