Browse Source

cleaning

master
thajohns 3 years ago
parent
commit
b7d545c610
  1. 4
      README.md
  2. 18
      bugage.c
  3. 10
      bugage.h
  4. 37
      isim.c
  5. 14
      makefile
  6. 6
      model_plan.md
  7. 50
      s0.c
  8. 50
      timing.c
  9. 7
      timing.h

4
README.md

@ -2,6 +2,6 @@
### Introduction
In this project we created a simulation program to trial the spread of an invasive species of plant called by its scientific name, *Phytophthora infestans*, or known as Late Blight.
In this projecct, our goal is to create a simulation to model the growth of an invasive species, the Brown Marmorated Stink Bug.
Next, we created a program to model the data generated by the simulations into a visually appealing format.
We hope to accomplish this by testing our simulation using this program to simulate it.

18
bugage.c

@ -1,18 +0,0 @@
#include "bugage.h"
#include <string.h>
#include "rand.h"
void BugArrayTick()
{
BugArray[ADULTS] += BugArray[ADULTS-1];
memcpy(BugArray, BugArray + 1, ADULTS - 1);
for(int e = 0; e < eggCount; e++)
{
int r = (int) umremap(prngdn(), 28, 5);
if (r > 20 && r <= ADULTS)
{
BugArray[ADULTS-r]++;
}
}
}

10
bugage.h

@ -1,10 +0,0 @@
#ifndef BUGAGE_H
#define BUGAGE_H
#define ADULTS 127
int eggCount;
int* BugArray;
void BugArrayTick();
#endif

37
isim.c

@ -0,0 +1,37 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
const double Rmate = 5.1;
const double Rdeath = 0.05;
const double R = Rmate - Rdeath;
const double step_size = 0.01;
const double time_for_total_death = 0.1; // years
const double t_stop = 100.0;
const double lambda = step_size / time_for_total_death;
const double max_sustainable_pop = 1000000;
const double initial_p = 0.01;
int main()
{
double p = initial_p;
int ii;
const double r_to_lambda = pow(R, lambda);
FILE *f = fopen("data/data.txt", "w");
if (!f)
{
fprintf(stderr, "bad file\n");
return 1;
}
for (int ii = 0; ii < t_stop / step_size; ii++)
{
double p_new = r_to_lambda * p * pow(1 - p, lambda);
fprintf(f, "%lf %lf %lf\n", ii * step_size, p, p * max_sustainable_pop);
p = p_new;
}
fclose(f);
}

14
makefile

@ -0,0 +1,14 @@
CC=clang
all : bug_sim
isim.o : isim.c
$(CC) -c isim.c
bug_sim : isim.o
$(CC) -obug_sim isim.o -lm
clean :
rm bug_sim
rm isim.o

6
model_plan.md

@ -1,6 +0,0 @@
## Minimal Model:
* Population of bugs (Predictable change at starting of simulation)
* Death chance (Random per day)
* Mating chance (Somewhat random per day. Kind of depends on population)
* Amount of eggs laid (Random aomunt within range, is part of population now)
* Seasons affect chances of things (Random variable)

50
s0.c

@ -1,50 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <time.h>
#include "rand.h"
#include "bugage.h"
#include "timing.h"
// Many variables have been omitted; this is just to get a minimal (dysfuncitonal) model working.
int main(int argc, char** argv)
{
BugArray = calloc(ADULTS, sizeof(int));
BugArray[ADULTS] = atoi(argv[1]);
prn = (int32_t) time(NULL);
FILE *dataout = fopen("data/newdata.dat", "w");
if (dataout == NULL)
{
fprintf(stderr, "Could not open data file for writing\n");
return 1;
}
for (int day = 90; day < 3650 + 90; day++)
{
fprintf(dataout, "%i, %d, %d\n", day, BugArray[ADULTS], eggCount);
int deathCount = 0;
eggCount = 0;
for (int adult = 0; adult < BugArray[ADULTS]; adult++)
{
if (adult % 2)
{
if(prngd() < mating_chance(day))
{
eggCount += bound_int((int) umremap(prngdn(), 28, 2), 0 , 40);
}
}
if(prngd() < death_chance(day))
{
deathCount += 1;
}
}
BugArray[ADULTS] -= deathCount;
BugArrayTick();
}
fclose(dataout);
}

50
timing.c

@ -1,50 +0,0 @@
// Timing
#include <math.h>
/*
Timing of months in years
Month Days Days (Cumulative)
0 * trough = 0, assumed
Jan 31 31
Feb 28 59
Mar 31 90
Apr 30 120
May 31 151
Jun 30 181
Jul 31 212 * peak = 212, assumed
Aug 31 243
Sep 30 273
Oct 31 304
Nov 30 334
Dec 31 365 * trough again
*/
#define YEAR_DAYS 365
#define MATING_PROB_ULIMIT 0.001
#define MATING_PROB_LLIMIT 0.000
#define MATING_TIME_PEAK 212
#define DEATH_PROB_LLIMIT 0.0005
#define DEATH_PROB_ULIMIT 0.001
#define DEATH_TIME_TROUGH 212
double mating_chance(int day)
{
int doy = day % 365;
return (doy % 365) < MATING_TIME_PEAK?
MATING_PROB_LLIMIT + 0.5 * (MATING_PROB_ULIMIT - MATING_PROB_LLIMIT) * (2 - cos(doy / MATING_TIME_PEAK * M_PI)):
MATING_PROB_LLIMIT + 0.5 * (MATING_PROB_ULIMIT - MATING_PROB_LLIMIT) * ((doy - MATING_TIME_PEAK) / (YEAR_DAYS - MATING_TIME_PEAK) * M_PI);
}
double death_chance(int day)
{
int doy = day % 365;
return (doy % 365) < DEATH_TIME_TROUGH?
DEATH_PROB_ULIMIT + 0.5 * (DEATH_PROB_LLIMIT - DEATH_PROB_ULIMIT) * (2 - cos(doy / DEATH_TIME_TROUGH * M_PI)):
DEATH_PROB_ULIMIT + 0.5 * (DEATH_PROB_LLIMIT - DEATH_PROB_ULIMIT) * ((doy - DEATH_TIME_TROUGH) / (YEAR_DAYS - DEATH_TIME_TROUGH) * M_PI);
}

7
timing.h

@ -1,7 +0,0 @@
#ifndef TIMING_H
#define TIMING_H
double mating_chance(int day);
double death_chance(int day);
#endif
Loading…
Cancel
Save