27 #ifndef SRC_METHODS_F2_IPP_ 28 #define SRC_METHODS_F2_IPP_ 32 template<
class UserNodeLabel,
class UserEdgeLabel>
33 F2<UserNodeLabel, UserEdgeLabel>::
36 template<
class UserNodeLabel,
class UserEdgeLabel>
37 F2<UserNodeLabel, UserEdgeLabel>::
38 F2(
const GEDData<UserNodeLabel, UserEdgeLabel> & ged_data) :
39 MIPBasedMethod<UserNodeLabel, UserEdgeLabel>(ged_data),
43 template<
class UserNodeLabel,
class UserEdgeLabel>
54 std::vector<double> del_cost;
55 for (
auto i = g.
nodes().first; i != g.
nodes().second; i++) {
57 obj += del_cost.back();
61 std::vector<double> ins_cost;
62 for (
auto k = h.
nodes().first; k != h.
nodes().second; k++) {
64 obj += ins_cost.back();
68 std::pair<GEDGraph::NodeID, GEDGraph::NodeID> key_x;
69 for (
auto i = g.
nodes().first; i != g.
nodes().second; i++) {
71 for (
auto k = h.
nodes().first; k != h.
nodes().second; k++) {
74 x_[key_x] = model.addVar(1, 1, 0, variable_type_());
77 x_[key_x] = model.addVar(0, 1, 0, variable_type_());
85 for (
auto e = g.
edges().first; e != g.
edges().second; e++) {
87 obj += del_cost.back();
93 for (
auto f = h.
edges().first; f != h.
edges().second; f++) {
95 obj += ins_cost.back();
99 std::pair<GEDGraph::EdgeID, GEDGraph::EdgeID> key_y;
100 std::size_t counter_e{0};
101 std::size_t counter_f{0};
102 for (
auto e = g.
edges().first; e != g.
edges().second; e++, counter_e++) {
105 for (
auto f = h.
edges().first; f != h.
edges().second; f++, counter_f++) {
107 y_[key_y] = model.addVar(0, 1, 0, variable_type_());
113 model.setObjective(obj, GRB_MINIMIZE);
117 for (
auto i = g.
nodes().first; i != g.
nodes().second; i++) {
120 for (
auto k = h.
nodes().first; k != h.
nodes().second; k++) {
124 model.addConstr(lhs, GRB_LESS_EQUAL, 1);
126 for (
auto k = h.
nodes().first; k != h.
nodes().second; k++) {
129 for (
auto i = g.
nodes().first; i != g.
nodes().second; i++) {
133 model.addConstr(lhs, GRB_LESS_EQUAL, 1);
137 for (
auto e = g.
edges().first; e != g.
edges().second; e++, counter_e++) {
139 for (
auto k = h.
nodes().first; k != h.
nodes().second; k++) {
146 key_x.first = g.
tail(*e);
148 key_x.first = g.
head(*e);
150 model.addConstr(lhs, GRB_LESS_EQUAL, 0);
156 template<
class UserNodeLabel,
class UserEdgeLabel>
162 std::vector<bool> delete_node(g.
num_nodes(),
true);
163 std::vector<bool> insert_node(h.
num_nodes(),
true);
167 for (
auto it = x_.begin(); it != x_.end(); it++) {
168 if (it->second.get(GRB_DoubleAttr_X) > 0) {
170 k = it->first.second;
172 delete_node[i] =
false;
173 insert_node[k] =
false;
179 if (delete_node.at(i)) {
186 if (insert_node.at(k)) {
196 template<
class UserNodeLabel,
class UserEdgeLabel>
201 std::vector<double> delete_node(g.
num_nodes(), 0);
202 std::vector<double> insert_node(h.
num_nodes(), 0);
205 for (
auto it = x_.begin(); it != x_.end(); it++) {
207 k = it->first.second;
208 lsape_instance(i, k) -= it->second.get(GRB_DoubleAttr_X);
209 delete_node[i] += it->second.get(GRB_DoubleAttr_X);
210 insert_node[k] += it->second.get(GRB_DoubleAttr_X);
213 lsape_instance(i, h.
num_nodes()) = delete_node.at(i);
216 lsape_instance(g.
num_nodes(), k) = insert_node.at(k);
221 template<
class UserNodeLabel,
class UserEdgeLabel>
226 return GRB_CONTINUOUS;
bool relax_
If true, the model populated by mip_populate_model_() must be continuous.
std::size_t num_nodes() const
Returns the number of nodes.
virtual void mip_populate_model_(const GEDGraph &g, const GEDGraph &h, GRBModel &model) final
Runs the local search from an initial node map.
const GEDData< UserNodeLabel, UserEdgeLabel > & ged_data_
The data on which the method is run.
NodeID head(EdgeID edge) const
Returns the head of an edge.
virtual void mip_model_to_node_map_(const GEDGraph &g, const GEDGraph &h, GRBModel &model, NodeMap &node_map) final
Given a, possibly sub-optimally, solved unrelaxed model, this method constructs a node map and sets i...
NodeID tail(EdgeID edge) const
Returns the tail of an edge.
LabelID get_node_label(NodeID node) const
Returns the label of a given node.
static NodeID dummy_node()
Returns a dummy node.
LabelID get_edge_label(EdgeID edge) const
Returns the label of a given edge.
std::pair< incident_edge_iterator, incident_edge_iterator > incident_edges(NodeID node) const
Provides access to all incident edges of a node.
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.
virtual bool mip_model_to_lsape_projection_problem_(const GEDGraph &g, const GEDGraph &h, GRBModel &model, DMatrix &lsape_instance) final
Given a, possibly sub-optimally, solved model, this method constructs an LSAPE instance for projectin...
void add_assignment(GEDGraph::NodeID i, GEDGraph::NodeID k)
Add node substitution, insertion, or deletion to the node map.
void set_induced_cost(double induced_cost)
Sets the induced cost of the node map.
constexpr LabelID dummy_label()
Returns a dummy label.
Global namespace for GEDLIB.
std::size_t NodeID
Internally used vertex ID type.
Mixed integer linear programming formulation of the graph edit distance.
std::pair< edge_iterator, edge_iterator > edges() const
Provides access to all edge in the graph.
bool map_root_to_root_
If true, the model populated by mip_populate_model_() must enforce that the nodes with ID 0 are mappe...