References

<< Click to Display Table of Contents >>

Navigation:  Defining Entity Types > Create a New Entity Type >

References

Previous pageReturn to chapter overviewNext page

A reference is the name for another entity, or a collection of entities, whose information will be used as an input to a calculation. For the correct information to be used, you must tell Ventity which entity or entities will provide the information, and what information they will provide.

 

Reference to a Particular Entity using an Attribute

Example: cookie-monster entities get two cookies when their mothers are in a good mood, but only one cookie otherwise. An input to this determination is the mood of a cookie-monster's mother:

 

ncookies = if (mother.mood=="good") {2} else {1} 

 

Creating the reference

For this to work, the cookie-monster entity definition must include a reference called "mother". References to a single entity are established automatically in Ventity whenever you create a named-relationship attribute (see previous section). In this case, we create an attribute called "mother" which refers to another entity of type cookie monster. When the value of this attribute is set to the mother's key (either during initialization or by an action -- see below), "mother" is now available as a reference. Any property of the mother entity (that is, any variable or attribute) can now be used as an input in the cookie monster entity.

 

You can also create a reference to a single entity by dragging right clicking an empty space on the diagram and choosing "add reference", or by clicking the "add" button on the references tab of the entity inspector. In the reference editor that appears, give a name to the reference, and choose the type of entity it will refer to. To refer to a single entity, choose a plain entity type name, without brackets. (Names with square brackets are collections, which refer to a set of entities. These are discussed later.) The "conditions" field is used to specify which entity to refer to. The "keys to the target" field will automatically include the key attribute for that type of entity. Under "value to match", write an expression that will produce the correct key for each entity using this reference.

 

Using the reference

Once the reference "mother" is created, there are two ways to actually use the reference to produce the cookie equation above.

In the editor for the variable ncookies, simply type the desired equation. Once you type "mother", the auto-complete will offer you all the mother entity's properties for use.

Or, from the entity inspector, expand "mother" on the references tab. All the available properties appear; choose "mood" and drag it onto the diagram. Draw an arrow to ncookies and complete the equation.

 

attribute_cookies

 

Reference to a Collection of Entities

 

It is also possible to create a reference to a collection of entities of the same type. For example, a business entity might have a reference to the collection of all its customers. Collections, and references to collections, are discussed in the Collections section.

 

Reference to a Singular Entity

 

Accessing information from singular entities does not require a reference. Simply use the name of the entity in place of the reference. The Model entity is singular, for example, so to use the value of time step in an equation of another entity, type model.time step into the equation. If your model of bacteria growth in a laboratory has a singular lab entity with a variable called temperature, and the bacteria need information about the lab temperature, you can simply enter lab.temperature in bacteria entity equations.  

 

Testing for a Reference (Null)

 

If an entity or collection has not been assigned to a reference, then the reference will have the value Null. This allows you to test for whether the relationship exists or not, for example:

  taxstatus = if (spouse==Null) {"single"} else {"married"}.

See also Reference Functions.