[Avida-SVN] r2721 - in branches/collect: . documentation source/cpu source/main
blwalker at myxo.css.msu.edu
blwalker at myxo.css.msu.edu
Mon Jul 21 11:37:18 PDT 2008
Author: blwalker
Date: 2008-07-21 14:37:17 -0400 (Mon, 21 Jul 2008)
New Revision: 2721
Modified:
branches/collect/Avida.vcproj
branches/collect/KNOWN_BUGS
branches/collect/README
branches/collect/documentation/index.html
branches/collect/documentation/svn.html
branches/collect/source/cpu/cHardwareCPU.cc
branches/collect/source/cpu/cHardwareCPU.h
branches/collect/source/main/cAvidaConfig.h
branches/collect/source/main/cDeme.cc
branches/collect/source/main/cDeme.h
branches/collect/source/main/cDemeCellEvent.cc
branches/collect/source/main/cOrgMovementPredicate.h
branches/collect/source/main/cOrganism.cc
branches/collect/source/main/cOrganism.h
branches/collect/source/main/cPopulation.cc
branches/collect/source/main/cResourceCount.cc
branches/collect/source/main/cSpatialCountElem.h
branches/collect/source/main/cSpatialResCount.cc
Log:
Merging development r2670:2720 into the collect branch.
Modified: branches/collect/Avida.vcproj
===================================================================
--- branches/collect/Avida.vcproj 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/Avida.vcproj 2008-07-21 18:37:17 UTC (rev 2721)
@@ -653,6 +653,14 @@
>
</File>
<File
+ RelativePath=".\source\main\cOrgMessagePredicate.h"
+ >
+ </File>
+ <File
+ RelativePath=".\source\main\cOrgMovementPredicate.h"
+ >
+ </File>
+ <File
RelativePath=".\source\main\cOrgSeqMessage.h"
>
</File>
Modified: branches/collect/KNOWN_BUGS
===================================================================
--- branches/collect/KNOWN_BUGS 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/KNOWN_BUGS 2008-07-21 18:37:17 UTC (rev 2721)
@@ -11,3 +11,4 @@
* BIRTH_METHOD 7 is currently a local birth method, but not grouped with the
rest of them. This required a special condition in cBirthChamber.cc for
local recombination and in cPopulation.cc for offspring facing parent.
+
Modified: branches/collect/README
===================================================================
--- branches/collect/README 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/README 2008-07-21 18:37:17 UTC (rev 2721)
@@ -1,6 +1,7 @@
Avida 2.9.x
----------------------------------------------------------------------
Digital Evolution Laboratory at Michigan State University
+(http://devolab.cse.msu.edu)
I. REQUIREMENTS
Modified: branches/collect/documentation/index.html
===================================================================
--- branches/collect/documentation/index.html 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/documentation/index.html 2008-07-21 18:37:17 UTC (rev 2721)
@@ -5,6 +5,7 @@
</head>
<body>
+
<div align="center">
<table border="0">
<tr>
Modified: branches/collect/documentation/svn.html
===================================================================
--- branches/collect/documentation/svn.html 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/documentation/svn.html 2008-07-21 18:37:17 UTC (rev 2721)
@@ -43,14 +43,11 @@
<p>
To download the Avida project, issue the 'checkout' command with the path
to the Avida repository. The following two command lines show how this
-command should look and provide the repository paths. The first line is
-the preferred path. The second can be used in instances where outbound
-firewalls have blocked access to non-standard web ports.
+command should look and provide the repository paths.
</p>
<pre>
-svn checkout http://myxo.css.msu.edu:7632/avida/trunk
-svn checkout http://myxo.css.msu.edu:443/avida/trunk
+svn checkout https://avida.devosoft.org/svn/development
</pre>
@@ -113,4 +110,4 @@
<p><a href="index.html">Return to the Index</a></p>
</body>
-</html>
\ No newline at end of file
+</html>
Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/cpu/cHardwareCPU.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -447,6 +447,11 @@
tInstLibEntry<tMethod>("if-pheromone", &cHardwareCPU::Inst_IfPheromone),
tInstLibEntry<tMethod>("if-not-pheromone", &cHardwareCPU::Inst_IfNotPheromone),
tInstLibEntry<tMethod>("drop-pheromone", &cHardwareCPU::Inst_DropPheromone, nInstFlag::STALL),
+
+ // Opinion instructions.
+ // These are STALLs because opinions are only relevant with respect to time.
+ tInstLibEntry<tMethod>("set-opinion", &cHardwareCPU::Inst_SetOpinion, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("get-opinion", &cHardwareCPU::Inst_GetOpinion, nInstFlag::STALL),
// Must always be the last instruction in the array
tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -5485,8 +5490,11 @@
}
}
- GetRegister(reg_to_set) = (int)round(pher_amount);
+ // In Visual Studio 2005 round function does not exist use floor instead
+ // GetRegister(reg_to_set) = (int)round(pher_amount);
+ GetRegister(reg_to_set) = (int)floor(pher_amount + 0.5);
+
return true;
} //End DoSensePheromone()
@@ -6725,3 +6733,28 @@
} //End Inst_DropPheromone()
+
+/*! Set this organism's current opinion to the value in ?BX?.
+ */
+bool cHardwareCPU::Inst_SetOpinion(cAvidaContext& ctx)
+{
+ organism->SetOpinion(GetRegister(FindModifiedRegister(REG_BX)));
+ return true;
+}
+
+
+/*! Sense this organism's current opinion, placing the opinion in register ?BX?
+ and the age of that opinion (in updates) in register !?BX?. If the organism has no
+ opinion, do nothing.
+ */
+bool cHardwareCPU::Inst_GetOpinion(cAvidaContext& ctx)
+{
+ if(organism->HasOpinion()) {
+ const int opinion_reg = FindModifiedRegister(REG_BX);
+ const int age_reg = FindNextRegister(opinion_reg);
+
+ GetRegister(opinion_reg) = organism->GetOpinion().first;
+ GetRegister(age_reg) = m_world->GetStats().GetUpdate() - organism->GetOpinion().second;
+ }
+ return true;
+}
Modified: branches/collect/source/cpu/cHardwareCPU.h
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.h 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/cpu/cHardwareCPU.h 2008-07-21 18:37:17 UTC (rev 2721)
@@ -655,6 +655,18 @@
bool Inst_IfNotPheromone(cAvidaContext& ctx);
bool Inst_DropPheromone(cAvidaContext& ctx);
+ // -------- Opinion support --------
+ /* These instructions interact with the "opinion" support in cOrganism.h. The
+ idea is that we're enabling organisms to express an opinion about *something*,
+ where that something is defined by the particular tasks and/or (deme) fitness function
+ in use. This may have to be extended in the future to support different kinds of
+ opinions that can be expressed during the same experiment, and possibly augmented
+ with a "strength" of that opinion (but not right now).
+ */
+ //! Set this organism's current opinion.
+ bool Inst_SetOpinion(cAvidaContext& ctx);
+ //! Retrieve this organism's current opinion.
+ bool Inst_GetOpinion(cAvidaContext& ctx);
};
Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cAvidaConfig.h 2008-07-21 18:37:17 UTC (rev 2721)
@@ -302,6 +302,8 @@
CONFIG_ADD_VAR(DEMES_PREVENT_STERILE, int, 0, "Whether to prevent sterile demes from\nreplicating (default=0 or no).");
CONFIG_ADD_VAR(DEMES_RESET_RESOURCES, int, 0, "Reset resources in demes on replication. \n0 = reset both demes \n1 = reset target deme \n2 = deme resources remain unchanged\n");
CONFIG_ADD_VAR(DEMES_REPLICATE_SIZE, int, 1, "Number of identical organisms to create or copy from the\nsource deme to the target deme (default=1).");
+ CONFIG_ADD_VAR(LOG_DEMES_REPLICATE, bool, 0, "Log deme replications. 0/1 (off/on)");
+ CONFIG_ADD_VAR(DEMES_REPLICATE_LOG_START, int, 0, "Update at which to start logging deme replications");
CONFIG_ADD_VAR(DEMES_PROB_ORG_TRANSFER, double, 0.0, "Probablity of an organism being transferred from the\nsource deme to the target deme (default=0.0).");
CONFIG_ADD_VAR(DEMES_ORGANISM_SELECTION, int, 0, "How organisms are selected for transfer from\nsource to target during deme replication.\n0=random with replacement (default).\n1=sequential.");
CONFIG_ADD_VAR(DEMES_ORGANISM_PLACEMENT, int, 0, "How organisms are placed during deme replication.\n0=cell-array middle (default).\n1=deme center.\n2=random placement.\n3=sequential.");
Modified: branches/collect/source/main/cDeme.cc
===================================================================
--- branches/collect/source/main/cDeme.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cDeme.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -103,11 +103,18 @@
return std::make_pair(cellid % GetWidth(), ( cellid % cell_ids.GetSize() ) / GetWidth());
}
-cPopulationCell& cDeme::GetCell(int pos)
+cPopulationCell& cDeme::GetCell(int pos) const
{
return m_world->GetPopulation().GetCell(cell_ids[pos]);
}
+
+cOrganism* cDeme::GetOrganism(int pos) const
+{
+ return GetCell(pos).GetOrganism();
+}
+
+
void cDeme::ProcessUpdate() {
energyUsage.Clear();
Modified: branches/collect/source/main/cDeme.h
===================================================================
--- branches/collect/source/main/cDeme.h 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cDeme.h 2008-07-21 18:37:17 UTC (rev 2721)
@@ -137,7 +137,8 @@
int GetDemeID() const { return _id; }
//! Returns an (x,y) pair for the position of the passed-in cell ID.
std::pair<int, int> GetCellPosition(int cellid) const;
- cPopulationCell& GetCell(int pos);
+ cPopulationCell& GetCell(int pos) const;
+ cOrganism* GetOrganism(int pos) const;
int GetWidth() const { return width; }
int GetHeight() const { return cell_ids.GetSize() / width; }
Modified: branches/collect/source/main/cDemeCellEvent.cc
===================================================================
--- branches/collect/source/main/cDemeCellEvent.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cDemeCellEvent.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -15,6 +15,7 @@
, m_static_pos(static_pos)
, m_deme(deme)
, m_world(world)
+ , m_id_set(false)
{
assert(x1 <= x2);
assert(y1 <= y2);
Modified: branches/collect/source/main/cOrgMovementPredicate.h
===================================================================
--- branches/collect/source/main/cOrgMovementPredicate.h 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cOrgMovementPredicate.h 2008-07-21 18:37:17 UTC (rev 2721)
@@ -194,7 +194,7 @@
{
// See how many times this org has gone back and forth. If it has
// done it enough times, it is considered successful
- unsigned int num_backforth = (int) floor(org.GetNumTaskCellsReached()/2);
+ unsigned int num_backforth = org.GetNumTaskCellsReached()/2;
if(num_backforth >= m_total_times) {
m_successful_orgs.insert(org_id);
Modified: branches/collect/source/main/cOrganism.cc
===================================================================
--- branches/collect/source/main/cOrganism.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cOrganism.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -46,6 +46,7 @@
#include "cStats.h"
#include <iomanip>
+#include <utility>
using namespace std;
@@ -75,6 +76,7 @@
, killed_event(false)
, m_net(NULL)
, m_msg(0)
+ , m_opinion(0)
{
// Initialization of structures...
m_hardware = m_world->GetHardwareManager().Create(this);
@@ -106,8 +108,9 @@
assert(m_is_running == false);
delete m_hardware;
delete m_interface;
- if (m_net != NULL) delete m_net;
- if(!m_msg) delete m_msg;
+ if(m_net) delete m_net;
+ if(m_msg) delete m_msg;
+ if(m_opinion) delete m_opinion;
}
cOrganism::cNetSupport::~cNetSupport()
@@ -725,3 +728,13 @@
// move IP to alarm_label
m_hardware->Jump_To_Alarm_Label(jump_label);
}
+
+
+/*! Called to set this organism's opinion, which remains valid until a new opinion
+ is expressed.
+ */
+void cOrganism::SetOpinion(const Opinion& opinion)
+{
+ InitOpinions();
+ m_opinion->opinion_list.push_back(std::make_pair(opinion, m_world->GetStats().GetUpdate()));
+}
Modified: branches/collect/source/main/cOrganism.h
===================================================================
--- branches/collect/source/main/cOrganism.h 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cOrganism.h 2008-07-21 18:37:17 UTC (rev 2721)
@@ -401,6 +401,43 @@
void SetEventKilled() { killed_event = true; }
bool GetEventKilled() { return killed_event; }
+
+ // -------- Opinion support --------
+ /* Organisms express an opinion at a given point in time. We can assume that they
+ hold this opinion until they express a new one. The semantics of opinions are
+ left to the particular tasks or fitness functions in use; opinions are merely a generic
+ approach that we as developers can use to evaluate when an organism has made a decision.
+
+ If we ever have a need for organisms to express different kinds of opinions, this code
+ can easily be adapted for that purpose (e.g., change the OpinionList typedef to a
+ std::map<int, DatedOpinion>, where the key represents the kind of opinion being expressed).
+
+ As with other such types of "extended" functionality, opinion support is encapsulated in
+ a lazily-initialized struct.
+ */
+public:
+ typedef int Opinion; //!< Typedef for an opinion.
+ typedef std::pair<Opinion, int> DatedOpinion; //!< Typedef for an opinion held at a given update.
+ typedef std::vector<DatedOpinion> DatedOpinionList; //!< Typedef for a list of dated opinions.
+ //! Called to set this organism's opinion.
+ void SetOpinion(const Opinion& opinion);
+ //! Retrieve this organism's current opinion.
+ const DatedOpinion& GetOpinion() { InitOpinions(); return m_opinion->opinion_list.back(); }
+ //! Retrieve all opinions expressed during this organism's lifetime.
+ const DatedOpinionList& GetOpinions() { InitOpinions(); return m_opinion->opinion_list; }
+ //! Return whether this organism has an opinion.
+ bool HasOpinion() { InitOpinions(); return m_opinion->opinion_list.size(); }
+
+protected:
+ //! Initialize opinion support.
+ inline void InitOpinions() { if(!m_opinion) { m_opinion = new cOpinionSupport(); } }
+ //! Container for the data used to support opinions.
+ struct cOpinionSupport
+ {
+ DatedOpinionList opinion_list; //!< All opinions expressed by this organism during its lifetime.
+ };
+ cOpinionSupport* m_opinion; //!< Lazily-initialized pointer to the opinion data.
+ // -------- End of opinion support --------
};
Modified: branches/collect/source/main/cPopulation.cc
===================================================================
--- branches/collect/source/main/cPopulation.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cPopulation.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -1150,6 +1150,12 @@
}
}
+ //re-inject demes with count of 1 back into self
+ for(int i = 0; i < (int)deme_counts.size(); i++) {
+ if(deme_counts[i] == 1)
+ ReplaceDeme(deme_array[i], deme_array[i]);
+ }
+
// Now, while we can find both a source deme (one with a count greater than 1)
// and a target deme (one with a count of 0), replace the target with the source.
while(true) {
@@ -1336,6 +1342,19 @@
target_id = m_world->GetRandom().GetUInt(num_demes);
}
}
+
+ // Write some logging information if LOG_DEMES_REPLICATE is set.
+ if( (m_world->GetConfig().LOG_DEMES_REPLICATE.Get() == 1) &&
+ (m_world->GetStats().GetUpdate() >= m_world->GetConfig().DEMES_REPLICATE_LOG_START.Get()) ) {
+ cString tmpfilename = cStringUtil::Stringf("deme_replication.dat");
+ cDataFile& df = m_world->GetDataFile(tmpfilename);
+
+ cString UpdateStr = cStringUtil::Stringf("%d,%d,%d",
+ m_world->GetStats().GetUpdate(),
+ source_deme.GetDemeID(), target_id);
+ df.WriteRaw(UpdateStr);
+ }
+
ReplaceDeme(source_deme, deme_array[target_id]);
}
Modified: branches/collect/source/main/cResourceCount.cc
===================================================================
--- branches/collect/source/main/cResourceCount.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cResourceCount.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -493,7 +493,25 @@
}
void cResourceCount::ReinitializeResources(double additional_resource){
+ cSpatialResCount src;
+ double c_curr_amount;
+ double c_initial_amount;
+ double c_new_amount;
+
for(int i = 0; i < resource_name.GetSize(); i++) {
- Set(i, resource_initial[i]+additional_resource); //will cause problem if more than one resource is used.
- }
-}
+ Set(i, resource_initial[i]+additional_resource); //will cause problem if more than one resource is used. -- why? each resource is stored separately (BDC)
+
+ // Additionally, set any initial values given by the CELL command
+ src = GetSpatialResource(i);
+ for(int j = 0; j < src.GetSize(); j++) {
+ c_initial_amount = src.Element(j).GetInitial();
+ if(c_initial_amount > 0) {
+ c_curr_amount = spatial_resource_count[i].GetAmount(j);
+ c_new_amount = c_curr_amount + c_initial_amount + additional_resource;
+ spatial_resource_count[i].SetCellAmount(j, c_new_amount);
+ }
+ }
+
+ } //End going through the resources
+
+} //End ReinitializeResources()
Modified: branches/collect/source/main/cSpatialCountElem.h
===================================================================
--- branches/collect/source/main/cSpatialCountElem.h 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cSpatialCountElem.h 2008-07-21 18:37:17 UTC (rev 2721)
@@ -33,7 +33,7 @@
class cSpatialCountElem
{
private:
- mutable double amount, delta;
+ mutable double amount, delta, initial;
tArray<int> elempt, xdist, ydist;
tArray<double> dist;
@@ -52,6 +52,8 @@
double GetPtrDist(int innum) { return dist[innum]; }
friend void FlowMatter(cSpatialCountElem&, cSpatialCountElem&, double, double, double, double,
int, int, double);
+ void SetInitial(double init) { initial = init; }
+ double GetInitial() { return initial; }
};
Modified: branches/collect/source/main/cSpatialResCount.cc
===================================================================
--- branches/collect/source/main/cSpatialResCount.cc 2008-07-10 20:57:36 UTC (rev 2720)
+++ branches/collect/source/main/cSpatialResCount.cc 2008-07-21 18:37:17 UTC (rev 2721)
@@ -226,6 +226,7 @@
if (cell_id >= 0 && cell_id <= grid.GetSize()) {
Rate((*cell_list_ptr)[i].GetId(), (*cell_list_ptr)[i].GetInitial());
State((*cell_list_ptr)[i].GetId());
+ Element(cell_id).SetInitial((*cell_list_ptr)[i].GetInitial());
}
}
}
More information about the Avida-cvs
mailing list