Beispiel #1
0
bool parse_config(const char* config_file, Arguments& args) {
  std::ifstream config_stream(config_file);
  if (!config_stream) {
    fprintf(stderr, "ERROR: cannot find config file\n");
    return false;
  }
  config_stream >> args.config; // parse JSON
  return true;
}
Beispiel #2
0
void ConfigTable::parse_config_file(const std::string& config_file)
{
  std::ifstream config_stream(config_file.c_str());
  if(!config_stream)
  {
    std::clog << "ConfigTable: Error: Could not open file " << config_file
              << "." << std::endl;
    return;
  }
  po::store(po::parse_config_file(config_stream, options.options), options.variables);
  notify(options.variables);
}
void FFM::avito_init_params(const std::string & data_conf_path)
{
    bool debug = false;

    std::ifstream config_stream((char*)data_conf_path.c_str(), std::ios::in);

    std::string line;
    std::string token;
    std::string header;

    // Read header:
    for(unsigned int i = 0; i < 8; i++){
      getline(config_stream, line);
    }

    std::istringstream line_stream(line);
    while(line_stream){	if (!getline( line_stream, token, ':' )) break;	}
    if(debug) std::cout << "Default hash: " << token << std::endl;

    bool useDefaultHash = ( token != "false" ) ? true : false;
    if ( useDefaultHash ){
      num_features = atoi(token.c_str());
    }

    getline(config_stream, line);
    getline(config_stream, line);

    unsigned int feature_count = 0;
    while(getline(config_stream, line)){
      std::istringstream hash_stream(line);
      getline( hash_stream, header, ':' );
      getline( hash_stream, token, ':' );
      
      num_fields++;
      if ( !useDefaultHash ) {
	num_features += atoi(token.c_str());
      }
      if(debug) std::cout << header << ": " << token << " Current inputDim: " << num_features << std::endl;
      feature_count++;
    }

    if(debug) std::cout << "Num-features: " << num_features << std::endl;
    
    initParams();    
}
Beispiel #4
0
Imbalancer::Imbalancer(const std::string config_path)
    : Imbalancer()
{
    if (config_path.length()) {
        char hostname[HOST_NAME_MAX + 1];
        hostname[HOST_NAME_MAX] = '\0';
        if (gethostname(hostname, HOST_NAME_MAX)) {
            throw geopm::Exception("gethostname():", errno ? errno : GEOPM_ERROR_RUNTIME, __FILE__, __LINE__);
        }
        std::ifstream config_stream(config_path, std::ifstream::in);
        std::string this_host;
        double this_frac;
        while(config_stream.good()) {
            config_stream >> this_host >> this_frac;
            if (strncmp(hostname, this_host.c_str(), HOST_NAME_MAX) == 0) {
                frac(this_frac);
            }
        }
        config_stream.close();
    }
Beispiel #5
0
    rapidjson::Document parseJSONConfig(const std::string &config_filename) {
        rapidjson::Document config_doc;

        FILE *config_file_ptr = fopen(config_filename.c_str(), "r");

        if (!config_file_ptr) {
            throw std::runtime_error(
                    (boost::format("Cannot open configuration input file %s.") % config_filename).str()
            );
        }
        char readBuffer[65536];
        rapidjson::FileReadStream config_stream(config_file_ptr, readBuffer, sizeof(readBuffer));
        config_doc.ParseStream(config_stream);
        if (config_doc.HasParseError()) {
            throw std::runtime_error(
                    (boost::format("Error parsing %s (offset %d):\t%s") % config_filename % config_doc.GetErrorOffset() % rapidjson::GetParseError_En(config_doc.GetParseError())).str()
            );
        }
        fclose(config_file_ptr);
        return config_doc;
    }
Beispiel #6
0
    rapidjson::Document parseJSONConfig(const std::string &config_filename) {
        rapidjson::Document config_doc;

        FILE* config_file_ptr = fopen(config_filename.c_str(), "r");

        if (!config_file_ptr) {
            throw std::runtime_error(
                (boost::format("Cannot open configuration input file %s.") % config_filename).str()
            );
        }
        char readBuffer[65536];
        rapidjson::FileReadStream config_stream(config_file_ptr, readBuffer, sizeof(readBuffer));
        config_doc.ParseStream(config_stream);
        fclose(config_file_ptr);

        if (!config_doc.IsObject()) {
            throw std::runtime_error(
                (boost::format("Invalid configuration file: %s") % config_filename).str()
            );
        }

        return config_doc;
    }
void FFM::read_conf(const std::string &conf_path)
{
  bool debug = false;

  std::ifstream config_stream((char*)conf_path.c_str(), std::ios::in);
  std::istringstream line_stream;

  std::string line;
  std::string token;

  // Read header:
  getline(config_stream, line);

  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  parameters.num_factors = atoi(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();

  if(debug) std::cout << "num_factors: " << token << " " <<  parameters.num_factors << std::endl;

  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  parameters.stepsize = atof(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();

  if(debug) std::cout << "stepsize: " << token << " " <<  parameters.stepsize << std::endl;

  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  parameters.stepsize_decay = atof(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();

  if(debug) std::cout << "stepsize_decay: " << token << " " <<  parameters.stepsize_decay << std::endl;

  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  parameters.l1_lambda_v = atof(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();
  
  if(debug) std::cout << "l1_lambda_v:" << token << " " <<  parameters.l1_lambda_v << std::endl;

  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  parameters.l2_lambda_v = atof(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();

  if(debug) std::cout << "l2_lambda_v:" << token << " " <<  parameters.l2_lambda_v << std::endl;

  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  parameters.epochs = atoi(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();

  if(debug) std::cout << "epochs:" << token << " " <<  parameters.epochs << std::endl;
  
  //Read parameters:
  getline(config_stream, line);
  line_stream.str(line);
  while(line_stream){	if (!getline( line_stream, token, '=' )) break;	}
  num_features = atoi(token.c_str());

  line_stream.str(std::string());
  line_stream.clear();
  
  if(debug) std::cout << "num_features:" << token << " " <<  num_features << std::endl;

}
Beispiel #8
0
// generate boost::program_options object for the routing part
inline unsigned GenerateServerProgramOptions(const int argc,
                                             const char *argv[],
                                             ServerPaths &paths,
                                             std::string &ip_address,
                                             int &ip_port,
                                             int &requested_num_threads,
                                             bool &use_shared_memory,
                                             bool &trial,
                                             int &max_locations_distance_table,
                                             int &max_locations_map_matching)
{
    // declare a group of options that will be allowed only on command line
    boost::program_options::options_description generic_options("Options");
    generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
        "config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])
                        ->default_value("server.ini"),
        "Path to a configuration file")(
        "trial", boost::program_options::value<bool>(&trial)->implicit_value(true),
        "Quit after initialization");

    // declare a group of options that will be allowed both on command line
    // as well as in a config file
    boost::program_options::options_description config_options("Configuration");
    config_options.add_options()(
        "hsgrdata", boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
        ".hsgr file")("nodesdata",
                      boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
                      ".nodes file")(
        "edgesdata", boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
        ".edges file")("geometry",
                       boost::program_options::value<boost::filesystem::path>(&paths["geometries"]),
                       ".geometry file")(
        "ramindex", boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
        ".ramIndex file")(
        "fileindex", boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
        "File index file")(
        "namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
        ".names file")("timestamp",
                       boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
                       ".timestamp file")(
        "ip,i", boost::program_options::value<std::string>(&ip_address)->default_value("0.0.0.0"),
        "IP address")("port,p", boost::program_options::value<int>(&ip_port)->default_value(5000),
                      "TCP/IP port")(
        "threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
        "Number of threads to use")(
        "shared-memory,s",
        boost::program_options::value<bool>(&use_shared_memory)->implicit_value(true),
        "Load data from shared memory")(
        "max-table-size,m",
        boost::program_options::value<int>(&max_locations_distance_table)->default_value(1000000),
        "Max. locations supported in distance table query")(
        "max-matching-size,m",
        boost::program_options::value<int>(&max_locations_map_matching)->default_value(2),
        "Max. locations supported in map matching query");

    // hidden options, will be allowed both on command line and in config
    // file, but will not be shown to the user
    boost::program_options::options_description hidden_options("Hidden options");
    hidden_options.add_options()(
        "base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
        "base path to .osrm file");

    // positional option
    boost::program_options::positional_options_description positional_options;
    positional_options.add("base", 1);

    // combine above options for parsing
    boost::program_options::options_description cmdline_options;
    cmdline_options.add(generic_options).add(config_options).add(hidden_options);

    boost::program_options::options_description config_file_options;
    config_file_options.add(config_options).add(hidden_options);

    boost::program_options::options_description visible_options(
        boost::filesystem::basename(argv[0]) + " <base.osrm> [<options>]");
    visible_options.add(generic_options).add(config_options);

    // parse command line options
    boost::program_options::variables_map option_variables;
    boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
                                      .options(cmdline_options)
                                      .positional(positional_options)
                                      .run(),
                                  option_variables);

    if (option_variables.count("version"))
    {
        SimpleLogger().Write() << g_GIT_DESCRIPTION;
        return INIT_OK_DO_NOT_START_ENGINE;
    }

    if (option_variables.count("help"))
    {
        SimpleLogger().Write() << visible_options;
        return INIT_OK_DO_NOT_START_ENGINE;
    }

    boost::program_options::notify(option_variables);

    // parse config file
    auto path_iterator = paths.find("config");
    if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
        !option_variables.count("base"))
    {
        SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
        std::string ini_file_contents = read_file_lower_content(path_iterator->second);
        std::stringstream config_stream(ini_file_contents);
        boost::program_options::store(parse_config_file(config_stream, config_file_options),
                                      option_variables);
        boost::program_options::notify(option_variables);
        return INIT_OK_START_ENGINE;
    }

    if (1 > requested_num_threads)
    {
        throw osrm::exception("Number of threads must be a positive number");
    }

    if (!use_shared_memory && option_variables.count("base"))
    {
        return INIT_OK_START_ENGINE;
    }
    if (use_shared_memory && !option_variables.count("base"))
    {
        return INIT_OK_START_ENGINE;
    }
    if (1 > max_locations_distance_table)
    {
        throw osrm::exception("Max location for distance table must be a positive number");
    }
    if (2 > max_locations_map_matching)
    {
        throw osrm::exception("Max location for map matching must be at least two");
    }

    SimpleLogger().Write() << visible_options;
    return INIT_OK_DO_NOT_START_ENGINE;
}
return_code
ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &extractor_config)
{
    // declare a group of options that will be allowed only on command line
    boost::program_options::options_description generic_options("Options");
    generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
        "config,c", boost::program_options::value<boost::filesystem::path>(
                        &extractor_config.config_file_path)->default_value("extractor.ini"),
        "Path to a configuration file.");

    // declare a group of options that will be allowed both on command line and in config file
    boost::program_options::options_description config_options("Configuration");
    config_options.add_options()("profile,p",
                                 boost::program_options::value<boost::filesystem::path>(
                                     &extractor_config.profile_path)->default_value("profile.lua"),
                                 "Path to LUA routing profile")(
        "threads,t",
        boost::program_options::value<unsigned int>(&extractor_config.requested_num_threads)
            ->default_value(tbb::task_scheduler_init::default_num_threads()),
        "Number of threads to use");

    // hidden options, will be allowed both on command line and in config file, but will not be
    // shown to the user
    boost::program_options::options_description hidden_options("Hidden options");
    hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
                                                &extractor_config.input_path),
                                 "Input file in .osm, .osm.bz2 or .osm.pbf format");

    // positional option
    boost::program_options::positional_options_description positional_options;
    positional_options.add("input", 1);

    // combine above options for parsing
    boost::program_options::options_description cmdline_options;
    cmdline_options.add(generic_options).add(config_options).add(hidden_options);

    boost::program_options::options_description config_file_options;
    config_file_options.add(config_options).add(hidden_options);

    boost::program_options::options_description visible_options(
        boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
    visible_options.add(generic_options).add(config_options);

    // parse command line options
    try
    {
        boost::program_options::variables_map option_variables;
        boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
                                          .options(cmdline_options)
                                          .positional(positional_options)
                                          .run(),
                                      option_variables);
        if (option_variables.count("version"))
        {
            SimpleLogger().Write() << g_GIT_DESCRIPTION;
            return return_code::exit;
        }

        if (option_variables.count("help"))
        {
            SimpleLogger().Write() << visible_options;
            return return_code::exit;
        }

        boost::program_options::notify(option_variables);

        // parse config file
        if (boost::filesystem::is_regular_file(extractor_config.config_file_path))
        {
            SimpleLogger().Write()
                << "Reading options from: " << extractor_config.config_file_path.string();
            std::string ini_file_contents =
                read_file_lower_content(extractor_config.config_file_path);
            std::stringstream config_stream(ini_file_contents);
            boost::program_options::store(parse_config_file(config_stream, config_file_options),
                                          option_variables);
            boost::program_options::notify(option_variables);
        }

        if (!option_variables.count("input"))
        {
            SimpleLogger().Write() << visible_options;
            return return_code::exit;
        }
    }
    catch (std::exception &e)
    {
        SimpleLogger().Write(logWARNING) << e.what();
        return return_code::fail;
    }

    return return_code::ok;
}
int main(int argc, char* argv[]) {
  //************************************************
  // Initialize environments
  //************************************************
  MPI_Init(&argc,&argv);
  int rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  // variables to be filled by command line and/or input file values
  std::string inputFile;
  double priorMean;
  double priorVar;
  std::string dataString;
  likelihoodData dat;

  po::options_description generic("Generic options");
  generic.add_options()
    ("help,h", "Produce help message");

  po::options_description config("GaussianMean1DRegression specific options");
  config.add_options()
    ("GaussianMean1DRegression_priorMean", po::value<double>(&priorMean)->default_value(priorMeanODV), "Prior Mean")
    ("GaussianMean1DRegression_priorVar", po::value<double>(&priorVar)->default_value(priorVarODV), "Prior Standard Deviation")
    ("GaussianMean1DRegression_samplingVar", po::value<double>(&dat.samplingVar)->default_value(samplingVarODV), "Data Sampling Standard Deviation")
    ("GaussianMean1DRegression_dataSet", po::value<std::string>(&dataString)->default_value(dataSetODV), "Calibration Data");

  po::options_description hidden("hidden options");
  hidden.add_options()
    ("input_file", po::value<std::string>(&inputFile)->default_value(inputFileODV), "QUESO configuration file");
  po::positional_options_description p;
  p.add("input_file", -1);

  po::options_description cmdline_options;
  cmdline_options.add(generic).add(config).add(hidden);
  po::options_description visible("Allowed options");
  visible.add(generic).add(config);

  // parse command line for help, inputFile, and any config options present
  po::variables_map vm;
  try {
    po::store(po::command_line_parser(argc, argv).
	      options(cmdline_options).positional(p).run(), vm);
  } catch (std::exception& e) {
    if(rank == 0)
      std::cout<<"Caught exception: "<<e.what()<<std::endl;
    MPI_Abort(MPI_COMM_WORLD, -1);
  }
  po::notify(vm);

  // if help is requested, print out usgae and visible options, then exit cleanly
  if (vm.count("help")) {
    if (rank == 0) {
      std::cout << "Usage: " << argv[0] << " <input_file (=" << inputFileODV
        << ")>" << std::endl;
      std::cout << visible << std::endl;
    }
    MPI_Finalize();
    return 1;
  }

  // parse the input file to get GaussianMean1DRegression option values
  std::ifstream config_stream(inputFile.c_str());
  try {
    po::store(po::parse_config_file(config_stream, config, true), vm);
  } catch (std::exception& e) {
    if(rank == 0)
      std::cout << "Caught exception: " << e.what() << std::endl;
    MPI_Abort(MPI_COMM_WORLD, -1);
  }
  po::notify(vm);
  config_stream.close();

   // parse the data string into a vector of doubles and store them in dat.dataSet
  std::istringstream iss(dataString);
  std::copy(std::istream_iterator<double>(iss), std::istream_iterator<double>(), std::back_inserter(dat.dataSet));

  // output the option values that will be used by QUESO
  if (rank == 0) {
    std::cout << "QUESO options file: " << inputFile << std::endl;
    std::cout << "Read option GaussianMean1DRegression_priorMean: "
      << priorMean << std::endl;
    std::cout << "Read option GaussianMean1DRegression_priorVar: "
      << priorVar << std::endl;
    std::cout << "Read option GaussianMean1DRegression_samplingVar: "
      << dat.samplingVar << std::endl;
    std::cout << "Read option GaussianMean1DRegression_dataSet: ";
    for (unsigned int i = 0; i < dat.dataSet.size(); i++)
      std::cout << dat.dataSet[i] << " ";
    std::cout << std::endl;
  }

   // initilize environment
  QUESO::FullEnvironment env(MPI_COMM_WORLD,  // MPI communicator
			     inputFile.c_str(),  // input file name
			     "",                 // name prefix
			     NULL );             // alt options

  // reset seed to value in input file + fullRank
  env.resetSeed(env.seed() + env.fullRank());

  // Work routine, with GSL
  GaussianMean1DRegressionCompute<QUESO::GslVector, QUESO::GslMatrix>(env,
      priorMean, priorVar, dat);

  MPI_Finalize();

  return 0;
}
Beispiel #11
0
//------------------------------------------------------------------------------
// Purpose    : Parse the command line and config file
// Parameters : argc, argv
// Returns    : Filled-in Options structure
//------------------------------------------------------------------------------
Options GetOptions(int argc, char * const argv[])
{

  // Read command line options
  Options opt;
  po::options_description desc("Allowed options");
  desc.add_options()
  ("help,h", "Show this message")
  ("callsign", po::value<string>(&opt.callsign), "Sender's Callsign")
  ("sequence", po::value<int>(&opt.sequence)->default_value(1),
   "Message Sequence Number")
  ("user", po::value<string>(&opt.user), "Google User Name")
  ("password", po::value<string>(&opt.password), "Google Password")
  ("from", po::value<string>(&opt.from), "FM Addee")
  ("to", po::value<string>(&opt.to), "TO Addee")
  ("info", po::value<string>(&opt.info), "INFO Addee")
  ("subject", po::value<string>(&opt.subject), "Message Subject")
  ("spreadsheet-name", po::value<string>(&opt.spreadsheet_name),
   "Spreadsheet Name")
  ("spreadsheet-id", po::value<string>(&opt.spreadsheet_id), "Spreadsheet ID")
  ("worksheet-name", po::value<string>(&opt.worksheet_name), "Worksheet Name")
  ("worksheet-id", po::value<string>(&opt.worksheet_id), "Worksheet ID")
  ;

  // Config file
  string config_file = ExpandDirectory("~/.thirteenrc");
  fs::path config_path(config_file);

  // Load configuration
  po::variables_map vm;
  try {
    po::store(po::parse_command_line(argc, argv, desc), vm);
    if(fs::exists(config_path)) {
      ifstream config_stream(config_file.c_str());
      po::store(po::parse_config_file(config_stream, desc), vm);
    }
  } catch(exception& e) {
    cerr << "Unable to parse command line: " << e.what() << endl;
    exit(1);
  }
  po::notify(vm);
  if (vm.count("help")) {
    cout << desc << "\n";
    exit(1);
  }

  // Test for errors
  vector<string> errors;
  if(!(opt.spreadsheet_name.size() || opt.spreadsheet_id.size())) {
    errors.push_back("Either a spreadsheet name or a spreadsheet"
                     " id must be specified");
  }
  if(!opt.user.size()) {
    errors.push_back("No Google Docs user specified");
  }
  if(!opt.password.size()) {
    errors.push_back("No Google Docs password specified");
  }
  if(!opt.from.size()) {
    errors.push_back("No FM addee specified");
  }
  if(!opt.to.size()) {
    errors.push_back("No TO addee specified");
  }
  if(!opt.info.size()) {
    errors.push_back("No INFO addee specified");
  }
  if(!opt.subject.size()) {
    errors.push_back("No subject specified");
  }
  if(errors.size()) {
    cout << "Error:" << endl;
    BOOST_FOREACH(string error, errors) {
      cout << "  " << error << endl;
    }
    exit(1);
  }
Beispiel #12
0
int main (int argc, char *argv[]) {
    try {
        LogPolicy::GetInstance().Unmute();
        double startup_time = get_timestamp();

        boost::filesystem::path config_file_path, input_path, profile_path;
        int requested_num_threads;

        // declare a group of options that will be allowed only on command line
        boost::program_options::options_description generic_options("Options");
        generic_options.add_options()
            ("version,v", "Show version")
            ("help,h", "Show this help message")
            ("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("extractor.ini"),
                  "Path to a configuration file.");

        // declare a group of options that will be allowed both on command line and in config file
        boost::program_options::options_description config_options("Configuration");
        config_options.add_options()
            ("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
                "Path to LUA routing profile")
            ("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
                "Number of threads to use");

        // hidden options, will be allowed both on command line and in config file, but will not be shown to the user
        boost::program_options::options_description hidden_options("Hidden options");
        hidden_options.add_options()
            ("input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
                "Input file in .osm, .osm.bz2 or .osm.pbf format");

        // positional option
        boost::program_options::positional_options_description positional_options;
        positional_options.add("input", 1);

        // combine above options for parsing
        boost::program_options::options_description cmdline_options;
        cmdline_options.add(generic_options).add(config_options).add(hidden_options);

        boost::program_options::options_description config_file_options;
        config_file_options.add(config_options).add(hidden_options);

        boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
        visible_options.add(generic_options).add(config_options);

        // parse command line options
        boost::program_options::variables_map option_variables;
        boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
            options(cmdline_options).positional(positional_options).run(), option_variables);

        if(option_variables.count("version")) {
            SimpleLogger().Write() << g_GIT_DESCRIPTION;
            return 0;
        }

        if(option_variables.count("help")) {
            SimpleLogger().Write() << visible_options;
            return 0;
        }

        boost::program_options::notify(option_variables);

        // parse config file
        if(boost::filesystem::is_regular_file(config_file_path)) {
            SimpleLogger().Write() << "Reading options from: " << config_file_path.c_str();
            std::string config_str;
            PrepareConfigFile( config_file_path.c_str(), config_str );
            std::stringstream config_stream( config_str );
            boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables);
            boost::program_options::notify(option_variables);
        }

        if(!option_variables.count("input")) {
            SimpleLogger().Write(logWARNING) << "No input file specified";
            SimpleLogger().Write() << visible_options;
            return -1;
        }

        if(1 > requested_num_threads) {
            SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
            return -1;
        }

        SimpleLogger().Write() << "Input file: " << input_path.filename().string();
        SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
        SimpleLogger().Write() << "Threads: " << requested_num_threads;

        /*** Setup Scripting Environment ***/
        ScriptingEnvironment scriptingEnvironment(profile_path.c_str());

        omp_set_num_threads( std::min( omp_get_num_procs(), requested_num_threads) );

        bool file_has_pbf_format(false);
        std::string output_file_name(input_path.c_str());
        std::string restrictionsFileName(input_path.c_str());
        std::string::size_type pos = output_file_name.find(".osm.bz2");
        if(pos==std::string::npos) {
            pos = output_file_name.find(".osm.pbf");
            if(pos!=std::string::npos) {
                file_has_pbf_format = true;
            }
        }
        if(pos==std::string::npos) {
            pos = output_file_name.find(".pbf");
            if(pos!=std::string::npos) {
                file_has_pbf_format = true;
            }
        }
        if(pos!=std::string::npos) {
            output_file_name.replace(pos, 8, ".osrm");
            restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
        } else {
            pos=output_file_name.find(".osm");
            if(pos!=std::string::npos) {
                output_file_name.replace(pos, 5, ".osrm");
                restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
            } else {
                output_file_name.append(".osrm");
                restrictionsFileName.append(".osrm.restrictions");
            }
        }

        StringMap stringMap;
        ExtractionContainers externalMemory;

        stringMap[""] = 0;
        extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
        BaseParser* parser;
        if(file_has_pbf_format) {
            parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
        } else {
            parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
        }

        if(!parser->ReadHeader()) {
            throw OSRMException("Parser not initialized!");
        }
        SimpleLogger().Write() << "Parsing in progress..";
        double parsing_start_time = get_timestamp();
        parser->Parse();
        SimpleLogger().Write() << "Parsing finished after " <<
            (get_timestamp() - parsing_start_time) <<
            " seconds";

        if( externalMemory.all_edges_list.empty() ) {
            SimpleLogger().Write(logWARNING) << "The input data is empty, exiting.";
            return -1;
        }

        externalMemory.PrepareData(output_file_name, restrictionsFileName);

        delete parser;
        delete extractCallBacks;

        SimpleLogger().Write() <<
            "extraction finished after " << get_timestamp() - startup_time <<
            "s";

         SimpleLogger().Write() << "To prepare the data for routing, run: "
            << "./osrm-prepare " << output_file_name << std::endl;

    } catch(boost::program_options::too_many_positional_options_error& e) {
        SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
        return -1;
    } catch(boost::program_options::error& e) {
        SimpleLogger().Write(logWARNING) << e.what();
        return -1;
    } catch(std::exception & e) {
        SimpleLogger().Write(logWARNING) << "Unhandled exception: " << e.what();
        return -1;
    }
    return 0;
}
Beispiel #13
0
void init_gamedata(gamedata &g){

  //--JAM: Read from config file
  ap_home = getHomeDir(ap_home);
  string filename((string)ap_home);
  filename += "apricots.cfg";
  printf("Filename: %s\n", filename.c_str());
  ifstream config_stream(filename.c_str());
  string config;
  if (!config_stream.fail()){
    // Read config file line by line
    char line[256];
    while (!config_stream.eof()){
      config_stream.getline(line, 255);
      if (line[0] != '#'){
        config.append(line);
        config += "\n";
      }
    }
  }else{
  // Config file not found
    config = "\n";
  }
  config_stream.close();

  // Number of planes (1-6)
  g.planes = getConfig(config, "NUM_PLANES", 2, 1, 6);
  
  // Number of players (1 or 2)
  g.players = getConfig(config, "NUM_HUMANS", 1, 1, 2);
  // Error check
  if (g.players > g.planes){
    cerr << "Invalid configuration in apricots.cfg" << endl;
    cerr << "Number of human players cannot exceed number of planes" << endl;
    exit(EXIT_FAILURE);
  }

  // Mission
  // 0/1 means winner is first to reach targetscore and reach airbase
  // 1 makes score reduce to targetscore-200 upon dying (so must land)
  // 2 means winner is first to destroy all enemy airbases and reach airbase
  g.mission = getConfig(config, "MISSION", 0, 0, 2);

  // Targetscore for missions 0/1
  g.targetscore = getConfig(config, "TARGET_SCORE", 1400, 100, 5000);

  // Planetypes: 1=Spitfire, 2=Jet, 3=Stealth Bomber
  g.planeinfo[1].planetype = getConfig(config, "PLANE1", 1, 1, 3);
  g.planeinfo[2].planetype = getConfig(config, "PLANE2", 1, 1, 3);
  g.planeinfo[3].planetype = getConfig(config, "PLANE3", 1, 1, 3);
  g.planeinfo[4].planetype = getConfig(config, "PLANE4", 1, 1, 3);
  g.planeinfo[5].planetype = getConfig(config, "PLANE5", 1, 1, 3);
  g.planeinfo[6].planetype = getConfig(config, "PLANE6", 1, 1, 3);


  // Basetype: See create_airbases in setup.cpp
  g.planeinfo[1].basetype = getConfig(config, "BASE1", 1, 1, 7);
  g.planeinfo[2].basetype = getConfig(config, "BASE2", 1, 1, 7);
  g.planeinfo[3].basetype = getConfig(config, "BASE3", 1, 1, 7);
  g.planeinfo[4].basetype = getConfig(config, "BASE4", 1, 1, 7);
  g.planeinfo[5].basetype = getConfig(config, "BASE5", 1, 1, 7);
  g.planeinfo[6].basetype = getConfig(config, "BASE6", 1, 1, 7);


  // Control: 1=Player 1, 2=Player 2, 0=AI
  g.planeinfo[1].control = getConfig(config, "CONTROL1", 1, 0, 2);
  g.planeinfo[2].control = getConfig(config, "CONTROL2", 0, 0, 2);
  g.planeinfo[3].control = getConfig(config, "CONTROL3", 0, 0, 2);
  g.planeinfo[4].control = getConfig(config, "CONTROL4", 0, 0, 2);
  g.planeinfo[5].control = getConfig(config, "CONTROL5", 0, 0, 2);
  g.planeinfo[6].control = getConfig(config, "CONTROL6", 0, 0, 2);
  // Error check
  int count[3];
  count[0] = 0;
  count[1] = 0;
  count[2] = 0;
  for (int i=1; i<=g.planes; i++){
  count[g.planeinfo[i].control]++;
  }
  if (count[1] != 1){
    cerr << "Invalid configuration in apricots.cfg" << endl;
    cerr << "Invalid control selection for player 1" << endl;
    exit(EXIT_FAILURE);
  }
  if (count[2] != (g.players-1)){
    cerr << "Invalid configuration in apricots.cfg" << endl;
    cerr << "Invalid control selection for player 2" << endl;
    exit(EXIT_FAILURE);
  }
  for (int j=g.planes+1;j<=6;j++){
  if (g.planeinfo[j].control > 0){
      cerr << "Invalid configuration in apricots.cfg" << endl;
      cerr << "Human controls specified for non-playing plane" << endl;
      exit(EXIT_FAILURE);
    }
  }
  // Number of towerblocks
  g.towers = getConfig(config, "NUM_TOWERS", 5, 0, 30);

  // Number of neutral anti-aircraft guns
  g.guns = getConfig(config, "NUM_GUNS", 5, 0, 20);
  
  // Number of other buildings
  g.buildings = getConfig(config, "NUM_BUILDINGS", 20, 0 ,50);
  
  // Number of trees (max)
  g.trees = getConfig(config, "NUM_TREES", 50, 0, 100); 

  // Draks: 0=Never, 1=5% probability, 2=Always
  string drakval = getConfig(config, "DRAK", "sometimes");
  if (!drakval.compare("always"))
  {
    g.drakoption = 2;
  }
  else if (!drakval.compare("sometimes"))
  {
    g.drakoption = 1;
  }
  else
  {
    g.drakoption = 0;
  }

  g.playerJoy[0] = -1;
  g.playerJoy[1] = -1;
  g.playerJoyBut[0][0] = -1;
  g.playerJoyBut[0][1] = -1;
  g.playerJoyBut[0][2] = -1;
  g.playerJoyBut[1][0] = -1;
  g.playerJoyBut[1][1] = -1;
  g.playerJoyBut[1][2] = -1;

  // Score bar position
  g.scoreBarPos = getConfig(config, "SCOREBAR_POS", 0, 0, 1); 
}
Beispiel #14
0
 bool ParseString(const std::string &config_string) {
     std::stringstream config_stream(config_string);
     return parser_.Parse(&config_stream, &config_);
 }