62 constexpr
double Zero = 0.000001;
88 template<
typename T,
typename ...Args>
91 return std::unique_ptr<T>(
new T( std::forward<Args>(args)... ) );
98 template<
typename T,
typename ...Args>
99 void ptr_reset(std::unique_ptr<T> &target, Args&& ...args)
101 target.reset(
new T(std::forward<Args>(args)...));
108 template<
typename ElemType,
typename PredType>
111 vec.erase(std::remove_if(vec.begin(), vec.end(), pred), vec.end());
120 template <
typename T>
136 template<
typename numtype>
137 using c_array_ptr = std::unique_ptr<numtype, C_resource_deleter<numtype>>;
150 { data = std::move(M.data);
return *
this; }
156 for (
auto i = 0; i < size; ++i)
157 data[i] = std::vector<T>(size - i);
163 for (
auto i = 0; i < size; ++i)
164 data[i] = std::vector<T>(size - i, val);
170 return data[row][column - row];
176 for (std::vector<T> &vec : data)
177 std::fill(vec.begin(), vec.end(), val);
182 std::vector<std::vector<T>>
data;
203 Segment(
int lo,
int hi) : start(lo), end(hi) {}
209 int size()
const {
return end - start + 1; }
214 bool contains(
int vx)
const {
return start <= vx && vx <= end; }
226 return std::make_tuple(size(), start, end) >
232 {
return start == rhs.
start && end == rhs.
end; }
240 EndPts() : end{{-1, -1}} {}
241 EndPts(
int e0,
int e1) : end{{e0, e1}}
242 {
if (end[0] > end[1]) std::swap(end[0], end[1]); }
244 std::array<int, 2> end;
249 return e1.end == e2.end;
252 inline std::ostream &operator<<(std::ostream &os,
const EndPts &e)
254 os <<
"(" << e.end[0] <<
", " << e.end[1] <<
")";
Class template for a square upper triangular matrix.
Definition: util.hpp:141
constexpr double Zero
Numbers less than this treated as zero.
Definition: util.hpp:62
double zeit(void)
CPU time function.
Definition: util.cpp:14
Segment(int lo, int hi)
Construct a Segment with specified start and end point.
Definition: util.hpp:203
constexpr double TotalDelta
A round of cuts is a failure if the pivot deltas sum to less than this.
Definition: util.hpp:71
Class template for deleting resources allocated by C functions.
Definition: util.hpp:121
std::vector< std::vector< T > > data
The entries of the matrix, stored as a ragged vector of vectors.
Definition: util.hpp:182
bool detailed_stats
Detailed timer/profiling of the code.
Definition: util.hpp:54
bool gif_tour
Record each augmenting tour as specified by save_tour/save_tour_edges.
Definition: util.hpp:44
void ptr_reset(std::unique_ptr< T > &target, Args &&...args)
Adaptation of make_unique to reset a unique_ptr to an object.
Definition: util.hpp:99
int end
The end index of the Segment.
Definition: util.hpp:235
void fill(const T &val)
Fill all entries of this matrix with val.
Definition: util.hpp:174
std::unique_ptr< numtype, C_resource_deleter< numtype >> c_array_ptr
Alias declaration for unique_ptr to C array.
Definition: util.hpp:137
SquareUT(size_t size, T val)
Construct a matrix of dimension size with val as all entries.
Definition: util.hpp:161
void operator()(T *ptr) const
Call operator for deleting the managed pointer.
Definition: util.hpp:123
std::unique_ptr< T > make_unique(Args &&...args)
As per Herb Sutter, port of C++14's make_unique faculty.
Definition: util.hpp:89
bool prog_bar
A jittering progress bar for pivot values.
Definition: util.hpp:51
T & operator()(size_t row, size_t column)
Access entry by matrix subscripting.
Definition: util.hpp:168
bool save_tour_edges
Save save_tour edges to probname_tour.x
Definition: util.hpp:37
SquareUT(SquareUT &&M) noexcept
Move constructor.
Definition: util.hpp:146
bool dump_xy
If possible, dump x-y coords to probname.xy
Definition: util.hpp:36
std::string probname
The instance name.
Definition: util.hpp:26
Preferences related to tour file output and verbosity.
Definition: util.hpp:25
bool operator>(const Segment &rhs) const
Compare segments by size and then start point.
Definition: util.hpp:224
SquareUT & operator=(SquareUT &&M) noexcept
Move assignment.
Definition: util.hpp:149
bool operator==(const Segment &rhs) const
Equality operator.
Definition: util.hpp:231
bool contains(int vx) const
Does the Segment contain a certain vertex.
Definition: util.hpp:214
void erase_remove(std::vector< ElemType > &vec, PredType pred)
Standardization of erase-remove idiom.
Definition: util.hpp:109
The namespace for this project.
Definition: abc_nodesel.hpp:20
constexpr double CutViol
Cuts are not considered violated unless by at least this much.
Definition: util.hpp:66
bool verbose
Verbose output from classes and subroutines.
Definition: util.hpp:48
bool save_tour
Save the latest, best tour to probname.sol.
Definition: util.hpp:35
SquareUT(size_t size)
Construct a matrix of dimension size.
Definition: util.hpp:154
Simple base class for storing edge of a graph as a sorted pair of nodes.
Definition: util.hpp:239
Simple utility struct for storing an interval of nodes.
Definition: util.hpp:198
constexpr double PHratio
A small value of the Padberg-Hong metric.
Definition: util.hpp:73
constexpr double MinCut
Tolerance for min cut computations.
Definition: util.hpp:63
bool var_integral(double d)
Is a zero-one variable considered integral.
Definition: util.hpp:81
int size() const
Size of the Segment.
Definition: util.hpp:209
double real_zeit(void)
Wall clock time function.
Definition: util.cpp:24
constexpr double DualDust
Small dual values.
Definition: util.hpp:68
bool subset_of(const Segment &seg) const
Is one Segment a subset of the other.
Definition: util.hpp:220
int start
The start index of the Segment.
Definition: util.hpp:234