Replaced BOOSE_FOREACH with for in gtsam_unstable folder.
parent
ce2cd71112
commit
3b7c57aedf
|
@ -19,7 +19,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtsam_unstable/base/BTree.h>
|
#include <gtsam_unstable/base/BTree.h>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
@ -58,14 +57,14 @@ public:
|
||||||
// constructor with a list of unconnected keys
|
// constructor with a list of unconnected keys
|
||||||
DSF(const std::list<KEY>& keys) :
|
DSF(const std::list<KEY>& keys) :
|
||||||
Tree() {
|
Tree() {
|
||||||
BOOST_FOREACH(const KEY& key, keys)
|
for(const KEY& key: keys)
|
||||||
*this = this->add(key, key);
|
*this = this->add(key, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor with a set of unconnected keys
|
// constructor with a set of unconnected keys
|
||||||
DSF(const std::set<KEY>& keys) :
|
DSF(const std::set<KEY>& keys) :
|
||||||
Tree() {
|
Tree() {
|
||||||
BOOST_FOREACH(const KEY& key, keys)
|
for(const KEY& key: keys)
|
||||||
*this = this->add(key, key);
|
*this = this->add(key, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ public:
|
||||||
// create a new singleton with a list of fully connected keys
|
// create a new singleton with a list of fully connected keys
|
||||||
Self makeList(const std::list<KEY>& keys) const {
|
Self makeList(const std::list<KEY>& keys) const {
|
||||||
Self t = *this;
|
Self t = *this;
|
||||||
BOOST_FOREACH(const KEY& key, keys)
|
for(const KEY& key: keys)
|
||||||
t = t.makePair(key, keys.front());
|
t = t.makePair(key, keys.front());
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +116,7 @@ public:
|
||||||
// return a dsf in which all find_set operations will be O(1) due to path compression.
|
// return a dsf in which all find_set operations will be O(1) due to path compression.
|
||||||
DSF flatten() const {
|
DSF flatten() const {
|
||||||
DSF t = *this;
|
DSF t = *this;
|
||||||
BOOST_FOREACH(const KeyLabel& pair, (Tree)t)
|
for(const KeyLabel& pair: (Tree)t)
|
||||||
t.findSet_(pair.first);
|
t.findSet_(pair.first);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +124,7 @@ public:
|
||||||
// maps f over all keys, must be invertible
|
// maps f over all keys, must be invertible
|
||||||
DSF map(boost::function<KEY(const KEY&)> func) const {
|
DSF map(boost::function<KEY(const KEY&)> func) const {
|
||||||
DSF t;
|
DSF t;
|
||||||
BOOST_FOREACH(const KeyLabel& pair, (Tree)*this)
|
for(const KeyLabel& pair: (Tree)*this)
|
||||||
t = t.add(func(pair.first), func(pair.second));
|
t = t.add(func(pair.first), func(pair.second));
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +132,7 @@ public:
|
||||||
// return the number of sets
|
// return the number of sets
|
||||||
size_t numSets() const {
|
size_t numSets() const {
|
||||||
size_t num = 0;
|
size_t num = 0;
|
||||||
BOOST_FOREACH(const KeyLabel& pair, (Tree)*this)
|
for(const KeyLabel& pair: (Tree)*this)
|
||||||
if (pair.first == pair.second)
|
if (pair.first == pair.second)
|
||||||
num++;
|
num++;
|
||||||
return num;
|
return num;
|
||||||
|
@ -147,7 +146,7 @@ public:
|
||||||
// return all sets, i.e. a partition of all elements
|
// return all sets, i.e. a partition of all elements
|
||||||
std::map<KEY, Set> sets() const {
|
std::map<KEY, Set> sets() const {
|
||||||
std::map<KEY, Set> sets;
|
std::map<KEY, Set> sets;
|
||||||
BOOST_FOREACH(const KeyLabel& pair, (Tree)*this)
|
for(const KeyLabel& pair: (Tree)*this)
|
||||||
sets[findSet(pair.second)].insert(pair.first);
|
sets[findSet(pair.second)].insert(pair.first);
|
||||||
return sets;
|
return sets;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +154,7 @@ public:
|
||||||
// return a partition of the given elements {keys}
|
// return a partition of the given elements {keys}
|
||||||
std::map<KEY, Set> partition(const std::list<KEY>& keys) const {
|
std::map<KEY, Set> partition(const std::list<KEY>& keys) const {
|
||||||
std::map<KEY, Set> partitions;
|
std::map<KEY, Set> partitions;
|
||||||
BOOST_FOREACH(const KEY& key, keys)
|
for(const KEY& key: keys)
|
||||||
partitions[findSet(key)].insert(key);
|
partitions[findSet(key)].insert(key);
|
||||||
return partitions;
|
return partitions;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +162,7 @@ public:
|
||||||
// get the nodes in the tree with the given label
|
// get the nodes in the tree with the given label
|
||||||
Set set(const KEY& label) const {
|
Set set(const KEY& label) const {
|
||||||
Set set;
|
Set set;
|
||||||
BOOST_FOREACH(const KeyLabel& pair, (Tree)*this) {
|
for(const KeyLabel& pair: (Tree)*this) {
|
||||||
if (pair.second == label || findSet(pair.second) == label)
|
if (pair.second == label || findSet(pair.second) == label)
|
||||||
set.insert(pair.first);
|
set.insert(pair.first);
|
||||||
}
|
}
|
||||||
|
@ -183,7 +182,7 @@ public:
|
||||||
// print the object
|
// print the object
|
||||||
void print(const std::string& name = "DSF") const {
|
void print(const std::string& name = "DSF") const {
|
||||||
std::cout << name << std::endl;
|
std::cout << name << std::endl;
|
||||||
BOOST_FOREACH(const KeyLabel& pair, (Tree)*this)
|
for(const KeyLabel& pair: (Tree)*this)
|
||||||
std::cout << (std::string) pair.first << " " << (std::string) pair.second
|
std::cout << (std::string) pair.first << " " << (std::string) pair.second
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/assign/std/list.hpp> // for +=
|
#include <boost/assign/std/list.hpp> // for +=
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
|
@ -148,7 +147,7 @@ TEST( BTree, iterating )
|
||||||
|
|
||||||
// acid iterator test: BOOST_FOREACH
|
// acid iterator test: BOOST_FOREACH
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
BOOST_FOREACH(const KeyInt& p, tree)
|
for(const KeyInt& p: tree)
|
||||||
sum += p.second;
|
sum += p.second;
|
||||||
LONGS_EQUAL(15,sum)
|
LONGS_EQUAL(15,sum)
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ TEST(DSF, mergePairwiseMatches) {
|
||||||
|
|
||||||
// Merge matches
|
// Merge matches
|
||||||
DSF<Measurement> dsf(measurements);
|
DSF<Measurement> dsf(measurements);
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m, matches)
|
||||||
dsf.makeUnionInPlace(m.first,m.second);
|
dsf.makeUnionInPlace(m.first,m.second);
|
||||||
|
|
||||||
// Check that sets are merged correctly
|
// Check that sets are merged correctly
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include <gtsam_unstable/base/DSFMap.h>
|
#include <gtsam_unstable/base/DSFMap.h>
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/assign/std/list.hpp>
|
#include <boost/assign/std/list.hpp>
|
||||||
#include <boost/assign/std/set.hpp>
|
#include <boost/assign/std/set.hpp>
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
@ -72,7 +71,7 @@ TEST(DSFMap, mergePairwiseMatches) {
|
||||||
|
|
||||||
// Merge matches
|
// Merge matches
|
||||||
DSFMap<size_t> dsf;
|
DSFMap<size_t> dsf;
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf.merge(m.first,m.second);
|
dsf.merge(m.first,m.second);
|
||||||
|
|
||||||
// Each point is now associated with a set, represented by one of its members
|
// Each point is now associated with a set, represented by one of its members
|
||||||
|
@ -102,7 +101,7 @@ TEST(DSFMap, mergePairwiseMatches2) {
|
||||||
|
|
||||||
// Merge matches
|
// Merge matches
|
||||||
DSFMap<Measurement> dsf;
|
DSFMap<Measurement> dsf;
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf.merge(m.first,m.second);
|
dsf.merge(m.first,m.second);
|
||||||
|
|
||||||
// Check that sets are merged correctly
|
// Check that sets are merged correctly
|
||||||
|
@ -122,7 +121,7 @@ TEST(DSFMap, sets){
|
||||||
|
|
||||||
// Merge matches
|
// Merge matches
|
||||||
DSFMap<size_t> dsf;
|
DSFMap<size_t> dsf;
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf.merge(m.first,m.second);
|
dsf.merge(m.first,m.second);
|
||||||
|
|
||||||
map<size_t, set<size_t> > sets = dsf.sets();
|
map<size_t, set<size_t> > sets = dsf.sets();
|
||||||
|
@ -130,9 +129,9 @@ TEST(DSFMap, sets){
|
||||||
s1 += 1,2,3;
|
s1 += 1,2,3;
|
||||||
s2 += 4,5,6;
|
s2 += 4,5,6;
|
||||||
|
|
||||||
/*BOOST_FOREACH(key_pair st, sets){
|
/*for(key_pair st: sets){
|
||||||
cout << "Set " << st.first << " :{";
|
cout << "Set " << st.first << " :{";
|
||||||
BOOST_FOREACH(const size_t s, st.second)
|
for(const size_t s: st.second)
|
||||||
cout << s << ", ";
|
cout << s << ", ";
|
||||||
cout << "}" << endl;
|
cout << "}" << endl;
|
||||||
}*/
|
}*/
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace gtsam {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
AllDiff::AllDiff(const DiscreteKeys& dkeys) :
|
AllDiff::AllDiff(const DiscreteKeys& dkeys) :
|
||||||
Constraint(dkeys.indices()) {
|
Constraint(dkeys.indices()) {
|
||||||
BOOST_FOREACH(const DiscreteKey& dkey, dkeys)
|
for(const DiscreteKey& dkey: dkeys)
|
||||||
cardinalities_.insert(dkey);
|
cardinalities_.insert(dkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace gtsam {
|
||||||
void AllDiff::print(const std::string& s,
|
void AllDiff::print(const std::string& s,
|
||||||
const KeyFormatter& formatter) const {
|
const KeyFormatter& formatter) const {
|
||||||
std::cout << s << "AllDiff on ";
|
std::cout << s << "AllDiff on ";
|
||||||
BOOST_FOREACH (Key dkey, keys_)
|
for (Key dkey: keys_)
|
||||||
std::cout << formatter(dkey) << " ";
|
std::cout << formatter(dkey) << " ";
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace gtsam {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
double AllDiff::operator()(const Values& values) const {
|
double AllDiff::operator()(const Values& values) const {
|
||||||
std::set < size_t > taken; // record values taken by keys
|
std::set < size_t > taken; // record values taken by keys
|
||||||
BOOST_FOREACH(Key dkey, keys_) {
|
for(Key dkey: keys_) {
|
||||||
size_t value = values.at(dkey); // get the value for that key
|
size_t value = values.at(dkey); // get the value for that key
|
||||||
if (taken.count(value)) return 0.0;// check if value alreday taken
|
if (taken.count(value)) return 0.0;// check if value alreday taken
|
||||||
taken.insert(value);// if not, record it as taken and keep checking
|
taken.insert(value);// if not, record it as taken and keep checking
|
||||||
|
@ -70,7 +70,7 @@ namespace gtsam {
|
||||||
// Check all other domains for singletons and erase corresponding values
|
// Check all other domains for singletons and erase corresponding values
|
||||||
// This is the same as arc-consistency on the equivalent binary constraints
|
// This is the same as arc-consistency on the equivalent binary constraints
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
BOOST_FOREACH(Key k, keys_)
|
for(Key k: keys_)
|
||||||
if (k != j) {
|
if (k != j) {
|
||||||
const Domain& Dk = domains[k];
|
const Domain& Dk = domains[k];
|
||||||
if (Dk.isSingleton()) { // check if singleton
|
if (Dk.isSingleton()) { // check if singleton
|
||||||
|
@ -88,7 +88,7 @@ namespace gtsam {
|
||||||
Constraint::shared_ptr AllDiff::partiallyApply(const Values& values) const {
|
Constraint::shared_ptr AllDiff::partiallyApply(const Values& values) const {
|
||||||
DiscreteKeys newKeys;
|
DiscreteKeys newKeys;
|
||||||
// loop over keys and add them only if they do not appear in values
|
// loop over keys and add them only if they do not appear in values
|
||||||
BOOST_FOREACH(Key k, keys_)
|
for(Key k: keys_)
|
||||||
if (values.find(k) == values.end()) {
|
if (values.find(k) == values.end()) {
|
||||||
newKeys.push_back(DiscreteKey(k,cardinalities_.at(k)));
|
newKeys.push_back(DiscreteKey(k,cardinalities_.at(k)));
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ namespace gtsam {
|
||||||
Constraint::shared_ptr AllDiff::partiallyApply(
|
Constraint::shared_ptr AllDiff::partiallyApply(
|
||||||
const std::vector<Domain>& domains) const {
|
const std::vector<Domain>& domains) const {
|
||||||
DiscreteFactor::Values known;
|
DiscreteFactor::Values known;
|
||||||
BOOST_FOREACH(Key k, keys_) {
|
for(Key k: keys_) {
|
||||||
const Domain& Dk = domains[k];
|
const Domain& Dk = domains[k];
|
||||||
if (Dk.isSingleton())
|
if (Dk.isSingleton())
|
||||||
known[k] = Dk.firstValue();
|
known[k] = Dk.firstValue();
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <gtsam_unstable/discrete/Domain.h>
|
#include <gtsam_unstable/discrete/Domain.h>
|
||||||
#include <gtsam_unstable/discrete/CSP.h>
|
#include <gtsam_unstable/discrete/CSP.h>
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ namespace gtsam {
|
||||||
changed[v] = false;
|
changed[v] = false;
|
||||||
// loop over all factors/constraints for variable v
|
// loop over all factors/constraints for variable v
|
||||||
const VariableIndex::Factors& factors = index[v];
|
const VariableIndex::Factors& factors = index[v];
|
||||||
BOOST_FOREACH(size_t f,factors) {
|
for(size_t f: factors) {
|
||||||
// if not already a singleton
|
// if not already a singleton
|
||||||
if (!domains[v].isSingleton()) {
|
if (!domains[v].isSingleton()) {
|
||||||
// get the constraint and call its ensureArcConsistency method
|
// get the constraint and call its ensureArcConsistency method
|
||||||
|
@ -85,7 +84,7 @@ namespace gtsam {
|
||||||
// TODO: create a new ordering as we go, to ensure a connected graph
|
// TODO: create a new ordering as we go, to ensure a connected graph
|
||||||
// KeyOrdering ordering;
|
// KeyOrdering ordering;
|
||||||
// vector<Index> dkeys;
|
// vector<Index> dkeys;
|
||||||
BOOST_FOREACH(const DiscreteFactor::shared_ptr& f, factors_) {
|
for(const DiscreteFactor::shared_ptr& f: factors_) {
|
||||||
Constraint::shared_ptr constraint = boost::dynamic_pointer_cast<Constraint>(f);
|
Constraint::shared_ptr constraint = boost::dynamic_pointer_cast<Constraint>(f);
|
||||||
if (!constraint) throw runtime_error("CSP:runArcConsistency: non-constraint factor");
|
if (!constraint) throw runtime_error("CSP:runArcConsistency: non-constraint factor");
|
||||||
Constraint::shared_ptr reduced = constraint->partiallyApply(domains);
|
Constraint::shared_ptr reduced = constraint->partiallyApply(domains);
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace gtsam {
|
||||||
// /** return product of all factors as a single factor */
|
// /** return product of all factors as a single factor */
|
||||||
// DecisionTreeFactor product() const {
|
// DecisionTreeFactor product() const {
|
||||||
// DecisionTreeFactor result;
|
// DecisionTreeFactor result;
|
||||||
// BOOST_FOREACH(const sharedFactor& factor, *this)
|
// for(const sharedFactor& factor: *this)
|
||||||
// if (factor) result = (*factor) * result;
|
// if (factor) result = (*factor) * result;
|
||||||
// return result;
|
// return result;
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -19,9 +19,9 @@ namespace gtsam {
|
||||||
const KeyFormatter& formatter) const {
|
const KeyFormatter& formatter) const {
|
||||||
// cout << s << ": Domain on " << formatter(keys_[0]) << " (j=" <<
|
// cout << s << ": Domain on " << formatter(keys_[0]) << " (j=" <<
|
||||||
// formatter(keys_[0]) << ") with values";
|
// formatter(keys_[0]) << ") with values";
|
||||||
// BOOST_FOREACH (size_t v,values_) cout << " " << v;
|
// for (size_t v: values_) cout << " " << v;
|
||||||
// cout << endl;
|
// cout << endl;
|
||||||
BOOST_FOREACH (size_t v,values_) cout << v;
|
for (size_t v: values_) cout << v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -50,7 +50,7 @@ namespace gtsam {
|
||||||
bool Domain::ensureArcConsistency(size_t j, vector<Domain>& domains) const {
|
bool Domain::ensureArcConsistency(size_t j, vector<Domain>& domains) const {
|
||||||
if (j != keys_[0]) throw invalid_argument("Domain check on wrong domain");
|
if (j != keys_[0]) throw invalid_argument("Domain check on wrong domain");
|
||||||
Domain& D = domains[j];
|
Domain& D = domains[j];
|
||||||
BOOST_FOREACH(size_t value, values_)
|
for(size_t value: values_)
|
||||||
if (!D.contains(value)) throw runtime_error("Unsatisfiable");
|
if (!D.contains(value)) throw runtime_error("Unsatisfiable");
|
||||||
D = *this;
|
D = *this;
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,9 +60,9 @@ namespace gtsam {
|
||||||
bool Domain::checkAllDiff(const vector<Key> keys, vector<Domain>& domains) {
|
bool Domain::checkAllDiff(const vector<Key> keys, vector<Domain>& domains) {
|
||||||
Key j = keys_[0];
|
Key j = keys_[0];
|
||||||
// for all values in this domain
|
// for all values in this domain
|
||||||
BOOST_FOREACH(size_t value, values_) {
|
for(size_t value: values_) {
|
||||||
// for all connected domains
|
// for all connected domains
|
||||||
BOOST_FOREACH(Key k, keys)
|
for(Key k: keys)
|
||||||
// if any domain contains the value we cannot make this domain singleton
|
// if any domain contains the value we cannot make this domain singleton
|
||||||
if (k!=j && domains[k].contains(value))
|
if (k!=j && domains[k].contains(value))
|
||||||
goto found;
|
goto found;
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
|
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -163,7 +162,7 @@ namespace gtsam {
|
||||||
|
|
||||||
if (!mutexBound) {
|
if (!mutexBound) {
|
||||||
DiscreteKeys dkeys;
|
DiscreteKeys dkeys;
|
||||||
BOOST_FOREACH(const Student& s, students_)
|
for(const Student& s: students_)
|
||||||
dkeys.push_back(s.key_);
|
dkeys.push_back(s.key_);
|
||||||
addAllDiff(dkeys);
|
addAllDiff(dkeys);
|
||||||
} else {
|
} else {
|
||||||
|
@ -182,30 +181,30 @@ namespace gtsam {
|
||||||
void Scheduler::print(const string& s) const {
|
void Scheduler::print(const string& s) const {
|
||||||
|
|
||||||
cout << s << " Faculty:" << endl;
|
cout << s << " Faculty:" << endl;
|
||||||
BOOST_FOREACH(const string& name, facultyName_)
|
for(const string& name: facultyName_)
|
||||||
cout << name << '\n';
|
cout << name << '\n';
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << s << " Slots:\n";
|
cout << s << " Slots:\n";
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
BOOST_FOREACH(const string& name, slotName_)
|
for(const string& name: slotName_)
|
||||||
cout << i++ << " " << name << endl;
|
cout << i++ << " " << name << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << "Availability:\n" << available_ << '\n';
|
cout << "Availability:\n" << available_ << '\n';
|
||||||
|
|
||||||
cout << s << " Area constraints:\n";
|
cout << s << " Area constraints:\n";
|
||||||
BOOST_FOREACH(const FacultyInArea::value_type& it, facultyInArea_)
|
for(const FacultyInArea::value_type& it: facultyInArea_)
|
||||||
{
|
{
|
||||||
cout << setw(12) << it.first << ": ";
|
cout << setw(12) << it.first << ": ";
|
||||||
BOOST_FOREACH(double v, it.second)
|
for(double v: it.second)
|
||||||
cout << v << " ";
|
cout << v << " ";
|
||||||
cout << '\n';
|
cout << '\n';
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << s << " Students:\n";
|
cout << s << " Students:\n";
|
||||||
BOOST_FOREACH (const Student& student, students_)
|
for (const Student& student: students_)
|
||||||
student.print();
|
student.print();
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include <boost/assign/std/vector.hpp>
|
#include <boost/assign/std/vector.hpp>
|
||||||
#include <boost/assign/std/map.hpp>
|
#include <boost/assign/std/map.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -303,7 +302,7 @@ void accomodateStudent() {
|
||||||
vector<size_t> slots;
|
vector<size_t> slots;
|
||||||
slots += 16, 17, 11, 2, 0, 5, 9, 14;
|
slots += 16, 17, 11, 2, 0, 5, 9, 14;
|
||||||
vector<double> slotsAvailable(scheduler.nrTimeSlots(), 1.0);
|
vector<double> slotsAvailable(scheduler.nrTimeSlots(), 1.0);
|
||||||
BOOST_FOREACH(size_t s, slots)
|
for(size_t s: slots)
|
||||||
slotsAvailable[s] = 0;
|
slotsAvailable[s] = 0;
|
||||||
scheduler.setSlotsAvailable(slotsAvailable);
|
scheduler.setSlotsAvailable(slotsAvailable);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ class LoopyBelief {
|
||||||
void print(const std::string& s = "") const {
|
void print(const std::string& s = "") const {
|
||||||
cout << s << ":" << endl;
|
cout << s << ":" << endl;
|
||||||
star->print("Star graph: ");
|
star->print("Star graph: ");
|
||||||
BOOST_FOREACH(Key key, correctedBeliefIndices | boost::adaptors::map_keys) {
|
for(Key key: correctedBeliefIndices | boost::adaptors::map_keys) {
|
||||||
cout << "Belief factor index for " << key << ": "
|
cout << "Belief factor index for " << key << ": "
|
||||||
<< correctedBeliefIndices.at(key) << endl;
|
<< correctedBeliefIndices.at(key) << endl;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public:
|
||||||
/// print
|
/// print
|
||||||
void print(const std::string& s = "") const {
|
void print(const std::string& s = "") const {
|
||||||
cout << s << ":" << endl;
|
cout << s << ":" << endl;
|
||||||
BOOST_FOREACH(Key key, starGraphs_ | boost::adaptors::map_keys) {
|
for(Key key: starGraphs_ | boost::adaptors::map_keys) {
|
||||||
starGraphs_.at(key).print((boost::format("Node %d:") % key).str());
|
starGraphs_.at(key).print((boost::format("Node %d:") % key).str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public:
|
||||||
DiscreteFactorGraph::shared_ptr beliefs(new DiscreteFactorGraph());
|
DiscreteFactorGraph::shared_ptr beliefs(new DiscreteFactorGraph());
|
||||||
std::map<Key, std::map<Key, DiscreteFactor::shared_ptr> > allMessages;
|
std::map<Key, std::map<Key, DiscreteFactor::shared_ptr> > allMessages;
|
||||||
// Eliminate each star graph
|
// Eliminate each star graph
|
||||||
BOOST_FOREACH(Key key, starGraphs_ | boost::adaptors::map_keys) {
|
for(Key key: starGraphs_ | boost::adaptors::map_keys) {
|
||||||
// cout << "***** Node " << key << "*****" << endl;
|
// cout << "***** Node " << key << "*****" << endl;
|
||||||
// initialize belief to the unary factor from the original graph
|
// initialize belief to the unary factor from the original graph
|
||||||
DecisionTreeFactor::shared_ptr beliefAtKey;
|
DecisionTreeFactor::shared_ptr beliefAtKey;
|
||||||
|
@ -92,9 +92,9 @@ public:
|
||||||
std::map<Key, DiscreteFactor::shared_ptr> messages;
|
std::map<Key, DiscreteFactor::shared_ptr> messages;
|
||||||
|
|
||||||
// eliminate each neighbor in this star graph one by one
|
// eliminate each neighbor in this star graph one by one
|
||||||
BOOST_FOREACH(Key neighbor, starGraphs_.at(key).correctedBeliefIndices | boost::adaptors::map_keys) {
|
for(Key neighbor: starGraphs_.at(key).correctedBeliefIndices | boost::adaptors::map_keys) {
|
||||||
DiscreteFactorGraph subGraph;
|
DiscreteFactorGraph subGraph;
|
||||||
BOOST_FOREACH(size_t factor, starGraphs_.at(key).varIndex_[neighbor]) {
|
for(size_t factor: starGraphs_.at(key).varIndex_[neighbor]) {
|
||||||
subGraph.push_back(starGraphs_.at(key).star->at(factor));
|
subGraph.push_back(starGraphs_.at(key).star->at(factor));
|
||||||
}
|
}
|
||||||
if (debug) subGraph.print("------- Subgraph:");
|
if (debug) subGraph.print("------- Subgraph:");
|
||||||
|
@ -141,9 +141,9 @@ public:
|
||||||
|
|
||||||
// Update corrected beliefs
|
// Update corrected beliefs
|
||||||
VariableIndex beliefFactors(*beliefs);
|
VariableIndex beliefFactors(*beliefs);
|
||||||
BOOST_FOREACH(Key key, starGraphs_ | boost::adaptors::map_keys) {
|
for(Key key: starGraphs_ | boost::adaptors::map_keys) {
|
||||||
std::map<Key, DiscreteFactor::shared_ptr> messages = allMessages[key];
|
std::map<Key, DiscreteFactor::shared_ptr> messages = allMessages[key];
|
||||||
BOOST_FOREACH(Key neighbor, starGraphs_.at(key).correctedBeliefIndices | boost::adaptors::map_keys) {
|
for(Key neighbor: starGraphs_.at(key).correctedBeliefIndices | boost::adaptors::map_keys) {
|
||||||
DecisionTreeFactor correctedBelief = (*boost::dynamic_pointer_cast<
|
DecisionTreeFactor correctedBelief = (*boost::dynamic_pointer_cast<
|
||||||
DecisionTreeFactor>(beliefs->at(beliefFactors[key].front())))
|
DecisionTreeFactor>(beliefs->at(beliefFactors[key].front())))
|
||||||
/ (*boost::dynamic_pointer_cast<DecisionTreeFactor>(
|
/ (*boost::dynamic_pointer_cast<DecisionTreeFactor>(
|
||||||
|
@ -169,13 +169,13 @@ private:
|
||||||
const std::map<Key, DiscreteKey>& allDiscreteKeys) const {
|
const std::map<Key, DiscreteKey>& allDiscreteKeys) const {
|
||||||
StarGraphs starGraphs;
|
StarGraphs starGraphs;
|
||||||
VariableIndex varIndex(graph); ///< access to all factors of each node
|
VariableIndex varIndex(graph); ///< access to all factors of each node
|
||||||
BOOST_FOREACH(Key key, varIndex | boost::adaptors::map_keys) {
|
for(Key key: varIndex | boost::adaptors::map_keys) {
|
||||||
// initialize to multiply with other unary factors later
|
// initialize to multiply with other unary factors later
|
||||||
DecisionTreeFactor::shared_ptr prodOfUnaries;
|
DecisionTreeFactor::shared_ptr prodOfUnaries;
|
||||||
|
|
||||||
// collect all factors involving this key in the original graph
|
// collect all factors involving this key in the original graph
|
||||||
DiscreteFactorGraph::shared_ptr star(new DiscreteFactorGraph());
|
DiscreteFactorGraph::shared_ptr star(new DiscreteFactorGraph());
|
||||||
BOOST_FOREACH(size_t factorIdx, varIndex[key]) {
|
for(size_t factorIdx: varIndex[key]) {
|
||||||
star->push_back(graph.at(factorIdx));
|
star->push_back(graph.at(factorIdx));
|
||||||
|
|
||||||
// accumulate unary factors
|
// accumulate unary factors
|
||||||
|
@ -196,7 +196,7 @@ private:
|
||||||
KeySet neighbors = star->keys();
|
KeySet neighbors = star->keys();
|
||||||
neighbors.erase(key);
|
neighbors.erase(key);
|
||||||
CorrectedBeliefIndices correctedBeliefIndices;
|
CorrectedBeliefIndices correctedBeliefIndices;
|
||||||
BOOST_FOREACH(Key neighbor, neighbors) {
|
for(Key neighbor: neighbors) {
|
||||||
// TODO: default table for keys with more than 2 values?
|
// TODO: default table for keys with more than 2 values?
|
||||||
string initialBelief;
|
string initialBelief;
|
||||||
for (size_t v = 0; v < allDiscreteKeys.at(neighbor).second - 1; ++v) {
|
for (size_t v = 0; v < allDiscreteKeys.at(neighbor).second - 1; ++v) {
|
||||||
|
|
|
@ -309,19 +309,19 @@ int main(int argc, char** argv) {
|
||||||
// And to demonstrate the fixed-lag aspect, print the keys contained in each smoother after 3.0 seconds
|
// And to demonstrate the fixed-lag aspect, print the keys contained in each smoother after 3.0 seconds
|
||||||
cout << "After 15.0 seconds, each version contains to the following keys:" << endl;
|
cout << "After 15.0 seconds, each version contains to the following keys:" << endl;
|
||||||
cout << " Concurrent Filter Keys: " << endl;
|
cout << " Concurrent Filter Keys: " << endl;
|
||||||
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, concurrentFilter.getLinearizationPoint()) {
|
for(const Values::ConstKeyValuePair& key_value: concurrentFilter.getLinearizationPoint()) {
|
||||||
cout << setprecision(5) << " Key: " << key_value.key << endl;
|
cout << setprecision(5) << " Key: " << key_value.key << endl;
|
||||||
}
|
}
|
||||||
cout << " Concurrent Smoother Keys: " << endl;
|
cout << " Concurrent Smoother Keys: " << endl;
|
||||||
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, concurrentSmoother.getLinearizationPoint()) {
|
for(const Values::ConstKeyValuePair& key_value: concurrentSmoother.getLinearizationPoint()) {
|
||||||
cout << setprecision(5) << " Key: " << key_value.key << endl;
|
cout << setprecision(5) << " Key: " << key_value.key << endl;
|
||||||
}
|
}
|
||||||
cout << " Fixed-Lag Smoother Keys: " << endl;
|
cout << " Fixed-Lag Smoother Keys: " << endl;
|
||||||
BOOST_FOREACH(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp, fixedlagSmoother.timestamps()) {
|
for(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp: fixedlagSmoother.timestamps()) {
|
||||||
cout << setprecision(5) << " Key: " << key_timestamp.first << endl;
|
cout << setprecision(5) << " Key: " << key_timestamp.first << endl;
|
||||||
}
|
}
|
||||||
cout << " Batch Smoother Keys: " << endl;
|
cout << " Batch Smoother Keys: " << endl;
|
||||||
BOOST_FOREACH(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp, batchSmoother.timestamps()) {
|
for(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp: batchSmoother.timestamps()) {
|
||||||
cout << setprecision(5) << " Key: " << key_timestamp.first << endl;
|
cout << setprecision(5) << " Key: " << key_timestamp.first << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,11 +133,11 @@ int main(int argc, char** argv) {
|
||||||
// And to demonstrate the fixed-lag aspect, print the keys contained in each smoother after 3.0 seconds
|
// And to demonstrate the fixed-lag aspect, print the keys contained in each smoother after 3.0 seconds
|
||||||
cout << "After 3.0 seconds, " << endl;
|
cout << "After 3.0 seconds, " << endl;
|
||||||
cout << " Batch Smoother Keys: " << endl;
|
cout << " Batch Smoother Keys: " << endl;
|
||||||
BOOST_FOREACH(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp, smootherBatch.timestamps()) {
|
for(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp: smootherBatch.timestamps()) {
|
||||||
cout << setprecision(5) << " Key: " << key_timestamp.first << " Time: " << key_timestamp.second << endl;
|
cout << setprecision(5) << " Key: " << key_timestamp.first << " Time: " << key_timestamp.second << endl;
|
||||||
}
|
}
|
||||||
cout << " iSAM2 Smoother Keys: " << endl;
|
cout << " iSAM2 Smoother Keys: " << endl;
|
||||||
BOOST_FOREACH(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp, smootherISAM2.timestamps()) {
|
for(const FixedLagSmoother::KeyTimestampMap::value_type& key_timestamp: smootherISAM2.timestamps()) {
|
||||||
cout << setprecision(5) << " Key: " << key_timestamp.first << " Time: " << key_timestamp.second << endl;
|
cout << setprecision(5) << " Key: " << key_timestamp.first << " Time: " << key_timestamp.second << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
#include <gtsam_unstable/slam/SmartRangeFactor.h>
|
#include <gtsam_unstable/slam/SmartRangeFactor.h>
|
||||||
|
|
||||||
// Standard headers, added last, so we know headers above work on their own
|
// Standard headers, added last, so we know headers above work on their own
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ int main(int argc, char** argv) {
|
||||||
typedef boost::shared_ptr<SmartRangeFactor> SmartPtr;
|
typedef boost::shared_ptr<SmartRangeFactor> SmartPtr;
|
||||||
map<size_t, SmartPtr> smartFactors;
|
map<size_t, SmartPtr> smartFactors;
|
||||||
if (smart) {
|
if (smart) {
|
||||||
BOOST_FOREACH(size_t jj,ids) {
|
for(size_t jj: ids) {
|
||||||
smartFactors[jj] = SmartPtr(new SmartRangeFactor(sigmaR));
|
smartFactors[jj] = SmartPtr(new SmartRangeFactor(sigmaR));
|
||||||
newFactors.push_back(smartFactors[jj]);
|
newFactors.push_back(smartFactors[jj]);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +165,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
// Loop over odometry
|
// Loop over odometry
|
||||||
gttic_(iSAM);
|
gttic_(iSAM);
|
||||||
BOOST_FOREACH(const TimedOdometry& timedOdometry, odometry) {
|
for(const TimedOdometry& timedOdometry: odometry) {
|
||||||
//--------------------------------- odometry loop -----------------------------------------
|
//--------------------------------- odometry loop -----------------------------------------
|
||||||
double t;
|
double t;
|
||||||
Pose2 odometry;
|
Pose2 odometry;
|
||||||
|
@ -219,25 +218,25 @@ int main(int argc, char** argv) {
|
||||||
if (hasLandmarks) {
|
if (hasLandmarks) {
|
||||||
// update landmark estimates
|
// update landmark estimates
|
||||||
landmarkEstimates = Values();
|
landmarkEstimates = Values();
|
||||||
BOOST_FOREACH(size_t jj,ids)
|
for(size_t jj: ids)
|
||||||
landmarkEstimates.insert(symbol('L', jj), result.at(symbol('L', jj)));
|
landmarkEstimates.insert(symbol('L', jj), result.at(symbol('L', jj)));
|
||||||
}
|
}
|
||||||
newFactors = NonlinearFactorGraph();
|
newFactors = NonlinearFactorGraph();
|
||||||
initial = Values();
|
initial = Values();
|
||||||
if (smart && !hasLandmarks) {
|
if (smart && !hasLandmarks) {
|
||||||
cout << "initialize from smart landmarks" << endl;
|
cout << "initialize from smart landmarks" << endl;
|
||||||
BOOST_FOREACH(size_t jj,ids) {
|
for(size_t jj: ids) {
|
||||||
Point2 landmark = smartFactors[jj]->triangulate(result);
|
Point2 landmark = smartFactors[jj]->triangulate(result);
|
||||||
initial.insert(symbol('L', jj), landmark);
|
initial.insert(symbol('L', jj), landmark);
|
||||||
landmarkEstimates.insert(symbol('L', jj), landmark);
|
landmarkEstimates.insert(symbol('L', jj), landmark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
countK = 0;
|
countK = 0;
|
||||||
BOOST_FOREACH(const Values::ConstFiltered<Point2>::KeyValuePair& it, result.filter<Point2>())
|
for(const Values::ConstFiltered<Point2>::KeyValuePair& it: result.filter<Point2>())
|
||||||
os2 << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t1"
|
os2 << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t1"
|
||||||
<< endl;
|
<< endl;
|
||||||
if (smart) {
|
if (smart) {
|
||||||
BOOST_FOREACH(size_t jj,ids) {
|
for(size_t jj: ids) {
|
||||||
Point2 landmark = smartFactors[jj]->triangulate(result);
|
Point2 landmark = smartFactors[jj]->triangulate(result);
|
||||||
os3 << jj << "\t" << landmark.x() << "\t" << landmark.y() << "\t1"
|
os3 << jj << "\t" << landmark.x() << "\t" << landmark.y() << "\t1"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
@ -247,7 +246,7 @@ int main(int argc, char** argv) {
|
||||||
i += 1;
|
i += 1;
|
||||||
if (i>end) break;
|
if (i>end) break;
|
||||||
//--------------------------------- odometry loop -----------------------------------------
|
//--------------------------------- odometry loop -----------------------------------------
|
||||||
} // BOOST_FOREACH
|
} // end for
|
||||||
gttoc_(iSAM);
|
gttoc_(iSAM);
|
||||||
|
|
||||||
// Print timings
|
// Print timings
|
||||||
|
@ -257,7 +256,7 @@ int main(int argc, char** argv) {
|
||||||
Values result = isam.calculateEstimate();
|
Values result = isam.calculateEstimate();
|
||||||
ofstream os(
|
ofstream os(
|
||||||
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResult.txt");
|
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResult.txt");
|
||||||
BOOST_FOREACH(const Values::ConstFiltered<Pose2>::KeyValuePair& it, result.filter<Pose2>())
|
for(const Values::ConstFiltered<Pose2>::KeyValuePair& it: result.filter<Pose2>())
|
||||||
os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t"
|
os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t"
|
||||||
<< it.value.theta() << endl;
|
<< it.value.theta() << endl;
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include <gtsam/sam/RangeFactor.h>
|
#include <gtsam/sam/RangeFactor.h>
|
||||||
|
|
||||||
// Standard headers, added last, so we know headers above work on their own
|
// Standard headers, added last, so we know headers above work on their own
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -143,7 +142,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
// Loop over odometry
|
// Loop over odometry
|
||||||
gttic_(iSAM);
|
gttic_(iSAM);
|
||||||
BOOST_FOREACH(const TimedOdometry& timedOdometry, odometry) {
|
for(const TimedOdometry& timedOdometry: odometry) {
|
||||||
//--------------------------------- odometry loop -----------------------------------------
|
//--------------------------------- odometry loop -----------------------------------------
|
||||||
double t;
|
double t;
|
||||||
Pose2 odometry;
|
Pose2 odometry;
|
||||||
|
@ -194,7 +193,7 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
//--------------------------------- odometry loop -----------------------------------------
|
//--------------------------------- odometry loop -----------------------------------------
|
||||||
} // BOOST_FOREACH
|
} // end for
|
||||||
gttoc_(iSAM);
|
gttoc_(iSAM);
|
||||||
|
|
||||||
// Print timings
|
// Print timings
|
||||||
|
@ -204,12 +203,12 @@ int main(int argc, char** argv) {
|
||||||
Values result = isam.calculateEstimate();
|
Values result = isam.calculateEstimate();
|
||||||
ofstream os2(
|
ofstream os2(
|
||||||
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResultLM.txt");
|
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResultLM.txt");
|
||||||
BOOST_FOREACH(const Values::ConstFiltered<Point2>::KeyValuePair& it, result.filter<Point2>())
|
for(const Values::ConstFiltered<Point2>::KeyValuePair& it: result.filter<Point2>())
|
||||||
os2 << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t1"
|
os2 << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t1"
|
||||||
<< endl;
|
<< endl;
|
||||||
ofstream os(
|
ofstream os(
|
||||||
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResult.txt");
|
"/Users/dellaert/borg/gtsam/gtsam_unstable/examples/rangeResult.txt");
|
||||||
BOOST_FOREACH(const Values::ConstFiltered<Pose2>::KeyValuePair& it, result.filter<Pose2>())
|
for(const Values::ConstFiltered<Pose2>::KeyValuePair& it: result.filter<Pose2>())
|
||||||
os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t"
|
os << it.key << "\t" << it.value.x() << "\t" << it.value.y() << "\t"
|
||||||
<< it.value.theta() << endl;
|
<< it.value.theta() << endl;
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/random/linear_congruential.hpp>
|
#include <boost/random/linear_congruential.hpp>
|
||||||
#include <boost/random/uniform_real.hpp>
|
#include <boost/random/uniform_real.hpp>
|
||||||
#include <boost/random/normal_distribution.hpp>
|
#include <boost/random/normal_distribution.hpp>
|
||||||
|
@ -55,7 +54,7 @@ bool SimPolygon2D::equals(const SimPolygon2D& p, double tol) const {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void SimPolygon2D::print(const string& s) const {
|
void SimPolygon2D::print(const string& s) const {
|
||||||
cout << "SimPolygon " << s << ": " << endl;
|
cout << "SimPolygon " << s << ": " << endl;
|
||||||
BOOST_FOREACH(const Point2& p, landmarks_)
|
for(const Point2& p: landmarks_)
|
||||||
p.print(" ");
|
p.print(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ bool SimPolygon2D::contains(const Point2& c) const {
|
||||||
vector<SimWall2D> edges = walls();
|
vector<SimWall2D> edges = walls();
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
bool lastSide = false;
|
bool lastSide = false;
|
||||||
BOOST_FOREACH(const SimWall2D& ab, edges) {
|
for(const SimWall2D& ab: edges) {
|
||||||
// compute cross product of ab and ac
|
// compute cross product of ab and ac
|
||||||
Point2 dab = ab.b() - ab.a();
|
Point2 dab = ab.b() - ab.a();
|
||||||
Point2 dac = c - ab.a();
|
Point2 dac = c - ab.a();
|
||||||
|
@ -97,10 +96,10 @@ bool SimPolygon2D::contains(const Point2& c) const {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
bool SimPolygon2D::overlaps(const SimPolygon2D& p) const {
|
bool SimPolygon2D::overlaps(const SimPolygon2D& p) const {
|
||||||
BOOST_FOREACH(const Point2& a, landmarks_)
|
for(const Point2& a: landmarks_)
|
||||||
if (p.contains(a))
|
if (p.contains(a))
|
||||||
return true;
|
return true;
|
||||||
BOOST_FOREACH(const Point2& a, p.landmarks_)
|
for(const Point2& a: p.landmarks_)
|
||||||
if (contains(a))
|
if (contains(a))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -108,7 +107,7 @@ bool SimPolygon2D::overlaps(const SimPolygon2D& p) const {
|
||||||
|
|
||||||
/* ***************************************************************** */
|
/* ***************************************************************** */
|
||||||
bool SimPolygon2D::anyContains(const Point2& p, const vector<SimPolygon2D>& obstacles) {
|
bool SimPolygon2D::anyContains(const Point2& p, const vector<SimPolygon2D>& obstacles) {
|
||||||
BOOST_FOREACH(const SimPolygon2D& poly, obstacles)
|
for(const SimPolygon2D& poly: obstacles)
|
||||||
if (poly.contains(p))
|
if (poly.contains(p))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -116,7 +115,7 @@ bool SimPolygon2D::anyContains(const Point2& p, const vector<SimPolygon2D>& obst
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
bool SimPolygon2D::anyOverlaps(const SimPolygon2D& p, const vector<SimPolygon2D>& obstacles) {
|
bool SimPolygon2D::anyOverlaps(const SimPolygon2D& p, const vector<SimPolygon2D>& obstacles) {
|
||||||
BOOST_FOREACH(const SimPolygon2D& poly, obstacles)
|
for(const SimPolygon2D& poly: obstacles)
|
||||||
if (poly.overlaps(p))
|
if (poly.overlaps(p))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -134,7 +133,7 @@ SimPolygon2D SimPolygon2D::randomTriangle(
|
||||||
lms.push_back(Point2(-d2,-d2));
|
lms.push_back(Point2(-d2,-d2));
|
||||||
lms.push_back(Point2( d2,-d2));
|
lms.push_back(Point2( d2,-d2));
|
||||||
|
|
||||||
BOOST_FOREACH(const SimPolygon2D& poly, existing_polys)
|
for(const SimPolygon2D& poly: existing_polys)
|
||||||
lms.insert(lms.begin(), poly.vertices().begin(), poly.vertices().end());
|
lms.insert(lms.begin(), poly.vertices().begin(), poly.vertices().end());
|
||||||
|
|
||||||
for (size_t i=0; i<max_it; ++i) {
|
for (size_t i=0; i<max_it; ++i) {
|
||||||
|
@ -188,7 +187,7 @@ SimPolygon2D SimPolygon2D::randomRectangle(
|
||||||
lms.push_back(Point2(-d2, d2));
|
lms.push_back(Point2(-d2, d2));
|
||||||
lms.push_back(Point2(-d2,-d2));
|
lms.push_back(Point2(-d2,-d2));
|
||||||
lms.push_back(Point2( d2,-d2));
|
lms.push_back(Point2( d2,-d2));
|
||||||
BOOST_FOREACH(const SimPolygon2D& poly, existing_polys)
|
for(const SimPolygon2D& poly: existing_polys)
|
||||||
lms.insert(lms.begin(), poly.vertices().begin(), poly.vertices().end());
|
lms.insert(lms.begin(), poly.vertices().begin(), poly.vertices().end());
|
||||||
|
|
||||||
const Point2 lower_corner(-side_len,-side_len);
|
const Point2 lower_corner(-side_len,-side_len);
|
||||||
|
@ -320,7 +319,7 @@ bool SimPolygon2D::insideBox(double s, const Point2& p) {
|
||||||
/* ***************************************************************** */
|
/* ***************************************************************** */
|
||||||
bool SimPolygon2D::nearExisting(const std::vector<Point2>& S,
|
bool SimPolygon2D::nearExisting(const std::vector<Point2>& S,
|
||||||
const Point2& p, double threshold) {
|
const Point2& p, double threshold) {
|
||||||
BOOST_FOREACH(const Point2& Sp, S)
|
for(const Point2& Sp: S)
|
||||||
if (Sp.distance(p) < threshold)
|
if (Sp.distance(p) < threshold)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* @author Alex Cunningham
|
* @author Alex Cunningham
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
#include <gtsam/geometry/Pose2.h>
|
#include <gtsam/geometry/Pose2.h>
|
||||||
#include <gtsam_unstable/geometry/SimWall2D.h>
|
#include <gtsam_unstable/geometry/SimWall2D.h>
|
||||||
|
@ -135,7 +134,7 @@ std::pair<Pose2, bool> moveWithBounce(const Pose2& cur_pose, double step_size,
|
||||||
SimWall2D traj(test_pose.t(), cur_pose.t());
|
SimWall2D traj(test_pose.t(), cur_pose.t());
|
||||||
bool collision = false; Point2 intersection(1e+10, 1e+10);
|
bool collision = false; Point2 intersection(1e+10, 1e+10);
|
||||||
SimWall2D closest_wall;
|
SimWall2D closest_wall;
|
||||||
BOOST_FOREACH(const SimWall2D& wall, walls) {
|
for(const SimWall2D& wall: walls) {
|
||||||
Point2 cur_intersection;
|
Point2 cur_intersection;
|
||||||
if (wall.intersects(traj,cur_intersection)) {
|
if (wall.intersects(traj,cur_intersection)) {
|
||||||
collision = true;
|
collision = true;
|
||||||
|
|
|
@ -30,7 +30,7 @@ QPSolver::QPSolver(const QP& qp) : qp_(qp) {
|
||||||
VectorValues QPSolver::solveWithCurrentWorkingSet(
|
VectorValues QPSolver::solveWithCurrentWorkingSet(
|
||||||
const LinearInequalityFactorGraph& workingSet) const {
|
const LinearInequalityFactorGraph& workingSet) const {
|
||||||
GaussianFactorGraph workingGraph = baseGraph_;
|
GaussianFactorGraph workingGraph = baseGraph_;
|
||||||
BOOST_FOREACH(const LinearInequality::shared_ptr& factor, workingSet) {
|
for(const LinearInequality::shared_ptr& factor: workingSet) {
|
||||||
if (factor->active())
|
if (factor->active())
|
||||||
workingGraph.push_back(factor);
|
workingGraph.push_back(factor);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ JacobianFactor::shared_ptr QPSolver::createDualFactor(Key key,
|
||||||
if (Aterms.size() > 0) {
|
if (Aterms.size() > 0) {
|
||||||
Vector b = Vector::Zero(delta.at(key).size());
|
Vector b = Vector::Zero(delta.at(key).size());
|
||||||
if (costVariableIndex_.find(key) != costVariableIndex_.end()) {
|
if (costVariableIndex_.find(key) != costVariableIndex_.end()) {
|
||||||
BOOST_FOREACH(size_t factorIx, costVariableIndex_[key]) {
|
for(size_t factorIx: costVariableIndex_[key]) {
|
||||||
GaussianFactor::shared_ptr factor = qp_.cost.at(factorIx);
|
GaussianFactor::shared_ptr factor = qp_.cost.at(factorIx);
|
||||||
b += factor->gradient(key, delta);
|
b += factor->gradient(key, delta);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ JacobianFactor::shared_ptr QPSolver::createDualFactor(Key key,
|
||||||
GaussianFactorGraph::shared_ptr QPSolver::buildDualGraph(
|
GaussianFactorGraph::shared_ptr QPSolver::buildDualGraph(
|
||||||
const LinearInequalityFactorGraph& workingSet, const VectorValues& delta) const {
|
const LinearInequalityFactorGraph& workingSet, const VectorValues& delta) const {
|
||||||
GaussianFactorGraph::shared_ptr dualGraph(new GaussianFactorGraph());
|
GaussianFactorGraph::shared_ptr dualGraph(new GaussianFactorGraph());
|
||||||
BOOST_FOREACH(Key key, constrainedKeys_) {
|
for(Key key: constrainedKeys_) {
|
||||||
// Each constrained key becomes a factor in the dual graph
|
// Each constrained key becomes a factor in the dual graph
|
||||||
JacobianFactor::shared_ptr dualFactor = createDualFactor(key, workingSet, delta);
|
JacobianFactor::shared_ptr dualFactor = createDualFactor(key, workingSet, delta);
|
||||||
if (!dualFactor->empty())
|
if (!dualFactor->empty())
|
||||||
|
@ -219,7 +219,7 @@ LinearInequalityFactorGraph QPSolver::identifyActiveConstraints(
|
||||||
const LinearInequalityFactorGraph& inequalities,
|
const LinearInequalityFactorGraph& inequalities,
|
||||||
const VectorValues& initialValues) const {
|
const VectorValues& initialValues) const {
|
||||||
LinearInequalityFactorGraph workingSet;
|
LinearInequalityFactorGraph workingSet;
|
||||||
BOOST_FOREACH(const LinearInequality::shared_ptr& factor, inequalities){
|
for(const LinearInequality::shared_ptr& factor: inequalities){
|
||||||
LinearInequality::shared_ptr workingFactor(new LinearInequality(*factor));
|
LinearInequality::shared_ptr workingFactor(new LinearInequality(*factor));
|
||||||
double error = workingFactor->error(initialValues);
|
double error = workingFactor->error(initialValues);
|
||||||
if (fabs(error)>1e-7){
|
if (fabs(error)>1e-7){
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
const VariableIndex& variableIndex) const {
|
const VariableIndex& variableIndex) const {
|
||||||
std::vector<std::pair<Key, Matrix> > Aterms;
|
std::vector<std::pair<Key, Matrix> > Aterms;
|
||||||
if (variableIndex.find(key) != variableIndex.end()) {
|
if (variableIndex.find(key) != variableIndex.end()) {
|
||||||
BOOST_FOREACH(size_t factorIx, variableIndex[key]){
|
for(size_t factorIx: variableIndex[key]){
|
||||||
typename FACTOR::shared_ptr factor = graph.at(factorIx);
|
typename FACTOR::shared_ptr factor = graph.at(factorIx);
|
||||||
if (!factor->active()) continue;
|
if (!factor->active()) continue;
|
||||||
Matrix Ai = factor->getA(factor->find(key)).transpose();
|
Matrix Ai = factor->getA(factor->find(key)).transpose();
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <gtsam_unstable/slam/DummyFactor.h>
|
#include <gtsam_unstable/slam/DummyFactor.h>
|
||||||
|
|
||||||
#include <boost/assign/list_of.hpp>
|
#include <boost/assign/list_of.hpp>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
|
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ DummyFactor::DummyFactor(const Key& key1, size_t dim1, const Key& key2, size_t d
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void DummyFactor::print(const std::string& s, const KeyFormatter& keyFormatter) const {
|
void DummyFactor::print(const std::string& s, const KeyFormatter& keyFormatter) const {
|
||||||
std::cout << s << " DummyFactor dim = " << rowDim_ << ", keys = { ";
|
std::cout << s << " DummyFactor dim = " << rowDim_ << ", keys = { ";
|
||||||
BOOST_FOREACH(Key key, this->keys()) { std::cout << keyFormatter(key) << " "; }
|
for(Key key: this->keys()) { std::cout << keyFormatter(key) << " "; }
|
||||||
std::cout << "}" << std::endl;
|
std::cout << "}" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <gtsam/inference/Key.h>
|
#include <gtsam/inference/Key.h>
|
||||||
#include <gtsam/geometry/Pose2.h>
|
#include <gtsam/geometry/Pose2.h>
|
||||||
#include <gtsam/base/timing.h>
|
#include <gtsam/base/timing.h>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -100,7 +99,7 @@ public:
|
||||||
boost::optional<Circle2> best_circle;
|
boost::optional<Circle2> best_circle;
|
||||||
|
|
||||||
// loop over all circles
|
// loop over all circles
|
||||||
BOOST_FOREACH(const Circle2& it, circles) {
|
for(const Circle2& it: circles) {
|
||||||
// distance between circle centers.
|
// distance between circle centers.
|
||||||
double d = circle1.center.dist(it.center);
|
double d = circle1.center.dist(it.center);
|
||||||
if (d < 1e-9)
|
if (d < 1e-9)
|
||||||
|
@ -123,7 +122,7 @@ public:
|
||||||
// pick winner based on other measurements
|
// pick winner based on other measurements
|
||||||
double error1 = 0, error2 = 0;
|
double error1 = 0, error2 = 0;
|
||||||
Point2 p1 = intersections.front(), p2 = intersections.back();
|
Point2 p1 = intersections.front(), p2 = intersections.back();
|
||||||
BOOST_FOREACH(const Circle2& it, circles) {
|
for(const Circle2& it: circles) {
|
||||||
error1 += it.center.dist(p1);
|
error1 += it.center.dist(p1);
|
||||||
error2 += it.center.dist(p2);
|
error2 += it.center.dist(p2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,7 +254,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Point3 pw_sum(0,0,0);
|
Point3 pw_sum(0,0,0);
|
||||||
BOOST_FOREACH(const Point3& pw, reprojections) {
|
for(const Point3& pw: reprojections) {
|
||||||
pw_sum = pw_sum + pw;
|
pw_sum = pw_sum + pw;
|
||||||
}
|
}
|
||||||
// average reprojected landmark
|
// average reprojected landmark
|
||||||
|
@ -339,9 +339,9 @@ public:
|
||||||
|
|
||||||
if (params_.degeneracyMode == ZERO_ON_DEGENERACY && !result_) {
|
if (params_.degeneracyMode == ZERO_ON_DEGENERACY && !result_) {
|
||||||
// failed: return"empty" Hessian
|
// failed: return"empty" Hessian
|
||||||
BOOST_FOREACH(Matrix& m, Gs)
|
for(Matrix& m: Gs)
|
||||||
m = Matrix::Zero(Base::Dim, Base::Dim);
|
m = Matrix::Zero(Base::Dim, Base::Dim);
|
||||||
BOOST_FOREACH(Vector& v, gs)
|
for(Vector& v: gs)
|
||||||
v = Vector::Zero(Base::Dim);
|
v = Vector::Zero(Base::Dim);
|
||||||
return boost::make_shared<RegularHessianFactor<Base::Dim> >(this->keys_,
|
return boost::make_shared<RegularHessianFactor<Base::Dim> >(this->keys_,
|
||||||
Gs, gs, 0.0);
|
Gs, gs, 0.0);
|
||||||
|
|
|
@ -122,7 +122,7 @@ public:
|
||||||
void print(const std::string& s = "", const KeyFormatter& keyFormatter =
|
void print(const std::string& s = "", const KeyFormatter& keyFormatter =
|
||||||
DefaultKeyFormatter) const {
|
DefaultKeyFormatter) const {
|
||||||
std::cout << s << "SmartStereoProjectionPoseFactor, z = \n ";
|
std::cout << s << "SmartStereoProjectionPoseFactor, z = \n ";
|
||||||
BOOST_FOREACH(const boost::shared_ptr<Cal3_S2Stereo>& K, K_all_)
|
for(const boost::shared_ptr<Cal3_S2Stereo>& K: K_all_)
|
||||||
K->print("calibration = ");
|
K->print("calibration = ");
|
||||||
Base::print("", keyFormatter);
|
Base::print("", keyFormatter);
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ public:
|
||||||
Base::Cameras cameras(const Values& values) const {
|
Base::Cameras cameras(const Values& values) const {
|
||||||
Base::Cameras cameras;
|
Base::Cameras cameras;
|
||||||
size_t i=0;
|
size_t i=0;
|
||||||
BOOST_FOREACH(const Key& k, this->keys_) {
|
for(const Key& k: this->keys_) {
|
||||||
const Pose3& pose = values.at<Pose3>(k);
|
const Pose3& pose = values.at<Pose3>(k);
|
||||||
StereoCamera camera(pose, K_all_[i++]);
|
StereoCamera camera(pose, K_all_[i++]);
|
||||||
cameras.push_back(camera);
|
cameras.push_back(camera);
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include <boost/random.hpp>
|
#include <boost/random.hpp>
|
||||||
#include <boost/timer.hpp>
|
#include <boost/timer.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/assign/std/vector.hpp>
|
#include <boost/assign/std/vector.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -46,7 +45,7 @@ int main(int argc, char* argv[]) {
|
||||||
// loop over number of images
|
// loop over number of images
|
||||||
vector<size_t> ms;
|
vector<size_t> ms;
|
||||||
ms += 10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000;
|
ms += 10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000;
|
||||||
BOOST_FOREACH(size_t m,ms) {
|
for(size_t m: ms) {
|
||||||
// We use volatile here to make these appear to the optimizing compiler as
|
// We use volatile here to make these appear to the optimizing compiler as
|
||||||
// if their values are only known at run-time.
|
// if their values are only known at run-time.
|
||||||
volatile size_t n = 500; // number of points per image
|
volatile size_t n = 500; // number of points per image
|
||||||
|
@ -74,7 +73,7 @@ int main(int argc, char* argv[]) {
|
||||||
// DSFBase version
|
// DSFBase version
|
||||||
timer tim;
|
timer tim;
|
||||||
DSFBase dsf(N); // Allow for N keys
|
DSFBase dsf(N); // Allow for N keys
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf.merge(m.first, m.second);
|
dsf.merge(m.first, m.second);
|
||||||
os << tim.elapsed() << ",";
|
os << tim.elapsed() << ",";
|
||||||
cout << format("DSFBase: %1% s") % tim.elapsed() << endl;
|
cout << format("DSFBase: %1% s") % tim.elapsed() << endl;
|
||||||
|
@ -84,7 +83,7 @@ int main(int argc, char* argv[]) {
|
||||||
// DSFMap version
|
// DSFMap version
|
||||||
timer tim;
|
timer tim;
|
||||||
DSFMap<size_t> dsf;
|
DSFMap<size_t> dsf;
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf.merge(m.first, m.second);
|
dsf.merge(m.first, m.second);
|
||||||
os << tim.elapsed() << endl;
|
os << tim.elapsed() << endl;
|
||||||
cout << format("DSFMap: %1% s") % tim.elapsed() << endl;
|
cout << format("DSFMap: %1% s") % tim.elapsed() << endl;
|
||||||
|
@ -96,7 +95,7 @@ int main(int argc, char* argv[]) {
|
||||||
DSF<size_t> dsf;
|
DSF<size_t> dsf;
|
||||||
for (size_t j = 0; j < N; j++)
|
for (size_t j = 0; j < N; j++)
|
||||||
dsf = dsf.makeSet(j);
|
dsf = dsf.makeSet(j);
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf = dsf.makeUnion(m.first, m.second);
|
dsf = dsf.makeUnion(m.first, m.second);
|
||||||
os << tim.elapsed() << endl;
|
os << tim.elapsed() << endl;
|
||||||
cout << format("DSF functional: %1% s") % tim.elapsed() << endl;
|
cout << format("DSF functional: %1% s") % tim.elapsed() << endl;
|
||||||
|
@ -108,7 +107,7 @@ int main(int argc, char* argv[]) {
|
||||||
DSF<size_t> dsf;
|
DSF<size_t> dsf;
|
||||||
for (size_t j = 0; j < N; j++)
|
for (size_t j = 0; j < N; j++)
|
||||||
dsf.makeSetInPlace(j);
|
dsf.makeSetInPlace(j);
|
||||||
BOOST_FOREACH(const Match& m, matches)
|
for(const Match& m: matches)
|
||||||
dsf.makeUnionInPlace(m.first, m.second);
|
dsf.makeUnionInPlace(m.first, m.second);
|
||||||
os << tim.elapsed() << ",";
|
os << tim.elapsed() << ",";
|
||||||
cout << format("DSF in-place: %1% s") % tim.elapsed() << endl;
|
cout << format("DSF in-place: %1% s") % tim.elapsed() << endl;
|
||||||
|
|
Loading…
Reference in New Issue