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