Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f3b4426

Browse files
Updated working example.
1 parent 29c85a7 commit f3b4426

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

‎AIProgrammer.Fitness/Concrete/Research/ExtractInQuotesExtraFitness.cs

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
using System.Threading.Tasks;
1212
using System.Xml;
1313

14-
namespace AIProgrammer.Fitness.Concrete.Research
14+
namespace AIProgrammer.Fitness.Concrete
1515
{
1616
/// <summary>
1717
/// Outputs the text inside quotes, with additional text in front of it.
1818
/// </summary>
1919
public class ExtractInQuotesExtraFitness : FitnessBase
2020
{
21-
private static string[] _trainingExamples = { "dot \"inside\"", "milk \"test\"", "final \"foresting\"" };
21+
private static string[] _trainingExamples = { "dot \"inside\"", "mil \"test\"", "fin \"foresting\"" };
2222
private static string[] _trainingResults = new string[] { "inside", "test", "foresting" };
2323

2424
#region Settings
@@ -42,7 +42,7 @@ public override int? GenomeSize
4242
{
4343
get
4444
{
45-
return 50;
45+
return 15;
4646
}
4747
}
4848

@@ -97,9 +97,8 @@ protected override double GetFitnessMethod(string program)
9797
try
9898
{
9999
int state = 0;
100-
int startingDataPointer = -1;
101100
HashSet<int> memoryHash = new HashSet<int>();
102-
bool aBonus = false;
101+
int aBonus = 0;
103102

104103
_console.Clear();
105104

@@ -108,12 +107,6 @@ protected override double GetFitnessMethod(string program)
108107
{
109108
if (state < _trainingExamples[i].Length)
110109
{
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-
117110
// Store data in different memory positions, so that function can access the data.
118111
memoryHash.Add(_bf.m_CurrentDataPointer);
119112

@@ -128,47 +121,16 @@ protected override double GetFitnessMethod(string program)
128121
},
129122
(b) =>
130123
{
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-
144124
_console.Append((char)b);
145125
},
146126
(function) =>
147127
{
148-
switch (function)
128+
if (function=='a'&&aBonus<2&&_bf.IsInsideLoop)
149129
{
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+
}
172134
}, new InterpreterOptions() { FunctionMaxIterationCounts = new int[] { 100 } });
173135
_bf.Run(_maxIterationCount);
174136

@@ -200,13 +162,11 @@ protected override double GetFitnessMethod(string program)
200162
// Check for solution.
201163
IsFitnessAchieved();
202164

203-
// Bonus for executing functions.
204-
countBonus += _bf.m_ExecutedFunctions.Count * 100;
205-
206165
// Bonus for less operations to optimize the code.
207166
countBonus += ((_maxIterationCount - _bf.m_Ticks) / 20.0);
208167

209168
Ticks += _bf.m_Ticks;
169+
TotalTicks += _bf.m_TotalTicks;
210170
}
211171

212172
if (_fitness != Double.MaxValue)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /