Ruby Kaigi 2015: Prepare yourself against Zombie epidemic

Ruby Kaigi 2015: Prepare yourself against Zombie epidemic

The news is everywhere: some weird disease makes the dead walking. We do not know yet if it is highly contagious. What should we do? What we do everyday: writing code.

This couldn't be a better moment to use an agent based model — a technique that simulates interactions between agents in a environment to understand their effects as a whole. For such, we'll visit its minimal Ruby implementation, address some common design, simulate the Zombie epidemic, visualize it, and test different survival strategies to hopefully find the best one.

We can code, we'll be prepared ... or not.

The code: https://github.com/toch/zombie_epidemic

3f8fcddf7ab5d1bd90b0a0a9adfd6527?s=128

Christophe Philemotte

December 14, 2015
Tweet

Transcript

  1. Benjamin Lehman, ©2011

  2. Benjamin Lehman, ©2011 Prepare yourself against Zombie ゾンビ epidemic

  3. Agent Based Model

  4. None
  5. None
  6. None
  7. None
  8. None
  9. Agent Based Model

  10. Map National Geographics, ©2011

  11. map = Map.new(4, 4)

  12. point = Point.new point_north = Point.new point.neighborhood[:north] = point_north point_north.neighborhood[:south]

    = point # ...
  13. John DellAngelo, ©2013 Agent

  14. agent = Agent.new(age, start_point, stm)

  15. agent.perceive # => {}

  16. agent.act # => :walk agent.walk(:east)

  17. None
  18. agent.age # => 1

  19. agent.age agent.commit # => #<ZombieEpidemic::State:... # @name=:susceptible, ...

  20. State

  21. state = State.new(:susceptible) state.define_possible_actions( ->(agent) { [:walk, :stay, :fight].sample }

    )
  22. state.decide_action_for(agent) # => :walk

  23. infected = State.new(:susceptible) state.add_transition( infected, ->(state, agent) { true }

    )
  24. state.trigger_transition(agent) # => #<ZombieEpidemic::State:... # @name=:infected, ...

  25. None
  26. State Transition Machine

  27. stm = StateTransitionMachine.new # create states: # - susceptible #

    - infected # - zombie # - dead # create transitions # set default initial state
  28. Simulation Loop

  29. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  30. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  31. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  32. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  33. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  34. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  35. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  36. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  37. steps = 100 agents = create_the_agents steps.times do agents.each do

    |agent| agent.act; agent.age end agents.each { |agent| agent.commit } remove_the_deads(agents) end
  38. None
  39. None
  40. Validation & Calibration

  41. # validation # == # functional test

  42. None
  43. None
  44. # Calibration # f(x, y, z, ?) = a

  45. Simulate & Prepare yourself

  46. Live Demo

  47. None
  48. Outro

  49. ? toch _toch toch/zombie_epidemic