use emplace_shared

release/4.3a0
Frank Dellaert 2021-11-20 11:46:32 -05:00
parent fa28bbb925
commit 0c6d5d438f
2 changed files with 15 additions and 23 deletions

View File

@ -101,25 +101,27 @@ public:
/// @} /// @}
template<class SOURCE> // Add single key decision-tree factor.
template <class SOURCE>
void add(const DiscreteKey& j, SOURCE table) { void add(const DiscreteKey& j, SOURCE table) {
DiscreteKeys keys; DiscreteKeys keys;
keys.push_back(j); keys.push_back(j);
push_back(boost::make_shared<DecisionTreeFactor>(keys, table)); emplace_shared<DecisionTreeFactor>(keys, table);
} }
template<class SOURCE> // Add binary key decision-tree factor.
template <class SOURCE>
void add(const DiscreteKey& j1, const DiscreteKey& j2, SOURCE table) { void add(const DiscreteKey& j1, const DiscreteKey& j2, SOURCE table) {
DiscreteKeys keys; DiscreteKeys keys;
keys.push_back(j1); keys.push_back(j1);
keys.push_back(j2); keys.push_back(j2);
push_back(boost::make_shared<DecisionTreeFactor>(keys, table)); emplace_shared<DecisionTreeFactor>(keys, table);
} }
/** add shared discreteFactor immediately from arguments */ // Add shared discreteFactor immediately from arguments.
template<class SOURCE> template <class SOURCE>
void add(const DiscreteKeys& keys, SOURCE table) { void add(const DiscreteKeys& keys, SOURCE table) {
push_back(boost::make_shared<DecisionTreeFactor>(keys, table)); emplace_shared<DecisionTreeFactor>(keys, table);
} }
/** Return the set of variables involved in the factors (set union) */ /** Return the set of variables involved in the factors (set union) */

View File

@ -21,32 +21,22 @@ namespace gtsam {
class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph { class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph {
public: public:
/** A map from keys to values */ /** A map from keys to values */
typedef KeyVector Indices;
typedef Assignment<Key> Values; typedef Assignment<Key> Values;
typedef boost::shared_ptr<Values> sharedValues; typedef boost::shared_ptr<Values> sharedValues;
public: public:
// /// Constructor
// CSP() {
// }
/// Add a unary constraint, allowing only a single value /// Add a unary constraint, allowing only a single value
void addSingleValue(const DiscreteKey& dkey, size_t value) { void addSingleValue(const DiscreteKey& dkey, size_t value) {
boost::shared_ptr<SingleValue> factor(new SingleValue(dkey, value)); emplace_shared<SingleValue>(dkey, value);
push_back(factor);
} }
/// Add a binary AllDiff constraint /// Add a binary AllDiff constraint
void addAllDiff(const DiscreteKey& key1, const DiscreteKey& key2) { void addAllDiff(const DiscreteKey& key1, const DiscreteKey& key2) {
boost::shared_ptr<BinaryAllDiff> factor(new BinaryAllDiff(key1, key2)); emplace_shared<BinaryAllDiff>(key1, key2);
push_back(factor);
} }
/// Add a general AllDiff constraint /// Add a general AllDiff constraint
void addAllDiff(const DiscreteKeys& dkeys) { void addAllDiff(const DiscreteKeys& dkeys) { emplace_shared<AllDiff>(dkeys); }
boost::shared_ptr<AllDiff> factor(new AllDiff(dkeys));
push_back(factor);
}
// /** return product of all factors as a single factor */ // /** return product of all factors as a single factor */
// DecisionTreeFactor product() const { // DecisionTreeFactor product() const {
@ -56,10 +46,10 @@ class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph {
// return result; // return result;
// } // }
/// Find the best total assignment - can be expensive /// Find the best total assignment - can be expensive.
sharedValues optimalAssignment() const; 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; sharedValues optimalAssignment(const Ordering& ordering) const;
// /* // /*
@ -78,7 +68,7 @@ class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph {
* Apply arc-consistency ~ Approximate loopy belief propagation * Apply arc-consistency ~ Approximate loopy belief propagation
* We need to give the domains to a constraint, and it returns * We need to give the domains to a constraint, and it returns
* a domain whose values don't conflict in the arc-consistency way. * 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, void runArcConsistency(size_t cardinality, size_t nrIterations = 10,
bool print = false) const; bool print = false) const;