Commit d46c228c authored by jlopez's avatar jlopez
Browse files

Parse input argv

parent 8ff32bd4
......@@ -3,7 +3,7 @@ project(Population)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES src/main.cpp src/sources/Population.cpp src/headers/Population.h src/sources/Parameters.cpp src/headers/Parameters.h src/sources/GMatrix.cpp src/headers/GMatrix.h src/sources/GRandom.cpp src/headers/GRandom.h src/headers/Utils.h src/sources/DynamicSave.cpp src/headers/DynamicSave.h src/sources/Rescuers.cpp src/headers/Rescuers.h)
set(SOURCE_FILES src/main.cpp src/sources/Population.cpp src/headers/Population.h src/sources/Parameters.cpp src/headers/Parameters.h src/sources/GMatrix.cpp src/headers/GMatrix.h src/sources/GRandom.cpp src/headers/GRandom.h src/headers/Utils.h src/sources/DynamicSave.cpp src/headers/DynamicSave.h src/sources/Rescuers.cpp src/headers/Rescuers.h src/sources/InputParser.cpp src/headers/InputParser.h)
add_executable(Population ${SOURCE_FILES})
find_package(GSL REQUIRED)
......
//
// Created by jimmy on 05/10/17.
//
#ifndef POPULATION_INPUTPARSER_H
#define POPULATION_INPUTPARSER_H
#include <string>
#include <vector>
class InputParser {
public:
InputParser (int &argc, char **argv);
virtual ~InputParser() = default;
const std::string& getCmdOption(const std::string &option) const;
bool cmdOptionExists(const std::string &option) const;
private:
std::vector <std::string> m_tokens;
};
#endif //POPULATION_INPUTPARSER_H
......@@ -33,6 +33,18 @@ public:
#endif
}
static void showUsage() {
std::cerr << "Usage: \n"
<< "\t-h\t\tShow this help message\n"
<< "\t-i INPUT\tSpecify the input path\n"
<< "\t-o OUTPUT\tSpecify the output path\n"
<< "\t-g MAX_GENO\tSpecify the max genotype\toptional & default 500\n"
<< "\t-m MATRIX\tSpecify the input matrix path\tpath to matA.dat, matSb.dat & vectxo.dat\n"
<< std::endl;
exit(-1);
}
};
#endif //POPULATION_UTILS_H
#include <iostream>
#include "headers/Population.h"
#include "headers/Parameters.h"
#include "headers/GMatrix.h"
#include "headers/GRandom.h"
#include "headers/Utils.h"
#include "headers/DynamicSave.h"
#include "headers/Rescuers.h"
#include <cmath>
#include <fstream>
#include "headers/InputParser.h"
int main(int argc, char *argv[]) {
int main() {
InputParser input(argc, argv);
const bool SAVE_DYN = false;
if(input.cmdOptionExists("-h") || input.cmdOptionExists("--help")){
Utils::showUsage();
}
const bool save_output_simulation = true;
std::string file;
if(input.cmdOptionExists("-i")) {
file = input.getCmdOption("-i");
} else {
Utils::showUsage();
}
const bool debug = false;
std::string output;
bool save_output_simulation = true;
if(input.cmdOptionExists("-o")) {
output = input.getCmdOption("-o");
} else {
save_output_simulation = false;
}
const unsigned long MAX_GENO = 500;
unsigned long MAX_GENO = 500;
if(input.cmdOptionExists("-g")) {
MAX_GENO = std::stoul(input.getCmdOption("-g"));
}
const int PARAM_INPUT = 16;
std::string matrix;
if(input.cmdOptionExists("-m")) {
matrix = input.getCmdOption("-m");
} else {
Utils::showUsage();
}
const std::string file = "/home/jimmy/jimmy/projets/guillaume/old_src/paramC.dat";
const bool SAVE_DYN = false;
const std::string output = "/home/jimmy/Bureau/";
std::cout << "Start" << std::endl;
Parameters param(SAVE_DYN, file);
GMatrix A("/home/jimmy/jimmy/projets/guillaume/old_src/matA.dat", param.getNa(), param.getN(), true);
GMatrix Sb("/home/jimmy/jimmy/projets/guillaume/old_src/matSb.dat", param.getN(), param.getN(), false);
GMatrix x0("/home/jimmy/jimmy/projets/guillaume/old_src/vectxo.dat", param.getN(), 1, false);
GMatrix A(matrix+Utils::separator()+"matA.dat", param.getNa(), param.getN(), true);
GMatrix Sb(matrix+Utils::separator()+"matSb.dat", param.getN(), param.getN(), false);
GMatrix x0(matrix+Utils::separator()+"vectxo.dat", param.getN(), 1, false);
GRandom grd;
......@@ -41,7 +60,7 @@ int main() {
for(unsigned long i_rep = 0; i_rep < param.getN_rep(); i_rep++) {
std::cout << "i_rep: " << i_rep << std::endl;
//std::cout << "i_rep: " << i_rep << std::endl;
Population pop(MAX_GENO, param.getN());
pop.setng(1);
......@@ -170,5 +189,7 @@ int main() {
}
std::cout << "Finish" << std::endl;
return 0;
}
\ No newline at end of file
//
// Created by jimmy on 05/10/17.
//
#include "../headers/InputParser.h"
#include <algorithm>
InputParser::InputParser(int &argc, char **argv) {
for (int i=1; i < argc; ++i)
m_tokens.push_back(std::string(argv[i]));
}
const std::string &InputParser::getCmdOption(const std::string &option) const {
std::vector<std::string>::const_iterator itr;
itr = std::find(m_tokens.begin(), m_tokens.end(), option);
if (itr != m_tokens.end() && ++itr != m_tokens.end()){
return *itr;
}
static const std::string empty_string;
return empty_string;
}
bool InputParser::cmdOptionExists(const std::string &option) const {
return std::find(m_tokens.begin(), m_tokens.end(), option)
!= m_tokens.end();
}
......@@ -28,7 +28,7 @@ Parameters::Parameters(bool dynamic, const std::string file) {
} else {
if(params.size() != 14) {
//TODO error
exit(1);
//exit(1);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment