metawards.Links¶
-
class
metawards.
Links
(N: int = 0)[source]¶ This is a container class for Links. This uses arrays to store a list of Link objects as a “struct of arrays”. This should improve speed of loading and access.
Methods
__delattr__
(name, /)Implement delattr(self, name).
__dir__
()Default dir() implementation.
__eq__
(value, /)Return self==value.
__format__
(format_spec, /)Default object formatter.
__ge__
(value, /)Return self>=value.
__getattribute__
(name, /)Return getattr(self, name).
__getitem__
(i)Return the link at index ‘i’.
__gt__
(value, /)Return self>value.
__hash__
()Return hash(self).
__init__
([N])Create a container for up to “N” Links
__init_subclass__
This method is called when a class is subclassed.
__le__
(value, /)Return self<=value.
__len__
()Return the number of links in this container
__lt__
(value, /)Return self<value.
__ne__
(value, /)Return self!=value.
__new__
(**kwargs)Create and return a new object.
__reduce__
()Helper for pickle.
__reduce_ex__
(protocol, /)Helper for pickle.
__repr__
()Return repr(self).
__setattr__
(name, value, /)Implement setattr(self, name, value).
__setitem__
(i, value)Set the item as index ‘i’ equal to ‘value’.
__sizeof__
()Size of object in memory, in bytes.
__str__
()Return str(self).
__subclasshook__
Abstract classes can override this to customize issubclass().
Assert that this collection of links is not null
Assert that the passed index ‘i’ is valid for this collection.
copy
()Return a copy of these links, using a shallow copy for things that stay the same (e.g.
is_null
()Return the population of these links
resize
(N)Resize this container to hold ‘N’ links.
scale_susceptibles
([ratio])Scale the number of susceptibles in these Links by the passed scale ratio.
Attributes
__dict__
__doc__
__module__
__weakref__
list of weak references to the object (if defined)
-
__getitem__
(i: int)[source]¶ Return the link at index ‘i’. Note that this is a deep copy of the link. Changing the link will not change the data in this container. To update the data in this container you need to use __setitem__, e.g. via the index operator (see __setitem__)
-
__setitem__
(i: int, value: metawards._link.Link)[source]¶ Set the item as index ‘i’ equal to ‘value’. This deep-copies ‘value’ into this container
-
assert_valid_index
(i)[source]¶ Assert that the passed index ‘i’ is valid for this collection. This will return the index with Python reverse indexing, so that “-1” refers to the last link in the collection
-
copy
()[source]¶ Return a copy of these links, using a shallow copy for things that stay the same (e.g. ifrom, ito, distance) and a deep copy for things that are variable (e.g. weight and suscept)
-
distance
¶ The distance between the two wards of this link
-
ifrom
¶ The index of the home ward
-
ito
¶ The index of the commute ward
-
resize
(N: int)[source]¶ Resize this container to hold ‘N’ links. This will expand the container if ‘N’ is greater than len(self), or will contract the container (deleting excess links) if ‘N’ is less than len(self). This function is called typically when you pre-allocate a large Links container, and then want to reduce the size to fit the number of loaded links
-
scale_susceptibles
(ratio: Optional[any] = None)[source]¶ Scale the number of susceptibles in these Links by the passed scale ratio. This can be a value, e.g. ratio = 2.0 will scale the total number of susceptibles by 2.0. This can also be lists of values, where ward[i] will be scaled by ratio[i]. They can also be dictionaries, e.g. ward[i] scaled by ratio[i]
- Parameters
ratio (None, float, list or dict) – The amount by which to scale the total population of susceptibles - evenly scales the work and play populations
- Returns
- Return type
None
-
suscept
¶ The number of susceptible workers in this link
-
weight
¶ The number of workers in this link, or the weight if this is a player link
-