def __init__(self, id, p_move, states, transitions, durations, current_state, home_cell_id, current_state_duration=0, been_infected=0): self.id = id self.p_move = p_move self.states = states self.transitions = transitions self.durations = durations self.current_state = current_state self.home_cell_id = home_cell_id self.current_state_duration = current_state_duration # how long the agent has been in this state self.been_infected = been_infected self.least_state = get_least_severe_state(states)
def __init__(self, id, p_move, transitions, states, durations, current_state, home_cell_id): """ An agent can move from cell to cell and get infected by another agent being simoultaneously in the same cell. :param id: id of the agent :type id: Integer (int) :param p_move: Probability for an agent to move if a move is made in the <Map> where it is :type p_move: float between 0 and 1 :param transitions: Markovian transition matrix between the `states` :type transitions: numpy array of shape (#states, #states) with rows summing up to 1 :param states: states in which an agent can be :type states: list of <State> :param durations: durations of the states if the agent move to them :type durations: iterable of length #states containing strictly positive integers :param current_state: state of the agent at its initialization :type current_state: <State> :param home_cell_id: if of the home cell of the agent :type home_cell_id: int """ self.id = id self.p_move = p_move self.transitions = transitions self.states = states self.durations = durations self.current_state = current_state self.home_cell_id = home_cell_id self.current_cell_id = home_cell_id # Define dicts for `states` self.name2state = {state.get_name(): state for state in states} self.name2index = { state.get_name(): i for i, state in enumerate(states) } self.index2state = {i: state for i, state in enumerate(states)} self.state_names = {state.get_name() for state in states} # Define variables for `current_state` self.n_states = len(states) self.current_state_age = 0 self.current_state_index = self.name2index.get( current_state.get_name()) self.least_severe_state = get_least_severe_state(states)
""" Test1: contagions Simulation with 2 agents in the same cell who can be in 2 distinct states: 'healthy' or 'sick'. Those agents have distinct durations `durations_1` and `durations_2` attached to those states. After one step, agent 1 gets sick. He contaminates agent 2. Then both get healthy again after different durations """ state0 = State(id=0, name='healthy', contagiousity=0, sensitivity=1, severity=0) state1 = State(id=1, name='sick', contagiousity=1, sensitivity=0, severity=0.5) transitions = array([[1, 0], [1, 0]]) states = [state0, state1] least_severe_state = get_least_severe_state([state0, state1]) validated = 'OK' if least_severe_state.get_id() == state1.get_id() else 'Failed' print(f'Check for least_severe_state: {validated}') durations_1 = (-1, 3) # 1st state duration: undefinite, 2nd state duration: 3 timesteps (days) durations_2 = (-1, 2) # 1st state duration: undefinite, 2nd state duration: 2 timesteps (days) p_move_1 = 0.3 p_move_2 = 0.5 ind_1 = Agent(id=1, p_move=p_move_1, transitions=transitions, states=states, durations=durations_1, current_state=state0, home_cell_id=1) ind_2 = Agent(id=2, p_move=p_move_2, transitions=transitions, states=states, durations=durations_2, current_state=state0, home_cell_id=1) position_1 = (1, 1) attractivity_1 = 0.5 cell_1 = Cell(id=1, position=position_1, attractivity=attractivity_1, unsafety=1, agents=[ind_1, ind_2])