A config object
This commit is contained in:
parent
f323248610
commit
e47864752a
@ -192,10 +192,10 @@ int DLASystem::checkStick() {
|
||||
|
||||
|
||||
// constructor
|
||||
DLASystem::DLASystem(std::ofstream csv_out, double stickProbability)
|
||||
: stickProbability(stickProbability), csv_out(std::move(csv_out)) {
|
||||
DLASystem::DLASystem(Config config)
|
||||
: stickProbability(config.stickProbability), csv_out(std::move(config.csv)), endNum(config.maxParticles) {
|
||||
cout << "creating system, gridSize " << gridSize << endl;
|
||||
endNum = 1000;
|
||||
rgen.setSeed(config.seed);
|
||||
|
||||
// allocate memory for the grid, remember to free the memory in destructor
|
||||
grid = new int *[gridSize];
|
||||
@ -210,9 +210,6 @@ DLASystem::DLASystem(std::ofstream csv_out, double stickProbability)
|
||||
|
||||
addRatio = 1.2; // how much bigger the addCircle should be, compared to cluster radius
|
||||
killRatio = 1.7; // how much bigger is the killCircle, compared to the addCircle
|
||||
|
||||
// this opens a logfile, if we want to...
|
||||
//logfile.open("opfile.txt");
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
11
DLASystem.h
11
DLASystem.h
@ -15,6 +15,15 @@
|
||||
#include "Particle.h"
|
||||
#include "rnd.h"
|
||||
|
||||
class Config {
|
||||
public:
|
||||
int seed;
|
||||
double stickProbability;
|
||||
std::ofstream csv;
|
||||
int maxParticles;
|
||||
Config(int argc, char **argv);
|
||||
};
|
||||
|
||||
class DLASystem {
|
||||
private:
|
||||
// these are private variables and functions that the user will not see
|
||||
@ -66,7 +75,7 @@ public:
|
||||
int lastParticleIsActive;
|
||||
|
||||
// constructor
|
||||
DLASystem(std::ofstream csv_out, double stickProbability);
|
||||
DLASystem(Config config);
|
||||
|
||||
// destructor
|
||||
~DLASystem();
|
||||
|
||||
32
mainDLA.cpp
32
mainDLA.cpp
@ -12,26 +12,32 @@ using std::endl;
|
||||
// this is a global pointer, which is how we access the system itself
|
||||
DLASystem *sys;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int seed;
|
||||
double stickProbability = 0.5;
|
||||
|
||||
if (argc != 3) {
|
||||
return 1;
|
||||
Config::Config(int argc, char **argv) {
|
||||
if (argc != 4) {
|
||||
exit(1);
|
||||
} else {
|
||||
seed = std::stoi(argv[1]);
|
||||
stickProbability = std::stod(argv[2]);
|
||||
this->seed = std::stoi(argv[1]);
|
||||
this->stickProbability = std::stod(argv[2]);
|
||||
this->maxParticles = std::stoi(argv[3]);
|
||||
|
||||
if (stickProbability <= 0 || stickProbability > 1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cout << "Seed: " << seed << ", Stick P: " << stickProbability << endl;
|
||||
|
||||
std::stringstream str;
|
||||
str << "./out-" << seed << '-' << stickProbability << ".csv";
|
||||
// Ensure the output file name contains all information required to replicate data
|
||||
str << "./out-" << seed << '-' << stickProbability << "-" << maxParticles << ".csv";
|
||||
std::ofstream csv_out(str.str());
|
||||
this->csv = std::move(csv_out);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Config config(argc, argv);
|
||||
cout << "Seed: " << config.seed << ", Stick P: " << config.stickProbability << endl;
|
||||
|
||||
// create the system
|
||||
sys = new DLASystem(std::move(csv_out), stickProbability);
|
||||
sys->setSeed(seed);
|
||||
sys = new DLASystem(std::move(config));
|
||||
sys->setRunning();
|
||||
|
||||
/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user