XNetwork 1.7.5; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
rand_cover.hpp
Go to the documentation of this file.
1#pragma once
2
23#include <cassert>
24#include <optional>
25#include <py2cpp/set.hpp>
26#include <random>
27#include <utility>
28#include <vector>
30
31namespace detail {
32
46 template <typename Node, typename Validator>
47 void reverse_delete_cover(py::set<Node>& soln, const std::vector<Node>& added_order,
49 for (auto it = added_order.rbegin(); it != added_order.rend(); ++it) {
50 soln.erase(*it);
51 if (!std::forward<Validator>(is_valid)()) {
52 soln.insert(*it);
53 }
54 }
55 }
56
57} // namespace detail
58
71template <typename Graph, typename WeightMap, typename RNG>
72auto rand_vertex_cover_trial(const Graph& ugraph, const WeightMap& weight,
74 -> std::pair<py::set<typename Graph::node_t>, typename WeightMap::mapped_type>;
75
76// -----------------------------------------------------------------------
77// Convenience overload - single trial with seed
78// -----------------------------------------------------------------------
79
89template <typename Graph, typename WeightMap>
90auto rand_vertex_cover(const Graph& ugraph, const WeightMap& weight,
91 std::optional<unsigned int> seed = std::optional<unsigned int>{0},
94 // using node_t = typename Graph::node_t;
95
96 if (seed.has_value()) {
97 std::mt19937 rng{seed.value()};
99 }
100 std::random_device rd;
101 std::mt19937 rng{rd()};
102 return rand_vertex_cover_trial(ugraph, weight, coverset, rng);
103}
104
105// -----------------------------------------------------------------------
106// Multi-threaded: run num_trials independent trials, return best cover
107// -----------------------------------------------------------------------
108
124template <typename Graph, typename WeightMap>
125auto rand_vertex_cover_mt(const Graph& ugraph, const WeightMap& weight,
126 unsigned int num_trials = 64, unsigned int seed = 0,
Read-only map of maps of maps (view into a dict-of-dict-of-dict structure)
Definition coreviews.hpp:109
AdjacencyView(Atlas &d)
Construct an AdjacencyView from an Atlas container.
Definition coreviews.hpp:115
Definition hadlock.hpp:40
void reverse_delete_cover(py::set< Node > &soln, const std::vector< Node > &added_order, Validator &&is_valid)
Reverse-delete post-processing step.
Definition rand_cover.hpp:47
auto rand_vertex_cover_trial(const Graph &ugraph, const WeightMap &weight, const py::set< typename Graph::node_t > &coverset, RNG &rng) -> std::pair< py::set< typename Graph::node_t >, typename WeightMap::mapped_type >
Single trial of Pitt's randomized vertex cover algorithm.
auto rand_vertex_cover(const Graph &ugraph, const WeightMap &weight, std::optional< unsigned int > seed=std::optional< unsigned int >{0}, const py::set< typename Graph::node_t > &coverset={}) -> std::pair< py::set< typename Graph::node_t >, typename WeightMap::mapped_type >
Single-trial randomized vertex cover (seeded convenience wrapper).
Definition rand_cover.hpp:90
auto rand_vertex_cover_mt(const Graph &ugraph, const WeightMap &weight, unsigned int num_trials=64, unsigned int seed=0, const py::set< typename Graph::node_t > &coverset={}) -> std::pair< py::set< typename Graph::node_t >, typename WeightMap::mapped_type >
Multi-threaded randomized vertex cover.