27 #ifndef SRC_UTIL_MISC_IPP_ 28 #define SRC_UTIL_MISC_IPP_ 36 for (std::size_t row{0}; row < adj_matrix.
num_rows(); row++) {
37 for (std::size_t col{0}; col < adj_matrix.
num_cols(); col++) {
39 adj_matrix(row, col) = 1.0;
42 adj_matrix(row, col) = 0.0;
49 parse_config_file(
const std::string & filename, std::map<std::string, std::string> & options) {
50 std::ifstream config_file(filename);
52 std::size_t line_nr{1};
53 while(std::getline(config_file, line)) {
54 if (line.at(0) ==
'#') {
57 std::string error_msg(
"Line " + std::to_string(line_nr) +
" has invalid format.\nExpected format: \"<key>=<value>\"\nLine " + std::to_string(line_nr) +
": " + line);
58 std::istringstream line_stream(line);
60 if (not std::getline(line_stream, key,
'=')) {
61 throw Error(error_msg);
64 if(not std::getline(line_stream, value)) {
65 throw Error(error_msg);
76 save_as_config_file(
const std::string & filename,
const std::map<std::string, std::string> & options) {
77 std::ofstream config_file(filename);
78 for (
auto key_value = options.begin(); key_value != options.end(); key_value++) {
79 config_file << key_value->first <<
"=" << key_value->second <<
"\n";
84 template<
class Solver>
92 for (std::size_t row{0}; row < num_nodes_g; row++) {
93 std::size_t col{solver.get_assigned_col(row, solution_id)};
94 if (col >= num_nodes_h) {
103 for (std::size_t col{0}; col < num_nodes_h; col++) {
104 if (solver.get_assigned_row(col, solution_id) >= num_nodes_g) {
111 counting_sort(std::vector<LabelID>::iterator first, std::vector<LabelID>::iterator last) {
114 std::size_t range{0};
115 for (
auto label = first; label != last; label++) {
116 max_label_val = std::max(max_label_val, *label);
121 std::vector<LabelID> hist(max_label_val + 1, 0);
122 for (
auto label = first; label != last; label++) {
127 std::vector<LabelID> pos(max_label_val + 1, 0);
128 for (std::size_t label_val{0}; label_val < max_label_val; label_val++) {
129 pos[label_val + 1] = pos.at(label_val) + hist.at(label_val);
133 std::vector<LabelID> sorted_labels(range);
134 for (
auto label = first; label != last; label++) {
135 sorted_labels[pos[*label]++] = *label;
139 for (
auto label = sorted_labels.begin(); label != sorted_labels.end(); label++) {
A matrix class with basic functionality.
std::size_t num_source_nodes() const
Returns number of source nodes contained in the node map.
bool is_edge(NodeID tail, NodeID head) const
Checks if an edge exists.
std::size_t num_cols() const
Returns the number of columns.
std::size_t LabelID
Internally used type of node and edge labels.
void counting_sort(std::vector< LabelID >::iterator first, std::vector< LabelID >::iterator last)
Implementation of counting sort.
static NodeID dummy_node()
Returns a dummy node.
void parse_config_file(const std::string &filename, std::map< std::string, std::string > &options)
Parses a configuration file.
The normalized input graphs used by GEDLIB. All labels are integers.
void add_assignment(GEDGraph::NodeID i, GEDGraph::NodeID k)
Add node substitution, insertion, or deletion to the node map.
std::size_t num_target_nodes() const
Returns number of target nodes contained in the node map.
Global namespace for GEDLIB.
void clear()
Clears the node map.
void save_as_config_file(const std::string &filename, const std::map< std::string, std::string > &options)
Saves a string map as a configuration file as expected by parse_config_file().
void construct_node_map_from_solver(const Solver &solver, NodeMap &node_map, std::size_t solution_id=0)
Constructs a node map from a solution to LSAPE or LSAPE stored in a ged::LSAPESolver or a ged::LSAPSo...
void init_adj_matrix(const GEDGraph &graph, DMatrix &adj_matrix)
Initalizes the adjacency matrix of a graph.
std::size_t num_rows() const
Returns the number of rows.