Remove dependence on Boost.Hash
This commit is contained in:
parent
731b202af3
commit
9c669f2d03
|
@ -1,8 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Algorithm for finding a maximum weight matching in general graphs.
|
* Algorithm for finding a maximum weight matching in general graphs.
|
||||||
*
|
|
||||||
* Depends on Boost.Hash.
|
|
||||||
* Tested with Boost v1.74, available from https://www.boost.org/
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MWMATCHING_H_
|
#ifndef MWMATCHING_H_
|
||||||
|
@ -18,12 +15,9 @@
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <unordered_set>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/functional/hash.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace mwmatching {
|
namespace mwmatching {
|
||||||
|
|
||||||
|
@ -95,7 +89,7 @@ inline VertexPair flip_vertex_pair(const VertexPair& vt)
|
||||||
* The graph may not have self-edges or multiple edges between
|
* The graph may not have self-edges or multiple edges between
|
||||||
* the same pair of vertices. Edge weights must be within a valid range.
|
* the same pair of vertices. Edge weights must be within a valid range.
|
||||||
*
|
*
|
||||||
* This function takes time O(m).
|
* This function takes time O(m * log(m)).
|
||||||
*
|
*
|
||||||
* @param edges Vector of weighted edges defining the graph.
|
* @param edges Vector of weighted edges defining the graph.
|
||||||
* @throw std::invalid_argument If the input graph is not valid.
|
* @throw std::invalid_argument If the input graph is not valid.
|
||||||
|
@ -136,18 +130,22 @@ void check_input_graph(const std::vector<Edge<WeightType>>& edges)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the graph does not contain duplicate edges.
|
// Check that the graph does not contain duplicate edges.
|
||||||
std::unordered_set<VertexPair, boost::hash<VertexPair>> edges_seen;
|
std::vector<VertexPair> edge_endpoints;
|
||||||
|
edge_endpoints.reserve(edges.size());
|
||||||
for (const Edge<WeightType>& edge : edges) {
|
for (const Edge<WeightType>& edge : edges) {
|
||||||
VertexPair vt = edge.vt;
|
VertexPair vt = edge.vt;
|
||||||
if (vt.first > vt.second) {
|
if (vt.first > vt.second) {
|
||||||
vt = flip_vertex_pair(vt);
|
std::swap(vt.first, vt.second);
|
||||||
}
|
}
|
||||||
auto status = edges_seen.insert(vt);
|
edge_endpoints.push_back(vt);
|
||||||
if (!status.second) {
|
}
|
||||||
|
|
||||||
|
std::sort(edge_endpoints.begin(), edge_endpoints.end());
|
||||||
|
if (std::unique(edge_endpoints.begin(), edge_endpoints.end())
|
||||||
|
!= edge_endpoints.end()) {
|
||||||
throw std::invalid_argument("Duplicate edges are not supported");
|
throw std::invalid_argument("Duplicate edges are not supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue