group
index
/home/gcallah/TandonDevOps/IndraABM/lib/group.py

This file defines a Group, which is composed
of zero or more Agents (see agent.py).
(A group might have its membership reduced to zero!)

 
Modules
       
json

 
Classes
       
builtins.object
Members
lib.agent.Agent(builtins.object)
Group

 
class Group(lib.agent.Agent)
    Group(name, attrs=None, members=None, action=None, mbr_creator=None, mbr_action=None, color=None, num_mbrs=None, serial_obj=None, exec_key=None, **kwargs)
 
This is the base class of all collections
of entities. It itself is an agent.
Args:
    attrs: a dictionary of group properties
    members: a list of members, that will be turned
        into a dictionary
    mbr_creator: a function to create members
    num_mbrs: how many members to create
 
 
Method resolution order:
Group
lib.agent.Agent
builtins.object

Methods defined here:
__add__(self, other)
This implements set union and returns
a new Group that is self union other.
If other is an atomic agent, just add it to
this group.
__call__(self, **kwargs)
Call the members' functions, and the group's
action func if it has one.
This should return the total of all
agents who acted in a particular call.
__contains__(self, item)
A test whether item is a member of this set.
__delitem__(self, key)
This will delete a member from this group.
__eq__(self, other)
Return self==value.
__getitem__(self, key)
We are going to return the 'key' member
of our member dictionary.
__iadd__(self, other)
Add other to set self.
If other is a group, add all its members.
If other is an atom, add it.
__init__(self, name, attrs=None, members=None, action=None, mbr_creator=None, mbr_action=None, color=None, num_mbrs=None, serial_obj=None, exec_key=None, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
__iter__(self)
__len__(self)
__repr__(self)
Return repr(self).
__reversed__(self)
__setitem__(self, key, member)
In contrast to agent, which sets a val
for setitem, for groups, we are going to set
the 'key' member.
__sub__(self, other)
This implements set difference.
add_member(self, member)
Should be called by join()
del_member(self, member)
Should be called by split()
from_json(self, serial_obj)
Turn a serilaized JSON stream back into a group:
get_color(self)
Return this group's display color.
get_marker(self)
Return this group's display marker.
get_members(self)
has_color(self)
is_active(self)
For now, groups just stay active.
We might want to revisit later the question
of whether a group with all inactive members
should be inactivated.
is_mbr_comp(self, mbr)
ismember(self, agent)
pop_count(self, mbr)
rand_member(self)
rand_subset(self, n, name='rand_subset', exec_key=None)
Choose a random subset of N members from this group.
restore(self, serial_obj)
Here we restore a group from a serialized object.
subset(self, predicate, *args, name=None, exec_key=None)
to_json(self)
Here we turn a group into a serialized object.

Data and other attributes defined here:
__hash__ = None

Methods inherited from lib.agent.Agent:
__str__(self)
Return str(self).
add_group(self, group)
check_null_pos(fn)
Should be used to decorate any function that uses pos[X] or pos[Y]
del_group(self, group)
die(self)
get(self, key, default=None)
This is a call to get_attr() to not break existing code
that calls get().
get_attr(self, key, default=None)
get_pos(self)
get_x(self)
get_y(self)
group_name(self)
is_located(self)
move(self, max_move=None, angle=None)
Move this agent to a random pos within max_move
of its current pos.
prim_group_nm(self)
prim_group is just a name, but we don't want models
going straight at it!
primary_group(self)
set_attr(self, key, val)
set_pos(self, x, y)
set_prim_group(self, group)
We want this to store the name of the group.
The str() of the group is its name.
The str() of the name is itself.
If we are passed None, set to blank.
switch_groups(self, g1, g2)

Data descriptors inherited from lib.agent.Agent:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Members(builtins.object)
    Members(serial_mbrs=None)
 
group.members was once simply a dictionary; now we are going to wrap the
dict in a class so we can give it the same color interface as pop hist.
 
  Methods defined here:
__contains__(self, item)
A test whether item is a member of this set.
__delitem__(self, key)
This will delete a member from this group.
__eq__(self, other)
Return self==value.
__getitem__(self, key)
We are going to return the 'key' member
of our member dictionary.
__init__(self, serial_mbrs=None)
Initialize self.  See help(type(self)) for accurate signature.
__iter__(self)
__len__(self)
__repr__(self)
Return repr(self).
__reversed__(self)
__setitem__(self, key, member)
In contrast to agent, which sets a val
for setitem, for groups, we are going to set
the 'key' member.
from_json(self, serial_mbrs)
get_color(self, name)
See if a pop has a specific color.
has_color(self, name)
See if a pop has a specific color.
items(self)
keys(self)
to_json(self)
update(self, other)
Implements set union of members.
values(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__hash__ = None

 
Functions
       
grp_from_nm_mbrs(nm, mbrs, exec_key=None)

 
Data
        DEBUG = <lib.utils.Debug object>
INF = 9223372036854775807