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