Camargue
|
Utility functions/structures used miscellaneous places in the project. More...
Classes | |
struct | C_resource_deleter |
Class template for deleting resources allocated by C functions. More... | |
class | EdgeHash |
Hash map for node pairs representing edges. More... | |
class | Fixed64 |
A 64-bit fixed precision number type "implemented" as a wrapper to CCbigguy. More... | |
struct | retcode_error |
Structure for converting retcodes to exceptions. More... | |
class | ScopeGuard |
Code from Andrei Alexandrescu's ScopeGuard11 slides. More... | |
class | SquareUT |
Class template for a square upper triangular matrix. More... | |
Typedefs | |
template<typename numtype > | |
using | c_array_ptr = std::unique_ptr< numtype, C_resource_deleter< numtype >> |
Alias declaration for unique_ptr to C array. More... | |
Functions | |
template<typename act_type > | |
ScopeGuard< act_type > | make_guard (act_type f) |
Type deduction function for ScopeGuard, also from Andrei Alexandrescu. More... | |
Fixed64 | operator+ (Fixed64 a, Fixed64 b) |
Fixed64 | operator- (Fixed64 a, Fixed64 b) |
void | add_mult (Fixed64 &f, const Fixed64 &g, int m) |
void | add_mult (double &d, const double &g, int m) |
std::ostream & | operator<< (std::ostream &os, const Fixed64 &f) |
void | write_tour_nodes (const std::vector< int > &tour_nodes, const std::string &tour_nodes_fname) |
Writes a tour to file. More... | |
void | write_tour_edges (const std::vector< int > &tour_edges, const std::vector< Graph::Edge > &edges, const int node_count, const std::string &tour_edges_fname) |
Writes tour edges to file. More... | |
void | write_lp_edges (const std::vector< int > &lp_elist, const std::vector< double > &lp_ecap, const int node_count, const std::string &lp_edges_fname) |
Writes LP edges to file. More... | |
void | write_xy_coords (const double *x, const double *y, const int ncount, const std::string &xy_coords_fname) |
Dumps the xy-coordinates for nodes in a graph. More... | |
void | get_tour_nodes (const int node_count, std::vector< int > &tour_nodes, const std::string &tour_nodes_fname) |
Load a tour from file. More... | |
void | get_lp_sol (const int node_count, std::vector< int > &support_elist, std::vector< double > &support_ecap, const std::string &lp_sol_fname) |
Loads an lp solution from file. More... | |
bool | var_integral (double d) |
Is a zero-one variable considered integral. | |
double | zeit (void) |
CPU time function. | |
double | real_zeit (void) |
Wall clock time function. | |
template<typename T , typename... Args> | |
std::unique_ptr< T > | make_unique (Args &&...args) |
As per Herb Sutter, port of C++14's make_unique faculty. | |
template<typename T , typename... Args> | |
void | ptr_reset (std::unique_ptr< T > &target, Args &&...args) |
Adaptation of make_unique to reset a unique_ptr to an object. More... | |
template<typename ElemType , typename PredType > | |
void | erase_remove (std::vector< ElemType > &vec, PredType pred) |
Standardization of erase-remove idiom. More... | |
Utility functions/structures used miscellaneous places in the project.
using CMR::util::c_array_ptr = typedef std::unique_ptr<numtype, C_resource_deleter<numtype>> |
Alias declaration for unique_ptr to C array.
This specialization of unique_ptr takes ownership of a C-style array which was dynamically allocated by a C routine, freeing its memory appropriately when necessary.
void CMR::util::erase_remove | ( | std::vector< ElemType > & | vec, |
PredType | pred | ||
) |
Standardization of erase-remove idiom.
[in,out] | vec | the vector to modify. |
[in] | pred | the predicate to apply. |
vec
for which pred
returns true. void CMR::util::get_lp_sol | ( | const int | node_count, |
std::vector< int > & | support_elist, | ||
std::vector< double > & | support_ecap, | ||
const std::string & | lp_sol_fname | ||
) |
Loads an lp solution from file.
Reads a specified solution from file, storing edge endpoints and capacities in vectors.
[in] | node_count | the dimension of the instance. |
[out] | support_elist | a node-node list of the edges in the solution. |
[out] | support_ecap | capacities corresponding to the edges in support_elist. |
[in] | lp_sol_fname | the filename to read from. |
lp_sol_fname
names an existant file whose first line is n m
where n
is node_count
and m
is the number of nonzero edges in the solution. support_ecap.size() == m
and support_elist.size() == 2 * m
.i
, if the i
th line of lp_sol_fname
is u v w
then support_elist[2 * i] == u
suppor_elist[(2 * i) + 1] == v
support_ecap[i] == w
void CMR::util::get_tour_nodes | ( | const int | node_count, |
std::vector< int > & | tour_nodes, | ||
const std::string & | tour_nodes_fname | ||
) |
Load a tour from file.
Reads a tour from file, storing it in a vector of nodes.
Some basic checks are performed to ensure that the tour is on the right number of nodes, and visits no city more than once.
[in] | node_count | the number of nodes in the instance. |
[out] | tour_nodes | the vector used to store the nodes. |
[in] | tour_nodes_fname | the filename to read from. |
tour_nodes_fname
names an existant file whose first line is node_count
and whose following entries are a cyclic permutation of the numbers 0, ..., node_count
tour_nodes
has length node_count
and its entries are the nodes from tour_nodes_fname
in the same order ScopeGuard<act_type> CMR::util::make_guard | ( | act_type | f | ) |
Type deduction function for ScopeGuard, also from Andrei Alexandrescu.
[in] | f | the function to be called when the guard goes out of scope. The suggested usage is auto cleanup = make_guard([] {cleanup_lambda}); |
void CMR::util::ptr_reset | ( | std::unique_ptr< T > & | target, |
Args &&... | args | ||
) |
Adaptation of make_unique to reset a unique_ptr to an object.
For classes with reference members, we cannot easily define move constructors. This function provides a surrogate move constructor by resetting a unique_ptr to such an object.
void CMR::util::write_lp_edges | ( | const std::vector< int > & | lp_elist, |
const std::vector< double > & | lp_ecap, | ||
const int | node_count, | ||
const std::string & | lp_edges_fname | ||
) |
Writes LP edges to file.
Writes the specified lp solution with edges and capacities to file.
[in] | lp_elist | the edges in an LP solution in node node format |
[in] | lp_ecap | the value assigned to each edge in the LP solution |
[in] | node_count | the number of nodes in the instance. |
[in] | lp_edges_fname | the file to write to. |
lp_elist
and lp_ecap
nonempty lp_elist.size()
is twice lp_ecap.size()
lp_ecap[i]
is the weight on the edge lp_elist[2i]
, lp_elist[2i + 1]
lp_edges_fname
is a nonempty string lp_edges_fname
will be the name of a file with node_count
lp_ecap.size()
on the first line, followed by support_elist[2i] support_elist[2i + 1] support_ecap[2i]
for all i
from 0 to lp_ecap.size()
void CMR::util::write_tour_edges | ( | const std::vector< int > & | tour_edges, |
const std::vector< Graph::Edge > & | edges, | ||
const int | node_count, | ||
const std::string & | tour_edges_fname | ||
) |
Writes tour edges to file.
[in] | tour_edges | the edges of the tour to write to file. |
[in] | edges | a vector of Edge structs indicating edge endpoints |
[in] | node_count | the number of nodes in the problem, hence indicating maximum index of an endpoint in edges or tour_edges . |
[in] | tour_edges_fname | the file name to write to. |
tour_edges
and edges
are nonempty, of the same size tour_edges
is binary, and the collection of edges
[i] for which tour_edges
[i] == 1
gives a connected cyclical graph edges
is a list of edges in a graph with node_count
nodes tour_edges_fname
is a nonempty string tour_edges_fname
will be the name of a file with node_count
and edges.size()
on the top line, followed by edges
[i].end[0]
edges
[i].end[1]
1.0
for each i such that tour_edges
[i] == 1
void CMR::util::write_tour_nodes | ( | const std::vector< int > & | tour_nodes, |
const std::string & | tour_nodes_fname | ||
) |
Writes a tour to file.
Writes the tour specified by tour_nodes
to the file named tour_nodes_fname
.
tour_nodes
is nonempty, containing a cyclic permutation of the numbers from 0 to tour_nodes.size()
tour_nodes_fname
is a nonempty filename tour_nodes_fname
will be the name of a file with tour_nodes.size() at the top, followed by the entries of tour_nodes void CMR::util::write_xy_coords | ( | const double * | x, |
const double * | y, | ||
const int | node_count, | ||
const std::string & | xy_coords_fname | ||
) |
Dumps the xy-coordinates for nodes in a graph.
[in] | x | a c-style array of x coordinates |
[in] | y | a c-style array of y coordinates |
[in] | node_count | the number of nodes in the instance, hence the lengths of x and y . |
[in] | xy_coords_fname | the filename to write to. |
xy_coords_fname
has ncount
on its first line, followed by x
[i]
y
[i]
on all the following lines.