execution order of species init

21 views
Skip to first unread message

Achim Gädke

unread,
Mar 24, 2014, 9:49:19 PM3/24/14
to gama-p...@googlegroups.com
Hi there!

I get a bit confused with the init clauses in species. In which order are these executed?
To illustrate my confusion, I've written this little model.

It outputs to the console (using GAMA 1.6.1SVN):
0
0

I'd expect to receive:
1
1
as I would expect to have the initialization run during allocation.

Could you shed some light into the allocation/initialization/execution order?

Cheers, Achim
testInit.gaml

Srirama Bhamidipati

unread,
Mar 25, 2014, 3:35:47 AM3/25/14
to gama-p...@googlegroups.com
Hi,

to my understanding the order is as follows:

1. assignment in an init{ }
2. assignment outside init of the same variable overwrites values in init{ }

because your code not have any functions, reflexes, a lot also depends on the location of write statement. variable assignment closet to the write statement will take priority. 

there are more experts on this than I  :) :)

Achim Gädke

unread,
Mar 25, 2014, 5:59:15 AM3/25/14
to gama-p...@googlegroups.com

Hi Srirama!

So, an assignment as part of the initialization, e.g. in the definition will override the values in the init clause as well?

Please have a look to the code attached to the first post.

When thinking about the execution order in GAMA I always map species to classes and agents to objects. Then I assume things happen in the same order as I am used from C++ or java.

Cheers, Achim

Alexis Drogoul

unread,
Mar 25, 2014, 6:12:19 AM3/25/14
to gama-p...@googlegroups.com
Hi,

The order is as follows:

- first, the init of the world is executed without interruption, and this initializes the variables and executes the blocks passed in parameter to the create statements
- then, in the order they have been declared, the agents execute their init behavior (if it exists).

So, in your case, a is created with a value of 0, then b is created and catches this value and then you write their respective values in the init (i.e. before they have run the init statement).

If you need to specify a different initialization order, it is somewhat possible. For example, if you write in your model:

create a returns: aa;

ask aa {
do _init_;
}

then all your « a » agents will be inited before the init of the world is finished (and you will get 1,1 in the display as expected).

Cheers
Alexis
> --
> 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.

--
Senior Researcher, UMI UMMISCO 209, IRD & UPMC, France.
Invited Researcher, DREAM, Can Tho University, Viet Nam.
--
alexis....@gmail.com | http://tiny.cc/liqemw
[Vietnam] +84915088155 [France] +33608698845
--
GAMA: https://code.google.com/p/gama-platform/

Achim Gädke

unread,
Mar 25, 2014, 6:16:17 PM3/25/14
to gama-p...@googlegroups.com

Hi!

Thanks, that explains things. (Maybe your explanation could be another paragraph in the language reference?!)
Could you explain the order of init executions for sub-classed species?

I have to think through my modelling/coding approach, maybe I can avoid 'do _init_'.

Cheers, Achim

Achim Gädke

unread,
Mar 25, 2014, 6:23:55 AM3/25/14
to gama-p...@googlegroups.com

Hi!

Thanks, that explains things. (Maybe another paragraph in the documentation?!)

I have to think through my modelling/coding approach, maybe I can avoid this rather 'internal' looking do _init_.

Cheers, Achim

You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/KkKKGpCrHuk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages