How to import different worlds in a model?

54 views
Skip to first unread message

Mustafa Ali Saba

unread,
Sep 19, 2019, 2:05:20 AM9/19/19
to netlogo-users
Dear friends from the comunity,

My goal is to develop a multi-agent model in which to include different environtments
in order to my agents can interact in those.

What I wanna do is a core model (core.nlogo), and later on I would like to have every
world in different files, e.g., world1.nlogo, world2.nlogo, and so on.

My problem is that I dont really know what kinds of files must be. Or if I have to include
all my different worlds in the core model.

What is the best thing to do?

Suggestions please.

Warm regards,


--------------------------
Mustafa Ali Saba

Dale Frakes

unread,
Sep 19, 2019, 3:30:56 AM9/19/19
to netlog...@googlegroups.com
Mustafa,

it's not clear exactly what you want to do, but here's what I'm thinking...

the "environment" in NetLogo is generally made up of the patches (and their variables) and possibly some global variables.  My first thought is to just have a selector on the interface for which environment to use, and then within "setup", have code that creates each environment appropriately.  I've attached a super-simple model file that does this... it sets the color of the patches based on the selector.



to setup
 
  clear-all
 
  if world-type = "World 1" [
    ;; setup for World 1
    ask patches [set pcolor blue]
  ]
 
  if world-type = "World 2" [
    ;; setup for World 2
    ask patches [set pcolor green]
  ]
 
  if world-type = "World 3" [
    ;; setup for World 3
    ask patches [set pcolor red]
  ]

 
 
  ;; do the rest of the stuff you need to set up your agents
 
 
  reset-ticks
 
end


Another approach would be to come up with some way to create your environments then write the information to a csv file for each one (each row would represent a patch, with the columns being all the relevant patch variables).  Then in "setup", load the appropriate csv and set the patch variables.  The downside to this (as I see it) is that you still have to create some other model that generates your csv files... you might as well include the code in one big model.


I hope this helps!

Dale
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/1cbaec43-36c6-4685-b9af-fd9127ce60e3%40googlegroups.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Candidate
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/
different_worlds.nlogo

Mustafa Ali Saba

unread,
Sep 19, 2019, 4:00:06 AM9/19/19
to netlogo-users
Dale Frakes,

The template you send to me is very useful. I am beginning to learn multi-agent
simulation programming with netlogo. Particularly I am interested on pedestrian flow.

I was thinking about if NetLogo is as Python or any other language in the sense that
you can import other scripts, or include a model as a library. Anyway this template is
enough for me.

Thank you so much.

-------------------------
Mustafa Ali Saba
To unsubscribe from this group and stop receiving emails from it, send an email to netlog...@googlegroups.com.

Dale Frakes

unread,
Sep 19, 2019, 4:07:54 AM9/19/19
to netlog...@googlegroups.com
Hi Mustafa,

NetLogo does have the concept of importing/including code from other files.  The code to be imported should be in an ".nls" file.

http://ccl.northwestern.edu/netlogo/docs/dict/includes.html

Cheers!

Dale
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/2d9c16f2-5adf-48eb-8838-d2261871018a%40googlegroups.com.

Vanessa Roeben

unread,
Sep 20, 2019, 11:15:12 AM9/20/19
to Mustafa Ali Saba, netlogo-users
Hi Mustafa, 

You can indeed load .txt or .csv files into your NetLogo Model. 

An example code would look something like this:

to setup environment

file-open "filename01.txt"
set environmental-parameter-X file-read
file-close

end

It gets more complicated when you have parameters that change over time, for example with ticks. This highly depends on what your world looks like. Maybe the simple code helps already, if not, let me know.

Hope this helps, cheers, Vanessa

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.

Mustafa Ali Saba

unread,
Sep 24, 2019, 11:17:00 AM9/24/19
to netlogo-users
Hi Vanessa,

What is more appropriate to do,

to load my world drawing's in a file, or to implement directly on the model?

I have about 6 different world drawings.

Thank you,

----------------------
Ali
To unsubscribe from this group and stop receiving emails from it, send an email to netlog...@googlegroups.com.

Vanessa Roeben

unread,
Sep 30, 2019, 7:03:12 AM9/30/19
to Mustafa Ali Saba, netlogo-users
Hi Mustafa,

If you have six different world drawings, I personally would rather load them as a file. This is what this primitive is made for and it saves you many lines of code. You can also check out the model "File Input Example" in the Models Library under 'Code Examples',

Best regards, 
Vanessa

To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/2a56ab98-6c8d-4931-9d1b-8b6647294daf%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages