Version: 1.0
config_data.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020, the GRAPHGEN contributors, as
2 // shown by the AUTHORS file. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6 
7 #include "config_data.h"
8 
9 #include <algorithm>
10 
11 using namespace std;
12 using namespace filesystem;
13 
14 ConfigData::ConfigData(string& algorithm_name, const string& mask_name, bool use_frequencies) : algorithm_name_{ algorithm_name }, mask_name_{ mask_name } {
15  YAML::Node config;
16  try {
17  config = YAML::LoadFile(config_file_);
18  }
19  catch (...) {
20  cout << "ERROR: Unable to read configuration file '" << config_file_ << "'.\n";
21  exit(EXIT_FAILURE);
22  }
23 
24  if (config["paths"]["input"]) {
25  global_input_path_ = path(config["paths"]["input"].as<string>());
26  if (config["datasets"]) {
27  datasets_ = config["datasets"].as<vector<string>>();
28  datasets_path_.resize(datasets_.size());
29  generate(datasets_path_.begin(), datasets_path_.end(), [this, datasets_it = datasets_.begin()]() mutable { return global_input_path_ / path(*datasets_it++); });
30  }
31  }
32 
33  if (use_frequencies) {
34  UpdateAlgoNameWithDatasets();
35  algorithm_name = algorithm_name_;
36  }
37 
38  if (config["paths"]["output"]) {
39 
40  global_output_path_ = path(config["paths"]["output"].as<string>());
41  algorithm_output_path_ = global_output_path_ / path(algorithm_name);
42  create_directories(algorithm_output_path_);
43 
44  // ODT
45  odt_path_ = algorithm_output_path_ / path(algorithm_name + odt_suffix_);
46 
47  // Code
48  code_path_ = algorithm_output_path_ / path(algorithm_name + code_suffix_);
49 
50  // Rule Set / Decision Table
51  rstable_path_ = algorithm_output_path_ / path(algorithm_name + rstable_suffix_);
52 
53  // Tree / Forest / Dag (.inc)
54  treecode_path_ = algorithm_output_path_ / path(algorithm_name + treecode_suffix_);
55  forestcode_path_ = algorithm_output_path_ / path(algorithm_name + forestcode_suffix_);
56  treedagcode_path_ = algorithm_output_path_ / path(algorithm_name + treedagcode_suffix_);
57  forestdagcode_path_ = algorithm_output_path_ / path(algorithm_name + forestdagcode_suffix_);
58 
59  // Frequencies
60  frequencies_path_ = global_output_path_ / frequencies_local_path_;
61  create_directories(frequencies_path_ / mask_name_);
62 
63  // ChainCode Ruleset Path
64  chaincode_rstable_path_ = global_output_path_ / path(chaincode_rstable_filename_);
65 
66  // CTBE Ruleset Path
67  ctbe_rstable_path_ = global_output_path_ / path(ctbe_rstable_filename_);
68  }
69  else {
70  cout << "ERROR: missing output path in configuration file.\n";
71  exit(EXIT_FAILURE);
72  }
73 
74  if (config["dot"]["background"]) {
75  dot_background_color_ = "\"" + config["dot"]["background"].as<string>() + "\"";
76  }
77  else {
78  cout << "WARNING: missing dot background color, " + dot_background_color_ + " will be used.\n";
79  }
80 
81  if (config["dot"]["ranksep"]) {
82  dot_ranksep_ = config["dot"]["ranksep"].as<std::string>();
83  }
84  else {
85  std::cout << "WARNING: missing dot ranksep, " + dot_ranksep_ + " will be used.\n";
86  }
87 
88  if (config["dot"]["out_format"]) {
89  dot_output_format_ = "." + config["dot"]["out_format"].as<string>();
90  }
91  else {
92  cout << "WARNING: missing output file format, 'pdf' will be used.\n";
93  }
94 
95  if (config["force_odt_generation"]) {
96  force_odt_generation_ = config["force_odt_generation"].as<bool>();
97  }
98 }