diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h index 3fbb64d50..8b30cb963 100644 --- a/gtsam/discrete/DiscreteFactorGraph.h +++ b/gtsam/discrete/DiscreteFactorGraph.h @@ -155,7 +155,7 @@ class GTSAM_EXPORT DiscreteFactorGraph * @return DiscreteBayesNet encoding posterior P(X|Z) */ DiscreteBayesNet sumProduct( - OptionalOrderingType orderingType = boost::none) const; + OptionalOrderingType orderingType = {}) const; /** * @brief Implement the sum-product algorithm @@ -172,7 +172,7 @@ class GTSAM_EXPORT DiscreteFactorGraph * @return DiscreteLookupDAG DAG with lookup tables */ DiscreteLookupDAG maxProduct( - OptionalOrderingType orderingType = boost::none) const; + OptionalOrderingType orderingType = {}) const; /** * @brief Implement the max-product algorithm @@ -189,7 +189,7 @@ class GTSAM_EXPORT DiscreteFactorGraph * @return DiscreteValues : MPE */ DiscreteValues optimize( - OptionalOrderingType orderingType = boost::none) const; + OptionalOrderingType orderingType = {}) const; /** * @brief Find the maximum probable explanation (MPE) by doing max-product. diff --git a/gtsam/inference/BayesTree-inst.h b/gtsam/inference/BayesTree-inst.h index 055971a82..65ba37889 100644 --- a/gtsam/inference/BayesTree-inst.h +++ b/gtsam/inference/BayesTree-inst.h @@ -25,7 +25,6 @@ #include #include -#include #include namespace gtsam { diff --git a/gtsam/inference/BayesTreeCliqueBase-inst.h b/gtsam/inference/BayesTreeCliqueBase-inst.h index 6da7d0fe4..37ed49055 100644 --- a/gtsam/inference/BayesTreeCliqueBase-inst.h +++ b/gtsam/inference/BayesTreeCliqueBase-inst.h @@ -178,7 +178,7 @@ namespace gtsam { this->conditional()->endParents()); auto separatorMarginal = p_Cp.marginalMultifrontalBayesNet(Ordering(indicesS), function); - cachedSeparatorMarginal_.reset(*separatorMarginal); + cachedSeparatorMarginal_ = *separatorMarginal; } } @@ -217,7 +217,7 @@ namespace gtsam { } //Delete CachedShortcut for this clique - cachedSeparatorMarginal_ = boost::none; + cachedSeparatorMarginal_ = {}; } } diff --git a/gtsam/inference/BayesTreeCliqueBase.h b/gtsam/inference/BayesTreeCliqueBase.h index c9bb6db94..4cb0941b9 100644 --- a/gtsam/inference/BayesTreeCliqueBase.h +++ b/gtsam/inference/BayesTreeCliqueBase.h @@ -21,10 +21,10 @@ #include #include #include -#include #include #include +#include namespace gtsam { @@ -102,7 +102,7 @@ namespace gtsam { /// @} /// This stores the Cached separator marginal P(S) - mutable boost::optional cachedSeparatorMarginal_; + mutable std::optional cachedSeparatorMarginal_; /// This protects Cached seperator marginal P(S) from concurrent read/writes /// as many the functions which access it are const (hence the mutable) /// leading to the false impression that these const functions are thread-safe @@ -174,7 +174,7 @@ namespace gtsam { */ void deleteCachedShortcuts(); - const boost::optional& cachedSeparatorMarginal() const { + const std::optional& cachedSeparatorMarginal() const { std::lock_guard marginalLock(cachedSeparatorMarginalMutex_); return cachedSeparatorMarginal_; } @@ -194,7 +194,7 @@ namespace gtsam { /** Non-recursive delete cached shortcuts and marginals - internal only. */ void deleteCachedShortcutsNonRecursive() { std::lock_guard marginalLock(cachedSeparatorMarginalMutex_); - cachedSeparatorMarginal_ = boost::none; + cachedSeparatorMarginal_ = {}; } private: diff --git a/gtsam/inference/DotWriter.cpp b/gtsam/inference/DotWriter.cpp index eac0c90f9..8047c281f 100644 --- a/gtsam/inference/DotWriter.cpp +++ b/gtsam/inference/DotWriter.cpp @@ -40,7 +40,7 @@ void DotWriter::digraphPreamble(ostream* os) const { } void DotWriter::drawVariable(Key key, const KeyFormatter& keyFormatter, - const boost::optional& position, + const std::optional& position, ostream* os) const { // Label the node with the label from the KeyFormatter *os << " var" << key << "[label=\"" << keyFormatter(key) @@ -54,7 +54,7 @@ void DotWriter::drawVariable(Key key, const KeyFormatter& keyFormatter, *os << "];\n"; } -void DotWriter::DrawFactor(size_t i, const boost::optional& position, +void DotWriter::DrawFactor(size_t i, const std::optional& position, ostream* os) { *os << " factor" << i << "[label=\"\", shape=point"; if (position) { @@ -76,26 +76,28 @@ static void ConnectVariableFactor(Key key, const KeyFormatter& keyFormatter, } /// Return variable position or none -boost::optional DotWriter::variablePos(Key key) const { - boost::optional result = boost::none; +std::optional DotWriter::variablePos(Key key) const { + std::optional result = {}; // Check position hint Symbol symbol(key); auto hint = positionHints.find(symbol.chr()); - if (hint != positionHints.end()) - result.reset(Vector2(symbol.index(), hint->second)); + if (hint != positionHints.end()) { + result = Vector2(symbol.index(), hint->second); + } // Override with explicit position, if given. auto pos = variablePositions.find(key); - if (pos != variablePositions.end()) - result.reset(pos->second); + if (pos != variablePositions.end()) { + result = pos->second; + } return result; } void DotWriter::processFactor(size_t i, const KeyVector& keys, const KeyFormatter& keyFormatter, - const boost::optional& position, + const std::optional& position, ostream* os) const { if (plotFactorPoints) { if (binaryEdges && keys.size() == 2) { diff --git a/gtsam/inference/DotWriter.h b/gtsam/inference/DotWriter.h index 4973f0e53..ff20f5fa0 100644 --- a/gtsam/inference/DotWriter.h +++ b/gtsam/inference/DotWriter.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace gtsam { @@ -80,20 +81,20 @@ struct GTSAM_EXPORT DotWriter { /// Create a variable dot fragment. void drawVariable(Key key, const KeyFormatter& keyFormatter, - const boost::optional& position, + const std::optional& position, std::ostream* os) const; /// Create factor dot. - static void DrawFactor(size_t i, const boost::optional& position, + static void DrawFactor(size_t i, const std::optional& position, std::ostream* os); /// Return variable position or none - boost::optional variablePos(Key key) const; + std::optional variablePos(Key key) const; /// Draw a single factor, specified by its index i and its variable keys. void processFactor(size_t i, const KeyVector& keys, const KeyFormatter& keyFormatter, - const boost::optional& position, + const std::optional& position, std::ostream* os) const; }; diff --git a/gtsam/inference/EliminateableFactorGraph.h b/gtsam/inference/EliminateableFactorGraph.h index 900346f7f..c6cf56a11 100644 --- a/gtsam/inference/EliminateableFactorGraph.h +++ b/gtsam/inference/EliminateableFactorGraph.h @@ -20,8 +20,8 @@ #include #include +#include #include -#include #include #include @@ -92,7 +92,7 @@ namespace gtsam { typedef boost::optional OptionalVariableIndex; /// Typedef for an optional ordering type - typedef boost::optional OptionalOrderingType; + typedef std::optional OptionalOrderingType; /** Do sequential elimination of all variables to produce a Bayes net. If an ordering is not * provided, the ordering provided by COLAMD will be used. @@ -111,13 +111,13 @@ namespace gtsam { * \code * VariableIndex varIndex(graph); // Build variable index * Data data = otherFunctionUsingVariableIndex(graph, varIndex); // Other code that uses variable index - * boost::shared_ptr result = graph.eliminateSequential(EliminateQR, varIndex, boost::none); + * boost::shared_ptr result = graph.eliminateSequential(EliminateQR, varIndex, std::nullopt); * \endcode * */ boost::shared_ptr eliminateSequential( - OptionalOrderingType orderingType = boost::none, + OptionalOrderingType orderingType = {}, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do sequential elimination of all variables to produce a Bayes net. * @@ -130,13 +130,13 @@ namespace gtsam { * \code * VariableIndex varIndex(graph); // Build variable index * Data data = otherFunctionUsingVariableIndex(graph, varIndex); // Other code that uses variable index - * boost::shared_ptr result = graph.eliminateSequential(myOrdering, EliminateQR, varIndex, boost::none); + * boost::shared_ptr result = graph.eliminateSequential(myOrdering, EliminateQR, varIndex, std::nullopt); * \endcode * */ boost::shared_ptr eliminateSequential( const Ordering& ordering, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do multifrontal elimination of all variables to produce a Bayes tree. If an ordering is not * provided, the ordering will be computed using either COLAMD or METIS, dependeing on @@ -151,13 +151,13 @@ namespace gtsam { * \code * VariableIndex varIndex(graph); // Build variable index * Data data = otherFunctionUsingVariableIndex(graph, varIndex); // Other code that uses variable index - * boost::shared_ptr result = graph.eliminateMultifrontal(EliminateQR, boost::none, varIndex); + * boost::shared_ptr result = graph.eliminateMultifrontal(EliminateQR, {}, varIndex); * \endcode * */ boost::shared_ptr eliminateMultifrontal( - OptionalOrderingType orderingType = boost::none, + OptionalOrderingType orderingType = {}, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do multifrontal elimination of all variables to produce a Bayes tree. If an ordering is not * provided, the ordering will be computed using either COLAMD or METIS, dependeing on @@ -171,7 +171,7 @@ namespace gtsam { boost::shared_ptr eliminateMultifrontal( const Ordering& ordering, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do sequential elimination of some variables, in \c ordering provided, to produce a Bayes net * and a remaining factor graph. This computes the factorization \f$ p(X) = p(A|B) p(B) \f$, @@ -181,7 +181,7 @@ namespace gtsam { eliminatePartialSequential( const Ordering& ordering, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do sequential elimination of the given \c variables in an ordering computed by COLAMD to * produce a Bayes net and a remaining factor graph. This computes the factorization \f$ p(X) @@ -191,7 +191,7 @@ namespace gtsam { eliminatePartialSequential( const KeyVector& variables, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do multifrontal elimination of some variables, in \c ordering provided, to produce a Bayes * tree and a remaining factor graph. This computes the factorization \f$ p(X) = p(A|B) p(B) @@ -201,7 +201,7 @@ namespace gtsam { eliminatePartialMultifrontal( const Ordering& ordering, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Do multifrontal elimination of the given \c variables in an ordering computed by COLAMD to * produce a Bayes tree and a remaining factor graph. This computes the factorization \f$ p(X) @@ -211,7 +211,7 @@ namespace gtsam { eliminatePartialMultifrontal( const KeyVector& variables, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Compute the marginal of the requested variables and return the result as a Bayes net. Uses * COLAMD marginalization ordering by default @@ -225,7 +225,7 @@ namespace gtsam { boost::shared_ptr marginalMultifrontalBayesNet( boost::variant variables, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Compute the marginal of the requested variables and return the result as a Bayes net. * @param variables Determines the variables whose marginal to compute, if provided as an @@ -241,7 +241,7 @@ namespace gtsam { boost::variant variables, const Ordering& marginalizedVariableOrdering, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Compute the marginal of the requested variables and return the result as a Bayes tree. Uses * COLAMD marginalization order by default @@ -255,7 +255,7 @@ namespace gtsam { boost::shared_ptr marginalMultifrontalBayesTree( boost::variant variables, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Compute the marginal of the requested variables and return the result as a Bayes tree. * @param variables Determines the variables whose marginal to compute, if provided as an @@ -271,13 +271,13 @@ namespace gtsam { boost::variant variables, const Ordering& marginalizedVariableOrdering, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; /** Compute the marginal factor graph of the requested variables. */ boost::shared_ptr marginal( const KeyVector& variables, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const; + OptionalVariableIndex variableIndex = {}) const; private: @@ -301,8 +301,8 @@ namespace gtsam { /** @deprecated orderingType specified first for consistency */ boost::shared_ptr GTSAM_DEPRECATED eliminateSequential( const Eliminate& function, - OptionalVariableIndex variableIndex = boost::none, - OptionalOrderingType orderingType = boost::none) const { + OptionalVariableIndex variableIndex = {}, + OptionalOrderingType orderingType = {}) const { return eliminateSequential(orderingType, function, variableIndex); } @@ -318,8 +318,8 @@ namespace gtsam { /** @deprecated orderingType specified first for consistency */ boost::shared_ptr GTSAM_DEPRECATED eliminateMultifrontal( const Eliminate& function, - OptionalVariableIndex variableIndex = boost::none, - OptionalOrderingType orderingType = boost::none) const { + OptionalVariableIndex variableIndex = {}, + OptionalOrderingType orderingType = {}) const { return eliminateMultifrontal(orderingType, function, variableIndex); } @@ -328,7 +328,7 @@ namespace gtsam { boost::variant variables, boost::none_t, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const { + OptionalVariableIndex variableIndex = {}) const { return marginalMultifrontalBayesNet(variables, function, variableIndex); } @@ -337,7 +337,7 @@ namespace gtsam { boost::variant variables, boost::none_t, const Eliminate& function = EliminationTraitsType::DefaultEliminate, - OptionalVariableIndex variableIndex = boost::none) const { + OptionalVariableIndex variableIndex = {}) const { return marginalMultifrontalBayesTree(variables, function, variableIndex); } #endif diff --git a/gtsam/inference/FactorGraph-inst.h b/gtsam/inference/FactorGraph-inst.h index 355fdf87e..8460bbe2c 100644 --- a/gtsam/inference/FactorGraph-inst.h +++ b/gtsam/inference/FactorGraph-inst.h @@ -155,7 +155,7 @@ void FactorGraph::dot(std::ostream& os, const auto& factor = at(i); if (factor) { const KeyVector& factorKeys = factor->keys(); - writer.processFactor(i, factorKeys, keyFormatter, boost::none, &os); + writer.processFactor(i, factorKeys, keyFormatter, {}, &os); } } diff --git a/gtsam/inference/VariableIndex.h b/gtsam/inference/VariableIndex.h index f934a72af..1357eacdd 100644 --- a/gtsam/inference/VariableIndex.h +++ b/gtsam/inference/VariableIndex.h @@ -28,6 +28,7 @@ #include #include +#include namespace gtsam { diff --git a/gtsam/nonlinear/GraphvizFormatting.cpp b/gtsam/nonlinear/GraphvizFormatting.cpp index ca3466b6a..95c6e7faa 100644 --- a/gtsam/nonlinear/GraphvizFormatting.cpp +++ b/gtsam/nonlinear/GraphvizFormatting.cpp @@ -34,7 +34,7 @@ Vector2 GraphvizFormatting::findBounds(const Values& values, min.y() = std::numeric_limits::infinity(); for (const Key& key : keys) { if (values.exists(key)) { - boost::optional xy = extractPosition(values.at(key)); + std::optional xy = extractPosition(values.at(key)); if (xy) { if (xy->x() < min.x()) min.x() = xy->x(); if (xy->y() < min.y()) min.y() = xy->y(); @@ -44,7 +44,7 @@ Vector2 GraphvizFormatting::findBounds(const Values& values, return min; } -boost::optional GraphvizFormatting::extractPosition( +std::optional GraphvizFormatting::extractPosition( const Value& value) const { Vector3 t; if (const GenericValue* p = @@ -62,7 +62,7 @@ boost::optional GraphvizFormatting::extractPosition( const Eigen::Ref p_3d(p->value()); t = p_3d; } else { - return boost::none; + return {}; } } else if (const GenericValue* p = dynamic_cast*>(&value)) { @@ -71,7 +71,7 @@ boost::optional GraphvizFormatting::extractPosition( dynamic_cast*>(&value)) { t = p->value(); } else { - return boost::none; + return {}; } double x, y; switch (paperHorizontalAxis) { @@ -121,11 +121,11 @@ boost::optional GraphvizFormatting::extractPosition( return Vector2(x, y); } -boost::optional GraphvizFormatting::variablePos(const Values& values, +std::optional GraphvizFormatting::variablePos(const Values& values, const Vector2& min, Key key) const { if (!values.exists(key)) return DotWriter::variablePos(key); - boost::optional xy = extractPosition(values.at(key)); + std::optional xy = extractPosition(values.at(key)); if (xy) { xy->x() = scale * (xy->x() - min.x()); xy->y() = scale * (xy->y() - min.y()); @@ -133,11 +133,11 @@ boost::optional GraphvizFormatting::variablePos(const Values& values, return xy; } -boost::optional GraphvizFormatting::factorPos(const Vector2& min, +std::optional GraphvizFormatting::factorPos(const Vector2& min, size_t i) const { - if (factorPositions.size() == 0) return boost::none; + if (factorPositions.size() == 0) return {}; auto it = factorPositions.find(i); - if (it == factorPositions.end()) return boost::none; + if (it == factorPositions.end()) return {}; auto pos = it->second; return Vector2(scale * (pos.x() - min.x()), scale * (pos.y() - min.y())); } diff --git a/gtsam/nonlinear/GraphvizFormatting.h b/gtsam/nonlinear/GraphvizFormatting.h index 03cdb3469..fc3cfc95e 100644 --- a/gtsam/nonlinear/GraphvizFormatting.h +++ b/gtsam/nonlinear/GraphvizFormatting.h @@ -53,14 +53,14 @@ struct GTSAM_EXPORT GraphvizFormatting : public DotWriter { Vector2 findBounds(const Values& values, const KeySet& keys) const; /// Extract a Vector2 from either Vector2, Pose2, Pose3, or Point3 - boost::optional extractPosition(const Value& value) const; + std::optional extractPosition(const Value& value) const; /// Return affinely transformed variable position if it exists. - boost::optional variablePos(const Values& values, const Vector2& min, + std::optional variablePos(const Values& values, const Vector2& min, Key key) const; /// Return affinely transformed factor position if it exists. - boost::optional factorPos(const Vector2& min, size_t i) const; + std::optional factorPos(const Vector2& min, size_t i) const; }; } // namespace gtsam diff --git a/gtsam/nonlinear/NonlinearFactorGraph.cpp b/gtsam/nonlinear/NonlinearFactorGraph.cpp index dfa54f26f..3b7efd790 100644 --- a/gtsam/nonlinear/NonlinearFactorGraph.cpp +++ b/gtsam/nonlinear/NonlinearFactorGraph.cpp @@ -129,7 +129,7 @@ void NonlinearFactorGraph::dot(std::ostream& os, const Values& values, // Create factors and variable connections size_t i = 0; for (const KeyVector& factorKeys : structure) { - writer.processFactor(i++, factorKeys, keyFormatter, boost::none, &os); + writer.processFactor(i++, factorKeys, keyFormatter, {}, &os); } } else { // Create factors and variable connections diff --git a/gtsam/symbolic/tests/testSymbolicBayesTree.cpp b/gtsam/symbolic/tests/testSymbolicBayesTree.cpp index 0095c9293..f1cc6ee4f 100644 --- a/gtsam/symbolic/tests/testSymbolicBayesTree.cpp +++ b/gtsam/symbolic/tests/testSymbolicBayesTree.cpp @@ -213,7 +213,7 @@ TEST(BayesTree, shortcutCheck) { // Check if all the cached shortcuts are cleared rootClique->deleteCachedShortcuts(); for (SymbolicBayesTree::sharedClique& clique : allCliques) { - bool notCleared = clique->cachedSeparatorMarginal().is_initialized(); + bool notCleared = clique->cachedSeparatorMarginal().has_value(); CHECK(notCleared == false); } EXPECT_LONGS_EQUAL(0, (long)rootClique->numCachedSeparatorMarginals());