Beautify setHorusFlag

This commit is contained in:
Tiago Gomes 2013-01-08 21:13:58 +00:00
parent 2738d83302
commit dc536fabc2
1 changed files with 60 additions and 89 deletions

View File

@ -188,133 +188,104 @@ getStateLines (const Vars& vars)
bool invalidValue (string key, string value)
{
cerr << "Warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" ;
cerr << endl;
return false;
}
bool bool
setHorusFlag (string key, string value) setHorusFlag (string key, string value)
{ {
bool returnVal = true; bool returnVal = true;
if (key == "lifted_solver") { if (key == "lifted_solver") {
if ( value == "lve") { if (value == "lve") Globals::liftedSolver = LiftedSolverType::LVE;
Globals::liftedSolver = LiftedSolverType::LVE; else if (value == "lbp") Globals::liftedSolver = LiftedSolverType::LBP;
} else if (value == "lbp") { else if (value == "lkc") Globals::liftedSolver = LiftedSolverType::LKC;
Globals::liftedSolver = LiftedSolverType::LBP; else returnVal = invalidValue (key, value);
} else if (value == "lkc") {
Globals::liftedSolver = LiftedSolverType::LKC;
} else {
cerr << "warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "ground_solver" || key == "solver") { } else if (key == "ground_solver" || key == "solver") {
if ( value == "hve") { if (value == "hve") Globals::groundSolver = GroundSolverType::VE;
Globals::groundSolver = GroundSolverType::VE; else if (value == "bp") Globals::groundSolver = GroundSolverType::BP;
} else if (value == "bp") { else if (value == "cbp") Globals::groundSolver = GroundSolverType::CBP;
Globals::groundSolver = GroundSolverType::BP; else returnVal = invalidValue (key, value);
} else if (value == "cbp") {
Globals::groundSolver = GroundSolverType::CBP;
} else {
cerr << "warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "verbosity") { } else if (key == "verbosity") {
stringstream ss; stringstream ss;
ss << value; ss << value;
ss >> Globals::verbosity; ss >> Globals::verbosity;
} else if (key == "use_logarithms") { } else if (key == "use_logarithms") {
if ( value == "true") { if (value == "true") Globals::logDomain = true;
Globals::logDomain = true; else if (value == "false") Globals::logDomain = false;
} else if (value == "false") { else returnVal = invalidValue (key, value);
Globals::logDomain = false;
} else {
cerr << "warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "hve_elim_heuristic") { } else if (key == "hve_elim_heuristic") {
if ( value == "sequential") { if (value == "sequential")
ElimGraph::setElimHeuristic (ElimHeuristic::SEQUENTIAL); ElimGraph::setElimHeuristic (ElimHeuristic::SEQUENTIAL);
} else if (value == "min_neighbors") { else if (value == "min_neighbors")
ElimGraph::setElimHeuristic (ElimHeuristic::MIN_NEIGHBORS); ElimGraph::setElimHeuristic (ElimHeuristic::MIN_NEIGHBORS);
} else if (value == "min_weight") { else if (value == "min_weight")
ElimGraph::setElimHeuristic (ElimHeuristic::MIN_WEIGHT); ElimGraph::setElimHeuristic (ElimHeuristic::MIN_WEIGHT);
} else if (value == "min_fill") { else if (value == "min_fill")
ElimGraph::setElimHeuristic (ElimHeuristic::MIN_FILL); ElimGraph::setElimHeuristic (ElimHeuristic::MIN_FILL);
} else if (value == "weighted_min_fill") { else if (value == "weighted_min_fill")
ElimGraph::setElimHeuristic (ElimHeuristic::WEIGHTED_MIN_FILL); ElimGraph::setElimHeuristic (ElimHeuristic::WEIGHTED_MIN_FILL);
} else { else
cerr << "warning: invalid value `" << value << "' " ; returnVal = invalidValue (key, value);
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "bp_msg_schedule") { } else if (key == "bp_msg_schedule") {
if ( value == "seq_fixed") { if (value == "seq_fixed")
BeliefProp::setMsgSchedule (MsgSchedule::SEQ_FIXED); BeliefProp::setMsgSchedule (MsgSchedule::SEQ_FIXED);
} else if (value == "seq_random") { else if (value == "seq_random")
BeliefProp::setMsgSchedule (MsgSchedule::SEQ_RANDOM); BeliefProp::setMsgSchedule (MsgSchedule::SEQ_RANDOM);
} else if (value == "parallel") { else if (value == "parallel")
BeliefProp::setMsgSchedule (MsgSchedule::PARALLEL); BeliefProp::setMsgSchedule (MsgSchedule::PARALLEL);
} else if (value == "max_residual") { else if (value == "max_residual")
BeliefProp::setMsgSchedule (MsgSchedule::MAX_RESIDUAL); BeliefProp::setMsgSchedule (MsgSchedule::MAX_RESIDUAL);
} else { else
cerr << "warning: invalid value `" << value << "' " ; returnVal = invalidValue (key, value);
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "bp_accuracy") { } else if (key == "bp_accuracy") {
stringstream ss; stringstream ss;
double acc; double acc;
ss << value; ss << value;
ss >> acc; ss >> acc;
BeliefProp::setAccuracy (acc); BeliefProp::setAccuracy (acc);
} else if (key == "bp_max_iter") { } else if (key == "bp_max_iter") {
stringstream ss; stringstream ss;
unsigned mi; unsigned mi;
ss << value; ss << value;
ss >> mi; ss >> mi;
BeliefProp::setMaxIterations (mi); BeliefProp::setMaxIterations (mi);
} else if (key == "export_libdai") { } else if (key == "export_libdai") {
if ( value == "true") { if (value == "true") FactorGraph::enableExportToLibDai();
FactorGraph::enableExportToLibDai(); else if (value == "false") FactorGraph::disableExportToLibDai();
} else if (value == "false") { else returnVal = invalidValue (key, value);
FactorGraph::disableExportToLibDai();
Globals::logDomain = false;
} else {
cerr << "warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "export_uai") { } else if (key == "export_uai") {
if ( value == "true") { if (value == "true") FactorGraph::enableExportToUai();
FactorGraph::enableExportToUai(); else if (value == "false") FactorGraph::disableExportToUai();
} else if (value == "false") { else returnVal = invalidValue (key, value);
FactorGraph::disableExportToUai();
} else {
cerr << "warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "export_graphviz") { } else if (key == "export_graphviz") {
if ( value == "true") { if (value == "true") FactorGraph::enableExportToGraphViz();
FactorGraph::enableExportToGraphViz(); else if (value == "false") FactorGraph::disableExportToGraphViz();
} else if (value == "false") { else returnVal = invalidValue (key, value);
FactorGraph::disableExportToGraphViz();
} else {
cerr << "warning: invalid value `" << value << "' " ;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else if (key == "print_fg") { } else if (key == "print_fg") {
if ( value == "true") { if (value == "true") FactorGraph::enablePrintFactorGraph();
FactorGraph::enablePrintFactorGraph(); else if (value == "false") FactorGraph::disablePrintFactorGraph();
} else if (value == "false") { else returnVal = invalidValue (key, value);
FactorGraph::disablePrintFactorGraph();
} else { } else {
cerr << "warning: invalid value `" << value << "' " ; cerr << "Warning: invalid key `" << key << "'" << endl;
cerr << "for `" << key << "'" << endl;
returnVal = false;
}
} else {
cerr << "warning: invalid key `" << key << "'" << endl;
returnVal = false; returnVal = false;
} }
return returnVal; return returnVal;