CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

18
CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo

Transcript of CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

Page 1: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

CISC 1600 – Lecture 3.2

SimulationsComplex Input & Output

NetLogo

Page 2: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

Content1. Agent Based Programming and Simulations

1. Cost Savings2. Danger Prevention

2. Digital and Analog, Input and Output3. NetLogo KeyConcepts

1. Agents2. Procedures and Primitives (functions)3. Variables4. ask and show5. Sensors and Effectors6. General Program Outline

4. Modeling a problem

Page 3: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

Agent Based Programming and Simulations

• We discussed the two main reasons for agent-based programming in our last lecture:1. Managing Complexity2. Emergent Behavior (phenomena)

• Another SIGNIFIGANT reason for using agent based programming is that it allows us to run "virtual simulations" of real world scenarios.

• Why would we do this?

Page 4: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(1.1) Simulations – Cost Savings• Biosphere2 (Biosphere 1 is

Earth) was built to help explore the use of an enclosed biosphere as part of future space colonization.

• It cost $200 million to build and operate (1985-2007).

• During the 1st Biosphere experiment oxygen levels fell below safe levels.

• The reason for the oxygen drop was that the exposed concrete of the structure was absorbing gases (CO2).

Biosphere 2: Planners failed to model in all the possible variables when designing the enclosed ecosystem.

Page 5: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(1.2) Simulations – Danger Prevention

• On 21 May 1946, Louis Slotin, a researcher at Los Alamos, accidentally irradiated himself when an experiment with a sphere of plutonium took a wrong turn.

• Immediately realizing what had happened Slotin quickly disassembled the device, likely saving the lives of seven fellow scientists nearby.

• Slotin himself succumbed to radiation poisoning nine days later.

Many of the first computers and computer programs created/written were used to help calculate radiation yields for nuclear devices.

Page 6: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(2) Digital and Analog Signals• Most of our work in

multimedia programming, up to this point, has used text files and text instructions as input.

• Input can also come in the form or analog and digital signal waves.

• Those input waves, in turn, can represent any real world phenomena that you can imagine.

Page 7: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.1) Netlogo - Key Concepts Agents

• Netlogo creates programs by specifying behaviors for sets of agents and then allowing those agents to interact in a controlled "chain reaction".

• Netlogo has 4 types of agents:1. Patches -> The squares on the world grid.2. Turtles -> Agents that can move.3. Links -> Lines between agents.4. The Observer -> The master controller.

Page 8: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.2) Netlogo - Key Concepts Procedures and Primitives

• Procedures are functions that you create and name yourself.

• Primitives are functions that are part of the semantics of the Netlogo language.

• Note: The syntax of the Netlogo language is different than the syntax of other text based languages we have examined.

Page 9: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.3) Netlogo - Key Concepts Variables

• Variables can be created in several ways, and can either be:– global -> anyone can see and use. – agent-based -> limited to use by a set of agents.– Local -> only available within a procedure.

Page 10: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.3) Global Variables – Interface

Page 11: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.4) Netlogo - Key Concepts ask and show

• Instructions can be given to agents and the values for variables can be set using the ask command.

• The show command in turn can be used to display the values of variables.

• In Netlogo groups of related commands are placed within square ('[' ']' ) brackets.

Page 12: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.5) Netlogo - Key Concepts sensors and effectors

• Agents in Netlogo can use special primitives (built in functions) to "see" their environment.– turtles-here– patches-here – turtles-at– patches-at– self

• Agents can also use special primitives (built in functions) to "effect" their environment.– setxy– set color– set pcolor– hatch– die

Page 13: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.5) sensors & effectors

Page 14: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(3.6) General Program Outline

Page 15: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

Bonus Question

• How is Netlogo implementing the following Imperative Paradigm requirements:– Sequence– Selection– Repetition

Page 16: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(4) Modeling a Problem

1. Get a very clear idea of the problem.2. What/who are the agents?

1. Which are turtles?2. Which are patches?

3. What variables will you need?4. How do the agents interact?5. What order will events need to happen in?

Page 17: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(5) Modeling in Netlogo1. Adjust world (screen) settings.2. Create setup and start buttons.3. Create interface controlled variables (sliders, etc..).4. Create breeds (if needed).5. Create global and local variables (if needed).6. Create and fill setup procedure with sub-setup

procedures.7. Create and fill sub-setup procedures.8. Create and fill go procedure with sub-go procedures.9. Create and fill sub-go procedures.10. Create plot and plot pens (in the interface).11. Create and fill do-plots procedure.

Page 18: CISC 1600 – Lecture 3.2 Simulations Complex Input & Output NetLogo.

(6) Getting Help

• Fantastic (short) NetLogo Quick Guide• Full Netlogo Manual• NetLogo Dictionary

• Example Nuclear Reaction Project