diff --git a/gtsam_unstable/partition/FindSeparator-inl.h b/gtsam_unstable/partition/FindSeparator-inl.h index 0e4950b79..45868e78e 100644 --- a/gtsam_unstable/partition/FindSeparator-inl.h +++ b/gtsam_unstable/partition/FindSeparator-inl.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -237,7 +238,7 @@ namespace gtsam { namespace partition { /* ************************************************************************* */ template - boost::optional separatorPartitionByMetis(const GenericGraph& graph, + std::optional separatorPartitionByMetis(const GenericGraph& graph, const std::vector& 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(); + if (!sepsize) return std::optional(); // 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 - boost::optional edgePartitionByMetis(const GenericGraph& graph, + std::optional edgePartitionByMetis(const GenericGraph& graph, const std::vector& 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 - boost::optional findPartitoning(const GenericGraph& graph, const std::vector& keys, + std::optional findPartitoning(const GenericGraph& graph, const std::vector& keys, WorkSpace& workspace, bool verbose, - const boost::optional >& int2symbol, const bool reduceGraph) { - boost::optional result; + const std::optional >& int2symbol, const bool reduceGraph) { + std::optional result; GenericGraph reducedGraph; std::vector keyToPartition; std::vector 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 int findSeparator(const GenericGraph& graph, const std::vector& keys, const int minNodesPerMap, WorkSpace& workspace, bool verbose, - const boost::optional >& int2symbol, const bool reduceGraph, + const std::optional >& int2symbol, const bool reduceGraph, const int minNrConstraintsPerCamera, const int minNrConstraintsPerLandmark) { - boost::optional result = findPartitoning(graph, keys, workspace, + std::optional result = findPartitoning(graph, keys, workspace, verbose, int2symbol, reduceGraph); // find the island in A and B, and make them separated submaps diff --git a/gtsam_unstable/partition/FindSeparator.h b/gtsam_unstable/partition/FindSeparator.h index f4342695b..9a6c61800 100644 --- a/gtsam_unstable/partition/FindSeparator.h +++ b/gtsam_unstable/partition/FindSeparator.h @@ -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 - boost::optional separatorPartitionByMetis(const GenericGraph& graph, const std::vector& keys, + std::optional separatorPartitionByMetis(const GenericGraph& graph, const std::vector& keys, WorkSpace& workspace, bool verbose); /** @@ -40,7 +40,7 @@ namespace gtsam { namespace partition { */ template int findSeparator(const GenericGraph& graph, const std::vector& keys, - const int minNodesPerMap, WorkSpace& workspace, bool verbose, const boost::optional >& int2symbol, + const int minNodesPerMap, WorkSpace& workspace, bool verbose, const std::optional >& int2symbol, const bool reduceGraph, const int minNrConstraintsPerCamera, const int minNrConstraintsPerLandmark); }} //namespace diff --git a/gtsam_unstable/partition/tests/testFindSeparator.cpp b/gtsam_unstable/partition/tests/testFindSeparator.cpp index 49796f80d..b086be7ff 100644 --- a/gtsam_unstable/partition/tests/testFindSeparator.cpp +++ b/gtsam_unstable/partition/tests/testFindSeparator.cpp @@ -29,10 +29,10 @@ TEST ( Partition, separatorPartitionByMetis ) std::vector keys{0, 1, 2, 3, 4}; WorkSpace workspace(5); - boost::optional actual = separatorPartitionByMetis(graph, keys, + std::optional actual = separatorPartitionByMetis(graph, keys, workspace, true); - CHECK(actual.is_initialized()); + CHECK(actual.has_value()); vector A_expected{0, 3}; // frontal vector B_expected{2, 4}; // frontal vector C_expected{1}; // separator @@ -54,10 +54,10 @@ TEST ( Partition, separatorPartitionByMetis2 ) std::vector keys{1, 2, 3, 5, 6}; WorkSpace workspace(8); - boost::optional actual = separatorPartitionByMetis(graph, keys, + std::optional actual = separatorPartitionByMetis(graph, keys, workspace, true); - CHECK(actual.is_initialized()); + CHECK(actual.has_value()); vector A_expected{1, 5}; // frontal vector B_expected{3, 6}; // frontal vector C_expected{2}; // separator @@ -77,10 +77,10 @@ TEST ( Partition, edgePartitionByMetis ) std::vector keys{0, 1, 2, 3}; WorkSpace workspace(6); - boost::optional actual = edgePartitionByMetis(graph, keys, + std::optional actual = edgePartitionByMetis(graph, keys, workspace, true); - CHECK(actual.is_initialized()); + CHECK(actual.has_value()); vector A_expected{0, 1}; // frontal vector B_expected{2, 3}; // frontal vector C_expected; // separator @@ -108,9 +108,9 @@ TEST ( Partition, edgePartitionByMetis2 ) std::vector keys{0, 1, 2, 3, 4}; WorkSpace workspace(6); - boost::optional actual = edgePartitionByMetis(graph, keys, + std::optional actual = edgePartitionByMetis(graph, keys, workspace, true); - CHECK(actual.is_initialized()); + CHECK(actual.has_value()); vector A_expected{0, 1}; // frontal vector B_expected{2, 3, 4}; // frontal vector C_expected; // separator @@ -135,7 +135,7 @@ TEST ( Partition, findSeparator ) int minNodesPerMap = -1; bool reduceGraph = false; int numSubmaps = findSeparator(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(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]);