In [ ]:

Space Classes

Physical Grid

Information Diffusion Network


In [5]:
class Grid2D(object):
    """
    2-D grid class.
    """
    pass

class InformationNetwork(object):
    """
    Information diffusion network.
    """
    pass

Model Class


In [41]:
class Model(object):
    """
    Model class.
    """
    
    def __init__(self, population_size=100,
                 initial_zombies=1,
                 grid_size=20,
                 information_network_type="default",
                 infection_rate=0.1,
                 defend_probability=0.1,
                 human_speed=1,
                 zombie_speed=1,
                 pheromone_deposit_rate=0.1,
                 pheromone_dissipation_rate=0.1
                ):
        """
        Constructor.
        """
        
        # Top level model parameters
        self.population_size = population_size
        self.initial_zombies = initial_zombies
        self.grid_size = grid_size
        self.information_network_type = information_network_type
        self.defend_probability = defend_probability
        self.human_speed = human_speed
        self.zombie_speed = zombie_speed
        self.pheromone_deposit_rate = pheromone_deposit_rate
        self.pheromone_dissipation_rate = pheromone_dissipation_rate
        
        # Storage
        self.agent_list = []
        
        # Call setup methods
        self.create_agents()
    
    def create_agents(self):
        """
        Create the agents for the model.
        """
        # Create humans
        for agent_id in range(self.population_size):
            self.agent_list.append(Human(self, agent_id,
                                        self.human_speed,
                                        self.defend_probability))
        
        # Create zombies
        for zombie_id in range(self.initial_zombies):
            # Get agent ID
            agent_id = self.population_size + zombie_id
            self.agent_list.append(Zombie(self, agent_id,
                                        self.zombie_speed,
                                        self.defend_probability))

In [43]:
for i in range(len(m.agent_list)):
    print((i, m.agent_list[i].agent_id))


(0, 0)
(1, 1)
(2, 2)
(3, 3)
(4, 4)
(5, 5)
(6, 6)
(7, 7)
(8, 8)
(9, 9)
(10, 10)
(11, 11)

In [44]:
m = Model(population_size=10, initial_zombies=2)
print(m.agent_list)


[<__main__.Human object at 0x3888610>, <__main__.Human object at 0x3888450>, <__main__.Human object at 0x3888350>, <__main__.Human object at 0x3888750>, <__main__.Human object at 0x3888790>, <__main__.Human object at 0x38887d0>, <__main__.Human object at 0x3888a10>, <__main__.Human object at 0x3888850>, <__main__.Human object at 0x38888d0>, <__main__.Human object at 0x3888910>, <__main__.Zombie object at 0x3888a90>, <__main__.Zombie object at 0x3888990>]

Human

Qualitatively, humans can:

  • run away
  • share information
  • if attacked, defend themselves
  • if attacked and not successful in defending, converted
  • if attacked but adjacent to other people, better chance

Zombies

Qualitatively, zombies can:

  • if adjacent to a human, attack to convert
  • potential movement strategies
    * totally random
    * human-pheremone driven
  • slow down if too hungry

In [18]:
class Human(object):
    """
    Human class.
    """
    
    def __init__(self, model, agent_id,
                human_speed, defend_probability):

        # Set agent parameters
        self.model = model
        self.agent_id = agent_id
        self.human_speed = human_speed
        self.defend_probability = defend_probability

class Zombie(object):
    """
    Zombie class.
    """
    def __init__(self, model, agent_id,
                zombie_speed, defend_probability):
        # Set agent parameters
        self.model = model
        self.agent_id = agent_id
        self.zombie_speed = zombie_speed
        self.defend_probability = defend_probability

Pheromone Model

  • Humans can deposit pheromones
  • Rate at which they deposit may be varied
  • Pheromones will dissipate at some rate