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
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

View File

@ -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();

View File

@ -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);
}
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;
std::stringstream str;
str << "./out-" << seed << '-' << stickProbability << ".csv";
std::ofstream csv_out(str.str());
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();
/*