+#if KAPS_STATISTIC
+ pbqp->num_rm++;
+#endif
+
+ /* Reconnect the source's edges with the target node. */
+ for (edge_index = 0; edge_index < edge_len; ++edge_index) {
+ pbqp_edge *old_edge = src_node->edges[edge_index];
+ pbqp_edge *new_edge;
+ pbqp_matrix *old_matrix;
+ pbqp_matrix *new_matrix;
+ pbqp_node *other_node;
+ vector *other_vec;
+ unsigned other_len;
+ unsigned other_index;
+ unsigned tgt_index;
+
+ assert(old_edge);
+
+ if (old_edge == edge)
+ continue;
+
+ old_matrix = old_edge->costs;
+ assert(old_matrix);
+
+ if (old_edge->tgt == src_node) {
+ other_node = old_edge->src;
+ other_len = old_matrix->rows;
+ }
+ else {
+ other_node = old_edge->tgt;
+ other_len = old_matrix->cols;
+ }
+ assert(other_node);
+ other_vec = other_node->costs;
+
+ new_matrix = pbqp_matrix_alloc(pbqp, tgt_len, other_len);
+
+ /* Source node selects the column of the old_matrix. */
+ if (old_edge->tgt == src_node) {
+ for (tgt_index = 0; tgt_index < tgt_len; ++tgt_index) {
+ unsigned src_index = mapping[tgt_index];
+
+ if (tgt_vec->entries[tgt_index].data == INF_COSTS)
+ continue;
+
+ for (other_index = 0; other_index < other_len; ++other_index) {
+ if (other_vec->entries[other_index].data == INF_COSTS)
+ continue;
+
+ new_matrix->entries[tgt_index*other_len+other_index] = old_matrix->entries[other_index*src_len+src_index];
+ }
+ }
+ }
+ /* Source node selects the row of the old_matrix. */
+ else {
+ for (tgt_index = 0; tgt_index < tgt_len; ++tgt_index) {
+ unsigned src_index = mapping[tgt_index];
+
+ if (tgt_vec->entries[tgt_index].data == INF_COSTS)
+ continue;
+
+ for (other_index = 0; other_index < other_len; ++other_index) {
+ if (other_vec->entries[other_index].data == INF_COSTS)
+ continue;
+
+ new_matrix->entries[tgt_index*other_len+other_index] = old_matrix->entries[src_index*other_len+other_index];
+ }
+ }
+ }
+
+ add_edge_costs(pbqp, tgt_node->index, other_node->index, new_matrix);
+
+ delete_edge(old_edge);
+ reorder_node(src_node);
+ reorder_node(other_node);
+
+ new_edge = get_edge(pbqp, tgt_node->index, other_node->index);
+ insert_into_rm_bucket(new_edge);
+ }
+
+ /* Reduce the remaining source node via RI. */
+ apply_RI(pbqp);
+
+#if KAPS_STATISTIC
+ pbqp->num_r1--;
+#endif