Why NetLogo runs differently with the same syntax and logic in two time periods

61 views
Skip to first unread message

Dengxiao Lang

unread,
Apr 27, 2020, 9:39:46 AM4/27/20
to netlogo-users
Hi, everyone! I am struggling with NetLogo procedures. The code is seemingly correct, but the model cannot run. I hope anyone can help me with this. 
I designed this model like: 

Period1: 0 < ticks < 200, the turtles go to some patches(patch 1, patch 2, patch 3,...) and stop according to the rules, each patch has the maximum storage of turtles, if the patch reaches its maximum storage, ask all the turtles on this patch die.

Period2: 200 <= ticks < 400, ask the newly create turtles go to the same patches in Period1, and each patch has the different maximum storage, if the patch reaches its maximum storage, ask all the turtles on this patch die.

The logic and syntax are the same in Period1 and Period2, the only difference is the parameters' value. However, Period1 works, Period2 doesn't work. I mean in the Period1 turtles can go to the patches and die correctly; turtles even cannot move and nothing happened in Period2 but the ticks still run and without any error reminder. Why did this happen? Could anyone give me some suggestions? 

Any comments and suggestions will be really appreciated.

Message has been deleted

Kit Martin

unread,
Apr 28, 2020, 1:55:34 PM4/28/20
to Dengxiao Lang, netlogo-users
Hi Dengxiao,
It would be really helpful to see the code to answer your question. It's likely some state variable preventing execution, but please post the code.

Best
Kit

--
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/1fb09abb-90b3-47fc-b80f-c4c85f979162%40googlegroups.com.

Pradeesh Kumar K V

unread,
Apr 28, 2020, 1:55:34 PM4/28/20
to netlogo-users
Hello Lang,

It is difficult to determine the exact reason without seeing the code.

However, one point i can think of is whether you reset the parameter used to evaluate actual storage on the patch after end of first period. If its not reset, then the code may be asking the turtles to die even as second period starts.

Pradeesh

George BUTLER

unread,
Apr 28, 2020, 1:55:34 PM4/28/20
to Dengxiao Lang, netlogo-users
Hello,

If you can provide us with the code, it would be easier to help you out. 

+++
George J. Henry BUTLER STREESE


Pradeesh Kumar K V

unread,
Apr 28, 2020, 1:55:34 PM4/28/20
to netlogo-users
Hello Dengxiao,

Thanks for the file. I tried running the model. However, there is no change on the display when I click on setup or go. Its showing blank ('Black' color). 

Also can you please specify the code which is of concern.  'die' is used at multiple locations so just wanted to know the specific code which needs to be reviewed.  

Regards,

Pradeesh

On Tue, Apr 28, 2020 at 3:13 PM Dengxiao Lang <dengxi...@outlook.com> wrote:
Complementary file to the below post.

I added parts of the code file in this question. Period1 and Period2 represent different time periods in the model. 

Hopefully, anyone can help me with this struggling problem.

Mang thanks in advance!

Best,
Dengxiao
--
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.

Aaron Andre Brandes

unread,
Apr 28, 2020, 1:55:34 PM4/28/20
to Dengxiao Lang, netlogo-users

Hi Dengxiao,

Thanks for writing.

From what I understand the difference between period 1 and period 2 is just the maximum number of turtles allowed.

Without your code it is difficult to tell what is going on. I have attached a model that attempts to capture what you are saying.

One thing I noticed was that the model runs so much faster when the max number of turtles is random. This is because the turtles are dying at a rapid rate.

Until I vastly increased the number of turtles, I couldn’t see them move in the second condition.

 

Here are a few notes on my program:

When a patch has its turtles die, it turns yellow.

 

I use the procedures expt1 and expt2 to set up the two different initial conditions

 

I used random-seed to insure that the same random choices were made in for periods 1 and 2

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-seed

 

I used wait so the result of the first period could be seen for a few seconds before switching conditions,

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#wait

And also during period 2 to slow down the turtles so they could be seen.

 

Another thing you could do is to create a plot of the number of turtles over time, then you could see the rate at which they change.

https://ccl.northwestern.edu/netlogo/docs/programming.html#plotting

 

I used show to print the number of yellow patches.

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#show

 

If this doesn’t help, perhaps you can share your model or code with netlogo-users in order to get more specific help.

 

Aaron

 

 

 

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

--

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.

two-periods.nlogo

Aaron Andre Brandes

unread,
Apr 28, 2020, 3:34:11 PM4/28/20
to Pradeesh Kumar K V, netlogo-users

Hi Dengxiao,

Your file code.nlogo does not show the initialization step in which you create the different breeds of turtles,  and set the patch files.

That is why Pradeesh found that nothing happened.

 

Also if the second period is starting with different initial conditions you should expect some differences in behavior or results.

In addition there is randomness in your model, because “ask n-of”  will make different choices during the first and second period, unless you use the NetLogo

random-seed primitive, as I suggested earlier.

Aaron

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

 

 

Message has been deleted

Dengxiao Lang

unread,
Apr 29, 2020, 5:51:31 AM4/29/20
to netlogo-users
Complementary file to the below post.

Hi everyone,
I apologize if these emails troubling you.

I added the working code to the question. Period1 means "if day > 0 and day < 30 and time > 1", Period2 means "if day > 30 and day < 60 and time > 1". I added another time period " if day = 30" between these two periods which use to reset the patches' variables.

Any comments and suggestions will be really appreciated!

Cheers,
Dengxiao

On Monday, April 27, 2020 at 3:39:46 PM UTC+2, Dengxiao Lang wrote:
code.rar

Aaron Andre Brandes

unread,
Apr 29, 2020, 8:52:46 AM4/29/20
to netlog...@googlegroups.com

 Hi All,

For anyone who had trouble with the .rar file Dengxiao sent previously (a Windows archive) I am posting the two files it contains, as well as the text from the original post

 

I am sorry I forget to add the “drawing patches” in the code. This version of the code can show the initialization step.

I guess I need to reinitialize the patches. In my case, I should reset the CurrentStorage of the patches. I run the model, the [CurrentStorage] of the patches are the maximum storage in the FirstProcedure, even I let all the turtles die on the patches. I also added a procedure between these two time periods which is 

`if day = 30 [ask patches with [color = 64.2] [set CurrentStorage 0]]” to reset the patch variable. However, it doesn’t work,  it showed the [CurrentStorage] of the patches still the maximum storage in FirstProcedue, not to zero. From day 31, I set the patches have the new maximum storage and the turtles move to the patches, however, nothing happened during this period (the tick counter runs but the turtles don't move to the patches) and the [CurrentStorage] of each patch is still the maximum storage in FirstProcedure. 

 

I guess if I reset the [CurrentStorage] of the patches correctly, the model will work as what I expected. The way I reset the patches’ variable seems doesn’t work. Do you have any ideas?

 

 

Cheers,

Dengxiao

 

发送自 Windows 10 邮件应用

code.nlogo
patches.png

Aaron Andre Brandes

unread,
Apr 29, 2020, 9:31:10 AM4/29/20
to netlog...@googlegroups.com, 郎 登潇

Hi Dengxiao,

I really like the graphics of your model.

 

When I ran it there was action happening after day 30.

The model runs slowly. If you move the ticks slider all the way to the right it will run faster.

If you want to compare the first and second period and have it run faster you might want to do something to reduce the number of agents produced.

 

It’s possible your model would run better with more memory

http://ccl.northwestern.edu/netlogo/docs/faq.html#how-big-can-my-model-be-how-many-turtles-patches-procedures-buttons-and-so-on-can-my-model-contain

 

Closing other applications might also be helpful.

 

Also, just in case you are running with an unplugged laptop:

http://ccl.northwestern.edu/netlogo/docs/faq.html#why-is-netlogo-so-much-slower-when-i-unplug-my-windows-laptop

 

You can gather information by using any or all of the following lines in the command center. (Or you could put them all into a procedure and call that.)

 

print max [ CurrentStorage ] of patches

print SecondStorage

print count RiverVolumes

print count WaterVolumes

print count Crops

 

plotting some of these variables might also be useful

 

 

RiverVolumes were up to 241810 by day 40.

 

The model is barely moving on day 42 at time 2

RiverVolumes  290810

 

On the other hand Crops are at 9816 and have barely changed.

 

I suggest you experiment more with the model using plots and print  statements to learn whether it is doing what you want/expect.

 

Aaron

--

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.

Pradeesh Kumar K V

unread,
Apr 29, 2020, 9:45:35 AM4/29/20
to netlogo-users
Hello  Dengxiao,

I ran the updated model. It was working fine for both the periods; i.e. before day 30 and after day 30. The turtles were able to move after day 30 in the same fashion as it moved before day 30.

So I guess your problem is solved.

Best,

Pradeesh


--
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.
Reply all
Reply to author
Forward
0 new messages