[Avida-SVN] r1577 - in branches/dkdev/source: main tools
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Sun May 20 16:12:33 PDT 2007
Author: dknoester
Date: 2007-05-20 19:12:33 -0400 (Sun, 20 May 2007)
New Revision: 1577
Modified:
branches/dkdev/source/main/cPopulation.cc
branches/dkdev/source/tools/cTopology.h
Log:
Checking mean lsp first, then edge count.
Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc 2007-05-20 18:57:45 UTC (rev 1576)
+++ branches/dkdev/source/main/cPopulation.cc 2007-05-20 23:12:33 UTC (rev 1577)
@@ -44,7 +44,7 @@
#include <boost/graph/connected_components.hpp>
#include <float.h>
-#include <math.h>
+#include <cmath>
using namespace std;
@@ -889,10 +889,14 @@
// Source germline.
cGermline& source_germline = source_deme.GetGermline();
- unsigned int max_edges = max_connections(m_world->GetConfig().WORLD_GEOMETRY.Get(),
- source_deme.GetHeight(),
- source_deme.GetWidth());
+ const int max_edges = max_connections(m_world->GetConfig().WORLD_GEOMETRY.Get(),
+ source_deme.GetHeight(),
+ source_deme.GetWidth());
+ const int min_lsp = min_diameter(m_world->GetConfig().WORLD_GEOMETRY.Get(),
+ source_deme.GetHeight(),
+ source_deme.GetWidth());
+
// if(boost::num_edges(network)>=(boost::num_vertices(network))) {
// // Not yet a minimal network.
// source_germline.UpdateMerit(pow(max_edges - boost::num_edges(network)+1, 2));
@@ -900,7 +904,8 @@
//
// } else {
// It is a minimal network.
- // Calculate the shortest distances between all vertices.
+
+ // Calculate the shortest distances between all vertices.
typedef cDeme::Network::vertices_size_type size_type;
typedef std::vector<size_type> DistanceVector;
std::vector<DistanceVector> distance_matrix(boost::num_vertices(network),
@@ -917,19 +922,24 @@
sum_lsp += *std::max_element(distance_matrix[i].begin(), distance_matrix[i].end());
}
double mean_lsp = (double)sum_lsp / boost::num_vertices(network);
+ double max_lsp = world_x * world_y/num_demes * 0.75;
+
+ // Have we found the minimal lsp?
+ if(min_lsp != (int)mean_lsp) {
+ // Not a min LSP network.
+ source_germline.UpdateMerit(pow(max_lsp - mean_lsp + 1, 2));
+ } else {
+ // A min LSP network.
+ source_germline.UpdateMerit(pow((double)(max_edges - boost::num_edges(network)+1), 2)
+ + pow((double)(max_lsp - mean_lsp + 1), 2));
+// source_germline.UpdateMerit(pow((max_lsp-mean_lsp)/(max_lsp-min_lsp), 2)
+// + pow((max_edges-boost::num_edges(network))
+// / (max_edges-boost::num_vertices(network)-1), 2)
+// + 1);
+ }
- // Worst-case mean lsp == 3/4 of a single path.
- double max_lsp = world_x * world_y/num_demes * 0.75;
- double min_lsp = std::max(world_x, world_y) - 1;
-
-// source_germline.UpdateMerit(pow(max_edges - boost::num_edges(network)+1, 2)
-// + pow(max_lsp - mean_lsp + 1, 2));
- source_germline.UpdateMerit(pow((max_lsp-mean_lsp)/(max_lsp-min_lsp), 2)
- + pow((max_edges-boost::num_edges(network))
- / (max_edges-boost::num_vertices(network)-1), 2)
- + 1);
m_world->GetStats().ConnectedTopology(source_deme, mean_lsp);
-// }
+
// Now, update this deme's merit.
// This particular calculation doesn't work well; it rewards small diameter and small number of edges equally.
Modified: branches/dkdev/source/tools/cTopology.h
===================================================================
--- branches/dkdev/source/tools/cTopology.h 2007-05-20 18:57:45 UTC (rev 1576)
+++ branches/dkdev/source/tools/cTopology.h 2007-05-20 23:12:33 UTC (rev 1577)
@@ -10,6 +10,9 @@
#ifndef _TOPOLOGY_H_
#define _TOPOLOGY_H_
+#include <algorithm>
+#include <cmath>
+
#include "functions.h"
#include "nGeometry.h"
@@ -128,4 +131,28 @@
return edge_count;
}
+
+/*! Calculates the minimal diameter in a given region and geometry.
+Technically, this is the minimal mean longest shortest-path, over all cells. */
+int min_diameter(int geometry, unsigned int rowSize, unsigned int colSize) {
+ switch(geometry) {
+ case nGeometry::GRID: {
+ return std::max(rowSize, colSize) - 1;
+ }
+ case nGeometry::TORUS: {
+ // Not sure about this... no time...
+ //return ceil(std::max(rowSize, colSize) / 2);
+ assert(false);
+ }
+ case nGeometry::CLIQUE: {
+ return 1;
+ }
+ default: {
+ assert(false);
+ break;
+ }
+ }
+}
+
+
#endif
More information about the Avida-cvs
mailing list