cppyabm
1.0.17
An agent-based library to integrate C++ and Python
|
|
Go to the documentation of this file.
3 #include <cppyabm/bases.h>
4 #include "cppyabm/mesh.h"
13 struct Domain:
public Env<Domain,Cell,Tissue> {
15 using baseEnv::baseEnv;
28 std::map<std::string,std::vector<int>>
data= {{
"cell_count",{}}};
31 struct task_basic_info t_info;
32 mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
33 #endif //MEMORY_MONITOR
38 using basePatch::basePatch;
48 struct Cell:
public Agent<Domain,Cell,Tissue> {
50 using baseAgent::baseAgent;
65 auto agent_obj = make_shared<Cell>(this->shared_from_this(),agent_name);
66 this->
agents.push_back(agent_obj);
70 auto patch_obj = make_shared<Tissue>(this->shared_from_this(),mesh);
71 this->
patches.insert(pair<
unsigned,shared_ptr<Tissue>>(patch_obj->index,patch_obj));
77 std::map<std::string,unsigned>
settings = {{
"cell",2000}};
83 for (
auto &[index,patch]:this->
patches){
84 auto x = patch->coords[0];
85 auto y = patch->coords[1];
86 if ((
x >= 0.25 and
x <=1.25) and (y>=0.25 and y<=1.25)){
87 patch->damage_center =
true;
89 if (patch->empty() ==
false){
90 patch->get_agent()->disappear =
true;
98 for (
auto &agent: this->
agents){
101 int cell_count = this->agents.size();
102 this->
data[
"cell_count"].push_back(cell_count);
111 for (
auto &cell:this->agents){
119 auto neighbor_cell_count = this->
patch->find_neighbor_agents().size();
120 if (this->
patch->damage_center and this->clock >= this->cycle_t){
121 if (neighbor_cell_count <= 6){
126 if (this->
patch->ECM < 100) {
127 this->
patch->ECM += 1;
130 if (neighbor_cell_count >7){
135 for (
unsigned i = 0;
i < 336;
i++){
136 cout<<
"iteration "<<
i<<
" agents "<<this->agents.size()<<endl;
141 file1.open(
"memory_usage.csv");
149 file1.open(
"cells.csv");
150 file1 <<
"x,y,type,size\n";
151 for (
auto &agent:this->agents){
152 file1<<agent->patch->coords[0]<<
","<<agent->patch->coords[1]<<
","<< agent->class_name<<
", "<<10<<std::endl;
157 file2.open(
"ECM.csv");
158 file2<<
"x,y,type,size\n";
159 for (
auto &[index,patch]:this->patches){
160 file2<<patch->coords[0]<<
","<<patch->coords[1]<<
","<< patch->ECM<<
", "<<10<<std::endl;
165 file3.open(
"cell_count.csv");
166 file3<<
"cell_count\n";
167 for (
unsigned i=0;
i<this->
data[
"cell_count"].size();
i++){
168 file3<<
i<<
","<<this->
data[
"cell_count"][
i]<<std::endl;
void order_move(shared_ptr< Tissue > patch=nullptr, bool quiet=false, bool reset=false)
Orders agent to move. This will execute during Env::update.
void setup_domain(vector< MESH_ITEM > mesh)
Sets up the domain by creating patch objects in accordance to mesh objects.
void setup_agents(map< string, unsigned > config)
Creates agents and randomly distributes them in the simulation domain.
bool disappear
if set to true, the agent will be removed from the simulation. This will execute during Env::update
std::shared_ptr< Tissue > patch
Pointer to the residing patch.
Cell(shared_ptr< Domain > env, std::string agent_name)
virtual void update()
Update the world. All built-in utilities such as Agent::order_move are executed here.
virtual shared_ptr< Cell > generate_agent(std::string agent_name)
virtual shared_ptr< Cell > generate_agent(std::string agent_name)
virtual shared_ptr< Tissue > generate_patch(MESH_ITEM)
Domain(bool _output_flag)
void update()
To define inheritage.
Tissue(shared_ptr< Domain > env, MESH_ITEM mesh)
Domain class to coordinate the simulation.
void order_hatch(shared_ptr< Tissue > patch=nullptr, bool inherit=false, bool quiet=false, bool reset=false)
Orders agent to hatch. This will execute during Env::update.
virtual shared_ptr< Tissue > generate_patch(MESH_ITEM)
virtual void update()
Update the world. All built-in utilities such as Agent::order_move are executed here.
Base class for environment.
vector< MESH_ITEM > grid2(double length, double width, double mesh_length, bool share)
A function to create 2D rectangular mesh.
virtual void update()
Update the world. All built-in utilities such as Agent::order_move are executed here.
vector< shared_ptr< Cell > > agents
Agent container.
std::map< std::string, std::vector< int > > data
map< unsigned, shared_ptr< Tissue > > patches
Patch container.