Camargue
qpref_brancher.hpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7 
8 #ifndef CMR_QPREF_BRANCHER_H
9 #define CMR_QPREF_BRANCHER_H
10 
11 #include "datagroups.hpp"
12 #include "active_tour.hpp"
13 #include "branch_node.hpp"
14 #include "base_brancher.hpp"
15 #include "err_util.hpp"
16 
17 #include <vector>
18 #include <queue>
19 #include <stdexcept>
20 
21 namespace CMR {
22 namespace ABC {
23 
27 template <BranchNode::Pref q_pref>
28 class QprefBrancher : public BaseBrancher {
29 public:
30  QprefBrancher(const Data::Instance &inst, const Data::BestGroup &best_data,
31  const Graph::CoreGraph &core_graph, LP::CoreLP &core_lp);
32 
33  BranchHistory::iterator next_prob();
34 
35 protected:
36  void fetch_next();
37  void enqueue_split(BranchNode::Split prob_array);
38 
39 private:
40  std::priority_queue<BranchHistory::iterator,
41  std::vector<BranchHistory::iterator>,
42  BranchNode::Pref> prob_q;
43 };
44 
45 template<BranchNode::Pref q_pref>
47  const Data::BestGroup &best_data,
48  const Graph::CoreGraph &core_graph,
49  LP::CoreLP &core_lp) try
50  : BaseBrancher(inst, best_data, core_graph, core_lp),
51  prob_q(q_pref)
52 {
53  prob_q.push(branch_history.begin());
54 } catch (const std::exception &e) {
55  std::cerr << e.what() << std::endl;
56  throw std::runtime_error("QprefBrancher constructor failed.");
57 }
58 
59 template <BranchNode::Pref q_pref>
61 {
62  for (BranchNode &B : prob_array) {
63  branch_history.emplace_front(std::move(B));
64  prob_q.push(branch_history.begin());
65  }
66 } catch (const std::exception &e) {
67  std::cerr << e.what() << " putting nodes in history" << std::endl;
68  throw std::runtime_error("QprefBrancher::enqueue_split failed.");
69 }
70 
71 template <BranchNode::Pref q_pref>
72 BranchHistory::iterator QprefBrancher<q_pref>::next_prob()
73 {
74  using std::cout;
75  using std::endl;
76 
77  if (verbose > 1)
78  cout << "Calling QprefBrancher::next_prob...." << endl;
79 
80  if (next_itr == branch_history.end())
81  fetch_next();
82  else if (verbose > 1)
83  cout << "....already set." << endl;
84 
85  BranchHistory::iterator result = next_itr;
86 
87  next_itr = branch_history.end();
88  return result;
89 }
90 
91 template <BranchNode::Pref q_pref>
93 {
94  using std::cout;
95  using std::endl;
96 
97  if (verbose > 1)
98  cout << "Calling QprefBrancher::fetch_next..." << endl;
99  if (branch_history.empty() || prob_q.empty()) {
100  if (verbose > 1)
101  cout << "set to END" << endl;
102  next_itr = branch_history.end();
103  return;
104  }
105 
106  next_itr = prob_q.top();
107  prob_q.pop();
108 }
109 
110 
111 }
112 }
113 
114 #endif
void fetch_next()
Set next_itr to the next subproblem to be examined.
Definition: qpref_brancher.hpp:92
Information about the current best tour.
Definition: datagroups.hpp:154
void enqueue_split(BranchNode::Split prob_array)
Adding child subproblems to branch_history.
Definition: qpref_brancher.hpp:60
Data group structures.
ABC search nodes.
Graph structures for the edges currently in a CoreLP::Relaxation.
Definition: datagroups.hpp:100
Storing TSP instance data.
Definition: datagroups.hpp:36
ERROR HANDLING CLASSES AND ROUTINES.
Abstract base class for implementing a branching node selection rule.
Definition: base_brancher.hpp:20
std::array< BranchNode, 2 > Split
Alias declaration for returning two split child problems.
Definition: branch_node.hpp:50
Class template for branching with priority queue via some preference rule.
Definition: qpref_brancher.hpp:28
The namespace for this project.
Definition: abc_nodesel.hpp:20
Class for storing the core lp associated to a TSP instance and pivoting.
Definition: core_lp.hpp:33
Abstract branching control.
Definition: branch_node.hpp:25
Monitoring the active tour in the solution process.
BranchHistory::iterator next_prob()
Return the next subproblem to be examined.
Definition: qpref_brancher.hpp:72