• Keine Ergebnisse gefunden

Location Is Important!

Im Dokument Agent-Based Modeling (Seite 124-133)

4.8 Enhancing the Environment

5.1.3 Location Is Important!

The Sugarscape model is a sociological model, where the position hold great influence on interactions. Each agent (citizen) has an area of vision and moving distance for capturing sugar. The decisions are made locally depending on what happens in this area of vision of agents.

Figure 5.7 shows an area of influence of one agent, where agent decisions are based on local stimuli. Agents make all decisions locally, on what they see in the circle of influence or bounded view. This makes the society highly decentralized, similar to ant or termite colonies in nature. The model can be analyzed, on a larger scale, for patterns emerging from the complete society.

Table 5.1 summarizes the model parameters for distances considered in the FLAME Sugarscape model.

Table 5.2 describes how the model looks with agents, memory and func-tions. The citizen and sugar both need x and y coordinates located on a 2D landscape. The distance will allow closest citizens to eat sugar first. Once eaten, the sugar will ‘die’ or disappear from the scene. The messages allow

S u g a r

C i t i z e n A M o v i n g d i s t a n c e

V i e w i n g d i s t a n c e

A n o t h e r c i t i z e n i n t h e a r e a

FIGURE 5.7: View of a citizen agent in FLAME Sugarscape.

TABLE 5.1: Global variables used in FLAME Sugarscape.

Viewing distance 200

Eating distance 5

Moving or run distance 5.5

Landscape 200×200

agents to see or find each other and post information to each other. Figure 5.8 displays the basic functions the agents perform in one iteration. The sug-ars have to post their location allowing citizens to find them. If the sugar is eaten by citizens, these disappear from the landscape. Note that the iteration timeline shown in Figure 5.8 does not consider citizen agents dying or trading sugar.

<!-- Model file for Sugarscape-->

<xmodel version="1">

<name>Sugarscape Model</name>

<version>1</version>

<author>Mariam Kiran</author>

<date>300809</date>

<environment>

<functionFiles>

<file>my_library_functions.c</file>

<file>citizen.c</file>

<file>sugar.c</file>

</functionFiles>

</environment>

TABLE 5.2: FLAME Sugarscape model.

Identify Agents Citizen, Sugar

Agent memory Citizen: id, sugars, x, y; Sugar: id, x, y

Agent functions

Citizen functions: Citizen posts location, Cit-izen look for sugar, CitCit-izen eats sugar, Citi-zen updates its sugar count; Sugar functions:

Sugar posts location, Sugar checks it is eaten or not

Messages needed for communications

Citizen location: Contains citizen id, x, y;

Sugar location: Contains sugar id, x, y; Eaten:

Contains citizen id, sugar id

L o o k f o r s u g a r a r o u n d m e

P o s t l o c a t i o n o f s u g a r s

I f f o u n d , e a t s u g a r e l s e m o v e r a n d o m l y

I f s u g a r e a t e n ,

d i s a p p e a r f r o m l a n d s c a p e

C i t i z e n S u g a r

( F o r a l l a g e n t s ) ( I n t h e l a n d s c a p e ) D u r i n g o n e t i m e s t e p

S u g a r l o c a t i o n m e s s a g e s

E a t m e s s a g e s

FIGURE 5.8: Timeline of the basic FLAME Sugarscape model.

<agents>

<xagent>

</xagent>

<xagent>

<name>Sugar</name>

<description></description>

<memory>

<variable><type>int</type><name>id</name></variable>

<variable><type>double</type><name>x</name></variable>

<variable><type>double</type><name>y</name></variable>

</memory>

<functions>

<function>

<name>Sugar_post_location</name>

<currentState>00</currentState>

<nextState>01</nextState>

<outputs>

<output><messageName>sugar_location</messageName></output>

</outputs>

</function>

<function>

<name>Sugar_check_eaten</name>

<currentState>01</currentState>

<nextState>02</nextState>

<inputs>

<input><messageName>request_sugar</messageName></input>

</inputs>

<outputs>

<output><messageName>eaten</messageName></output>

</outputs>

</function>

</functions>

</xagent>

</agents>

<messages>

<message>

<name>citizen_location</name>

<variables>

<variable><type>int</type><name>citizen_id</name></variable>

<variable><type>double</type><name>x</name></variable>

<variable><type>double</type><name>y</name></variable>

</variables>

</message>

<message>

<name>sugar_location</name>

<variables>

<variable><type>int</type><name>sugar_id</name></variable>

<variable><type>double</type><name>x</name></variable>

<variable><type>double</type><name>y</name></variable>

</variables>

</message>

<message>

<name>eaten</name>

<variables>

<variable><type>int</type><name>citizen_id</name></variable>

