A config object

This commit is contained in:
Joshua Coles 2023-02-20 09:36:47 +00:00
parent f323248610
commit e47864752a
3 changed files with 34 additions and 22 deletions

View File

@ -192,10 +192,10 @@ int DLASystem::checkStick() {
// constructor // constructor
DLASystem::DLASystem(std::ofstream csv_out, double stickProbability) DLASystem::DLASystem(Config config)
: stickProbability(stickProbability), csv_out(std::move(csv_out)) { : stickProbability(config.stickProbability), csv_out(std::move(config.csv)), endNum(config.maxParticles) {
cout << "creating system, gridSize " << gridSize << endl; cout << "creating system, gridSize " << gridSize << endl;
endNum = 1000; rgen.setSeed(config.seed);
// allocate memory for the grid, remember to free the memory in destructor // allocate memory for the grid, remember to free the memory in destructor
grid = new int *[gridSize]; 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 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 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 // destructor

View File

@ -15,6 +15,15 @@
#include "Particle.h" #include "Particle.h"
#include "rnd.h" #include "rnd.h"
class Config {
public:
int seed;
double stickProbability;
std::ofstream csv;
int maxParticles;
Config(int argc, char **argv);
};
class DLASystem { class DLASystem {
private: private:
// these are private variables and functions that the user will not see // these are private variables and functions that the user will not see
@ -66,7 +75,7 @@ public:
int lastParticleIsActive; int lastParticleIsActive;
// constructor // constructor
DLASystem(std::ofstream csv_out, double stickProbability); DLASystem(Config config);
// destructor // destructor
~DLASystem(); ~DLASystem();

View File

@ -12,26 +12,32 @@ using std::endl;
// this is a global pointer, which is how we access the system itself // this is a global pointer, which is how we access the system itself
DLASystem *sys; DLASystem *sys;
int main(int argc, char **argv) { Config::Config(int argc, char **argv) {
int seed; if (argc != 4) {
double stickProbability = 0.5; exit(1);
if (argc != 3) {
return 1;
} else { } else {
seed = std::stoi(argv[1]); this->seed = std::stoi(argv[1]);
stickProbability = std::stod(argv[2]); this->stickProbability = std::stod(argv[2]);
this->maxParticles = std::stoi(argv[3]);
if (stickProbability <= 0 || stickProbability > 1) {
exit(1);
}
std::stringstream str;
// 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);
} }
}
cout << "Seed: " << seed << ", Stick P: " << stickProbability << endl; int main(int argc, char **argv) {
Config config(argc, argv);
std::stringstream str; cout << "Seed: " << config.seed << ", Stick P: " << config.stickProbability << endl;
str << "./out-" << seed << '-' << stickProbability << ".csv";
std::ofstream csv_out(str.str());
// create the system // create the system
sys = new DLASystem(std::move(csv_out), stickProbability); sys = new DLASystem(std::move(config));
sys->setSeed(seed);
sys->setRunning(); sys->setRunning();
/* /*