Random Walk

84 views
Skip to first unread message

Chris Harvey

unread,
Nov 11, 2014, 9:20:38 AM11/11/14
to gama-p...@googlegroups.com
I am attempting to simulate a random walk algorithm with the agents.  What I notice is that the agents jitter around randomly, but inevitably all move toward one side of the simulation.  I don't understand why this is occuring.  The code I've written to perform this simulation is as follows:

species bug skills: [moving] {
    float speed <- float(0.003);
   
   
    reflex RW {
        list the_list <- list(species_of(bug));
        loop i from: 0 to: length(the_list)-1{
            ask the_list at i{
               
                        int direction <- rnd(8);
                        write direction;
        if (direction = 7) {heading <- 270; do move speed: speed heading: heading;}
        else if (direction = 1) {heading <-45; do move speed: speed heading: heading;}
        else if (direction = 2) {heading <- 90; do move speed: speed heading: heading;}
        else if (direction = 3) {heading <- 125; do move speed: speed heading: heading;}
        else if (direction = 4) {heading <- 180; do move speed: speed heading: heading;}
        else if (direction = 5) {heading <- 225; do move speed: speed heading: heading;}
        else if (direction = 6) {heading <- 0; do move speed: speed heading: heading;}
        else {heading <- 335; do move speed: speed heading: heading;}
       
        //do move speed: speed heading: heading;
            }
        }

        }


Does anyone have any insight into what I'm doing wrong?

Thank you,


Chris

Srirama Bhamidipati

unread,
Nov 11, 2014, 9:28:26 AM11/11/14
to gama-p...@googlegroups.com
Just a side note: Do you think you could use "wander" ? :)

regards,
Srirama

Chris Harvey

unread,
Nov 11, 2014, 10:10:37 AM11/11/14
to gama-p...@googlegroups.com
I did try "wander"  and it does appear to move the agents randomly, however I have not found documentation explaining to me exactly what algorithm wander uses - it appears random - but is it truly random Brownian motion?

Patrick Taillandier

unread,
Nov 11, 2014, 10:32:58 AM11/11/14
to gama-p...@googlegroups.com
Hi,

I think wander is the good choice. Not that your model is a bit weird: why do you need to do a loop, then a ask in the bug RW reflex? I mean, you can do an ask on a list of agents (in your case, just "ask bug {...}" to ask all the bugs to do something. In addition, as you put your reflex inside the bug species, it means that all the bugs are going to execute the RW reflex (then to ask all the bugs to move... ).

Here, a simple model to test with 2 solutions (using the wander action and the move action). I tested both and it seems to work quite well:

model RandomWalk


global {

bool use_wander <- true;

init {

create bug number: 10 with: [location::location];

}

}


species bug skills: [moving] {

float speed <- float(0.003);

rgb color <- rnd_color(255);

reflex RW_1 when: not use_wander {

heading <- int(360 * rnd(7)/8);

do move speed: speed;

}

reflex RW_2 when: use_wander {

do wander speed: speed ;

}

aspect default {

draw circle(2) color: color;

}

}


experiment RandomWalk type: gui {

output{

display map {

species bug;

}

}

}


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 http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Chris Harvey

unread,
Nov 11, 2014, 11:04:55 AM11/11/14
to gama-p...@googlegroups.com
Hi Patrick -

I will try 'wander'.  Basically, the rationale for how I wrote the code is that I wanted each agent to move randomly and be independent of each other - so, I thought I had to loop through the agents then assign a random heading to each agent.  I'm new to GAMA and GAML, so - I'm feeling my way through this.   Thank you for the assistance to both you and Srirama!


Chris
Reply all
Reply to author
Forward
0 new messages