<variable><type>double</type><name>x</name></variable>

<variable><type>double</type><name>y</name></variable>

</variables>

</message>

<message>

<name>my_sugar</name>

<variables>

<variable><type>int</type><name>citizen_id</name></variable>

<variable><type>int</type><name>sugars</name></variable>

</variables>

</message>

</messages>

</xmodel>

//Library file contains the global values used by the C functions

#define citizen_view_length 200.0

#define citizen_eat_length 5.0

#define citizen_run_length 5.5

#define CitizenBoardSize 10

#define LENGTH 4

#define THRESHOLD 10.0

#define LANDSCAPE 200

double handle_boundary(double position);

//Library functions file contains common functions used by agents

#include "header.h"

#include "my_library_header.h"

double handle_boundary(double position)

{

double new_pos=position;

if(position >= LANDSCAPE) {

new_pos =LANDSCAPE -(position-LANDSCAPE);

}

else if(position<0) {

new_pos=new_pos*(-1);

} else {

printf("value is %f", new_pos);

}

return new_pos;

}

/**Citizen Agent functions file containing its actions**/

#include "header.h"

#include "my_library_header.h"

#include "Citizen_agent_header.h"

//Function to handle agent placement as a 2x2 Grid double sec_handle_boundary(double position)

{

double new_pos=position;

if(position >= LANDSCAPE) {

new_pos =LANDSCAPE -(position-LANDSCAPE);

}

else if(position<0) {

new_pos=new_pos*(-1);

} else {

print("Possible check");

}

return new_pos;

}

int Citizen_post_location() {

add_citizen_location_message(ID, X, Y, SCENE_ID);

return 0;

}

int Citizen_look_for_sugar() {

int closest_sugar_id=-1;

double shortest_distance=9999.0;

double current_distance_squared;

double current_distance_squared_citizen;

double closest_x,closest_y;

int richest_citizen_id=-1;

int citizen_sugars=0;

int max_sugar=0;//change to 0 FLAG_SUGAR_FOUND=0;

sugar_location_message=get_first_sugar_location_message();

while(sugar_location_message) {

//Extracting information from message current_distance_squared=

(sugar_location_message->x-X)*(sugar_location_message->x-X) + (sugar_location_message->y-Y)*(sugar_location_message->y-Y);

if(current_distance_squared <=

(citizen_view_length* citizen_view_length)) {

if(current_distance_squared<shortest_distance) {

shortest_distance=current_distance_squared;

closest_sugar_id=sugar_location_message->sugar_id;

closest_x=sugar_location_message->x;

closest_y=sugar_location_message->y;

FLAG_SUGAR_FOUND=closest_sugar_id;

printf("Sugar is found");

} } }

sugar_location_message=get_next_sugar_location_message (sugar_location_message);

}

if(FLAG_SUGAR_FOUND!=0) {

//move randomly in the space

X=X+(citizen_run_length-((double)rand()/(double)(RAND_MAX)*

(citizen_run_length*2.0)));

Y=Y+(citizen_run_length-((double)rand()/(double)(RAND_MAX)*

(citizen_run_length*2.0)));

}

X=sec_handle_boundary(X);

Y=sec_handle_boundary(Y);

return 0;

}

int Citizen_Eaten() {

eaten_message=get_first_eaten_message();

while(eaten_message) {

if(eaten_message->citizen_id==ID) {

SUGARS++;

}

eaten_message=get_next_eaten_message(eaten_message);

}

return 0;

}

/**Sugar Agent functions file containing its actions**/

#include "header.h"

#include "my_library_header.h"

#include "Sugar_agent_header.h"

int Sugar_post_location() {

add_sugar_location_message(ID, X,Y);

return 0;

}

int Sugar_check_eaten() {

int citizen_id=-1;

request_sugar_message=get_first_request_sugar_message();

while(request_sugar_message) {

if(request_sugar_message->sugar_id==ID) {

citizen_id=request_sugar_message->citizen_id;

}

request_sugar_message=get_next_request_sugar_message (request_sugar_message);

}

if(citizen_id!=-1) {

add_eaten_message(citizen_id, X, Y);

return 1; //returning 1 deletes the agent from the simulation

}

return 0;

}

<!-- Starting conditions with 1 citizen and 1 sugar-->

<states>

<itno>0</itno>

<xagent>

<name>Citizen</name>

<id>50</id>

<sugars>0</sugars>

<x>33.542894</x>

<y>59.733879</y>

<flag_sugar_found>0</flag_sugar_found>

</xagent>

<xagent>

<name>Sugar</name>

<id>1</id>

<x>90.304270</x>

<y>98.867763</y>

</xagent>

</states>

Im Dokument Agent-Based Modeling (Seite 124-133)