Logo
  • Features
  • Installation instructions
  • Model data
  • Quick Start Guide
  • Tutorial
  • Input files and formats
  • Usage
  • Running on a cluster
  • Help and support
  • Contributing
  • Developer Support
  • Roadmap
  • Packaging releases
  • Developer’s guide
  • Snag list
  • Documentation
    • MetaWards.app
    • MetaWards
      • MetaWards API Detail
        • Classes
        • Functions
    • MetaWards.iterators
    • MetaWards.extractors
    • MetaWards.mixers
    • MetaWards.movers
    • MetaWards.analysis
    • MetaWards.utils
    • MetaWards.themes
  • Changelog
  • Acknowledgements
MetaWards
  • »
  • Documentation »
  • MetaWards »
  • MetaWards API Detail »
  • metawards.Links
Previous Next

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.

__init__(N: int = 0)[source]

Create a container for up to “N” Links

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)

__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_not_null()

Assert that this collection of links is not null

assert_valid_index(i)

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.

get_index_of_link(ifrom, ito)

Return the index of the link from ward ifrom to ward ito.

is_null()

population()

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)

_is_null

Whether or not this is null

ifrom

The index of the home ward

ito

The index of the commute ward

weight

The number of workers in this link, or the weight if this is a player link

suscept

The number of susceptible workers in this link

distance

The distance between the two wards of this link

__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__)

__init__(N: int = 0)[source]

Create a container for up to “N” Links

__len__()[source]

Return the number of links in this container

__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_not_null()[source]

Assert that this collection of links is not null

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

get_index_of_link(ifrom: int, ito: int) → int[source]

Return the index of the link from ward ifrom to ward ito. This raises an exception if there is no such link

ifrom

The index of the home ward

ito

The index of the commute ward

population() → int[source]

Return the population of these links

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

Previous Next

Last updated on Mar 18, 2022.