[Avida-SVN] r3307 - in development/source: cpu main
dk at myxo.css.msu.edu
dk at myxo.css.msu.edu
Wed Jun 10 06:57:48 PDT 2009
Author: dk
Date: 2009-06-10 09:57:47 -0400 (Wed, 10 Jun 2009)
New Revision: 3307
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/cpu/cTestCPUInterface.h
development/source/main/cDeme.cc
development/source/main/cDeme.h
development/source/main/cDemeNetwork.h
development/source/main/cDemeTopologyNetwork.h
development/source/main/cOrgInterface.h
development/source/main/cPopulationInterface.cc
development/source/main/cPopulationInterface.h
Log:
Added instructions and associated plumbing for creating links in the deme networks.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/cpu/cHardwareCPU.cc 2009-06-10 13:57:47 UTC (rev 3307)
@@ -572,6 +572,11 @@
tInstLibEntry<tMethod>("orgs-in-my-group", &cHardwareCPU::Inst_NumberOrgsInMyGroup, nInstFlag::STALL),
tInstLibEntry<tMethod>("orgs-in-group", &cHardwareCPU::Inst_NumberOrgsInGroup, nInstFlag::STALL),
+ // Network creation instructions
+ tInstLibEntry<tMethod>("create-link-facing", &cHardwareCPU::Inst_CreateLinkByFacing, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("create-link-xy", &cHardwareCPU::Inst_CreateLinkByXY, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("create-link-index", &cHardwareCPU::Inst_CreateLinkByIndex, nInstFlag::STALL),
+
// Must always be the last instruction in the array
tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
};
@@ -8961,7 +8966,6 @@
return true;
}
-
//! Gets the number of organisms in the group of a given id
//! specified by the ?BX? register and places the value in the ?CX? register
bool cHardwareCPU::Inst_NumberOrgsInGroup(cAvidaContext& ctx)
@@ -8976,3 +8980,30 @@
GetRegister(num_org_reg) = num_orgs;
return true;
}
+
+/*! Create a link to the currently-faced cell.
+ */
+bool cHardwareCPU::Inst_CreateLinkByFacing(cAvidaContext& ctx) {
+ const int wreg = FindModifiedRegister(REG_BX);
+ m_organism->GetOrgInterface().CreateLinkByFacing(GetRegister(wreg));
+ return true;
+}
+
+/*! Create a link to the cell specified by xy-coordinates.
+ */
+bool cHardwareCPU::Inst_CreateLinkByXY(cAvidaContext& ctx) {
+ const int xreg = FindModifiedRegister(REG_BX);
+ const int yreg = FindNextRegister(xreg);
+ const int wreg = FindNextRegister(yreg);
+ m_organism->GetOrgInterface().CreateLinkByXY(GetRegister(xreg), GetRegister(yreg), GetRegister(wreg));
+ return true;
+}
+
+/*! Create a link to the cell specified by index.
+ */
+bool cHardwareCPU::Inst_CreateLinkByIndex(cAvidaContext& ctx) {
+ const int idxreg = FindModifiedRegister(REG_BX);
+ const int wreg = FindNextRegister(idxreg);
+ m_organism->GetOrgInterface().CreateLinkByIndex(GetRegister(idxreg), GetRegister(wreg));
+ return true;
+}
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/cpu/cHardwareCPU.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -848,7 +848,7 @@
bool Inst_IfNeighborhoodChanged(cAvidaContext& ctx);
-// -------- Group Formation Support --------
+ // -------- Group Formation Support --------
public:
//! An organism joins a group by setting it opinion to the group id.
bool Inst_JoinGroup(cAvidaContext& ctx);
@@ -856,8 +856,15 @@
bool Inst_NumberOrgsInMyGroup(cAvidaContext& ctx);
//! Returns the number of organisms in the current organism's group
bool Inst_NumberOrgsInGroup(cAvidaContext& ctx);
-
-
+
+ // -------- Network creation support --------
+public:
+ //! Create a link to the currently-faced cell.
+ bool Inst_CreateLinkByFacing(cAvidaContext& ctx);
+ //! Create a link to the cell specified by xy-coordinates.
+ bool Inst_CreateLinkByXY(cAvidaContext& ctx);
+ //! Create a link to the cell specified by index.
+ bool Inst_CreateLinkByIndex(cAvidaContext& ctx);
};
Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/cpu/cTestCPUInterface.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -105,6 +105,13 @@
void RotateToGreatestReputationWithDifferentLineage(int tag){ }
int GetStateGridID(cAvidaContext& ctx);
+
+ //! Link this organism's cell to the cell it is currently facing.
+ void CreateLinkByFacing(double weight=1.0) { }
+ //! Link this organism's cell to the cell with coordinates (x,y).
+ void CreateLinkByXY(int x, int y, double weight=1.0) { }
+ //! Link this organism's cell to the cell with index idx.
+ void CreateLinkByIndex(int idx, double weight=1.0) { }
};
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cDeme.cc 2009-06-10 13:57:47 UTC (rev 3307)
@@ -131,7 +131,12 @@
return m_world->GetPopulation().GetCell(cell_ids[pos]);
}
+cPopulationCell& cDeme::GetCell(int x, int y) const
+{
+ return m_world->GetPopulation().GetCell(GetCellID(x,y));
+}
+
cOrganism* cDeme::GetOrganism(int pos) const
{
return GetCell(pos).GetOrganism();
@@ -250,6 +255,9 @@
}
}
++_age;
+
+ // Let the network process the update too, if we have one.
+ if(IsNetworkInitialized()) { m_network->ProcessUpdate(); }
}
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cDeme.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -159,6 +159,7 @@
//! 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) const;
+ cPopulationCell& GetCell(int x, int y) const;
cOrganism* GetOrganism(int pos) const;
int GetWidth() const { return width; }
Modified: development/source/main/cDemeNetwork.h
===================================================================
--- development/source/main/cDemeNetwork.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cDemeNetwork.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -54,7 +54,7 @@
neighboring cells. The network's performance is based on its structure (evaluated as a graph).
*/
enum NetworkType { TOPOLOGY };
-
+
//! Factory method, the only way to create a deme network (pointer is owned by the caller).
static cDemeNetwork* DemeNetworkFactory(cWorld* world, cDeme& deme);
@@ -65,7 +65,7 @@
virtual void ProcessUpdate() = 0;
//! Connect u->v with weight w.
- virtual void Connect(cPopulationCell& u, cPopulationCell& v, double w=0.0) = 0;
+ virtual void Connect(cPopulationCell& u, cPopulationCell& v, double w=1.0) = 0;
//! Called when the organism living in cell u dies.
virtual void OrganismDeath(cPopulationCell& u) = 0;
Modified: development/source/main/cDemeTopologyNetwork.h
===================================================================
--- development/source/main/cDemeTopologyNetwork.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cDemeTopologyNetwork.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -78,7 +78,7 @@
virtual void ProcessUpdate() { }
//! Connect u->v with weight w.
- virtual void Connect(cPopulationCell& u, cPopulationCell& v, double w=0.0);
+ virtual void Connect(cPopulationCell& u, cPopulationCell& v, double w=1.0);
//! Called when the organism living in cell u dies.
virtual void OrganismDeath(cPopulationCell& u) { }
Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cOrgInterface.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -113,7 +113,10 @@
virtual void RotateToGreatestReputation() =0;
virtual void RotateToGreatestReputationWithDifferentTag(int tag) =0;
virtual void RotateToGreatestReputationWithDifferentLineage(int line) =0;
-
+
+ virtual void CreateLinkByFacing(double weight=1.0) = 0;
+ virtual void CreateLinkByXY(int x, int y, double weight=1.0) = 0;
+ virtual void CreateLinkByIndex(int idx, double weight=1.0) = 0;
};
#endif
Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cPopulationInterface.cc 2009-06-10 13:57:47 UTC (rev 3307)
@@ -25,6 +25,7 @@
#include "cPopulationInterface.h"
+#include "cDeme.h"
#include "cEnvironment.h"
#include "cGenotype.h"
#include "cHardwareManager.h"
@@ -42,8 +43,16 @@
#define NULL 0
#endif
-cDeme* cPopulationInterface::GetDeme()
-{
+
+cPopulationCell* cPopulationInterface::GetCell() {
+ return &m_world->GetPopulation().GetCell(m_cell_id);
+}
+
+cPopulationCell* cPopulationInterface::GetCellFaced() {
+ return &GetCell()->GetCellFaced();
+}
+
+cDeme* cPopulationInterface::GetDeme() {
return &m_world->GetPopulation().GetDeme(m_deme_id);
}
@@ -568,9 +577,32 @@
cell.ConnectionList().CircNext();
}
-
-
-
- }
-
+ }
}
+
+/*! Link this organism's cell to the cell it is currently facing.
+ */
+void cPopulationInterface::CreateLinkByFacing(double weight) {
+ cDeme* deme = GetDeme(); assert(deme);
+ cPopulationCell* this_cell = GetCell(); assert(this_cell);
+ cPopulationCell* that_cell = GetCellFaced(); assert(that_cell);
+ deme->GetNetwork().Connect(*this_cell, *that_cell, weight);
+}
+
+/*! Link this organism's cell to the cell with coordinates (x,y).
+ */
+void cPopulationInterface::CreateLinkByXY(int x, int y, double weight) {
+ cDeme* deme = GetDeme(); assert(deme);
+ cPopulationCell* this_cell = GetCell(); assert(this_cell);
+ cPopulationCell& that_cell = deme->GetCell(x % deme->GetWidth(), y % deme->GetHeight());
+ deme->GetNetwork().Connect(*this_cell, that_cell, weight);
+}
+
+/*! Link this organism's cell to the cell with index idx.
+ */
+void cPopulationInterface::CreateLinkByIndex(int idx, double weight) {
+ cDeme* deme = GetDeme(); assert(deme);
+ cPopulationCell* this_cell = GetCell(); assert(this_cell);
+ cPopulationCell& that_cell = deme->GetCell(idx % deme->GetSize());
+ deme->GetNetwork().Connect(*this_cell, that_cell, weight);
+}
Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h 2009-06-10 13:33:55 UTC (rev 3306)
+++ development/source/main/cPopulationInterface.h 2009-06-10 13:57:47 UTC (rev 3307)
@@ -35,9 +35,10 @@
#ifndef cWorldDriver_h
#include "cWorldDriver.h"
#endif
-#include "cDeme.h"
+class cDeme;
class cPopulation;
+class cPopulationCell;
class cOrgMessage;
@@ -61,7 +62,12 @@
virtual ~cPopulationInterface() { ; }
int GetCellID() { return m_cell_id; }
+ //! Retrieve the cell in which this organism lives.
+ cPopulationCell* GetCell();
+ //! Retrieve the cell currently faced by this organism.
+ cPopulationCell* GetCellFaced();
int GetDemeID() { return m_deme_id; }
+ //! Retrieve the deme in which this organism lives.
cDeme* GetDeme();
void SetCellID(int in_id) { m_cell_id = in_id; }
void SetDemeID(int in_id) { m_deme_id = in_id; }
@@ -119,7 +125,15 @@
// Reputation
void RotateToGreatestReputation();
void RotateToGreatestReputationWithDifferentTag(int tag);
- void RotateToGreatestReputationWithDifferentLineage(int line);
+ void RotateToGreatestReputationWithDifferentLineage(int line);
+
+ // -------- Network creation support --------
+ //! Link this organism's cell to the cell it is currently facing.
+ void CreateLinkByFacing(double weight=1.0);
+ //! Link this organism's cell to the cell with coordinates (x,y).
+ void CreateLinkByXY(int x, int y, double weight=1.0);
+ //! Link this organism's cell to the cell with index idx.
+ void CreateLinkByIndex(int idx, double weight=1.0);
};
More information about the Avida-cvs
mailing list