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

This file defines an Agent.

 
Modules
       
json
numpy
os
pickle
sys
types

 
Classes
       
builtins.object
Agent
json.encoder.JSONEncoder(builtins.object)
AgentEncoder

 
class Agent(builtins.object)
    Agent(name, attrs=None, action=None, duration=9223372036854775807, prim_group=None, serial_obj=None, exec_key=None, **kwargs)
 
This is the base class of all agents, environments,
and objects contained in an environment.
 
  Methods defined here:
__add__(self, other)
Adds agent and group to make new group.
__call__(self, **kwargs)
Agents will 'act' by being called as a function.
If the agent has no `action()` function, do nothing.
If returns False, by default agent will move.
__contains__(self, item)
__eq__(self, other)
Return self==value.
__getitem__(self, key)
__init__(self, name, attrs=None, action=None, duration=9223372036854775807, prim_group=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).
__setitem__(self, key, value)
__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)
from_json(self, serial_agent)
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)
has_color(self)
is_active(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)
restore(self, serial_obj)
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)
to_json(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

 
class AgentEncoder(json.encoder.JSONEncoder)
    AgentEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
 
The JSON encoder base class for all descendants
of Agent.
 
 
Method resolution order:
AgentEncoder
json.encoder.JSONEncoder
builtins.object

Methods defined here:
default(self, o)
Implement this method in a subclass such that it returns
a serializable object for ``o``, or calls the base implementation
(to raise a ``TypeError``).
 
For example, to support arbitrary iterators, you could
implement default like this::
 
    def default(self, o):
        try:
            iterable = iter(o)
        except TypeError:
            pass
        else:
            return list(iterable)
        # Let the base class default method raise the TypeError
        return JSONEncoder.default(self, o)

Methods inherited from json.encoder.JSONEncoder:
__init__(self, *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Constructor for JSONEncoder, with sensible defaults.
 
If skipkeys is false, then it is a TypeError to attempt
encoding of keys that are not str, int, float or None.  If
skipkeys is True, such items are simply skipped.
 
If ensure_ascii is true, the output is guaranteed to be str
objects with all incoming non-ASCII characters escaped.  If
ensure_ascii is false, the output can contain non-ASCII characters.
 
If check_circular is true, then lists, dicts, and custom encoded
objects will be checked for circular references during encoding to
prevent an infinite recursion (which would cause an OverflowError).
Otherwise, no such check takes place.
 
If allow_nan is true, then NaN, Infinity, and -Infinity will be
encoded as such.  This behavior is not JSON specification compliant,
but is consistent with most JavaScript based encoders and decoders.
Otherwise, it will be a ValueError to encode such floats.
 
If sort_keys is true, then the output of dictionaries will be
sorted by key; this is useful for regression tests to ensure
that JSON serializations can be compared on a day-to-day basis.
 
If indent is a non-negative integer, then JSON array
elements and object members will be pretty-printed with that
indent level.  An indent level of 0 will only insert newlines.
None is the most compact representation.
 
If specified, separators should be an (item_separator, key_separator)
tuple.  The default is (', ', ': ') if *indent* is ``None`` and
(',', ': ') otherwise.  To get the most compact JSON representation,
you should specify (',', ':') to eliminate whitespace.
 
If specified, default is a function that gets called for objects
that can't otherwise be serialized.  It should return a JSON encodable
version of the object or raise a ``TypeError``.
encode(self, o)
Return a JSON string representation of a Python data structure.
 
>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
iterencode(self, o, _one_shot=False)
Encode the given object and yield each string
representation as available.
 
For example::
 
    for chunk in JSONEncoder().iterencode(bigobject):
        mysocket.write(chunk)

Data descriptors inherited from json.encoder.JSONEncoder:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from json.encoder.JSONEncoder:
item_separator = ', '
key_separator = ': '

 
Functions
       
is_group(thing)
Is this thing a group?
is_space(thing)
How do we determine if a group we are a member of is a space?
join(agent1, agent2)
Create connection between agent1 and agent2.
agent1 should be a group.
possible_trans(states, start_state, end_state)
prob_state_trans(curr_state, states)
Do a probabilistic state transition.
random() method of random.Random instance
random() -> x in the interval [0, 1).
ratio_to_sin(ratio)
Take a ratio of y to x and turn it into a sine.
set_trans(states, curr_state, poss_state, val, compl_state=None)
Change the probability of transitioning from
curr_state to poss_state to val.
If compl_state is passed, set it equal to 1 - val.
At present it is assumed that states is a matrix.
All of the casting to int() is JSON nonsense.
sin(x, /)
Return the sine of x (measured in radians).
split(agent1, agent2)
Break connection between agent1 and agent2.
switch(agent_nm, grp1_nm, grp2_nm, exec_key)
Move agent from grp1 to grp2.
We first must recover agent objects from the registry.

 
Data
        DEBUG = <lib.utils.Debug object>
DEF_MAX_MOVE = None
DONT_MOVE = True
INF = 9223372036854775807
MOVE = False
NEUTRAL = 0.7071068
NEUT_VEC = array([0.7071068, 0.7071068])
NULL_VEC = array([0, 0])
X = 0
X_VEC = array([1, 0])
Y = 1
Y_VEC = array([0, 1])
pi = 3.141592653589793