Replaced initialize calls with C++11 delegating constructors
parent
485175e2f8
commit
6d938ce5cc
|
@ -33,54 +33,56 @@ namespace gtsam {
|
||||||
/**************************************************************************************************/
|
/**************************************************************************************************/
|
||||||
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph &gfg,
|
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph &gfg,
|
||||||
const Parameters ¶meters, const Ordering& ordering) :
|
const Parameters ¶meters, const Ordering& ordering) :
|
||||||
parameters_(parameters), ordering_(ordering) {
|
parameters_(parameters) {
|
||||||
initialize(gfg);
|
|
||||||
|
GaussianFactorGraph::shared_ptr Ab1,Ab2;
|
||||||
|
boost::tie(Ab1, Ab2) = splitGraph(gfg);
|
||||||
|
if (parameters_.verbosity())
|
||||||
|
cout << "Split A into (A1) " << Ab1->size() << " and (A2) " << Ab2->size()
|
||||||
|
<< " factors" << endl;
|
||||||
|
|
||||||
|
auto Rc1 = Ab1->eliminateSequential(ordering, EliminateQR);
|
||||||
|
auto xbar = boost::make_shared<VectorValues>(Rc1->optimize());
|
||||||
|
pc_ = boost::make_shared<SubgraphPreconditioner>(Ab2, Rc1, xbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************************************/
|
// delegate up
|
||||||
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph::shared_ptr &jfg,
|
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph::shared_ptr &factorGraph,
|
||||||
const Parameters ¶meters, const Ordering& ordering) :
|
const Parameters ¶meters, const Ordering& ordering) :
|
||||||
parameters_(parameters), ordering_(ordering) {
|
SubgraphSolver(*factorGraph, parameters, ordering) {}
|
||||||
initialize(*jfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************************************/
|
/**************************************************************************************************/
|
||||||
|
SubgraphSolver::SubgraphSolver(const GaussianBayesNet::shared_ptr &Rc1,
|
||||||
|
const GaussianFactorGraph::shared_ptr &Ab2,
|
||||||
|
const Parameters ¶meters)
|
||||||
|
: parameters_(parameters) {
|
||||||
|
auto xbar = boost::make_shared<VectorValues>(Rc1->optimize());
|
||||||
|
pc_ = boost::make_shared<SubgraphPreconditioner>(Ab2, Rc1, xbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delegate up
|
||||||
|
SubgraphSolver::SubgraphSolver(const GaussianBayesNet::shared_ptr &Rc1,
|
||||||
|
const GaussianFactorGraph &Ab2,
|
||||||
|
const Parameters ¶meters)
|
||||||
|
: SubgraphSolver(Rc1, boost::make_shared<GaussianFactorGraph>(Ab2),
|
||||||
|
parameters_) {}
|
||||||
|
|
||||||
|
// delegate up
|
||||||
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph &Ab1,
|
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph &Ab1,
|
||||||
const GaussianFactorGraph &Ab2, const Parameters ¶meters,
|
const GaussianFactorGraph &Ab2,
|
||||||
const Ordering& ordering) :
|
const Parameters ¶meters,
|
||||||
parameters_(parameters), ordering_(ordering) {
|
const Ordering &ordering)
|
||||||
|
: SubgraphSolver(Ab1.eliminateSequential(ordering, EliminateQR),
|
||||||
|
boost::make_shared<GaussianFactorGraph>(Ab2),
|
||||||
|
parameters_) {}
|
||||||
|
|
||||||
GaussianBayesNet::shared_ptr Rc1 = Ab1.eliminateSequential(ordering_,
|
// delegate up
|
||||||
EliminateQR);
|
|
||||||
initialize(Rc1, boost::make_shared<GaussianFactorGraph>(Ab2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************************************/
|
|
||||||
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph::shared_ptr &Ab1,
|
SubgraphSolver::SubgraphSolver(const GaussianFactorGraph::shared_ptr &Ab1,
|
||||||
const GaussianFactorGraph::shared_ptr &Ab2, const Parameters ¶meters,
|
const GaussianFactorGraph::shared_ptr &Ab2,
|
||||||
const Ordering& ordering) :
|
const Parameters ¶meters,
|
||||||
parameters_(parameters), ordering_(ordering) {
|
const Ordering &ordering)
|
||||||
|
: SubgraphSolver(Ab1->eliminateSequential(ordering, EliminateQR), Ab2,
|
||||||
GaussianBayesNet::shared_ptr Rc1 = Ab1->eliminateSequential(ordering_,
|
parameters) {}
|
||||||
EliminateQR);
|
|
||||||
initialize(Rc1, Ab2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************************************/
|
|
||||||
SubgraphSolver::SubgraphSolver(const GaussianBayesNet::shared_ptr &Rc1,
|
|
||||||
const GaussianFactorGraph &Ab2, const Parameters ¶meters,
|
|
||||||
const Ordering& ordering) :
|
|
||||||
parameters_(parameters), ordering_(ordering) {
|
|
||||||
initialize(Rc1, boost::make_shared<GaussianFactorGraph>(Ab2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************************************/
|
|
||||||
SubgraphSolver::SubgraphSolver(const GaussianBayesNet::shared_ptr &Rc1,
|
|
||||||
const GaussianFactorGraph::shared_ptr &Ab2, const Parameters ¶meters,
|
|
||||||
const Ordering& ordering) :
|
|
||||||
parameters_(parameters), ordering_(ordering) {
|
|
||||||
initialize(Rc1, Ab2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************************************/
|
/**************************************************************************************************/
|
||||||
VectorValues SubgraphSolver::optimize() {
|
VectorValues SubgraphSolver::optimize() {
|
||||||
|
@ -89,38 +91,16 @@ VectorValues SubgraphSolver::optimize() {
|
||||||
return pc_->x(ybar);
|
return pc_->x(ybar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************************************/
|
|
||||||
VectorValues SubgraphSolver::optimize(const VectorValues &initial) {
|
VectorValues SubgraphSolver::optimize(const VectorValues &initial) {
|
||||||
// the initial is ignored in this case ...
|
// the initial is ignored in this case ...
|
||||||
return optimize();
|
return optimize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************************************/
|
VectorValues SubgraphSolver::optimize(const GaussianFactorGraph &gfg,
|
||||||
void SubgraphSolver::initialize(const GaussianFactorGraph &jfg) {
|
const KeyInfo &keyInfo, const std::map<Key, Vector> &lambda,
|
||||||
GaussianFactorGraph::shared_ptr Ab1 =
|
const VectorValues &initial) {
|
||||||
boost::make_shared<GaussianFactorGraph>(), Ab2 = boost::make_shared<
|
return VectorValues();
|
||||||
GaussianFactorGraph>();
|
|
||||||
|
|
||||||
boost::tie(Ab1, Ab2) = splitGraph(jfg);
|
|
||||||
if (parameters_.verbosity())
|
|
||||||
cout << "Split A into (A1) " << Ab1->size() << " and (A2) " << Ab2->size()
|
|
||||||
<< " factors" << endl;
|
|
||||||
|
|
||||||
GaussianBayesNet::shared_ptr Rc1 = Ab1->eliminateSequential(ordering_,
|
|
||||||
EliminateQR);
|
|
||||||
VectorValues::shared_ptr xbar = boost::make_shared<VectorValues>(
|
|
||||||
Rc1->optimize());
|
|
||||||
pc_ = boost::make_shared<SubgraphPreconditioner>(Ab2, Rc1, xbar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************************************/
|
|
||||||
void SubgraphSolver::initialize(const GaussianBayesNet::shared_ptr &Rc1,
|
|
||||||
const GaussianFactorGraph::shared_ptr &Ab2) {
|
|
||||||
VectorValues::shared_ptr xbar = boost::make_shared<VectorValues>(
|
|
||||||
Rc1->optimize());
|
|
||||||
pc_ = boost::make_shared<SubgraphPreconditioner>(Ab2, Rc1, xbar);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************************************/
|
/**************************************************************************************************/
|
||||||
// Run Kruskal algorithm to create a spanning tree of factor "edges".
|
// Run Kruskal algorithm to create a spanning tree of factor "edges".
|
||||||
// Edges are not weighted, and will only work if factors are binary.
|
// Edges are not weighted, and will only work if factors are binary.
|
||||||
|
@ -163,9 +143,5 @@ SubgraphSolver::splitGraph(const GaussianFactorGraph &factorGraph) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
VectorValues SubgraphSolver::optimize(const GaussianFactorGraph &gfg,
|
|
||||||
const KeyInfo &keyInfo, const std::map<Key, Vector> &lambda,
|
|
||||||
const VectorValues &initial) {
|
|
||||||
return VectorValues();
|
|
||||||
}
|
|
||||||
} // \namespace gtsam
|
} // \namespace gtsam
|
||||||
|
|
|
@ -70,7 +70,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Parameters parameters_;
|
Parameters parameters_;
|
||||||
Ordering ordering_;
|
|
||||||
boost::shared_ptr<SubgraphPreconditioner> pc_; ///< preconditioner object
|
boost::shared_ptr<SubgraphPreconditioner> pc_; ///< preconditioner object
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -88,8 +87,8 @@ public:
|
||||||
const Parameters ¶meters, const Ordering& ordering);
|
const Parameters ¶meters, const Ordering& ordering);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user specify the subgraph part and the constraint part
|
* The user specifies the subgraph part and the constraints part.
|
||||||
* may throw exception if A1 is underdetermined
|
* May throw exception if A1 is underdetermined. An ordering is required to eliminate Ab1.
|
||||||
*/
|
*/
|
||||||
SubgraphSolver(const GaussianFactorGraph &Ab1, const GaussianFactorGraph &Ab2,
|
SubgraphSolver(const GaussianFactorGraph &Ab1, const GaussianFactorGraph &Ab2,
|
||||||
const Parameters ¶meters, const Ordering& ordering);
|
const Parameters ¶meters, const Ordering& ordering);
|
||||||
|
@ -99,15 +98,14 @@ public:
|
||||||
const boost::shared_ptr<GaussianFactorGraph> &Ab2,
|
const boost::shared_ptr<GaussianFactorGraph> &Ab2,
|
||||||
const Parameters ¶meters, const Ordering& ordering);
|
const Parameters ¶meters, const Ordering& ordering);
|
||||||
|
|
||||||
/* The same as above, but the A1 is solved before */
|
/// The same as above, but we assume A1 was solved by caller
|
||||||
SubgraphSolver(const boost::shared_ptr<GaussianBayesNet> &Rc1,
|
SubgraphSolver(const boost::shared_ptr<GaussianBayesNet> &Rc1,
|
||||||
const GaussianFactorGraph &Ab2, const Parameters ¶meters,
|
const GaussianFactorGraph &Ab2, const Parameters ¶meters);
|
||||||
const Ordering& ordering);
|
|
||||||
|
|
||||||
/// Shared pointer version
|
/// Shared pointer version
|
||||||
SubgraphSolver(const boost::shared_ptr<GaussianBayesNet> &Rc1,
|
SubgraphSolver(const boost::shared_ptr<GaussianBayesNet> &Rc1,
|
||||||
const boost::shared_ptr<GaussianFactorGraph> &Ab2,
|
const boost::shared_ptr<GaussianFactorGraph> &Ab2,
|
||||||
const Parameters ¶meters, const Ordering& ordering);
|
const Parameters ¶meters);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~SubgraphSolver() {
|
virtual ~SubgraphSolver() {
|
||||||
|
@ -125,13 +123,8 @@ public:
|
||||||
const VectorValues &initial);
|
const VectorValues &initial);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Split graph using Kruskal algorithm, treating binary factors as edges.
|
||||||
void initialize(const GaussianFactorGraph &jfg);
|
static boost::tuple<boost::shared_ptr<GaussianFactorGraph>, boost::shared_ptr<GaussianFactorGraph>>
|
||||||
void initialize(const boost::shared_ptr<GaussianBayesNet> &Rc1,
|
|
||||||
const boost::shared_ptr<GaussianFactorGraph> &Ab2);
|
|
||||||
|
|
||||||
boost::tuple<boost::shared_ptr<GaussianFactorGraph>,
|
|
||||||
boost::shared_ptr<GaussianFactorGraph> >
|
|
||||||
splitGraph(const GaussianFactorGraph &gfg);
|
splitGraph(const GaussianFactorGraph &gfg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue