Lab 10: Color Sort Turtles not yet sorted by color

Similar documents
CS108L Computer Science for All Module 7: Algorithms

Lab 5: Bumper Turtles

Lab 7: Experimenting with Life and Death

Lab 6: Energizer Turtles

Half-Lives of Antibiotics

GEOG 490/590 SPATIAL MODELING SPRING 2015 ASSIGNMENT 3: PATTERN-ORIENTED MODELING WITH AGENTS

5 State of the Turtles

COYOTES and FOXES. Final Report. - Chantilly Fulgham, - Gracie Sanchez,

Sketch Out the Design

Scratch Lesson Plan. Part One: Structure. Part Two: Movement

Getting Started with Java Using Alice. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Workbook. Version 3. Created by G. Mullin and D. Carty

1 Turtle Graphics Concepts

Candidate Number. Other Names

For ADAA users, you will see a page similar to the one shown below:

HerdMASTER 4 Tip Sheet CREATING ANIMALS AND SIRES

Reference Guide Playful Invention Company

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

Introduction to Python Dictionaries

~~~***~~~ A Book For Young Programmers On Scratch. ~~~***~~~

Overview of Online Record Keeping

Good Health Records Setup Guide for DHI Plus Health Event Users

Code Documentation MFA (Movable Finite Automata) Eric Klemchak CS391/CS392

Biology Meets Math. Predator-Prey Relationships in Belowground Ecosystems. US Department of Homeland Security

StarLogo Complete Command List (Edited and reformatted by Nicholas Gessler, 6 June 2001.)

KB Record Errors Report

6.14(a) - How to Run CAT Reports Record Errors Report

Package TurtleGraphics

PNCC Dogs Online. Customer Transactions Manual

User Manual. Senior Project Mission Control. Product Owner Charisse Shandro Mission Meow Cat Rescue and Adoptions, Inc.

Finch Robot: snap level 4

In this project you will use loops to create a racing turtle game and draw a race track.

Lecture 1: Turtle Graphics. the turtle and the crane and the swallow observe the time of their coming; Jeremiah 8:7

Use of Agent Based Modeling in an Ecological Conservation Context

Writing Simple Procedures Drawing a Pentagon Copying a Procedure Commanding PenUp and PenDown Drawing a Broken Line...

INFO 1103 Homework Project 2

Turtle Ballet: Simulating Parallel Turtles in a Nonparallel LOGO Version. Erich Neuwirth

Building Concepts: Mean as Fair Share

D irections. The Sea Turtle s Built-In Compass. by Sudipta Bardhan

Fractal. Fractals. L- Systems 1/17/12

SEDAR31-DW30: Shrimp Fishery Bycatch Estimates for Gulf of Mexico Red Snapper, Brian Linton SEDAR-PW6-RD17. 1 May 2014

Recursion with Turtles

Activity 1: Changes in beak size populations in low precipitation

Part III: Estimating Size

Getting Started! Searching for dog of a specific breed:

COMP Intro to Logic for Computer Scientists. Lecture 9

website 2.0! letting a CMS do the annoying work for you. <librarian.net/talks/nelacms>

Cat Swarm Optimization

PNCC Dogs Online. Customer Transactions Manual

Title: Sea Turtle Tracking

Position Statements. AAALAC Position Statements & FAQs. Laboratory Animals - Definition 2013 CLASS 1. The Attending Veterinarian & Veterinary Care

Dog Years Dilemma. Using as much math language and good reasoning as you can, figure out how many human years old Trina's puppy is?

USING FARMAX LITE. Upper navigation pane showing objects. Lower navigation pane showing tasks to be performed on objects

SMARTKITTY SELFCLEANING LITTER BOX

Level 2 Mathematics and Statistics, 2017

Dasher Web Service USER/DEVELOPER DOCUMENTATION June 2010 Version 1.1

Scratch Jigsaw Method Feelings and Variables

Naked Bunny Evolution

Sea Turtle Conservation: Public Service Announcement

KS1 Baby Animals. Marwell Wildlife Colden Common Winchester Hampshire SO21 1JH

Geometry from Scratch

Lab 7. Evolution Lab. Name: General Introduction:

Animal Welfare Update This document provides an overview of Costco s global status on animal welfare.

Chinese New Year ACTIVITY 1: Animals (all levels) - WORKSHEET 1

Naughty But Nice. minute. 3gamechangers

Biology 164 Laboratory

AP Lab Three: Comparing DNA Sequences to Understand Evolutionary Relationships with BLAST

The purchaser may copy the software for backup purposes. Unauthorized distribution of the software will not be supported.

Bluefang. All-In-One Smart Phone Controlled Super Collar. Instruction Manual. US and International Patents Pending

Check the box after reviewing with your staff. DNA Collection Kit (Cheek Swab) Mailing a DNA Cheek Swab to BioPet. Waste Sample Collection

Webkinz Friend Requests

