-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRule.cpp
More file actions
33 lines (27 loc) · 752 Bytes
/
Copy pathRule.cpp
File metadata and controls
33 lines (27 loc) · 752 Bytes
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
#include "Rule.h"
#include "S.h"
#include "NonTerminalShape.h"
Rule::Rule(bool test)
{
}
std::list<Shape*> Rule::expand(Shape *shape)
{
int alternatives = right.size();
std::list<Shape*> result;
int rightWinnerIdx = 0;
float uniform = rand()/(float)RAND_MAX;
float cumulativeProb = 0;
for (int i=0; i<rightProbs.size(); i++) {
cumulativeProb += rightProbs[i];
if (cumulativeProb > uniform) {
rightWinnerIdx = i;
break;
}
}
std::vector<Shape*> expandedShapes = right[rightWinnerIdx];
for (int i = 0; i < expandedShapes.size(); ++i) {
result.push_back(expandedShapes[i]); // TODO: This should perform a copy
}
// delete shape;
return result;
}