From dc536fabc2a1a5b690bdbf83e4bc9ee4e9da7cfb Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Tue, 8 Jan 2013 21:13:58 +0000 Subject: [PATCH] Beautify setHorusFlag --- packages/CLPBN/horus/Util.cpp | 149 ++++++++++++++-------------------- 1 file changed, 60 insertions(+), 89 deletions(-) diff --git a/packages/CLPBN/horus/Util.cpp b/packages/CLPBN/horus/Util.cpp index 8927d3d43..ca681b9d7 100644 --- a/packages/CLPBN/horus/Util.cpp +++ b/packages/CLPBN/horus/Util.cpp @@ -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;