<< Click to Display Table of Contents >> 5. Compute Totals |
|
Show/Hide Hidden Text |
In the first run of the cow model, cows ate grass, but the grass height did not decrease as a result. Before our second run, we will compute the total grass consumption in each pasture by using collections of cow entities. We will then use that information in the pasture entity definition to reduce grass height.
This exercise (along with the previous and next) are featured in this video:
Stages of Ventity™ Modeling |
In this run, we will ... |
Stage 1 - Define entity types
|
Create a collection of cows partitioned by pasture, and calculate the total grass consumption in each pasture. Then we will reduce grass height in the pasture by a commensurate amount.
|
Stage 2 - Initialize the model
|
(no changes from previous run)
|
Stage 3 - Run the model Configure time settings and perform calculations
|
(no changes from previous run)
|
Stage 4 - Examine results See model behavior in graphs and tables
|
Graph the grass heights over time in each pasture, now including the effects of total grazing in each pasture. |
For this run we're going to make two changes to our entity types. First, we're going to set up a collection of cows so that we can compute the total grass consumption in each pasture. Then we're going to change our pasture entity so that grass loses height as it is eaten. We'll pick up where we left off in the previous run, either from your own version of the Cows, or by opening Exercise 4 Complete [here].
In Ventity™ collections, entities are grouped by their attribute values. In fact, a primary reason for assign attribute values at all is to facilitate grouping in the way you need for your calculations. In this example, to learn how much grass is being eaten in each pasture, we want to add up the consumption of all the cows in each pasture.
The first step is to create a collection of cows by pasture, which is done from the cow entity inspector.
1. Double click the "cow" entry on the entity types list of the model overview to open the "cow" inspector, or right-click on "cow" and select "Inspect".
2. Click on the "collections" tab.
3. Click the "new collection" button.
A list of cow attributes appears; we can partition the population of cows by these attributes.
4. Check the box to partition our population of cows by pasture, and click "OK".
The desired collection has been created, and this is evident in three ways: as an item on the collections tab for cows (1), as an inspector for the new collection of cows by pasture (2), and as a new diagram for the new collection (3).
The collections tab for cow entities now lists two collections. The first collection, cow[] with empty [] brackets, is the collection of all cow entities in the model. This collection was created automatically when the cow entity type was defined. We just created the second collection, cow[pasture], which is a partitioned collection: it includes all cows in the model, but they are grouped according to which pasture they are in. This is the one we will use.
Each collection in Ventity can have aggregate variables that pertain to the collection rather than to each individual entity. For example, in the cow[pasture] collection inspector (item 2 in the previous figure) you can see a variable called Count. This variable is automatically provided in every collection, and reports the number of entities in the collection in each time period. All other variables that are calculated from members of a collection (sums, averages, products, minimums, maximums, and standard deviations) are called Aggregate variables, and we will use one now to calculate the total grass consumption in each pasture.
5. Drag an Aggregate variable to the cow[pasture] diagram. The new aggregate will be called Aggregate1.
6. Edit the aggregate by right-clicking. Under "aggregation function", choose "sum." Under "target variable", choose "consumption rate."
Note that with these choices, Ventity automatically renames this aggregate variable to "Sum consumption rate" and populates other fields. Add a description as shown:
Although we're not ready to move on to the initialization stage (we still need to write equations that use the total grass consumption to reduce grass height), you can do a quick run at this point to check that Sum consumption rate is working as it should. We'll use the same input file ("many pastures") and time configuration as in the previous run, so just click the green button to run the model. Right-click on total consumption and choose Line Chart, and you will see one value for each pasture:
Note that even though there is no pasture entity called "thistle hill" in the model, a value of total consumption for thistle hill is computed. This is because the calculation is performed on cows, not pastures, and there are cows in the model that are assigned the value pasture = "thistle hill".
Let's now use this consumption to reduce grass height in each pasture.
7. Return to the pasture diagram, drag a cloud to the right of the Grass Height stock, draw an arrow from the stock to the cloud, and name it "grazing".
8. If it isn't visible already, open the cow[pasture] collection inspector by double-clicking or right-clicking on cow[pasture] in the model overview:
9. Drag "Sum consumption rate" from the collection inspector onto the "pasture" diagram.
You will see that it appears in a different color than other variables and is labeled as "cow_pasture Sum consumption rate". This indicates it is a reference to information calculated in the cow[pasture] collection. References are shown on diagrams as shadow variables (their causes are not shown). Ventity lists references in the reference grid at the top of each diagram. If the grids are not showing, click the grid toggle on the upper left:
Notice that the "Condition" for the reference is "[pasture]= ???". This indicates we need to give Ventity more information about which pasture to use when.
10. On the references tab in the entity type inspector for pasture, double-click cow[pasture]. Set "value to match" equal to pastureID:
This tells Ventity that each time a pasture entity needs information about its cows, it will look for the group associated with the pasture's own name.
We can now use this to calculate the reduction in grass height due to grazing.
Grass Height is in centimeters, but the total consumption of cows in each pasture is measured in pounds. We need to make a conversion.
11. Add auxiliaries for area (with value 40 acres) and density (with value 280 pounds per acre*cm), to our definition of a pasture. Draw arrows from each (including Sum consumption rate) to "grazing" (by floating the cursor near, but not over, each cause until the cursor becomes a hand, then dragging an arrow to "grazing").
15. Right-click "grazing" and enter the equation to calculate it, using the three causes (total consumption, area, and density).
We are now set up to compute the total consumption of the cows on each pasture, and to compute the effect of that on grass height. We are ready to initialize and run the model.
|
We will use the same cows and pastures from the previous run. If we open the "many pastures" built-in file (by double-clicking it under Input 1 in the Model Overview), we will see all our previously entered inputs for both cows and pastures. On the "pasture" tab we will also see new columns for area and density. Let's use the default values for all except Green Gables, which we will make a small pasture (10 acres) with sparse vegetation (density of 100 pounds for each cm of grass on each acre).
|
We will use the same time configuration as the previous run, so no changes are necessary.
16. Run the model.
|
Create a Line Chart by right-clicking Grass Height:
Even with the cows, the grass is growing in all pastures except Green Gables, where the cows are eating the grass faster than it can grow. We'll deal with that in the next run.
To summarize: in this run, we created a collection of cows partitioned into pastures and computed the total grass consumption in each pasture. Then in the pasture entity definition, we created a reference to that collection, so the total consumption rate could be used to calculate net grass growth.
|