Camargue
process_cuts.hpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7 #ifndef CMR_PROCESS_CUTS_H
8 #define CMR_PROCESS_CUTS_H
9 
10 #include "datagroups.hpp"
11 #include "cc_lpcuts.hpp"
12 #include "graph.hpp"
13 #include "cut_structs.hpp"
14 #include "lp_util.hpp"
15 #include "util.hpp"
16 
17 #include <memory>
18 #include <vector>
19 #include <limits>
20 #include <list>
21 #include <utility>
22 
23 
24 
25 namespace CMR {
26 namespace Sep {
27 
29 template<typename cut_rep>
30 class CutQueue {
31 public:
33  CutQueue() : q_cap(std::numeric_limits<int>::max()) {}
34 
36  CutQueue(const int cap) : q_cap(cap) {}
37 
38  int q_capacity() const { return q_cap; }
39 
41  const cut_rep &peek_front() const { return cut_q.front(); }
42  cut_rep &peek_front() { return cut_q.front(); }
43 
45  void push_front(const cut_rep &H)
46  {
47  cut_q.push_front(H);
48  if(cut_q.size() > q_capacity()) cut_q.pop_back();
49  }
50 
51  template <typename ...Args>
52  void emplace_front(Args &&...args)
53  {
54  cut_q.emplace_front(std::forward<Args>(args)...);
55  if (cut_q.size() > q_capacity()) cut_q.pop_back();
56  }
57 
59  void push_back(const cut_rep &H)
60  {
61  if(cut_q.size() >= q_capacity()) cut_q.pop_back();
62  cut_q.push_back(H);
63  }
64 
65  template <typename ...Args>
66  void emplace_back(Args &&...args)
67  {
68  if(cut_q.size() >= q_capacity()) cut_q.pop_back();
69  cut_q.emplace_back(std::forward<Args>(args)...);
70  }
71 
72  void pop_front() { cut_q.pop_front(); }
73 
75  void splice(CutQueue<cut_rep> &Q){ cut_q.splice(cut_q.end(), Q.cut_q); }
76 
77 
78  bool empty() const { return cut_q.empty(); }
79  int size() const { return cut_q.size(); }
80 
81  void clear() { cut_q.clear(); }
82 
83  using Itr = typename std::list<cut_rep>::iterator;
84  using ConstItr = typename std::list<cut_rep>::const_iterator;
85 
86  Itr begin() { return cut_q.begin(); }
87  Itr end() { return cut_q.end(); }
88 
89  ConstItr begin() const { return cut_q.begin(); }
90  ConstItr end() const { return cut_q.end(); }
91 
92 private:
93  std::list<cut_rep> cut_q;
94  int q_cap;
95 };
96 
97 
99 LP::SparseRow get_row(const CCtsp_lpcut_in &cc_cut,
100  const std::vector<int> &perm,
101  const Graph::CoreGraph &core_graph);
102 
104 LP::SparseRow get_row(const dominoparity &dp_cut,
105  const std::vector<int> &tour_nodes,
106  const Graph::CoreGraph &core_graph);
107 
109 LP::SparseRow get_row(const std::vector<int> &handle_delta,
110  const std::vector<std::vector<int>> &tooth_edges,
111  const Graph::CoreGraph &core_graph);
112 
114 template<typename number_type>
115 double get_activity(const std::vector<number_type> &x,
116  const LP::SparseRow &R)
117 {
118  double result = 0.0;
119  for(auto i = 0; i < R.rmatind.size(); i++){
120  int index = R.rmatind[i];
121  result += x[index] * R.rmatval[i];
122  }
123  return result;
124 }
125 
126 
128 std::vector<int> teeth_inds(const ex_blossom &B,
129  const std::vector<double> &tour_edges,
130  const std::vector<double> &lp_vec,
131  const std::vector<Graph::Edge> &edges,
132  int ncount);
133 
135 std::vector<int> teeth_inds(const ex_blossom &B,
136  const std::vector<double> &tour_edges,
137  const std::vector<double> &lp_vec,
138  const std::vector<Graph::Edge> &edges,
139  int ncount, const std::vector<int> &handle_delta);
140 
141 
143 bool bad_blossom(const ex_blossom &B,
144  const std::vector<double> &tour_edges,
145  const std::vector<double> &lp_vec,
146  const std::vector<Graph::Edge> &edges, int ncount);
147 
148 }
149 }
150 
151 
152 
153 #endif
void clear()
Clear the queue.
Definition: process_cuts.hpp:81
Miscellaneous functions, structs/enums, and constants for LPs.
Structure for storing simple DP inequalities.
Definition: cut_structs.hpp:84
Header for classes/structures/functions to work with graphs.
Definition: cliq.hpp:118
Data group structures.
Class template for queue of cuts in some form.
Definition: process_cuts.hpp:30
Graph structures for the edges currently in a CoreLP::Relaxation.
Definition: datagroups.hpp:100
const cut_rep & peek_front() const
A reference to the most recently added cut.
Definition: process_cuts.hpp:41
LP::SparseRow get_row(const CCtsp_lpcut_in &cc_cut, const std::vector< int > &perm, const Graph::CoreGraph &core_graph)
SparseRow corresponding to Concorde cut.
Definition: process_cuts.cpp:30
void push_front(const cut_rep &H)
Push a new cut to the front, popping from the back if at capacity.
Definition: process_cuts.hpp:45
Utility functions, macros, and structures.
void push_back(const cut_rep &H)
Push to the back, popping from back first if at capacity.
Definition: process_cuts.hpp:59
void splice(CutQueue< cut_rep > &Q)
Add the cuts in Q to this list, emptying Q.
Definition: process_cuts.hpp:75
void pop_front()
Pop the front cut.
Definition: process_cuts.hpp:72
CutQueue(const int cap)
Construct a CutQueue with capacity cap.
Definition: process_cuts.hpp:36
std::vector< int > teeth_inds(const ex_blossom &B, const std::vector< double > &tour_edges, const std::vector< double > &lp_vec, const std::vector< Graph::Edge > &edges, int ncount)
Gets the indices of the teeth for an ex_blossom B relative to edges.
std::vector< int > rmatind
Indices of nonzero entries.
Definition: lp_util.hpp:150
std::vector< double > rmatval
Coefficients for indices in rmatind.
Definition: lp_util.hpp:151
The namespace for this project.
Definition: abc_nodesel.hpp:20
CutQueue()
Construct a CutQueue with unlimited capacity.
Definition: process_cuts.hpp:33
Simple struct representing sparse matrix row for passing to LP solver.
Definition: lp_util.hpp:149
Structure for storing blossom inequalities from exact primal separation.
Definition: cut_structs.hpp:17
Wrappers for Concorde cut structures/separators.
double get_activity(const std::vector< number_type > &x, const LP::SparseRow &R)
Function template for determining the activity or lhs of a vector on a row.
Definition: process_cuts.hpp:115
bool bad_blossom(const ex_blossom &B, const std::vector< double > &tour_edges, const std::vector< double > &lp_vec, const std::vector< Graph::Edge > &edges, int ncount)
Returns true if the blossom is invalid for some reason.