WHAT IS IT?
-----------

A thermostat is a device that responds to the temperature of
a room in order to maintain the temperature at some desired
level. Generally speaking, heating systems have only two
settings - on and off - and it is the job of the thermostat
to turn the heater on and off at the appropriate times.
A simple thermostat does this by switching the heater
on when the temperature of the room has fallen below the set
desired temperature, and switching the heater off once the
desired temperature has been reached or exceeded. This is
often used as an example of feedback control, where a system
adjusts its behavior in response the effects of its prior
behavior. 

In this model, heat is represented by the red turtles,
and the room whose temperature is being regulated is
demarcated by the yellow border. The yellow border is 
semi-permeable, allowing some of the heat that hits it to 
escape from the room. This heat disappears from the model
once it reaches the grey border around the edge of the
screen. A thermometer, indicated by the green square, 
measures the approximate temperature of the room
(effectively, the density of red turtles). The heater is 
located in the center of the room, represented by a white 
patch. 

It should be noted that use of turtles in this model to 
represent heat is not intended to be physically realistic.
Instead, it is an example where a model is simplified in
such a way so as to make another feature of the model more
salient. In this case, it is the regulating function of the
thermostat that we are primarily concerned with.


HOW TO USE IT
-------------

GO: Starts and stops the simulation.
SETUP: Resets the simulation, and sets the initial
temperature according to init-temp.
TEMPERATURE: Monitors the temperature in the room, as
detected by the green box near the top. 
GOAL-TEMP: The thermostat aims to maintain the room at
this temperature. It may be adjusted in the middle of a
simulation.
HEATER-STRENGTH: The number of red turtles created by the
heater in a tick (if the heater is 'on').
INSULATION: The efficiency of the room's insulation, or
the rate at which heat escapes from the room. Higher numbers
allow less heat to escape, lower number numbers allow more.
This may be adjusted during a simulation.
INIT-TEMP: The initial temperature of the room. This takes
effect only when the SETUP button is pressed. 

There is also a plot window, which tracks the temperature
over time (in red) and the desired temperature (in green).

THINGS TO NOTICE
----------------

With some settings, the room cannot be heated to the desired
temperature (for example, the room attains a maximum
temperature that is lower than the desired temperature).
Under what circumstances does this happen?

Look at the graph: does the thermostat do a good job of 
keeping the temperature at the desired level? If we hold the
variables constant, to what factors can we attribute 
fluctuations of the temperature (in red) over the desired 
temperature (in green)?

Try adjusting the insulation of the room and the strength of
the heater. Do these factors affect the efficiency of the
thermostat (i.e. cause the temperature to stay closer or
further from the desired temperature)?

Notice that there is a delay from the time the heater is 
turned on to the time when this added heat reached the 
thermometer. What are the consequences of this delay?

EXTENDING THE MODEL
-------------------

The thermostat in this model uses a very simple rule to
control the heater based on the temperature. It might be
possible to improve the performance of this system by making
it 'smarter'. One suggestion is to write a control program
that turns the heater or and off before the temperature hits
the desired temperature - this would compensate for the
delay mentioned above. Try rewriting the function
THERMO-CONTROL. Keep in mind that the only inputs your
control function should have are GOAL-TEMP and
TEMPERATURE, and the only action should be to either call 
RUN-HEATER or not. Notice this leaves open the possibility of
creating variables to store past information.

Much of observed instability in the temperature might simply
be attributed to the thermometer that we are using. The
current thermometer takes an average of the number of
turtles occupying the green patches over the past ten ticks.
Why do you suppose we are measuring the temperature in such
a way, instead of simply counting the number of turtles
inside the room? Can you design a better thermometer? 

This model doesn't account for changes in room temperature
due to effects of the temperature outside of the room
(outside the yellow box). Alter the model so that this now
becomes a factor.

The heater in this model puts out heat at a fixed rate,
regardless of how long it has been on. Real heaters
generally have a warm up period during which time they slowly
increase their output, until they reach their maximum rate.
Try adjusting the heater in this model to act more like a
real heater. How does this affect the behavior or efficiency
of the thermostat? How might we alter THERMO-CONTROL to
account for this?

Begin a simulation with INITIAL-TEMP set to zero, and notice
how long it takes to heat up the room. This means that if we
wanted to warm the room up at a certain time it might make
sense to turn the heater on beforehand. Introduce time into
this model, and try adjusting the thermostat so that it
heats the room according to some schedule.