//use std::mem;
use rand::Rng;
const MAXVAL:u32 =800000000; // total number of people in the model.
const RUNS:u32 =100000; // how many ticks will the simulation run?
const R0:f32 =3.0; // Number of people each infected person tries to infect per tick.
const R0INT:i32 = R0 as i32; //Integer version of R0. (Used to calculate infection probability when the R0 is not an integer.)
const R0FRACT:f32 = R0 - R0INT as f32 ; //Remainder of R0 when integer value is subtracted. (Used to calculate infection probability when the R0 is not an integer.)
const ILENGTH:i32 =12; // Sets the time a person is immune after infection. (Currently 50 days.)
//fn zombiecheck (zombie: u32, ztarget: u32) ->bool
fn main() {
struct human {
// This is people.
sick :bool,
ifect : bool,
immune : i32 }
struct virun {
//This is a single geographic node made up of yummy people.
zombies : Vec,
maxloop : u32,
loops : u32,
totalsick : u32,
totalimmune : u32
}
// This is where the member functions go.
impl human{}
impl virun{
fn loadhumans(&mut self)
{//Fills up the vector with people before the virus kills everyone. People are all added in a healthy state. (Probaby California)
let mut xi=0;
while xi rng.gen_range(0.0 .. 1.0) as f32
{
/* This is the part that handles the fractional part of the R0. If the R0 is 3.2, it wil generate a random number between 0 and 1.
If the fractional part is above that number, the person gets zotted.
*/
let r=rng.gen_range(0..MAXVAL-1);
if self.zombies[r as usize].immune ==0
{
self.zombies[r as usize].immune = ILENGTH;
self.zombies[r as usize].ifect = true;
self.totalimmune +=1;
}
}
}
}
}
for x in 0..self.zombies.len()-1
{
if self.zombies[x].immune!=0
{//println!("deincrementing {} value = {}",x,self.zombies[x].immune);
self.zombies[x].immune -=1;
self.totalimmune +=1;
}
if self.zombies[x].ifect==true
{self.zombies[x].ifect=false;
self.zombies[x].sick=true;
self.totalsick+=1;
}
}
}
}
let mut runlist = virun
{ zombies : Vec::with_capacity(MAXVAL as usize) ,
maxloop : RUNS,
loops : 0,
totalsick : 0,
totalimmune :0};
runlist.loadhumans();
let mut rng = rand::thread_rng();
let tempxrand:f32 = rng.gen_range (0.0 .. 1.0);
runlist.zombies[0].ifect=true; //start the pandemic. (Your uncle Bob gets bitten by a zombie marmot from space.)
for lcounter in 0..runlist.maxloop {
println!("looping {}",lcounter);
runlist.totalsick=0;
runlist.totalimmune=0;
runlist.infectscan();
println!("End of day :{} Total Sick = {}. Total Immune = {} empty {}",lcounter, runlist.totalsick, runlist.totalimmune, MAXVAL - runlist.totalimmune);
}
}