Browse Source

Sqashed some bugs and added makefile

master
thajohns 3 years ago
parent
commit
96b3c72056
  1. 4
      README.md
  2. 12
      bugage.c
  3. 5
      bugage.h
  4. 23
      makefile
  5. 20
      s0.c
  6. 1
      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.

12
bugage.c

@ -1,11 +1,17 @@
#include "bugage.h"
#include <string.h>
#include "bugage.h"
#include "rand.h"
int *BugArray;
int eggCount;
void BugArrayTick()
{
BugArray[ADULTS] += BugArray[ADULTS-1];
memcpy(BugArray, BugArray + 1, ADULTS - 1);
// BugArray size:ADULTS
// 0 ADUlTS-1
BugArray[ADULTS - 2] += BugArray[ADULTS - 1];
memmove(BugArray, BugArray + 1, ADULTS - 1);
for(int e = 0; e < eggCount; e++)
{

5
bugage.h

@ -3,8 +3,9 @@
#define ADULTS 127
int eggCount;
int* BugArray;
extern int eggCount;
extern int adultCount;
extern int *BugArray;
void BugArrayTick();
#endif

23
makefile

@ -0,0 +1,23 @@
CC=clang
all : bug_sim
s0.o : s0.c
$(CC) -c s0.c
rand.o : rand.c
$(CC) -c rand.c
timing.o : timing.c
$(CC) -c timing.c
bugage.o : bugage.c
$(CC) -c bugage.c
bug_sim : s0.o rand.o timing.o bugage.o
$(CC) -obug_sim s0.o rand.o timing.o bugage.o -lm
clean :
rm bug_sim
rm s0.o rand.o timing.o bugage.o

20
s0.c

@ -9,11 +9,17 @@
// Many variables have been omitted; this is just to get a minimal (dysfuncitonal) model working.
int main(int argc, char** argv)
{
BugArray = malloc(ADULTS);
BugArray[ADULTS] = atoi(argv[1]);
if (argc != 2)
{
fprintf(stderr, "No initial population\n");
return 1;
}
BugArray = malloc(ADULTS * sizeof(int));
BugArray[ADULTS - 1] = atoi(argv[1]);
eggCount = 0;
FILE *dataout = fopen("data/newdata.dat", "w");
if (dataout == NULL)
@ -21,19 +27,20 @@ int main(int argc, char** argv)
fprintf(stderr, "Could not open data file for writing\n");
return 1;
}
for (int day = 0; day < 3650; day++)
{
fprintf(dataout, "%i, %d, %d\n", day, BugArray[ADULTS], eggCount);
fprintf(dataout, "%i, %d, %d\n", day, BugArray[ADULTS - 1], eggCount);
int deathCount = 0;
eggCount = 0;
for (int adult = 0; adult < BugArray[ADULTS]; adult++)
for (int adult = 0; adult < BugArray[ADULTS - 1]; adult++)
{
if (adult % 2)
{
if(prngd() < mating_chance(day))
{
eggCount += bound_int((int) umremap(prngdn(), 28, 2), 0 , 40);
eggCount += bound_int((int) umremap(prngdn(), 28, 2), 0 , 40);
}
}
if(prngd() < death_chance(day))
@ -42,6 +49,7 @@ int main(int argc, char** argv)
}
}
BugArray[ADULTS] -= deathCount;
BugArrayTick();
}
fclose(dataout);
}

1
timing.h

@ -1,6 +1,7 @@
#ifndef TIMING_H
#define TIMING_H
// Prototypes for functions in timing.c
double mating_chance(int day);
double death_chance(int day);

Loading…
Cancel
Save