@@ -33,20 +33,20 @@ class DepthFirstSearch
33
33
GuideId guide_id_ = 0 ;
34
34
Info info_ = Info();
35
35
36
- void rec (const typename BranchingScheme::Node& node_cur);
36
+ void rec (const std::shared_ptr< const typename BranchingScheme::Node> & node_cur);
37
37
38
38
};
39
39
40
40
/* ************************* Template implementation ***************************/
41
41
42
42
template <typename Solution, typename BranchingScheme>
43
- void DepthFirstSearch<Solution, BranchingScheme>::rec(const typename BranchingScheme::Node& node_cur)
43
+ void DepthFirstSearch<Solution, BranchingScheme>::rec(const std::shared_ptr< const typename BranchingScheme::Node> & node_cur)
44
44
{
45
45
typedef typename BranchingScheme::Node Node;
46
46
typedef typename BranchingScheme::Insertion Insertion;
47
47
48
48
LOG_FOLD_START (info_, " rec" << std::endl);
49
- LOG_FOLD (info_, " node_cur" << std::endl << node_cur);
49
+ LOG_FOLD (info_, " node_cur" << std::endl << * node_cur);
50
50
51
51
// Check time
52
52
if (!info_.check_time ()) {
@@ -55,40 +55,39 @@ void DepthFirstSearch<Solution, BranchingScheme>::rec(const typename BranchingSc
55
55
}
56
56
57
57
// Bound
58
- if (node_cur. bound (sol_best_)) {
58
+ if (node_cur-> bound (sol_best_)) {
59
59
LOG (info_, " bound ×" << std::endl);
60
60
return ;
61
61
}
62
62
63
- std::vector<Node> children;
64
- for (const Insertion& insertion: node_cur .children (info_)) {
63
+ std::vector<std::shared_ptr< const Node> > children;
64
+ for (const Insertion& insertion: branching_scheme_ .children (node_cur, info_)) {
65
65
LOG (info_, insertion << std::endl);
66
- Node node_tmp (node_cur);
67
- node_tmp.apply_insertion (insertion, info_);
68
- LOG_FOLD (info_, " node_tmp" << std::endl << node_tmp);
66
+ auto child = branching_scheme_.child (node_cur, insertion);
67
+ LOG_FOLD (info_, " child" << std::endl << *child);
69
68
70
69
// Bound
71
- if (node_tmp. bound (sol_best_)) {
70
+ if (child-> bound (sol_best_)) {
72
71
LOG (info_, " bound ×" << std::endl);
73
72
continue ;
74
73
}
75
74
76
75
// Update best solution
77
- if (sol_best_ < node_tmp ) {
76
+ if (sol_best_ < *child ) {
78
77
std::stringstream ss;
79
78
ss << " A* (thread " << thread_id_ << " )" ;
80
- sol_best_.update (node_tmp. convert (sol_best_), ss, info_);
79
+ sol_best_.update (child-> convert (sol_best_), ss, info_);
81
80
}
82
81
83
82
// Add child to the queue
84
- if (!node_tmp. full ())
85
- children.push_back (node_tmp );
83
+ if (!child-> full ())
84
+ children.push_back (child );
86
85
}
87
86
88
87
auto comp = branching_scheme_.compare (guide_id_);
89
88
sort (children.begin (), children.end (), comp);
90
89
91
- for (const Node & child: children)
90
+ for (const auto & child: children)
92
91
rec (child);
93
92
94
93
LOG_FOLD_END (info_, " " );
@@ -99,8 +98,8 @@ void DepthFirstSearch<Solution, BranchingScheme>::run()
99
98
{
100
99
typedef typename BranchingScheme::Node Node;
101
100
102
- Node node ( branching_scheme_);
103
- rec (node );
101
+ std::shared_ptr< const Node> root = branching_scheme_. root ( );
102
+ rec (root );
104
103
}
105
104
106
105
}
0 commit comments