Strange behaviour accessing minimum of neighbour cells attributes

26 views
Skip to first unread message

Benjamin Mewes

unread,
Jan 26, 2016, 1:54:39 AM1/26/16
to GAMA
Hi all,

I wrote a small pathfinding model (see code attached). In this model the agents should choose the next cell by the lowest grid_value. In order to accelerate the model code, I decided to calculate the heading of my cells in the init section.

So basically, want I want to do is:

1. ASK CELL
2. TAKE A LOOK AT YOUR 8 DIRECT NEIGHBOURS
3. CHOOSE THE CELL AS TARGET WHICH HAS THE LOWEST ALTITUDE VAL
4. SET HEADING FROM SELF TO TARGET
5. AGENT JUST READS HEADING FROM CURRENT_CELL

This works in 5 of 6 cases, but, for example in cell 35 it doesn't work. My agents should go to cell 25 (which has the lowest altitude) but they are heading southwest? Any idea why this might be? Is my code wrong?

Thank all the best,

Benjamin
syn_dem.asc
model_002.gaml

Benjamin Mewes

unread,
Jan 26, 2016, 3:44:27 AM1/26/16
to GAMA
Okay, it is getting even stranger:

My algorithm finds its target (still wrong sometimes, anyhow):

target_cell <- neighbour_cells with_min_of (each.altitude);

If I try to read out target_cell.altitude it writes me 0.0. But I write out cell[target_cell.grid_x, target_cell.grid_y].altitude it gives me the correct value!

This seems not logical to me, to you?

Patrick Taillandier

unread,
Jan 26, 2016, 3:58:51 AM1/26/16
to gama-p...@googlegroups.com
Hi, 

It is because your are giving a value for the altitude and accessing it for the neighbours cells it in the same loop.... so for some of the cells the value of altitude is not yet initialized.

You can try to do:


ask cell {
//Hinterlegt in jeder Zelle die DGM Information als Höhe
switch (grid_value = -9999){
match false {altitude <- grid_value;}
match true {altitude <- 9999.0;}
}
}
ask cell {
//Fertig eine Liste der Nachbarn in der Distanz 1 an
          neighbour_cells <- (self neighbours_at 1);
         
          //Berechnet Richtung der Bewegung für jede Zelle und Slope
          target_cell <- neighbour_cells with_min_of (each.altitude);
         
          //Berechnet den Winkel
          heading <-   (target_cell) towards myself ;

 
   
          //Löschen der Liste mit Zellen für Nachbarn
          //neighbour_cells <- nil;
         
                     
         }

Note that I think that in your case, you should rather use the goto action than the move one.

Cheers,

Patrick



--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Cet e-mail a été envoyé depuis un ordinateur protégé par Avast.
www.avast.com

Benjamin Mewes

unread,
Jan 26, 2016, 4:06:13 AM1/26/16
to GAMA
Hi,

understood for the altitude value :)

In combination with the goto command it works. One question:How comes that my calculation of the heading doesn't work?

Benjamin Mewes

unread,
Jan 26, 2016, 4:11:26 AM1/26/16
to GAMA
Hi,

now it works. Good point with the initialisation of the loop.

One quick question: Why does the calculation of the heading doesn't work properly? Goto works like a charm but my move argument doesn't end in the wished results.


Am Dienstag, 26. Januar 2016 09:58:51 UTC+1 schrieb Patrick Taillandier:

Patrick Taillandier

unread,
Jan 26, 2016, 4:59:06 AM1/26/16
to gama-p...@googlegroups.com
Hi,

I think the move actions works well. Here a simple example to test it.

model headingmove

global {
goal the_goal;
init {
create goal;
create dummy_move;
}
}

species goal {
init {
the_goal <- self;
}
aspect default {
draw square(5) color: #yellow;
}
}

species dummy_move skills:[moving] {
aspect default {
draw circle(2) color: #red;
}
reflex movement {
do move heading: (self towards the_goal);
if (self distance_to the_goal <= 1.0) {
ask the_goal {do die;}
create goal;
}
}
}

experiment headingmove type: gui {
output {
display view {
species goal;
species dummy_move;
}
}
}

To make it works in your model, you can just write:

reflex movement {
do updateLocation;
//Änderung der Fließgeschwindigkeit
do move heading: (self towards current_cell.target_cell) bounds: world.shape speed: sf_speed;
}

Note that in your case, the use of the bounds facet is not useful and is very tiem consuming, so you should remove it:

do move heading: (self towards current_cell.target_cell) speed: sf_speed;

Cheers,

Patrick

Benjamin Mewes

unread,
Jan 26, 2016, 5:12:21 AM1/26/16
to GAMA
Ah okay, so you don't save the heading as one value for the cell but calculate it for every agent.

Patrick Taillandier

unread,
Jan 26, 2016, 5:13:28 AM1/26/16
to gama-p...@googlegroups.com
yes as the heading depends on the location of the agents (I compute its heading toward the target cell).
Reply all
Reply to author
Forward
0 new messages