World Animal awareness Society Wa2s.org

What s a CMS? how to let a CMS do the annoying work for you. AKLA March 5, Jessamyn West <librarian.net/talks/akla>

Activity 21. Teachers notes. Learning objective. Resources. Cross-curricular links. Activity. Extension

Biol 160: Lab 7. Modeling Evolution

Nathan A. Thompson, Ph.D. Adjunct Faculty, University of Cincinnati Vice President, Assessment Systems Corporation

The City School. Learn Create Program

Scratch. To do this, you re going to need to have Scratch!

Subdomain Entry Vocabulary Modules Evaluation

Step by step lead work training

LN #13 (1 Hr) Decomposition, Pattern Recognition & Abstraction CTPS Department of CSE

What our business is about How we will run it Prices and what we will sell Hours and time costumers can contact us Rules for the business How we will

Blood Type Pedigree Mystery lab

Eggstravaganza School Pack

NBN 3MIN GAME CHANGERS

Part One: Introduction to Pedigree teaches students how to use Pedigree tools to create and analyze pedigrees.

Manual Compustam-Cloud

S Fault Indicators. S.T.A.R. Type CR Faulted Circuit Indicator Installation Instructions. Contents PRODUCT INFORMATION

VBS 2015 Adult VBS Extras Conference

Welcome! Your interest in the veterinary technology program at ACC is greatly appreciated. AS a recently AVMA accredited program there are many

Grade 5, Prompt for Opinion Writing Common Core Standard W.CCR.1

Dealing with dairy cow lameness applying knowledge on farm

Texel Sheep Society. Basco Interface Guide. Contents

Hello Scratch! by Gabriel Ford, Sadie Ford, and Melissa Ford. Sample Chapter 3. Copyright 2018 Manning Publications

Oh Say Can You Say Di-no-saur?: All About Dinosaurs (Cat In The Hat's Learning Library) PDF

Number: WG Welsh Government. Consultation Document. Breeding of Dogs. The Animal Welfare (Breeding of Dogs) (Wales) Regulations 2012

Mexican Gray Wolf Endangered Population Modeling in the Blue Range Wolf Recovery Area

Virtual Dog Program in Scratch. By Phil code-it.co.uk

Coding with Scratch - First Steps

Creating an EHR-based Antimicrobial Stewardship Program Session #257, March 8, 2018 David Ratto M.D., Chief Medical Information Officer, Methodist

Transcription:

Lab 10: Color Sort 4000 Turtles not yet sorted by color Model Overview: Color Sort must be a Netlogo model that creates 4000 turtles: each in a uniformly distributed, random location, with one of 14 uniformly distributed random colors, and each with a uniformly distributed random heading on a 33x33 patch torus world. Your goal is to teach each turtle to group up with all other turtles of the same color using both an efficient and an inefficient method. -1 of 6-

Setup: The step is quite simple: all it does is clear the world (delete all turtles, clear all patches and reset ticks) create 4000 turtles, and set those turtles to random locations. By default, Netlogo creates each turtle with a uniformly distributed random heading and with one of 14 uniformly distributed random colors in random: thus, no extra programming. If you do not remember how to set turtles in random locations then review your Energizer Turtles Lab. Inefficient Method: The inefficient method is successful in getting all the turtles sorted by color. However, it does so rather slowly. The required algorithm for the inefficient method is: a) Each turtle examines the other 3999 turtles to see which have a color the same as its own and puts all of these in a NetLogo agentset (a set of agents). b) The turtle then randomly chooses one of the other turtles of the same color (in the created agentset). c) The turtle turns to face the turtle chosen in step (b). d) The turtle takes one patch size step forward. Hint: How to do Inefficient Method Steps a and b: The simplest way to do steps a and b of the inefficient method is to chain a few of Netlogo s reporters together: In NetLogo, commands and reporters tell agents what to do. A command is an action for an agent to carry out, resulting in some effect. A reporter is instructions for computing a value, which the agent then "reports" to whoever asked it. one-of agentset other agentset Given an agentset as input, one-of reports a random agent from that set. If the agentset is empty, the one-of reports nobody. Netlogo s other reporter is used to report a new agentset that is the same as the agentset it is given except with this turtle (the turtle in the current iteration of ask turtles) removed. The other reporter is used in this model because we want each turtle to move toward a turtle of the same color, BUT NOT to pick itself as the turtle to move toward. -2 of 6-

