From 8c2468c28b13cbae8d75843901470ada23834dbc Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Wed, 20 Feb 2013 11:52:42 +0000 Subject: [PATCH] Improve encapsulation in HorusYap and perform other small refactorings --- packages/CLPBN/horus/HorusCli.cpp | 1 + packages/CLPBN/horus/HorusYap.cpp | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/CLPBN/horus/HorusCli.cpp b/packages/CLPBN/horus/HorusCli.cpp index f8e51927f..1f7720e2c 100644 --- a/packages/CLPBN/horus/HorusCli.cpp +++ b/packages/CLPBN/horus/HorusCli.cpp @@ -8,6 +8,7 @@ #include "BeliefProp.h" #include "CountingBp.h" + namespace { int readHorusFlags (int, const char* []); diff --git a/packages/CLPBN/horus/HorusYap.cpp b/packages/CLPBN/horus/HorusYap.cpp index 5a527addb..b2c90e08d 100644 --- a/packages/CLPBN/horus/HorusYap.cpp +++ b/packages/CLPBN/horus/HorusYap.cpp @@ -20,9 +20,10 @@ #include "ElimGraph.h" #include "BayesBall.h" + namespace Horus { -typedef std::pair LiftedNetwork; +namespace { Parfactor* readParfactor (YAP_Term); @@ -34,6 +35,10 @@ Params readParameters (YAP_Term); YAP_Term fillSolutionList (const std::vector&); +} + +typedef std::pair LiftedNetwork; + int @@ -66,9 +71,9 @@ createLiftedNetwork (void) // read evidence ObservedFormulas* obsFormulas = readLiftedEvidence (YAP_ARG2); - LiftedNetwork* net = new LiftedNetwork (pfList, obsFormulas); + LiftedNetwork* network = new LiftedNetwork (pfList, obsFormulas); - YAP_Int p = (YAP_Int) (net); + YAP_Int p = (YAP_Int) (network); return YAP_Unify (YAP_MkIntTerm (p), YAP_ARG3); } @@ -134,14 +139,14 @@ int runLiftedSolver (void) { LiftedNetwork* network = (LiftedNetwork*) YAP_IntOfTerm (YAP_ARG1); - ParfactorList pfListCopy (*network->first); - LiftedOperations::absorveEvidence (pfListCopy, *network->second); + ParfactorList copy (*network->first); + LiftedOperations::absorveEvidence (copy, *network->second); LiftedSolver* solver = 0; switch (Globals::liftedSolver) { - case LiftedSolverType::lveSolver: solver = new LiftedVe (pfListCopy); break; - case LiftedSolverType::lbpSolver: solver = new LiftedBp (pfListCopy); break; - case LiftedSolverType::lkcSolver: solver = new LiftedKc (pfListCopy); break; + case LiftedSolverType::lveSolver: solver = new LiftedVe (copy); break; + case LiftedSolverType::lbpSolver: solver = new LiftedBp (copy); break; + case LiftedSolverType::lkcSolver: solver = new LiftedKc (copy); break; } if (Globals::verbosity > 0) { @@ -368,6 +373,8 @@ freeLiftedNetwork (void) +namespace { + Parfactor* readParfactor (YAP_Term pfTerm) { @@ -545,6 +552,8 @@ fillSolutionList (const std::vector& results) return list; } +} + extern "C" void