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"
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
61 auto agent_obj = make_shared<Cell>(this->shared_from_this(),agent_name);
62 this->
agents.push_back(agent_obj);
66 auto patch_obj = make_shared<Tissue>(this->shared_from_this(),mesh);
67 this->
patches.insert(pair<
unsigned,shared_ptr<Tissue>>(patch_obj->index,patch_obj));
73 std::map<std::string,unsigned>
settings = {{
"cell",2000}};
79 for (
auto &[index,patch]:this->
patches){
80 auto x = patch->coords[0];
81 auto y = patch->coords[1];
82 if ((
x >= 0.25 and
x <=1.25) and (y>=0.25 and y<=1.25)){
83 patch->damage_center =
true;
85 if (patch->empty() ==
false){
86 patch->get_agent()->disappear =
true;
94 for (
auto &agent: this->
agents){
97 int cell_count = this->agents.size();
98 this->
data[
"cell_count"].push_back(cell_count);
107 for (
auto &cell:this->
agents){
115 auto neighbor_cell_count = this->
patch->find_neighbor_agents().size();
116 if (this->
patch->damage_center and this->clock >= this->cycle_t){
117 if (neighbor_cell_count <= 6){
122 if (this->
patch->ECM < 100) {
123 this->
patch->ECM += 1;
126 if (neighbor_cell_count >7){
131 for (
unsigned i = 0;
i < 336;
i++){
132 cout<<
"iteration "<<
i<<
" agents "<<this->
agents.size()<<endl;
137 file1.open(
"memory_usage.csv");
145 file1.open(
"cells.csv");
146 file1 <<
"x,y,type,size\n";
147 for (
auto &agent:this->
agents){
148 file1<<agent->patch->coords[0]<<
","<<agent->patch->coords[1]<<
","<< agent->class_name<<
", "<<10<<std::endl;
153 file2.open(
"ECM.csv");
154 file2<<
"x,y,type,size\n";
155 for (
auto &[index,patch]:this->
patches){
156 file2<<patch->coords[0]<<
","<<patch->coords[1]<<
","<< patch->ECM<<
", "<<10<<std::endl;
161 file3.open(
"cell_count.csv");
162 file3<<
"cell_count\n";
163 for (
unsigned i=0;
i<this->
data[
"cell_count"].size();
i++){
164 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 shared_ptr< Cell > generate_agent(std::string agent_name)
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.