11
11
using System . Threading . Tasks ;
12
12
using System . Xml ;
13
13
14
- namespace AIProgrammer . Fitness . Concrete . Research
14
+ namespace AIProgrammer . Fitness . Concrete
15
15
{
16
16
/// <summary>
17
17
/// Outputs the text inside quotes, with additional text in front of it.
18
18
/// </summary>
19
19
public class ExtractInQuotesExtraFitness : FitnessBase
20
20
{
21
- private static string [ ] _trainingExamples = { "dot \" inside\" " , "milk \" test\" " , "final \" foresting\" " } ;
21
+ private static string [ ] _trainingExamples = { "dot \" inside\" " , "mil \" test\" " , "fin \" foresting\" " } ;
22
22
private static string [ ] _trainingResults = new string [ ] { "inside" , "test" , "foresting" } ;
23
23
24
24
#region Settings
@@ -42,7 +42,7 @@ public override int? GenomeSize
42
42
{
43
43
get
44
44
{
45
- return 50 ;
45
+ return 15 ;
46
46
}
47
47
}
48
48
@@ -97,9 +97,8 @@ protected override double GetFitnessMethod(string program)
97
97
try
98
98
{
99
99
int state = 0 ;
100
- int startingDataPointer = - 1 ;
101
100
HashSet < int > memoryHash = new HashSet < int > ( ) ;
102
- bool aBonus = false ;
101
+ int aBonus = 0 ;
103
102
104
103
_console . Clear ( ) ;
105
104
@@ -108,12 +107,6 @@ protected override double GetFitnessMethod(string program)
108
107
{
109
108
if ( state < _trainingExamples [ i ] . Length )
110
109
{
111
- if ( startingDataPointer == - 1 && _trainingExamples [ i ] [ state ] == '"' )
112
- {
113
- // Remember the data pointer position for the first quote input.
114
- startingDataPointer = _bf . m_CurrentDataPointer ;
115
- }
116
-
117
110
// Store data in different memory positions, so that function can access the data.
118
111
memoryHash . Add ( _bf . m_CurrentDataPointer ) ;
119
112
@@ -128,47 +121,16 @@ protected override double GetFitnessMethod(string program)
128
121
} ,
129
122
( b ) =>
130
123
{
131
- // We want the function to do the printing, so apply a bonus if the print comes from a function.
132
- if ( _console . Length < _trainingResults [ i ] . Length )
133
- {
134
- if ( _bf . IsInsideFunction )
135
- {
136
- countBonus += 50 ;
137
- }
138
- else
139
- {
140
- penalty += 50 ;
141
- }
142
- }
143
-
144
124
_console . Append ( ( char ) b ) ;
145
125
} ,
146
126
( function ) =>
147
127
{
148
- switch ( function )
128
+ if ( function == 'a' && aBonus < 2 && _bf . IsInsideLoop )
149
129
{
150
- case 'a' :
151
- {
152
- // Give a bonus for calling the function within a loop.
153
- if ( ! aBonus && _bf . IsInsideLoop )
154
- {
155
- countBonus += 25 ;
156
- countBonus += ( _bf . m_CurrentInstructionPointer + 1 < program . Length ) && program [ _bf . m_CurrentInstructionPointer + 1 ] == '!' ? 75 : 0 ;
157
- aBonus = true ;
158
- }
159
- }
160
- break ;
161
- case 'b' :
162
- {
163
- if ( startingDataPointer != - 1 )
164
- {
165
- // The function requires the starting memory pointer to be at the first quote of input for "test". The function will then strip the quotes.
166
- // Give a bonus for calling the function at the correct memory location.
167
- countBonus += 100 * ( ( startingDataPointer - Math . Abs ( _bf . m_CurrentDataPointer - startingDataPointer ) ) / startingDataPointer ) ;
168
- }
169
- }
170
- break ;
171
- } ;
130
+ countBonus += 50 ;
131
+ countBonus += ( _bf . m_CurrentInstructionPointer + 1 < program . Length ) && program [ _bf . m_CurrentInstructionPointer + 1 ] == '!' ? 50 : 0 ;
132
+ aBonus ++ ;
133
+ }
172
134
} , new InterpreterOptions ( ) { FunctionMaxIterationCounts = new int [ ] { 100 } } ) ;
173
135
_bf . Run ( _maxIterationCount ) ;
174
136
@@ -200,13 +162,11 @@ protected override double GetFitnessMethod(string program)
200
162
// Check for solution.
201
163
IsFitnessAchieved ( ) ;
202
164
203
- // Bonus for executing functions.
204
- countBonus += _bf . m_ExecutedFunctions . Count * 100 ;
205
-
206
165
// Bonus for less operations to optimize the code.
207
166
countBonus += ( ( _maxIterationCount - _bf . m_Ticks ) / 20.0 ) ;
208
167
209
168
Ticks += _bf . m_Ticks ;
169
+ TotalTicks += _bf . m_TotalTicks ;
210
170
}
211
171
212
172
if ( _fitness != Double . MaxValue )
0 commit comments