KeepRubyWeird 2015: Prepare yourself against Zombie epidemic

KeepRubyWeird 2015: Prepare yourself against Zombie epidemic

3f8fcddf7ab5d1bd90b0a0a9adfd6527?s=128

Christophe Philemotte

October 26, 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.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