#!/usr/bin/env python # coding: utf-8 # This example implements the first model from "Modeling civil violence: An agent-based computational approach," by Joshua Epstein. The paper (pdf) can be found [here](http://www.uvm.edu/~pdodds/files/papers/others/2002/epstein2002a.pdf). # # The model consists of two types of agents: "Citizens" (called "Agents" in the paper) and "Cops." Agents decide whether or not to rebel by weighing their unhappiness ('grievance') against the risk of rebelling, which they estimate by comparing the local ratio of rebels to cops. # # # # In[2]: import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') from civil_violence.agent import Citizen, Cop from civil_violence.model import CivilViolence # In[4]: model = CivilViolence(height=40, width=40, citizen_density=.7, cop_density=.074, citizen_vision=7, cop_vision=7, legitimacy=.8, max_jail_term=1000, max_iters=1000) # cap the number of steps the model takes model.run_model() # The model's data collector counts the number of citizens who are Active (in rebellion), Jailed, or Quiescent after each step. # In[11]: model_out = model.datacollector.get_model_vars_dataframe() # In[12]: ax = model_out.plot() ax.set_title('Citizen Condition Over Time') ax.set_xlabel('Step') ax.set_ylabel('Number of Citizens') _ = ax.legend(bbox_to_anchor=(1.35, 1.025)) # In[ ]: # In[ ]: