Skip to content

Commit

Permalink
Merge pull request #1217 from borglab/previous-hybrid
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
dellaert authored Jun 20, 2022
2 parents c663354 + 8482cee commit 844520f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 10 deletions.
5 changes: 1 addition & 4 deletions gtsam/discrete/DecisionTree-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,7 @@ namespace gtsam {
}

os << "\"" << this->id() << "\" -> \"" << branch->id() << "\"";
if (B == 2) {
if (i == 0) os << " [style=dashed]";
if (i > 1) os << " [style=bold]";
}
if (B == 2 && i == 0) os << " [style=dashed]";
os << std::endl;
branch->dot(os, labelFormatter, valueFormatter, showZero);
}
Expand Down
2 changes: 1 addition & 1 deletion gtsam/discrete/DecisionTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace gtsam {
/// @{

/// Make virtual
virtual ~DecisionTree() {}
virtual ~DecisionTree() = default;

/// Check if tree is empty.
bool empty() const { return !root_; }
Expand Down
4 changes: 4 additions & 0 deletions gtsam/discrete/DiscreteFactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class GTSAM_EXPORT DiscreteFactorGraph
/// @}
}; // \ DiscreteFactorGraph

std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr> //
EliminateForMPE(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys);

/// traits
template <>
struct traits<DiscreteFactorGraph> : public Testable<DiscreteFactorGraph> {};
Expand Down
2 changes: 1 addition & 1 deletion gtsam/inference/FactorGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class FactorGraph {
* less than the original, factors at the end will be removed. If the new
* size is larger than the original, null factors will be appended.
*/
void resize(size_t size) { factors_.resize(size); }
virtual void resize(size_t size) { factors_.resize(size); }

/** delete factor without re-arranging indexes by inserting a nullptr pointer
*/
Expand Down
11 changes: 11 additions & 0 deletions gtsam/inference/Ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ void Ordering::print(const std::string& str,
cout.flush();
}

/* ************************************************************************* */
Ordering::This& Ordering::operator+=(KeyVector& keys) {
this->insert(this->end(), keys.begin(), keys.end());
return *this;
}

/* ************************************************************************* */
bool Ordering::contains(const Key& key) const {
return std::find(this->begin(), this->end(), key) != this->end();
}

/* ************************************************************************* */
bool Ordering::equals(const Ordering& other, double tol) const {
return (*this) == other;
Expand Down
18 changes: 17 additions & 1 deletion gtsam/inference/Ordering.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,23 @@ class Ordering: public KeyVector {
boost::assign_detail::call_push_back<This>(*this))(key);
}

/// Invert (not reverse) the ordering - returns a map from key to order position
/**
* @brief Append new keys to the ordering as `ordering += keys`.
*
* @param key
* @return The ordering variable with appended keys.
*/
This& operator+=(KeyVector& keys);

/// Check if key exists in ordering.
bool contains(const Key& key) const;

/**
* @brief Invert (not reverse) the ordering - returns a map from key to order
* position.
*
* @return FastMap<Key, size_t>
*/
FastMap<Key, size_t> invert() const;

/// @name Fill-reducing Orderings @{
Expand Down
26 changes: 26 additions & 0 deletions gtsam/inference/tests/testOrdering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,32 @@ TEST(Ordering, csr_format_3) {
EXPECT(adjExpected == adjAcutal);
}

/* ************************************************************************* */
TEST(Ordering, AppendVector) {
using symbol_shorthand::X;
Ordering actual;
KeyVector keys = {X(0), X(1), X(2)};
actual += keys;

Ordering expected;
expected += X(0);
expected += X(1);
expected += X(2);
EXPECT(assert_equal(expected, actual));
}

/* ************************************************************************* */
TEST(Ordering, Contains) {
using symbol_shorthand::X;
Ordering ordering;
ordering += X(0);
ordering += X(1);
ordering += X(2);

EXPECT(ordering.contains(X(1)));
EXPECT(!ordering.contains(X(4)));
}

/* ************************************************************************* */
#ifdef GTSAM_SUPPORT_NESTED_DISSECTION
TEST(Ordering, csr_format_4) {
Expand Down
2 changes: 1 addition & 1 deletion gtsam/linear/GaussianBayesNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace gtsam {
/// @name Standard Constructors
/// @{

/** Construct empty factor graph */
/** Construct empty bayes net */
GaussianBayesNet() {}

/** Construct from iterator over conditionals */
Expand Down
4 changes: 2 additions & 2 deletions gtsam/linear/GaussianConditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* @author Christian Potthast, Frank Dellaert
*/

#include <gtsam/linear/linearExceptions.h>
#include <gtsam/linear/GaussianConditional.h>
#include <gtsam/linear/VectorValues.h>
#include <gtsam/linear/Sampler.h>
#include <gtsam/linear/VectorValues.h>
#include <gtsam/linear/linearExceptions.h>

#include <boost/format.hpp>
#ifdef __GNUC__
Expand Down
1 change: 1 addition & 0 deletions gtsam/linear/GaussianConditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gtsam/global_includes.h>
#include <gtsam/linear/JacobianFactor.h>
#include <gtsam/inference/Conditional.h>
#include <gtsam/inference/Conditional-inst.h>
#include <gtsam/linear/VectorValues.h>

#include <random> // for std::mt19937_64
Expand Down

0 comments on commit 844520f

Please sign in to comment.