From 0c6d5d438ff44dbb143b049f4ace02f8f10ff0f7 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sat, 20 Nov 2021 11:46:32 -0500 Subject: [PATCH] use emplace_shared --- gtsam/discrete/DiscreteFactorGraph.h | 16 +++++++++------- gtsam_unstable/discrete/CSP.h | 22 ++++++---------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h index f39adc9a8..3ea9c3cdd 100644 --- a/gtsam/discrete/DiscreteFactorGraph.h +++ b/gtsam/discrete/DiscreteFactorGraph.h @@ -101,25 +101,27 @@ public: /// @} - template + // Add single key decision-tree factor. + template void add(const DiscreteKey& j, SOURCE table) { DiscreteKeys keys; keys.push_back(j); - push_back(boost::make_shared(keys, table)); + emplace_shared(keys, table); } - template + // Add binary key decision-tree factor. + template void add(const DiscreteKey& j1, const DiscreteKey& j2, SOURCE table) { DiscreteKeys keys; keys.push_back(j1); keys.push_back(j2); - push_back(boost::make_shared(keys, table)); + emplace_shared(keys, table); } - /** add shared discreteFactor immediately from arguments */ - template + // Add shared discreteFactor immediately from arguments. + template void add(const DiscreteKeys& keys, SOURCE table) { - push_back(boost::make_shared(keys, table)); + emplace_shared(keys, table); } /** Return the set of variables involved in the factors (set union) */ diff --git a/gtsam_unstable/discrete/CSP.h b/gtsam_unstable/discrete/CSP.h index 544cdf0c9..e43e53932 100644 --- a/gtsam_unstable/discrete/CSP.h +++ b/gtsam_unstable/discrete/CSP.h @@ -21,32 +21,22 @@ namespace gtsam { class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph { public: /** A map from keys to values */ - typedef KeyVector Indices; typedef Assignment Values; typedef boost::shared_ptr sharedValues; public: - // /// Constructor - // CSP() { - // } - /// Add a unary constraint, allowing only a single value void addSingleValue(const DiscreteKey& dkey, size_t value) { - boost::shared_ptr factor(new SingleValue(dkey, value)); - push_back(factor); + emplace_shared(dkey, value); } /// Add a binary AllDiff constraint void addAllDiff(const DiscreteKey& key1, const DiscreteKey& key2) { - boost::shared_ptr factor(new BinaryAllDiff(key1, key2)); - push_back(factor); + emplace_shared(key1, key2); } /// Add a general AllDiff constraint - void addAllDiff(const DiscreteKeys& dkeys) { - boost::shared_ptr factor(new AllDiff(dkeys)); - push_back(factor); - } + void addAllDiff(const DiscreteKeys& dkeys) { emplace_shared(dkeys); } // /** return product of all factors as a single factor */ // DecisionTreeFactor product() const { @@ -56,10 +46,10 @@ class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph { // return result; // } - /// Find the best total assignment - can be expensive + /// Find the best total assignment - can be expensive. sharedValues optimalAssignment() const; - /// Find the best total assignment - can be expensive + /// Find the best total assignment, with given ordering - can be expensive. sharedValues optimalAssignment(const Ordering& ordering) const; // /* @@ -78,7 +68,7 @@ class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph { * Apply arc-consistency ~ Approximate loopy belief propagation * We need to give the domains to a constraint, and it returns * a domain whose values don't conflict in the arc-consistency way. - * TODO: should get cardinality from Indices + * TODO: should get cardinality from DiscreteKeys */ void runArcConsistency(size_t cardinality, size_t nrIterations = 10, bool print = false) const;