forked from wbrinksma/Viral-Simulation-2020-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
66 lines (52 loc) · 2.24 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Corona Simulation - basic simulation of a human transmissable virus
// Copyright (C) 2020 wbrinksma
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "simulation.h"
#include <iostream>
#include <random>
#include <math.h>
#include "html_canvas.h"
#include "ChartJS_handler.h"
//Constants to control the simulation
const int SUBJECT_COUNT = 100;
const int SIM_WIDTH = 800;
const int SIM_HEIGHT = 500;
const int SUBJECT_RADIUS = 2;
// B3 assignment
// constants which defines the time for how long the subject will be infected and is immune to the virus
const int INFECTION_TIME = 500;
const int IMMUNE_TIME = 500;
int main() {
corsim::Simulation s(SIM_WIDTH,SIM_HEIGHT, INFECTION_TIME, IMMUNE_TIME, std::make_unique<corsim::HTMLCanvas>(30,150,SIM_WIDTH,SIM_HEIGHT),
std::make_unique<corsim::ChartJSHandler>());
//Code to randomly generate certain numbers, which is done by using certain distributions
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<double> dist_w(1.0, SIM_WIDTH);
std::uniform_real_distribution<double> dist_h(1.0, SIM_HEIGHT);
std::uniform_real_distribution<double> dist_dx(-1.0, 1.0);
std::uniform_real_distribution<double> dist_dy(-1.0, 1.0);
for (int i = 0; i<SUBJECT_COUNT; ++i)
{
double x = dist_w(mt); //Randomly generate x position
double y = dist_h(mt); //Randomly generate y position
corsim::Subject su(x,y,SUBJECT_RADIUS,false, false);
su.set_dx(dist_dx(mt));
su.set_dy(dist_dy(mt));
if(i == SUBJECT_COUNT-1)
{
su.infect();
}
s.add_subject(std::move(su));
}
s.run();
}