예제 #1
0
    def __init__(self,
                 name,
                 width=DEF_WIDTH,
                 height=DEF_HEIGHT,
                 attrs=None,
                 members=None,
                 action=None,
                 random_placing=True,
                 serial_obj=None,
                 reg=True):
        super().__init__(name,
                         attrs=attrs,
                         members=members,
                         action=action,
                         serial_obj=serial_obj,
                         reg=False)

        # get rid of these type fields!
        self.type = "space"

        if serial_obj is not None:
            self.restore(serial_obj)
        else:
            self.width = width
            self.height = height
            # the location of members in the space {(tuple):Agent}
            self.locations = {}
            # by making two class methods for rand_place_members and
            # place_member, we allow two places to override
            if random_placing:
                self.rand_place_members(self.members)
            else:
                self.consec_place_members(self.members)
        if reg:
            register(self.name, self)
예제 #2
0
 def handle_womb(self):
     """
     The womb just contains group names -- they will be repeated
     as many times as that group needs to add members.
     We name the new members in the `member_creator()` method.
     This should be re-written as dict with:
         {"group_name": #agents_to_create}
     """
     if self.womb is not None:
         for group_nm in self.womb:
             group = regis.get_registration(group_nm)
             if group is not None and group.member_creator is not None:
                 group.num_members_ever += 1
                 agent = group.member_creator("", group.num_members_ever)
                 agent.env = group.env
                 regis.register(agent.name, agent)
                 join(group, agent)
         del self.womb[:]
예제 #3
0
    def __init__(self,
                 name,
                 action=None,
                 random_placing=True,
                 serial_obj=None,
                 census=None,
                 line_data_func=None,
                 exclude_member=None,
                 pop_hist_setup=None,
                 pop_hist_func=None,
                 members=None,
                 reg=True,
                 **kwargs):
        super().__init__(name,
                         action=action,
                         random_placing=random_placing,
                         serial_obj=serial_obj,
                         reg=False,
                         members=members,
                         **kwargs)

        self.type = "env"
        self.user_type = os.getenv("user_type", TERMINAL)
        # these funcs all must be restored from the function registry:
        self.census_func = census
        self.pop_hist_setup = pop_hist_setup
        self.pop_hist_func = pop_hist_func

        self.num_switches = 0
        if serial_obj is not None:
            # are we restoring env from json?
            self.restore_env(serial_obj)
        else:
            self.construct_anew(line_data_func, exclude_member)

        self.set_menu_excludes()

        if reg:
            regis.register(self.name, self)
        # now we set our global singleton:
        regis.set_env(self)
예제 #4
0
    def __init__(self,
                 name,
                 attrs=None,
                 action=None,
                 duration=INF,
                 prim_group=None,
                 serial_obj=None,
                 env=None,
                 reg=True):
        self.registry = {}

        if serial_obj is not None:
            self.restore(serial_obj)
        else:
            # self.type gotta go!
            self.type = "agent"
            self.name = name
            # cut locator over to a property
            self.action_key = None
            self.action = action
            if action is not None:
                self.action_key = get_func_name(action)
            self.duration = duration
            self.attrs = OrderedDict()
            self.neighbors = None
            if attrs is not None:
                self.attrs = attrs
            self.active = True
            self.pos = None

            # some thing we will fetch from registry:
            # for these, we only store the name but look up object
            self._env = None if env is None else env.name
            self._locator = None if self._env is None else self._env
            self._prim_group = None if prim_group is None else prim_group.name
            if prim_group is not None and is_space(prim_group):
                self.locator = prim_group

        if reg:
            register(self.name, self)
예제 #5
0
    def __init__(self, name, attrs=None, members=None,
                 duration=INF, action=None, member_creator=None,
                 num_members=None, serial_obj=None,
                 reg=True, **kwargs):

        self.num_members_ever = 0
        self.members = OrderedDict()
        super().__init__(name, attrs=attrs, duration=duration,
                         action=action, serial_obj=serial_obj,
                         reg=False)

        # we need to get rid of these uses of type!!!
        # (but carefully, of course)
        self.type = "composite"

        if serial_obj is not None:
            self.restore(serial_obj)
        else:
            if members is not None:
                for member in members:
                    join(self, member)
            if num_members is None:
                num_members = 1  # A default if they forgot to pass this.
            self.num_members_ever = num_members
            self.member_creator = None
            if member_creator is not None:
                self.member_creator = member_creator
                # If we have a member creator function, call it
                # `num_members` times to create group members.
                for i in range(num_members):
                    # += adds members
                    join(
                        self,
                        member_creator(self.name, i, **kwargs))
        if reg:
            add_group(self.name, self)
            register(self.name, self)