I have two agent in the GAMA-platform 1. water user 2. authority. I need help to make a water user agent to move to authority agent to get permision to user water then to go back to its original position.the authority go to the water source and back to its original position. this is the gaml code.
global {
//global attributes
float distance_to_intercept <- 100.0;
int number_of_water_source <-2;
int number_of_water_user <-2;
int number_of_authority <-1;
init{
//instantiate species
create water_source number:number_of_water_source;
create water_user number:number_of_water_user;
create pangani_board number:number_of_authority;
}
}
species water_source{
//attributes
string source_name;
string source_type;
string source_catchment_name;
float water_capacity;
//aspect to represent agents of this species in the simulation
aspect default{
draw circle(1)color:#blue border:#black;
}
}
species water_user skills:[moving]{
pangani_board target;
//attributes
float amount_requested <-5.0;
float amount_granted;
string water_use;
string source_type;
string source_name;
string catchment_name;
bool is_returning;
point location <- {rnd(100), rnd(100)}; // Random initial location
point original_location <- location; // Store the original location
//initialize agent speed
init {
speed <- 0.0;
is_returning <- false; // Initialize is_returning to false
}
//request water use permit
reflex request_water_use_permit {
ask authority{
myself.amount_granted<- grant_water_use_permit(myself.amount_requested);
}
}
//move to authority
reflex search_target when: target=nil and not is_returning {
ask authority at_distance(distance_to_intercept) {
myself.target <- self;
myself.speed <- 0.05; // Set speed to 0.05 when target is found
}
}
reflex follow when: target!=nil {
speed <- 0.0025;
do goto target: target;
float tolerance <- 0.9; // Tolerance for location comparison
if (abs(self.location.x - target.location.x) < tolerance and abs(self.location.y - target.location.y) < tolerance) { // Check if the water_user has reached the authority within tolerance
speed <- 0.0; // Stop the agent
do goback; // Call the goback action
}
}
action goback {
is_returning <- true; // Set the is_returning flag to true
speed <- 0.5; // Reset speed to the original value
do goto target: original_location; // Move back to the original location
if (self.location = original_location) { // Check if the water_user has reached the original location
speed <- 0.0; // Stop the agent
target <- nil; // Reset the target to nil to prevent re-activation of search_target reflex
// is_returning <- false; // Reset the is_returning flag to false
write("Agent has returned to original location"); // Log the return
}
}
//aspect to represent agents of this species in the simulation
aspect default{
draw circle(1)color:#red border:#black;
}
}
species authority{
//atributes
float amount_abstracted;
point location <- {50, 50}; // Fixed location for authority
float grant_water_use_permit(float amount_requested){
float requested_amount<-amount_requested;
if (requested_amount>=15 and requested_amount<=26.975){
amount_abstracted <-23.18;
}else if(requested_amount=10){
amount_abstracted <-3.98;
}else if(requested_amount<=2.0){
amount_abstracted <-2.62;
}else if (requested_amount<=5.0){
amount_abstracted <-2.87;
}else{
amount_abstracted<-0.0;
}
return amount_abstracted;
}
//aspect to represent agents of this species in the simulation
aspect default{
draw circle(1)color:#yellow border:#black;
}
}
experiment water_allocation type:gui{
output{
display my_agents{
species water_source aspect:default;
species water_user aspect:default;
species authority aspect:default;
}
}
}
I tried to make the water_user move to the authority using the code above. its actualy move but it doesnt go back to its original position