next up previous index
Next: Creating a New Model Up: Expressions Previous: Disaggregation   Index


Number of Agents

A common task in modeling is to determine a number of agents of one dataset that are assigned to another dataset. For this purpose, Opus contains a built-in method number_of_agents, which takes as an argument the name of the agent dataset. For example, our household dataset is assigned to the following locations:

>>> households.modify_attribute(name="location",
                              data=[2, 8, 3, 1, 5, 4, 9, 7, 3, 6])
Then, the number of households in each location can be determined by:
>>> dataset_pool.add_datasets_if_not_included({'household': households})
>>> locations.compute_variables("gridcell.number_of_agents(household)",
                                dataset_pool=dataset_pool)
gridcell.number_of_agents(household).....................0.0 sec
array([ 1.,  1.,  2.,  1.,  1.,  1.,  1.,  1.,  1.])
Note that we had to add the household dataset to the dataset pool in order to have it available in the computation process.

Similarly, the number of zones in neighborhoods is computed by

>>> neighborhoods.compute_variables("neighborhood.number_of_agents(zone)",
                                    dataset_pool=dataset_pool)
neighborhood.number_of_agents(zone)......................0.0 sec
array([ 2.,  1.,  2.])

As in the case of aggregate and disaggregate, the number_of_agents method must be preceded by the `owner' dataset name, e.g. neighborhood.number_of_agents for computing on the neighborhood dataset.


next up previous index
Next: Creating a New Model Up: Expressions Previous: Disaggregation   Index
info (at) urbansim.org