-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBestFirstStack.cpp
50 lines (44 loc) · 1.09 KB
/
BestFirstStack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* BestFirstStack.cpp
* TTree
*
* Created by Vincent Botta on 27/01/09.
* Copyright 2009 University of Liège. All rights reserved.
*
*/
#include "BestFirstStack.h"
#include "Score.h"
BestFirstStack::BestFirstStack(DB* d) { db = d; }
BestFirstStack::~BestFirstStack() {}
Node* BestFirstStack::pop() {
Node *ret = s[s.size()-1];
s.pop_back();
values.pop_back();
return ret;
}
/*
this push override the parent one to order the node by H(c)
*/
void BestFirstStack::push(Node* n) {
n->setId(nbpush++);
std::vector<unsigned int> set = n->getLS();
//printf("Node Size : %d\n",set.size());
double total = 0.0;
std::vector<double> sum(2,0.0);
for (int i = 0 ; i < set.size() ; ++i) {
total += db->getWeight(set[i]);
sum[db->getOutput(set[i])] += db->getWeight(set[i]);
}
Score score;
double hc = score.getShannonEntropy(sum,total) * total;
if (hc > 0.0) {
std::vector<double>::iterator it;
std::vector< Node* >::iterator itn;
for( it = values.begin(), itn = s.begin() ; it != values.end(); it++, itn++ ) {
if (hc <= *it)
break;
}
values.insert(it,hc);
s.insert(itn,n);
}
}