1 |
|
---|
2 | using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
|
---|
5 | // only counts the number of variable references
|
---|
6 | internal class SimpleConstraintHandler : IConstraintHandler {
|
---|
7 | private int maxVariables;
|
---|
8 | private int numVariables;
|
---|
9 |
|
---|
10 | public bool IsInvalidExpression {
|
---|
11 | get {
|
---|
12 | return numVariables > maxVariables;
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 | public SimpleConstraintHandler(int maxVars) {
|
---|
17 | this.maxVariables = maxVars;
|
---|
18 | }
|
---|
19 |
|
---|
20 | public void AddVarToCurrentFactor(int state) {
|
---|
21 | numVariables++;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public void EndFactor() {
|
---|
25 | // ignore
|
---|
26 | }
|
---|
27 |
|
---|
28 | public void EndTerm() {
|
---|
29 | // ignore
|
---|
30 | }
|
---|
31 |
|
---|
32 | public bool IsAllowedFollowState(int currentState, int followState) {
|
---|
33 | return numVariables < maxVariables ||
|
---|
34 | // going to the final state is always allowed (smaller states are closer to the final state)
|
---|
35 | currentState > followState;
|
---|
36 | // (
|
---|
37 | // followState != Automaton.StateExpFactorStart &&
|
---|
38 | // followState != Automaton.StateFactorStart &&
|
---|
39 | // followState != Automaton.StateTermStart &&
|
---|
40 | // followState != Automaton.StateLogTStart &&
|
---|
41 | // followState != Automaton.StateLogTFStart &&
|
---|
42 | // followState != Automaton.StateInvTStart &&
|
---|
43 | // followState != Automaton.StateInvTFStart);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void Reset() {
|
---|
47 | numVariables = 0;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void StartFactor(int state) {
|
---|
51 | // ignore
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void StartNewTermInPoly() {
|
---|
55 | // ignore
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void StartTerm() {
|
---|
59 | // ignore
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|