27 #ifndef SRC_METHODS_HYBRID_IPP_ 28 #define SRC_METHODS_HYBRID_IPP_ 33 template<
class UserNodeLabel,
class UserEdgeLabel>
34 Hybrid<UserNodeLabel, UserEdgeLabel>::
37 template<
class UserNodeLabel,
class UserEdgeLabel>
38 Hybrid<UserNodeLabel, UserEdgeLabel>::
39 Hybrid(
const GEDData<UserNodeLabel, UserEdgeLabel> & ged_data) :
40 GEDMethod<UserNodeLabel, UserEdgeLabel>(ged_data),
43 time_limit_in_sec_{0.0} {}
46 template<
class UserNodeLabel,
class UserEdgeLabel>
50 Timer timer(time_limit_in_sec_);
60 std::string options(std::string(
"--lsape-model ") + to_string_(lsape_model_) +
" --threads " + std::to_string(num_threads_));
67 SubstructItr_ current_substruct{partition.get_unmatched_substructs_().cbegin()};
68 SubstructItr_ end_substructs{partition.get_unmatched_substructs_().cend()};
70 if (current_substruct == end_substructs) {
74 options +=
" --wildcards YES";
75 double lower_bound{std::numeric_limits<double>::infinity()};
76 if (branch_uniform_dfs_(timer, options, g, h, current_substruct, end_substructs, lower_bound)) {
85 template<
class UserNodeLabel,
class UserEdgeLabel>
91 time_limit_in_sec_ = 0.;
94 template<
class UserNodeLabel,
class UserEdgeLabel>
98 return "[--lsape-model <arg>] [--time-limit <arg>] [--threads <arg>]";
101 template<
class UserNodeLabel,
class UserEdgeLabel>
105 if (option ==
"lsape-model") {
109 else if (arg ==
"FLWC") {
112 else if (arg ==
"FLCC") {
115 else if (arg ==
"FBP") {
118 else if (arg ==
"SFBP") {
121 else if (arg ==
"FBP0") {
124 else if (arg ==
"ECBP") {
128 throw Error(std::string(
"Invalid argument \"") + arg +
"\" for option lsape-model. Usage: options = \"[--lsape-model ECBP|EBP|FLWC|FLCC|FBP|SFBP|FBP0] [...]\"");
132 else if (option ==
"time-limit") {
134 time_limit_in_sec_ = std::stod(arg);
137 throw Error(std::string(
"Invalid argument \"") + arg +
"\" for option time-limit. Usage: options = \"[--time-limit <convertible to double>] [...]");
141 else if (option ==
"threads") {
143 num_threads_ = std::stoi(arg);
146 throw Error(std::string(
"Invalid argument \"") + arg +
"\" for option threads. Usage: options = \"[--threads <convertible to int greater 0>] [...]");
148 if (num_threads_ <= 0) {
149 throw Error(std::string(
"Invalid argument \"") + arg +
"\" for option threads. Usage: options = \"[--threads <convertible to int greater 0>] [...]");
157 template<
class UserNodeLabel,
class UserEdgeLabel>
166 if (current_substruct == end_substructs) {
171 lower_bound = std::min(lower_bound, bu_result.
lower_bound());
177 switch (current_substruct->type) {
180 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
188 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
193 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
197 h.
set_label(current_substruct->node_1, current_substruct->node_label_1);
200 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
208 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
212 h.
set_label(current_substruct->node_1, current_substruct->node_label_1);
215 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
219 h.
set_label(current_substruct->edge_1, current_substruct->edge_label_1);
222 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
230 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
234 h.
set_label(current_substruct->node_1, current_substruct->node_label_1);
237 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
241 h.
set_label(current_substruct->edge_1, current_substruct->edge_label_1);
244 success = success and branch_uniform_dfs_(timer, options, g, h, current_substruct + 1, end_substructs, lower_bound);
253 template<
class UserNodeLabel,
class UserEdgeLabel>
257 std::string method_string(
"");
258 switch (lsape_model) {
260 method_string =
"ECBP";
263 method_string =
"EBP";
266 method_string =
"FLWC";
269 method_string =
"FLCC";
272 method_string =
"FBP";
275 method_string =
"FBP0";
278 method_string =
"SFBP";
281 return method_string;
Computes a lower bound for uniform edit costs.
Reduction to compact LSAP instance for quasimetric costs.
Reduction to compact LSAP instance for quasimetric costs.
virtual bool ged_parse_option_(const std::string &option, const std::string &arg) final
Parses one option.
Reduction to compact LSAP instance without cost constraints.
A timer class that can be used by methods that support time limits.
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.
bool expired() const
Checks if the time limit has expired.
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.
A wrapper structure for the result of calls to ged::GEDMethod::run_as_util() and ged::GEDMethod::ged_...
Reduction to extended LSAP instance without cost constraints.
virtual void ged_set_default_options_() final
Sets all options to default values.
virtual void ged_run_(const GEDGraph &g, const GEDGraph &h, Result &result) final
Runs the method with options specified by set_options().
Adaption of Hungarian Algorithm to LSAPE.
void set_options(const std::string &options)
Sets the options of the method.
void set_label(NodeID node, LabelID label)
Sets a node's label.
virtual std::string ged_valid_options_string_() const final
Returns string of all valid options.
The normalized input graphs used by GEDLIB. All labels are integers.
constexpr LabelID dummy_label()
Returns a dummy label.
Computes a lower bound for uniform edit costs.
Reduction to compact LSAP instance for quasimetric costs.
Global namespace for GEDLIB.
Reduction to compact LSAP instance for quasimetric costs.
Model
Selects a model for solving LSAPE with the Hungarian algorithm.