00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef BELIEFPROPAGATOR_H_
00013 #define BELIEFPROPAGATOR_H_
00014
00015 #include "utils.h"
00016 #include "IntSet.h"
00017 #include "IndexHeap.h"
00018 #include "SparseMatrix.h"
00019 #include "WeightOracle.h"
00020 #include "OscillationDetector.h"
00021
00025 #define DEFAULT_MAX_ITERS 20000
00026
00030 #define REQUIRED_ITERATIONS 5
00031
00036 class BeliefPropagator {
00037 public:
00038 BeliefPropagator();
00039 virtual ~BeliefPropagator();
00040
00045 void setWeightOracle(WeightOracle * wo);
00046
00051 bool checkConvergence();
00052
00056 void updateBeliefs();
00057
00062 SparseMatrix<bool> * getEstimate();
00063
00068 int getIteration();
00069
00074 void setMaxIter(int i);
00075
00080 void setB(int * degrees);
00081
00088 void setB(int * brows, int * bcols);
00089
00094 void updateRow(double * newAlpha, double * newBeta, int i);
00095
00099 int getViolatedColumns() { return violatedColumns; }
00100
00104 double getIterationTime() { return iterationTime; }
00105
00109 double getChangeX() { return changex; }
00110
00111 private:
00112 int maxIter;
00113 int iter;
00114 int lookups;
00115 double * alpha;
00116 double * beta;
00117 int * betaIndex;
00118 int ** rowMatches;
00119 int ** colMatches;
00120 int * colMatchCount;
00121 int converged;
00122 int numThreads;
00123 int * b;
00124 bool * dontcare;
00125 WeightOracle * weightOracle;
00126 OscillationDetector * detector;
00127
00128
00129 int violatedColumns;
00130 double iterationTime;
00131 double changex;
00132
00133 pthread_t * threads;
00134
00135 void initBetas();
00136 int updateScore(double score, double *bestScores, int *bestIndex,
00137 int minIndex, int column, int b);
00138 };
00139
00140
00141
00145 typedef struct {
00149 int start;
00153 int interval;
00157 int size;
00161 double * newAlpha;
00165 double * newBeta;
00169 BeliefPropagator * bp;
00170 } threadParam;
00171
00172 void * threadedUpdateRows(void * v);
00173
00174 #endif
00175