gtsam_unstable/partition
parent
4bc2795299
commit
4e2f0cc36b
|
@ -13,6 +13,7 @@
|
|||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/shared_array.hpp>
|
||||
|
||||
|
@ -237,7 +238,7 @@ namespace gtsam { namespace partition {
|
|||
|
||||
/* ************************************************************************* */
|
||||
template<class GenericGraph>
|
||||
boost::optional<MetisResult> separatorPartitionByMetis(const GenericGraph& graph,
|
||||
std::optional<MetisResult> separatorPartitionByMetis(const GenericGraph& graph,
|
||||
const std::vector<size_t>& keys, WorkSpace& workspace, bool verbose) {
|
||||
// create a metis graph
|
||||
size_t numKeys = keys.size();
|
||||
|
@ -252,7 +253,7 @@ namespace gtsam { namespace partition {
|
|||
size_t sepsize;
|
||||
sharedInts part;
|
||||
boost::tie(sepsize, part) = separatorMetis(numKeys, xadj, adjncy, adjwgt, verbose);
|
||||
if (!sepsize) return boost::optional<MetisResult>();
|
||||
if (!sepsize) return std::optional<MetisResult>();
|
||||
|
||||
// convert the 0-1-2 from Metis to 1-2-0, so that the separator is 0, as later
|
||||
// we will have more submaps
|
||||
|
@ -291,7 +292,7 @@ namespace gtsam { namespace partition {
|
|||
|
||||
/* *************************************************************************/
|
||||
template<class GenericGraph>
|
||||
boost::optional<MetisResult> edgePartitionByMetis(const GenericGraph& graph,
|
||||
std::optional<MetisResult> edgePartitionByMetis(const GenericGraph& graph,
|
||||
const std::vector<size_t>& keys, WorkSpace& workspace, bool verbose) {
|
||||
|
||||
// a small hack for handling the camera1-camera2 case used in the unit tests
|
||||
|
@ -443,15 +444,15 @@ namespace gtsam { namespace partition {
|
|||
|
||||
/* ************************************************************************* */
|
||||
template<class GenericGraph>
|
||||
boost::optional<MetisResult> findPartitoning(const GenericGraph& graph, const std::vector<size_t>& keys,
|
||||
std::optional<MetisResult> findPartitoning(const GenericGraph& graph, const std::vector<size_t>& keys,
|
||||
WorkSpace& workspace, bool verbose,
|
||||
const boost::optional<std::vector<Symbol> >& int2symbol, const bool reduceGraph) {
|
||||
boost::optional<MetisResult> result;
|
||||
const std::optional<std::vector<Symbol> >& int2symbol, const bool reduceGraph) {
|
||||
std::optional<MetisResult> result;
|
||||
GenericGraph reducedGraph;
|
||||
std::vector<size_t> keyToPartition;
|
||||
std::vector<size_t> cameraKeys, landmarkKeys;
|
||||
if (reduceGraph) {
|
||||
if (!int2symbol.is_initialized())
|
||||
if (!int2symbol.has_value())
|
||||
throw std::invalid_argument("findSeparator: int2symbol must be valid!");
|
||||
|
||||
// find out all the landmark keys, which are to be eliminated
|
||||
|
@ -474,9 +475,9 @@ namespace gtsam { namespace partition {
|
|||
} else // call Metis to partition the graph to A, B, C
|
||||
result = separatorPartitionByMetis(graph, keys, workspace, verbose);
|
||||
|
||||
if (!result.is_initialized()) {
|
||||
if (!result.has_value()) {
|
||||
std::cout << "metis failed!" << std::endl;
|
||||
return boost::none;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (reduceGraph) {
|
||||
|
@ -491,10 +492,10 @@ namespace gtsam { namespace partition {
|
|||
template<class GenericGraph>
|
||||
int findSeparator(const GenericGraph& graph, const std::vector<size_t>& keys,
|
||||
const int minNodesPerMap, WorkSpace& workspace, bool verbose,
|
||||
const boost::optional<std::vector<Symbol> >& int2symbol, const bool reduceGraph,
|
||||
const std::optional<std::vector<Symbol> >& int2symbol, const bool reduceGraph,
|
||||
const int minNrConstraintsPerCamera, const int minNrConstraintsPerLandmark) {
|
||||
|
||||
boost::optional<MetisResult> result = findPartitoning(graph, keys, workspace,
|
||||
std::optional<MetisResult> result = findPartitoning(graph, keys, workspace,
|
||||
verbose, int2symbol, reduceGraph);
|
||||
|
||||
// find the island in A and B, and make them separated submaps
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace gtsam { namespace partition {
|
|||
* the size of dictionary mush be equal to the number of variables in the original graph (the largest one)
|
||||
*/
|
||||
template<class GenericGraph>
|
||||
boost::optional<MetisResult> separatorPartitionByMetis(const GenericGraph& graph, const std::vector<size_t>& keys,
|
||||
std::optional<MetisResult> separatorPartitionByMetis(const GenericGraph& graph, const std::vector<size_t>& keys,
|
||||
WorkSpace& workspace, bool verbose);
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ namespace gtsam { namespace partition {
|
|||
*/
|
||||
template<class GenericGraph>
|
||||
int findSeparator(const GenericGraph& graph, const std::vector<size_t>& keys,
|
||||
const int minNodesPerMap, WorkSpace& workspace, bool verbose, const boost::optional<std::vector<Symbol> >& int2symbol,
|
||||
const int minNodesPerMap, WorkSpace& workspace, bool verbose, const std::optional<std::vector<Symbol> >& int2symbol,
|
||||
const bool reduceGraph, const int minNrConstraintsPerCamera, const int minNrConstraintsPerLandmark);
|
||||
|
||||
}} //namespace
|
||||
|
|
|
@ -29,10 +29,10 @@ TEST ( Partition, separatorPartitionByMetis )
|
|||
std::vector<size_t> keys{0, 1, 2, 3, 4};
|
||||
|
||||
WorkSpace workspace(5);
|
||||
boost::optional<MetisResult> actual = separatorPartitionByMetis<GenericGraph2D>(graph, keys,
|
||||
std::optional<MetisResult> actual = separatorPartitionByMetis<GenericGraph2D>(graph, keys,
|
||||
workspace, true);
|
||||
|
||||
CHECK(actual.is_initialized());
|
||||
CHECK(actual.has_value());
|
||||
vector<size_t> A_expected{0, 3}; // frontal
|
||||
vector<size_t> B_expected{2, 4}; // frontal
|
||||
vector<size_t> C_expected{1}; // separator
|
||||
|
@ -54,10 +54,10 @@ TEST ( Partition, separatorPartitionByMetis2 )
|
|||
std::vector<size_t> keys{1, 2, 3, 5, 6};
|
||||
|
||||
WorkSpace workspace(8);
|
||||
boost::optional<MetisResult> actual = separatorPartitionByMetis<GenericGraph2D>(graph, keys,
|
||||
std::optional<MetisResult> actual = separatorPartitionByMetis<GenericGraph2D>(graph, keys,
|
||||
workspace, true);
|
||||
|
||||
CHECK(actual.is_initialized());
|
||||
CHECK(actual.has_value());
|
||||
vector<size_t> A_expected{1, 5}; // frontal
|
||||
vector<size_t> B_expected{3, 6}; // frontal
|
||||
vector<size_t> C_expected{2}; // separator
|
||||
|
@ -77,10 +77,10 @@ TEST ( Partition, edgePartitionByMetis )
|
|||
std::vector<size_t> keys{0, 1, 2, 3};
|
||||
|
||||
WorkSpace workspace(6);
|
||||
boost::optional<MetisResult> actual = edgePartitionByMetis<GenericGraph3D>(graph, keys,
|
||||
std::optional<MetisResult> actual = edgePartitionByMetis<GenericGraph3D>(graph, keys,
|
||||
workspace, true);
|
||||
|
||||
CHECK(actual.is_initialized());
|
||||
CHECK(actual.has_value());
|
||||
vector<size_t> A_expected{0, 1}; // frontal
|
||||
vector<size_t> B_expected{2, 3}; // frontal
|
||||
vector<size_t> C_expected; // separator
|
||||
|
@ -108,9 +108,9 @@ TEST ( Partition, edgePartitionByMetis2 )
|
|||
std::vector<size_t> keys{0, 1, 2, 3, 4};
|
||||
|
||||
WorkSpace workspace(6);
|
||||
boost::optional<MetisResult> actual = edgePartitionByMetis<GenericGraph3D>(graph, keys,
|
||||
std::optional<MetisResult> actual = edgePartitionByMetis<GenericGraph3D>(graph, keys,
|
||||
workspace, true);
|
||||
CHECK(actual.is_initialized());
|
||||
CHECK(actual.has_value());
|
||||
vector<size_t> A_expected{0, 1}; // frontal
|
||||
vector<size_t> B_expected{2, 3, 4}; // frontal
|
||||
vector<size_t> C_expected; // separator
|
||||
|
@ -135,7 +135,7 @@ TEST ( Partition, findSeparator )
|
|||
int minNodesPerMap = -1;
|
||||
bool reduceGraph = false;
|
||||
int numSubmaps = findSeparator<GenericGraph2D>(graph, keys, minNodesPerMap, workspace,
|
||||
false, boost::none, reduceGraph, 0, 0);
|
||||
false, {}, reduceGraph, 0, 0);
|
||||
LONGS_EQUAL(2, numSubmaps);
|
||||
LONGS_EQUAL(5, workspace.partitionTable.size());
|
||||
LONGS_EQUAL(1, workspace.partitionTable[0]);
|
||||
|
@ -161,7 +161,7 @@ TEST ( Partition, findSeparator2 )
|
|||
int minNodesPerMap = -1;
|
||||
bool reduceGraph = false;
|
||||
int numSubmaps = findSeparator<GenericGraph2D>(graph, keys, minNodesPerMap, workspace,
|
||||
false, boost::none, reduceGraph, 0, 0);
|
||||
false, {}, reduceGraph, 0, 0);
|
||||
LONGS_EQUAL(2, numSubmaps);
|
||||
LONGS_EQUAL(8, workspace.partitionTable.size());
|
||||
LONGS_EQUAL(-1,workspace.partitionTable[0]);
|
||||
|
|
Loading…
Reference in New Issue