add a sequential elimination heuristic

This commit is contained in:
Tiago Gomes 2012-05-29 17:12:57 +01:00
parent 0315cd51a3
commit 02395daed3
4 changed files with 21 additions and 6 deletions

View File

@ -139,12 +139,23 @@ ElimGraph::exportToGraphViz (
VarIds
ElimGraph::getEliminationOrder (
const vector<Factor*> factors,
const Factors& factors,
VarIds excludedVids)
{
if (elimHeuristic == ElimHeuristic::SEQUENTIAL) {
VarIds allVids;
Factors::const_iterator first = factors.begin();
Factors::const_iterator end = factors.end();
for (; first != end; ++first) {
Util::addToVector (allVids, (*first)->arguments());
}
TinySet<VarId> elimOrder (allVids);
for (size_t i = 0; i < excludedVids.size(); i++) {
elimOrder.remove (excludedVids[i]);
}
return elimOrder.elements();
}
ElimGraph graph (factors);
// graph.print();
// graph.exportToGraphViz ("_egg.dot");
return graph.getEliminatingOrder (excludedVids);
}

View File

@ -12,6 +12,7 @@ using namespace std;
enum ElimHeuristic
{
SEQUENTIAL,
MIN_NEIGHBORS,
MIN_WEIGHT,
MIN_FILL,
@ -45,7 +46,7 @@ class EgNode : public Var
class ElimGraph
{
public:
ElimGraph (const vector<Factor*>&); // TODO
ElimGraph (const Factors&);
~ElimGraph (void);
@ -56,7 +57,7 @@ class ElimGraph
void exportToGraphViz (const char*, bool = true,
const VarIds& = VarIds()) const;
static VarIds getEliminationOrder (const vector<Factor*>, VarIds);
static VarIds getEliminationOrder (const Factors&, VarIds);
static ElimHeuristic elimHeuristic;

View File

@ -219,7 +219,9 @@ setHorusFlag (string key, string value)
returnVal = false;
}
} else if (key == "elim_heuristic") {
if ( value == "min_neighbors") {
if ( value == "sequential") {
ElimGraph::elimHeuristic = ElimHeuristic::SEQUENTIAL;
} else if (value == "min_neighbors") {
ElimGraph::elimHeuristic = ElimHeuristic::MIN_NEIGHBORS;
} else if (value == "min_weight") {
ElimGraph::elimHeuristic = ElimHeuristic::MIN_WEIGHT;

View File

@ -48,6 +48,7 @@ VarElimSolver::printSolverFlags (void) const
ss << "elim_heuristic=" ;
ElimHeuristic eh = ElimGraph::elimHeuristic;
switch (eh) {
case SEQUENTIAL: ss << "sequential"; break;
case MIN_NEIGHBORS: ss << "min_neighbors"; break;
case MIN_WEIGHT: ss << "min_weight"; break;
case MIN_FILL: ss << "min_fill"; break;