27 #ifndef SRC_METHODS_GED_METHOD_IPP_ 28 #define SRC_METHODS_GED_METHOD_IPP_ 33 template<
class UserNodeLabel,
class UserEdgeLabel>
37 template<
class UserNodeLabel,
class UserEdgeLabel>
44 upper_bound_(std::numeric_limits<double>::infinity()),
50 template<
class UserNodeLabel,
class UserEdgeLabel>
57 template<
class UserNodeLabel,
class UserEdgeLabel>
64 template<
class UserNodeLabel,
class UserEdgeLabel>
71 template<
class UserNodeLabel,
class UserEdgeLabel>
78 template<
class UserNodeLabel,
class UserEdgeLabel>
82 auto start = std::chrono::high_resolution_clock::now();
84 auto end = std::chrono::high_resolution_clock::now();
85 init_time_ = end - start;
89 template<
class UserNodeLabel,
class UserEdgeLabel>
96 template<
class UserNodeLabel,
class UserEdgeLabel>
100 read_options_from_string_(options);
102 for (
auto option_arg : options_) {
110 template<
class UserNodeLabel,
class UserEdgeLabel>
115 auto start = std::chrono::high_resolution_clock::now();
117 auto end = std::chrono::high_resolution_clock::now();
123 runtime_ = end - start;
126 template<
class UserNodeLabel,
class UserEdgeLabel>
134 for (
auto node = g.
nodes().first; node != g.
nodes().second; node++) {
137 for (
auto node = h.
nodes().first; node != h.
nodes().second; node++) {
150 template<
class UserNodeLabel,
class UserEdgeLabel>
154 if (options ==
"")
return;
156 std::vector<std::string> words;
157 tokenize_(options, words);
158 std::string option_name;
159 bool expect_option_name{
true};
160 for (
auto word : words) {
161 if (expect_option_name) {
162 if (is_option_name_(word)) {
164 if (options_.find(option_name) != options_.end()) {
165 throw Error(
"Multiple specification of option \"" + option_name +
"\".");
167 options_[option_name] =
"";
170 throw Error(
"Invalid options \"" + options +
"\". Usage: options = \"[--<option> <arg>] [...]\"");
174 if (is_option_name_(word)) {
175 throw Error(
"Invalid options \"" + options +
"\". Usage: options = \"[--<option> <arg>] [...]\"");
178 options_[option_name] = word;
181 expect_option_name = not expect_option_name;
185 template<
class UserNodeLabel,
class UserEdgeLabel>
188 tokenize_(
const std::string & options, std::vector<std::string> & words)
const {
189 bool outside_quotes{
true};
190 std::size_t word_length{0};
191 std::size_t pos_word_start{0};
192 for (std::size_t pos{0}; pos < options.size(); pos++) {
193 if (options.at(pos) ==
'\'') {
194 if (not outside_quotes and pos < options.size() - 1) {
195 if (options.at(pos + 1) !=
' ') {
196 throw Error(
"Options string contains closing single quote which is followed by a char different from ' '.");
200 outside_quotes = not outside_quotes;
202 else if (outside_quotes and options.at(pos) ==
' ') {
203 if (word_length > 0) {
204 words.push_back(options.substr(pos_word_start, word_length));
206 pos_word_start = pos + 1;
213 if (not outside_quotes) {
214 throw Error(
"Options string contains unbalanced single quotes.");
216 if (word_length > 0) {
217 words.push_back(options.substr(pos_word_start, word_length));
221 template<
class UserNodeLabel,
class UserEdgeLabel>
225 if (word.at(0) ==
'\'') {
226 word = word.substr(1, word.size() - 2);
229 if (word.size() < 3) {
232 if ((word.at(0) ==
'-') and (word.at(1) ==
'-') and (word.at(2) !=
'-')) {
233 word = word.substr(2);
240 template<
class UserNodeLabel,
class UserEdgeLabel>
245 template<
class UserNodeLabel,
class UserEdgeLabel>
250 template<
class UserNodeLabel,
class UserEdgeLabel>
257 template<
class UserNodeLabel,
class UserEdgeLabel>
264 template<
class UserNodeLabel,
class UserEdgeLabel>
std::size_t num_nodes() const
Returns the number of nodes.
Contains the standardized input data along with basic functionality.
double upper_bound() const
Returns the upper bound for GED.
GEDMethod(const GEDData< UserNodeLabel, UserEdgeLabel > &ged_data)
Constructor.
virtual std::string ged_valid_options_string_() const
Returns string of all valid options.
std::vector< GEDGraph >::size_type GraphID
Type of internally used graph IDs.
const GEDData< UserNodeLabel, UserEdgeLabel > & ged_data_
The data on which the method is run.
void set_lower_bound(double lower_bound)
Sets the lower bound for GED.
void run_as_util(const GEDGraph &g, const GEDGraph &h, Result &result)
Runs the method with options specified by set_options().
double lower_bound() const
Returns the lower bound for GED.
std::size_t num_node_maps() const
Returns the number of node maps.
A wrapper structure for the result of calls to ged::GEDMethod::run_as_util() and ged::GEDMethod::ged_...
virtual void ged_set_default_options_()
Sets all options to default values.
Abstract class for the (suboptimal) computation of the graph edit distance.
double get_lower_bound() const
Returns a lower bound.
Seconds get_runtime() const
Returns the runtime.
const NodeMap & get_node_map() const
Returns a graph matching.
std::size_t add_node_map(std::size_t num_nodes_g, std::size_t num_nodes_h)
Adds an empty node map to the result.
std::chrono::duration< double > Seconds
Internally used type for measurements in seconds.
static NodeID dummy_node()
Returns a dummy node.
void run(GEDGraph::GraphID g_id, GEDGraph::GraphID h_id)
Runs the method with options specified by set_options().
double get_upper_bound() const
Returns an upper bound.
void set_options(const std::string &options)
Sets the options of the method.
bool initialized_
A flag that equals true if init() has been called and false otherwise.
virtual bool ged_parse_option_(const std::string &option, const std::string &arg)
Parses one option.
virtual void ged_run_(const GEDGraph &g, const GEDGraph &h, Result &result)
Runs the method with options specified by set_options().
virtual void ged_init_()
Initializes the method.
std::pair< node_iterator, node_iterator > nodes() const
Provides access to all nodes in the graph.
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.
Global namespace for GEDLIB.
Seconds get_init_time() const
Returns the initialization time.
NodeMap & node_map(std::size_t index_node_map)
Provides access to a node map.
void init()
Initializes the method with options specified by set_options().
virtual ~GEDMethod()=0
Pure virtual destructor.