17 {
18 std::pair<std::size_t, std::size_t> value =
21
22
23 AdjacencyMatrix with_edge_matrix =
paths_stack_[0]->matrix.Reducted();
24 with_edge_matrix =
25 DeleteEdge_(with_edge_matrix, edge.end_num, edge.start_num);
26
27
28 std::map<std::size_t, std::size_t> prev_chains =
paths_stack_[0]->chains;
29 std::map<std::size_t, std::size_t> new_chains =
paths_stack_[0]->chains;
30 bool is_new = true;
31 for (const auto& [start, end] : prev_chains) {
32 if (start == edge.end_num) {
33 new_chains.erase(start);
34 new_chains[edge.start_num] = end;
35 is_new = false;
36 break;
37 } else if (end == edge.start_num) {
38 new_chains[start] = edge.end_num;
39 is_new = false;
40 break;
41 }
42 }
43 if (is_new) new_chains[edge.start_num] = edge.end_num;
44 for (const auto& [start, end] : new_chains) {
45 for (const auto& [start2, end2] : new_chains) {
46 if (end2 == start) {
47 new_chains[start2] = end;
48 new_chains.erase(start);
49 }
50 if (end == start2) {
51 new_chains[start] = end2;
52 new_chains.erase(start2);
53 }
54 }
55 }
56 for (const auto& [start, end] : new_chains) {
57 with_edge_matrix =
DeleteEdge_(with_edge_matrix, end, start);
58 }
59
60
61 with_edge_matrix = with_edge_matrix.Minor(value.first, value.second);
66
67
68 AdjacencyMatrix without_edge_matrix =
paths_stack_[0]->matrix.Reducted();
69 without_edge_matrix =
70 DeleteEdge_(without_edge_matrix, edge.start_num, edge.end_num);
72 std::make_shared<TSPNode>(without_edge_matrix,
paths_stack_[0]);
73
74
75 double with_eval =
paths_stack_[0]->with_edge->evaluation;
76 double without_eval =
paths_stack_[0]->without_edge->evaluation;
77 if (!std::isinf(without_eval)) {
81 else
83 }
84 if (!std::isinf(with_eval)) {
88 else
90 }
92}
AdjacencyMatrix & DeleteEdge_(AdjacencyMatrix &matrix, std::size_t start_num, std::size_t end_num)
Удаляет ребро из матрицы смежности
Definition travelling_salesmans_problem.cpp:94
std::size_t FindIndex_(double eval) const
Находит место для вставки вершины для соблюдения порядка
Definition travelling_salesmans_problem.cpp:110