turtles agentset with [reporter] Reports the agentset consisting of all turtles. The with reporter takes two inputs: on the left, an agentset (usually "turtles" or "patches"). On the right, the reporter must be a boolean reporter. Given these inputs, with reports a new agentset containing only those agents that reported true -- in other words, the agents satisfying the given condition. Putting this all together, we can build the powerful Netlogo statement: let mytarget one-of other turtles with [color = mycolor] The statement above reads from turtles in the middle to outer edges as: turtles: Of the set of all turtles, turtles with [color = mycolor]: Create an agentset of all turtles with color equal to mycolor. Note that color is the color of each turtle in the agentset and mycolor is a local variable that needs to be defined as the color of this turtle. other: Remove this turtle (the turtle that is performing the action) from the agentset reported by with [color = mycolor]. one-of: Report a random agent form the agentset reported by other. let mytarget: assign the agent returned by one-of: to the local variable mytarget. If you do not understand the words above, then read them again...and again. Then try them out. Do some experiments with this stuff. Just as the only way to learn to skateboard is to practice skateboarding, the only way to learn to program is to practice programming. If you say to your teacher I do not understand, show me what to do, then, you will learn as much about programming as someone learns about skateboarding by watching others skate. Watching is an important part of learning, but it can only go so far. Ultimately, you need to try it before you fully know how and fall, get up and try again. Below are some practice grinds, kickflips and ollies: -3 of 6-

First, 4000 turtles are too many to play with when testing. Add an ollie button that clears everything and creates just 5 turtles that move a fixed distance from their starting location along their starting heading. Next, build an agentset of some of those turtles with a particular property. Finally, change some property of every agent in the agentset you build. Below is one example of this. You should try this out, then make a bunch of your own. to Ollie clear-all reset-ticks create-turtles 5 [ pen-down forward 10 ] let Lauren turtles with [pxcor > 0] ask Lauren [ set size 5 ] end Note: the ollie button is not one of the graded requirements. It is a requirement only in that before understanding how to work with agentsets in simple examples and before gaining some practice in manipulating them, you have no hope of coming up with the code that is a graded requirement. Optimize & Efficient Method: These two procedures basically split up the tasks done in the inefficient method. To understand why this can get the program to run much faster requires some observations of the system: 1) Each turtle is given a color in setup and that color is not changed as the model runs. 2) Each turtle must take many steps before it all the turtles are sorted by color. 3) In the inefficient method, every tick, every turtle builds an agentset of all turtles that share its color, then picks a random element of that agentset to turn towards. -4 of 6-

The key to efficiency is recognizing that while the random pick changes every tick and thus must be done every tick, each turtle s agentset of all turtles that share its color NEVER CHANGES! Therefore, each turtle s agentset of like colored turtles need only be built once. This can be done as follows: 1) Declare a new agent variable (in my implementation, I called it agents_with_mycolor ) to store each turtle s agentset of like colored turtles. 2) Build the agentset in the Optimize procedure. 3) In Efficient_Method, pick a random member from the agentset. When you get this to work, you will see that it saves lots of time. For one turtle to create its agentset of like colored turtles, that turtle must examine the color of all other turtles. Thus, the more turtles there are, the longer it takes for ONE turtle to build its agentset. Let n be the number of turtles (in this lab, n = 4000). Since EVERY turtle must build its own agentset, the total time to build an agentset is proportional to the time it takes one turtle to build its agentset, O(n) times the number of turtles that build lists, also O(n). The whole process then takes O(n 2 ) computational time! In the inefficient method, this is done every tick. Set verses List: In Netlogo, there are things called sets and different things called lists. An agentset is a set that contains only agents. In casual English, the words set and list are often used interchangeably. In computer science, however, these words have well defined and different meanings. A set is an unordered collection where any repeated elements make no difference to the set. For example, the sets: {1, 2, 3, 4} and {4, 2, 1, 3} are equivalent. Also, if 2 is added to the set {1, 2, 3, 4}, then the resulting set is still {1, 2, 3, 4} since 2 was already an element of the set. With a set, it makes no sense to ask what is the first element since none of the elements have any particular order. Try this in Netlogo: create a list, add to it a repeated element, then show the list. A list is an ordered collection where repeated elements DO make a difference. Thus, the lists, [1, 2, 3, 4] and [4, 2, 1, 3], are different. If 2 is added to the list, [1, 2, 3, 4], it is important to ask where the 2 is added because the lists [2, 1, 2, 3, 4], [1, 2, 2, 3, 4], [1, 2, 3, 4, 2],... are each different from one another. -5 of 6-

Grading Rubric [20 points total]: [A: 1 point]: Submit Netlogo source code named: W10.firstname.lastname.nlogo. [B: 1 point]: The first few lines of your code tab are comments including your name, the date, your school, and the assignment name. [C: 1 point]: The code in the code tab of your program is appropriately documented with inline comments. [D: 3 points]: Your program s Setup button works as specified. [E: 4 points]: Your program s Inefficient_method button works as specified. [F: 3 points]: Your program s Optimize button works as specified. [G: 4 points]: Your program s Efficient_method button works as specified. [H: 3 points]: Change your program s world settings by turning off the two world wraps checkboxes. Try to guess how you think this will affect the way the model runs? Run the model and see what happens. In your program s Info tab, explain why the results are so different with world wrapping turned off. -6 of 6-