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.

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 [1]:
import matplotlib.pyplot as plt
%matplotlib inline

from civil_violence.agent import Citizen, Copfrom civil_violence.model import CivilViolenceModel

In [2]:
model = CivilViolenceModel(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 [3]:
model_out = model.dc.get_model_vars_dataframe()

In [4]:
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 [ ]: