Courses/CS 461/Winter 2006/Martin Olsen/Week 1

From CSWiki

Jump to: navigation, search

Homework Week 1: NetLogo

Contents

[edit] Installation

I downloaded the pure Java version. No installer etc, so I can run it from my USB stick. java -jar NetLogo.jar

[edit] Tutorials

Before starting the tutorial itself I took a look at the party model, as suggested in the page. This clearly set the mood. Next time I go to a party, I will bring NetLogo with me. The actual tutorial starts here.

[edit] Tutorial 1

Going through this tutorial I learn the following:

  • Buttons are blue; they set up, start, and stop the model.
  • Sliders and switches are green; they alter model settings.
  • Monitors and plots are beige; they display data.
  • When you open the model everything is black. By pressing setup we initialize the model and we should see something. By pressing go we run the model.

The wolf sheep predation model:
This is a model that has wolf and sheep in it. Starts with 100 sheep and 50 wolves. If we let the model run for about 100 ticks we see that the wolves start eating sheep, and theres a decrease in sheep. We are able to change the outcome by changing the settings. For example we can set the grass regrowth time.

[edit] Tutorial 2

In this tutorial we get introduced to the command center, and we play around with some commands to change the colors etc of the model.

[edit] Tutotiral 3

This tutorial goes more in depth with the coding, and I got to make a model where turtles climb hills. Some useful links:

[edit] Deep Water Sea

I am now ready to make my own models. My first model is called "Deep Water Sea" and is inspired by the "Hill Climbing Turtles". This time. Instead of climbing hills, the turtles will swim to the bottom of the sea.

[edit] Code

patches-own [elevation] 

globals [highest ;; the highest patch elevation 
         lowest ;; the lowest patch elevation 
         turtles-moved? ]
         
to setup
  ca
  setup-patches
  setup-turtles
end

to setup-patches
  ask patches
    [ set elevation (random 10000) ]
  ;diffuse elevation 1
  ;repeat 20 [ diffuse elevation 1 ]
  repeat smoothness [ diffuse elevation 1 ]
  ask patches
    [ set pcolor scale-color blue elevation 1000 9000 ]
  set highest max values-from patches [elevation] 
  set lowest min values-from patches [elevation] 
  ask patches [
    if (elevation > (highest - 100)) 
      [set pcolor white] 
    if (elevation < (lowest + 100)) 
      [set pcolor black] ]
end

to setup-turtles
  crt number
  ask turtles [
    fd (random screen-edge-x)
    if (shade-of? green color)
      [ set color red ]  
  ]
end

to go
  set turtles-moved? false
  move-to-local-max
  do-plots
  if (not turtles-moved?)
    [ stop ]
end

to recolor-patches 
  ask patches 
  [
    set elevation pycor
    set pcolor scale-color green elevation
                 (0 - screen-edge-y) screen-edge-y
  ]
end

to move-turtles
  ask turtles [
    set heading (random 360)
    ;rt (random 360)
    fd 1
  ]
end

;; each turtle goes to the highest elevation in a radius of one
to move-to-local-max
  ask turtles [
    set heading downhill elevation
    if ( elevation-of patch-ahead 1 < elevation ) [
      fd 1
      set turtles-moved? true
    ]
  ]
end

to do-plots 
   set-current-plot "Turtles in Deep"
   plot count turtles with 
     [ elevation <= (lowest + 100) ] 
end


[edit] Screenshot

Image:Deepsea.jpg

Personal tools