SIMULATION_LENGTH = 100
PEOPLE_COUNT = 100
def create_people(people_count); end
def report; end
def simulate_to(count)
1.upto(count) {|i| yield i }
end
people = create_people(PEOPLE_COUNT)
simulate_to(SIMULATION_LENGTH) do |iteration|
# mish and mash people
end
report
Slide 16
Slide 16 text
class Simulator
def initialize(length, count)
# ...
end
end
s = Simulator.new 3650, 100
Define inputs
Slide 17
Slide 17 text
class Simulator
def simulate(iteration)
create_pairs(iteration)
transmit(iteration)
progress_infections(iteration)
end
end
Compute
Slide 18
Slide 18 text
s = Simulator.new 3650, 100
s.run
s.infected_people.each do |p|
i = p.infections.to_a
d = p.diseases.to_a
puts "#{p} #{i} #{d}"
end
Analyze output
class Simulation
def transmit(iteration)
current_pairs(iteration).each{|pair| pair.contact(iteration)}
end
end
class Pair
def contact(iteration)
@alpha.infect(iteration, @beta)
@beta.infect(iteration, @alpha)
end
end
class Person
def infect(iteration, person); end
def acquire(infection); end
end
Slide 25
Slide 25 text
Track infection
progress
Slide 26
Slide 26 text
class Person
def progress_infections(iteration)
@infections.each do |infection|
if rand <= infection.chance_to_acquire_disease
unless has_disease? infection.disease
@diseases << infection.disease.new(iteration)
end
end
end
end
end
irb(main):003:0> rand 1..7
TypeError: can't convert Range into Integer
from org/jruby/RubyKernel.java:1580:in `rand'
from (irb):3:in `evaluate'
from org/jruby/RubyKernel.java:1070:in `eval'
from org/jruby/RubyKernel.java:1395:in `loop'
from org/jruby/RubyKernel.java:1178:in `catch'
from org/jruby/RubyKernel.java:1178:in `catch'
from /Users/bryan/.rbenv/versions/jruby-1.7.0-preview2/bin/irb:13:in
`(root)'
JRuby 1.7 pre2