CS 1025 Computational Modeling and Simulation - Fall 2011 - NCAA week.

This page was automatically generated by NetLogo 4.1.1.

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.


 

powered by NetLogo

view/download model file: MonteCarloNCAA.nlogo DOWNLOAD and try it out yourself.

WHAT IS IT?

Monte Carlo - throwing darts randomly inside a known area and counting how many land in different regions to estimate the area of those regions. Calculate the proportion landing in a certain area. That proportion times the total area where "darts" or turtles were randomly thrown gives you the Monte Carlo estimate of the area of the given region.


HOW IT WORKS

The entire NetLogo grid of patches is a torus and is 33 by 65. Width is 33 units and height is 65 units. Note: Location of the origin (0, 0) is the bottom left corner of the rectangle and not the center square or patch.


HOW TO USE IT

You must use the command buttons in sequence from top button to bottom button. You can turn off the Rotating Airplanes switch. That is just added for fun, but will slow things down if you run the simulation with 1000 turtles.


THINGS TO NOTICE

You should get more precise estimates of the area with larger numberOfTurtles. Try 5 or more runs at 100 turtles, then try 5 or more runs at 1,000 turtles. Note the difference in the variation of the estimates. Which set of area estimates are more spread out? n = 100 or n = 1000 turtles?


THINGS TO TRY

Estimate the area of the circle. Estimate the area of the "airplanes" portion of the circle. Estimate the area of the "flowers" portion of the circle. Estimate the area of the region outside of the circle, which is the "stars" region.

What is the actual area of the circle? Hint: Look at the NetLogo code to figure out the radius. Also, counting the squares distance from the radius of circle will work too. I intentionally left the PD Pen Down when the turtle walked out from the center to prepare to draw the circle so you could see a radius radiating out from the center to the very top of the circle.


EXTENDING THE MODEL

Try changing the BREEDS or the SHAPES. Try making the STARS above the line but outside the circle all be a different COLOR than the STARS outside the circle that are below the line.


NETLOGO FEATURES

Look up the turtles command HATCH and see what that does. How is it used in the model?

Look up the turtle command DIE. Why is DIE important? Comment out the word DIE by placing ;; in front of one or all of the lines with the DIE command. What happened as a result?


RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.


PROCEDURES

globals [ theX theY ]

breed [ stars star ]
breed [ airplanes airplane ]
breed [ flowers flower ]

TO draw1.8X_plus_1
    ca
    checkerBoard

    crt 1
    
    set theX -0.5
    
    set theY 1.8 * theX + 3

    ask turtles
    [    
        setxy theX theY
        set pen-size 3
        pd
    
        repeat 330
        [
           set theX theX + 0.1
        
           set theY 1.8 * theX + 3
        
           setxy theX theY
        ]
        
        die        
    ]    
END

TO checkerBoard
   ask patches
   [
       ifelse (remainder (pxcor + pycor) 2 = 0)
       [
           set pcolor white
       ]
       [
           set pcolor yellow
       ]
   ]
END

TO circle
   crt 1
   
   ask turtles
   [
       set color black
       
       
       setxy 16 25
       set heading 0
       pd
       
       fd 16
       rt 90
       set pen-size 2
       
       repeat 720 [ fd 0.14 rt 0.5 ]
       pu
       die
   ]  
END

TO createRandomTurtles
   cro numberOfTurtles
   
   ask turtles 
   [
       setxy random-xcor random-ycor
       
   ]
   
   wait 2
   
   ask turtles 
   [
       ifelse distancexy 16 25 < 16
       [
          set theY 1.8 * xcor + 3
          ifelse ycor < theY
          [
             hatch-flowers 1 [ set shape "flower" set size 1.5 set color red ]
          ]
          [
             hatch-airplanes 1 [ set shape "airplane" set color black set size 1.5 set heading 0]
          ]          
          die
       ]
       [
          hatch-stars 1 [ set shape "star" set color blue set size 1.2]
          die
       ]
   ]
   
   if rotatingAirplanes 
   [
      ask-concurrent airplanes
      [
         repeat 360 [ set heading heading + 2 wait 0.01  ]
         repeat 180 [ set heading heading - 2 wait 0.01  ]
         repeat 180 [ set heading heading + 2 wait 0.005  ]
         repeat 180 [ set heading heading - 2 wait 0.0025  ]
      ]  
   ]       
END