Changeset 14392
- Timestamp:
- 11/15/16 21:10:17 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.Algorithms.PushGP
- Files:
-
- 67 added
- 19 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli/HeuristicLab.Algorithms.PushGP.Cli.csproj
r14328 r14392 36 36 </PropertyGroup> 37 37 <ItemGroup> 38 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 39 <SpecificVersion>False</SpecificVersion> 40 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 41 </Reference> 42 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 43 <SpecificVersion>False</SpecificVersion> 44 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 45 </Reference> 38 46 <Reference Include="System" /> 39 47 <Reference Include="System.Core" /> -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli/Program.cs
r14328 r14392 22 22 static async Task Stepwise() 23 23 { 24 var program = PushGPInterpreter.Encode(@"( CODE.QUOTE ( INTEGER.POP 1 )25 CODE.QUOTE ( CODE.DUP INTEGER.DUP 1 INTEGER.- CODE.DO INTEGER.* )26 INTEGER.DUP 2 INTEGER.< CODE.IF )");27 24 var interpreter = new PushGPInterpreter(); 28 25 29 interpreter.IntegerStack.Push(5); 30 interpreter.InterpretAsync(program, true).Wait(); 26 interpreter.InterpretAsync("( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )", true).Wait(); 31 27 32 28 while (!interpreter.IsCompleted) … … 72 68 var sw = new Stopwatch(); 73 69 70 var interpreter = new PushGPInterpreter(); 71 var generator = new CodeGenerator(interpreter); 72 74 73 sw.Start(); 75 var expressions = CodeGenerator.RandomCode(3000000);74 var expressions = generator.RandomCode(3000000); 76 75 sw.Stop(); 77 76 -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Expression.cs
r14328 r14392 1 using System; 2 using System.Collections.Generic; 3 using HeuristicLab.Algorithms.PushGP.Interpreter; 4 using HeuristicLab.Algorithms.PushGP.Stack; 1 using HeuristicLab.Algorithms.PushGP.Interpreter; 2 using HeuristicLab.Common; 5 3 6 4 namespace HeuristicLab.Algorithms.PushGP.Expressions 7 5 { 8 public abstract class Expression 6 public abstract class Expression : DeepCloneable 9 7 { 10 public abstract bool IsCodeOp { get; } 8 public Expression() { } 9 10 public Expression(string stringRepresenation) : this(stringRepresenation, stringRepresenation.GetHashCode()) 11 { } 12 13 public Expression(string stringRepresenation, int id) 14 { 15 this.StringRepresentation = stringRepresenation; 16 this.Id = id; 17 } 18 19 // copy constructor 20 public Expression(Expression original, Cloner cloner) : base(original, cloner) 21 { 22 this.StringRepresentation = original.StringRepresentation; 23 this.Id = original.Id; 24 } 25 26 protected int Id { get; set; } 27 protected string StringRepresentation { get; set; } 28 11 29 public abstract void Eval(IInterpreter interpreter); 12 30 13 public void PushResult<T>(IStack<T> stack, int count, Func<T[], T> templateFunc)31 public override string ToString() 14 32 { 15 PushResult(stack, stack, count, templateFunc);33 return this.StringRepresentation; 16 34 } 17 35 18 public void PushResult<T, R>(IStack<T> sourceStack, IStack<R> targetStack, int count, Func<T[], R> templateFunc)36 public override bool Equals(object obj) 19 37 { 20 // not enough arguments on stack 21 if (sourceStack.Count < count) 22 return; 23 24 var values = sourceStack.Pop(count); 25 var result = templateFunc(values); 26 27 targetStack.Push(result); 38 return obj != null && this.GetType() == obj.GetType(); 28 39 } 29 40 30 public void Duplicate<T>(IStack<T> stack)41 public override int GetHashCode() 31 42 { 32 // not enough arguments on stack 33 if (stack.Count == 0) 34 return; 35 36 var value = stack.Top; 37 stack.Push(value); 43 return this.Id; 38 44 } 39 45 40 public static void Define<T>(IStack<T> stack, IStack<string> nameStack, IDictionary<string, Expression> customExpressions, Func<T, Expression> creator)46 public override IDeepCloneable Clone(Cloner cloner) 41 47 { 42 // not enough arguments on stack 43 if (nameStack.Count == 0 || 44 stack.Count == 0) 45 return; 46 47 var name = nameStack.Pop(); 48 var expression = creator(stack.Top); 49 50 if (customExpressions.ContainsKey(name)) 51 { 52 customExpressions[name] = expression; 53 } 54 else 55 { 56 customExpressions.Add(name, expression); 57 } 48 return this; 58 49 } 59 50 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Generators/CodeGenerator.cs
r14328 r14392 1 using System.Collections.Generic; 1 using System; 2 using System.Collections.Generic; 2 3 using System.Linq; 3 4 using HeuristicLab.Algorithms.PushGP.Expressions; 5 using HeuristicLab.Algorithms.PushGP.Interpreter; 6 using HeuristicLab.Core; 4 7 using HeuristicLab.Random; 5 8 6 9 namespace HeuristicLab.Algorithms.PushGP.Generators 7 10 { 8 public static class CodeGenerator 11 /// <summary> 12 /// The following is the standard Push random code generation algorithm, which is used for the CODE.RAND instruction. 13 /// It may also be useful for the initialization of programs in evolutionary computation systems, and it is used for this purpose in PushGP. 14 /// It produces a uniform distribution of sizes and what seems to be a reasonable distribution of shapes, in a reasonable amount of time. 15 /// </summary> 16 /// <see cref="http://faculty.hampshire.edu/lspector/push3-description.html#RandomCode"/> 17 public class CodeGenerator 9 18 { 10 private static FastRandom random = new FastRandom(); 11 public static IEnumerable<Expression> RandomCode(int maxPoints) 19 private static IRandom random = new FastRandom(); 20 private readonly IInterpreter interpreter; 21 22 public CodeGenerator(IInterpreter interpreter) 12 23 { 13 var actualPoints = random.Next(1, maxPoints); 14 15 return RandomCodeWithSize(actualPoints).ToArray(); 24 this.interpreter = interpreter; 16 25 } 17 26 18 private static IEnumerable<Expression> RandomCodeWithSize(int points) 27 /// <summary> 28 /// Generates a random program with a given max size 29 /// </summary> 30 /// <param name="maxPoints"></param> 31 /// <returns>Returns an ExpandExpression if maxPoints smaller or equal to Configuration.MaxProgramPoints and Noop otherwise</returns> 32 public Expression RandomProgram(int maxPoints) 33 { 34 return ExecExpandExpression.TryCreate(interpreter.CodeGenerator.RandomCode(maxPoints).ToArray(), interpreter.Configuration); 35 } 36 37 public IEnumerable<Expression> RandomCode(int maxPoints) 38 { 39 var actualPoints = random.Next(1, Math.Max(1, maxPoints)); 40 41 return RandomCodeWithSize(actualPoints); 42 } 43 44 private IEnumerable<Expression> RandomCodeWithSize(int points) 19 45 { 20 46 if (points == 1) 21 47 { 22 // TODO: If this is an "ephemeral random constant"???? then return a randomly - chosen value of the appropriate type; 23 var opCode = (OpCode)random.Next(OpCodeExtensions.Min, OpCodeExtensions.Max); 24 25 return new[] { ExpressionFactory.Create(opCode) }; 48 var index = random.Next(0, ExpressionTable.Count + this.interpreter.CustomExpressions.Count - 2); 49 return new[] { this.CreateExpression(index) }; 26 50 } 27 51 else 28 52 { 29 53 var sizesThisLevel = Decompose(points - 1, points - 1); 30 31 54 return sizesThisLevel.SelectMany(size => RandomCodeWithSize(size)).Shuffle(random); 32 55 } 33 56 } 34 57 35 private staticIEnumerable<int> Decompose(int number, int maxParts)58 private IEnumerable<int> Decompose(int number, int maxParts) 36 59 { 37 60 if (number == 1 || maxParts == 1) … … 42 65 { 43 66 var thisPart = random.Next(1, number - 1); 44 45 67 return new[] { thisPart }.Concat(Decompose(number - thisPart, maxParts - 1)); 46 68 } 47 69 } 70 71 private Expression CreateExpression(int index) 72 { 73 return (index >= 0 && index < ExpressionTable.Count) 74 ? ExpressionTable.GetExpression(index) 75 : new NameDefineXExecExpression(this.interpreter.CustomExpressions.ElementAt(index - (ExpressionTable.Count - 1)).Key); 76 } 48 77 } 49 78 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.csproj
r14328 r14392 53 53 <ItemGroup> 54 54 <Compile Include="Exporter\Exporter.cs" /> 55 <Compile Include="Expressions\Boolean\BooleanPushExpression.cs" /> 56 <Compile Include="Expressions\Code\CodeDoExpression.cs" /> 57 <Compile Include="Expressions\Code\CodeDefineExpression.cs" /> 58 <Compile Include="Expressions\Code\CodeIfExpression.cs" /> 59 <Compile Include="Expressions\Code\CodeNoopExpression.cs" /> 60 <Compile Include="Expressions\Code\CodeQuoteExpression.cs" /> 61 <Compile Include="Expressions\Exec\ExecDefineExpression.cs" /> 62 <Compile Include="Expressions\Exec\ExecYExpression.cs" /> 63 <Compile Include="Expressions\Exec\ExecDoRangeExpression.cs" /> 64 <Compile Include="Expressions\Exec\ExecIfExpression.cs" /> 65 <Compile Include="Expressions\Exec\ExecPushExpression.cs" /> 66 <Compile Include="Expressions\Exec\ExecExpandExpression.cs" /> 67 <Compile Include="Expressions\ExpressionFactory.cs" /> 55 <Compile Include="Expressions\BooleanExpressions.cs" /> 56 <Compile Include="Expressions\CodeExpressions.cs" /> 57 <Compile Include="Expressions\DoCountExpressions.cs" /> 58 <Compile Include="Expressions\DoTimesExpressions.cs" /> 59 <Compile Include="Expressions\ERCExpressions.cs" /> 60 <Compile Include="Expressions\DoRangeExpressions.cs" /> 61 <Compile Include="Expressions\LoopExpression.cs" /> 62 <Compile Include="Expressions\PushResultExpression.cs" /> 63 <Compile Include="Expressions\EqualsExpressions.cs" /> 64 <Compile Include="Expressions\RandExpressions.cs" /> 65 <Compile Include="Expressions\SetExpressions.cs" /> 66 <Compile Include="Expressions\YankDuplicateExpressions.cs" /> 67 <Compile Include="Expressions\YankExpressions.cs" /> 68 <Compile Include="Expressions\StackdepthExpressions.cs" /> 69 <Compile Include="Expressions\ShoveExpressions.cs" /> 70 <Compile Include="Expressions\RotateExpressions.cs" /> 71 <Compile Include="Expressions\SwapExpressions.cs" /> 72 <Compile Include="Expressions\FlushExpressions.cs" /> 73 <Compile Include="Expressions\FloatExpressions.cs" /> 74 <Compile Include="Expressions\IntegerExpressions.cs" /> 75 <Compile Include="Expressions\DefineExpressions.cs" /> 76 <Compile Include="Expressions\DuplicateExpressions.cs" /> 77 <Compile Include="Expressions\PopExpressions.cs" /> 78 <Compile Include="Expressions\PushExpressions.cs" /> 79 <Compile Include="Expressions\ExecExpressions.cs" /> 68 80 <Compile Include="Expressions\Expression.cs" /> 69 <Compile Include="Expressions\Float\FloatPushExpression.cs" /> 70 <Compile Include="Expressions\Integer\IntegerPushExpression.cs" /> 71 <Compile Include="Expressions\Name\NameDefineXExecExpression.cs" /> 72 <Compile Include="Expressions\Templates\DefineExpressionTemplate.cs" /> 73 <Compile Include="Expressions\Templates\DuplicateExpressionTemplate.cs" /> 74 <Compile Include="Expressions\Templates\ExpressionTemplate.cs" /> 75 <Compile Include="Expressions\Templates\PopExpressionTemplate.cs" /> 76 <Compile Include="Expressions\Templates\PushResultExpressionTemplate.cs" /> 81 <Compile Include="Expressions\NameExpressions.cs" /> 82 <Compile Include="StateFullExpressionAttribute.cs" /> 83 <Compile Include="Generators\BooleanGenerator.cs" /> 84 <Compile Include="Generators\FloatGenerator.cs" /> 85 <Compile Include="Generators\IntegerGenerator.cs" /> 86 <Compile Include="Generators\NameGenerator.cs" /> 77 87 <Compile Include="Interpreter\Configuration.cs" /> 78 88 <Compile Include="Generators\CodeGenerator.cs" /> 79 <Compile Include="Generators\Configuration.cs" />80 <Compile Include="OpCode.cs" />81 <Compile Include="OpCodeExtensions.cs" />82 89 <Compile Include="Parser\Parser.cs" /> 83 90 <Compile Include="Stack\IStack.cs" /> 84 <Compile Include="Interpreter\ Interpreter.cs" />91 <Compile Include="Interpreter\PushGPInterpreter.cs" /> 85 92 <Compile Include="Properties\AssemblyInfo.cs" /> 86 93 <Compile Include="Interpreter\IInterpreter.cs" /> 87 94 <Compile Include="Stack\PushGPStack.cs" /> 88 <Compile Include="Parser\SymbolTable.cs" /> 89 <Compile Include="Symbols.cs" /> 95 <Compile Include="ExpressionTable.cs" /> 90 96 </ItemGroup> 91 97 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.csproj.user
r14329 r14392 2 2 <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 3 3 <PropertyGroup> 4 <ProjectView> ShowAllFiles</ProjectView>4 <ProjectView>ProjectFiles</ProjectView> 5 5 </PropertyGroup> 6 6 </Project> -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Interpreter/Configuration.cs
r14328 r14392 4 4 namespace HeuristicLab.Algorithms.PushGP.Interpreter 5 5 { 6 public class Configuration : Generators.Configuration6 public class Configuration 7 7 { 8 8 public Configuration() … … 14 14 this.IsNameStackEnabled = true; 15 15 16 this.EvalPushLimit = uint.MaxValue;17 this.MaxPointsInProgram = uint.MaxValue;18 this.MaxPointsInRandomExpression = uint.MaxValue;16 this.EvalPushLimit = 1024; 17 this.MaxPointsInProgram = 4096; 18 this.MaxPointsInRandomExpression = 4096; 19 19 20 20 this.TopLevelPushCode = true; 21 this.TopLevelPopCode = true;21 this.TopLevelPopCode = false; 22 22 23 23 this.RandomSeedMax = 30081; 24 24 this.RandomSeedMin = 0; 25 25 this.RandomSeed = null; 26 27 this.MinRandomInteger = -128; 28 this.MaxRandomInteger = 128; 29 this.MinRandomFloat = -128D; 30 this.MaxRandomFloat = 128D; 31 this.NewErcNameProbability = 0.5; 26 32 } 27 33 … … 32 38 public bool IsNameStackEnabled { get; set; } 33 39 34 public IList< OpCode> AllowedInclassions { get; set; }40 public IList<string> AllowedInstructions { get; set; } 35 41 36 42 public IList<Expression> PredefinedExpressions { get; set; } … … 38 44 /// <summary> 39 45 /// This is the maximum allowed number of "executions" in a single top-level call to the interpreter. 40 /// The execution of a single Push in classion counts as one execution, as does the processing of a single literal,46 /// The execution of a single Push instruction counts as one execution, as does the processing of a single literal, 41 47 /// as does the descent into one layer of parentheses (that is, the processing of the "(" counts as one execution). 42 48 /// When this limit is exceeded the interpreter aborts immediately, leaving its stacks in the states they were in prior … … 48 54 /// <summary> 49 55 /// This is the maximum size of an item on the CODE stack, expressed as a number of points. 50 /// A point is an in classion, a literal, or a pair of parentheses. Any inclassion that would cause this limit to be exceeded51 /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the in classion.56 /// A point is an instruction, a literal, or a pair of parentheses. Any instruction that would cause this limit to be exceeded 57 /// should instead act as a NOOP, leaving all stacks in the states that they were in before the execution of the instruction. 52 58 /// </summary> 53 59 public uint MaxPointsInProgram { get; set; } 54 60 55 61 /// <summary> 56 /// The maximum number of points in an expression produced by the CODE.RAND in classion.62 /// The maximum number of points in an expression produced by the CODE.RAND instruction. 57 63 /// </summary> 58 64 public uint MaxPointsInRandomExpression { get; set; } … … 69 75 public bool TopLevelPopCode { get; set; } 70 76 77 /// <summary> 78 /// The minimum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. 79 /// </summary> 80 public int MinRandomInteger { get; set; } 81 82 /// <summary> 83 /// The maximum INTEGER that will be produced as an ephemeral random INTEGER constant or from a call to INTEGER.RAND. 84 /// </summary> 85 public int MaxRandomInteger { get; set; } 86 87 /// <summary> 88 /// The minimum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. 89 /// </summary> 90 public double MinRandomFloat { get; set; } 91 92 /// <summary> 93 /// The maximum FLOAT that will be produced as an ephemeral random FLOAT constant or from a call to FLOAT.RAND. 94 /// </summary> 95 public double MaxRandomFloat { get; set; } 96 97 /// <summary> 98 /// The probability that the selection of the ephemeral 99 /// random NAME constant for inclusion in randomly generated code will produce a new name 100 /// (rather than a name that was previously generated). 101 /// </summary> 102 public double NewErcNameProbability { get; set; } 103 71 104 public ushort RandomSeedMax { get; set; } 72 105 public ushort RandomSeedMin { get; set; } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Interpreter/IInterpreter.cs
r14328 r14392 3 3 using System.Threading.Tasks; 4 4 using HeuristicLab.Algorithms.PushGP.Expressions; 5 using HeuristicLab.Algorithms.PushGP.Generators; 5 6 using HeuristicLab.Algorithms.PushGP.Stack; 6 7 … … 15 16 IStack<long> IntegerStack { get; } 16 17 IStack<double> FloatStack { get; } 18 IDictionary<string, Expression> CustomExpressions { get; } 17 19 18 IDictionary<string, Expression> CustomExpressions { get; } 20 Configuration Configuration { get; } 21 22 CodeGenerator CodeGenerator { get; } 23 24 bool IsNameQuoteFlagSet { get; set; } 19 25 20 26 void Interpret(string code); … … 22 28 void Interpret(Expression program); 23 29 Task InterpretAsync(Expression program, bool paused = false, CancellationToken token = default(CancellationToken)); 24 Task AbortAndReset ();30 Task AbortAndResetAsync(); 25 31 Task AbortAsync(); 26 32 Task PauseAsync(); -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Parser/Parser.cs
r14328 r14392 2 2 using System.Globalization; 3 3 using HeuristicLab.Algorithms.PushGP.Expressions; 4 using HeuristicLab.Algorithms.PushGP.Expressions.Boolean;5 using HeuristicLab.Algorithms.PushGP.Expressions.Code;6 using HeuristicLab.Algorithms.PushGP.Expressions.Exec;7 using HeuristicLab.Algorithms.PushGP.Expressions.Float;8 using HeuristicLab.Algorithms.PushGP.Expressions.Integer;9 using HeuristicLab.Algorithms.PushGP.Expressions.Name;10 4 11 5 namespace HeuristicLab.Algorithms.PushGP … … 51 45 { 52 46 endIndex = i; 53 return expressions.Count != 0 54 ? new ExecExpandExpression(expressions.ToArray()) 55 : new CodeNoopExpression() as Expression; 47 return new ExecExpandExpression(expressions.ToArray()); 56 48 } 57 49 … … 65 57 66 58 // expression 67 OpCode opCode;68 if (SymbolTable.TryGetOpCode(symbol, out opCode))59 if (ExpressionTable.TryGetStatelessExpression(symbol, out expression) || 60 ExpressionTable.TryGetStatefullExpression(symbol, out expression)) 69 61 { 70 expression = ExpressionFactory.Create(opCode);71 62 expressions.Insert(0, expression); 72 63 continue; -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/IStack.cs
r14323 r14392 1 using System.Collections.Generic; 1 using System; 2 using System.Collections.Generic; 2 3 3 4 namespace HeuristicLab.Algorithms.PushGP.Stack … … 5 6 public interface IStack<T> : IEnumerable<T>, ICollection<T> 6 7 { 8 void Swap(int count); 9 void Yank(int index); 7 10 bool IsEmpty { get; } 8 11 void Push(T item); 9 10 12 void Push(params T[] items); 11 12 13 void Push(IEnumerable<T> items); 13 14 void PushResult(int count, Func<T[], T> templateFunc); 14 15 void Insert(int index, T item); 15 16 16 void Insert(int index, params T[] items); 17 18 17 void Insert(int index, IEnumerable<T> items); 19 18 T ReverseElementAt(int offset); 19 void SetTop(T value); 20 void RemoveTop(); 21 void Remove(int count); 22 void RemoveAt(int index); 23 void RemoveAt(int index, int count); 20 24 T Pop(); 21 22 25 T[] Pop(int count); 23 24 26 bool TryPop(out T item); 25 26 27 T ElementAt(int index); 27 28 28 T Top { get; } 29 T TopOrDefault { get; } 30 T Bottom { get; } 31 T BottomOrDefault { get; } 32 T this[int key] { get; set; } 29 33 } 30 34 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/PushGPStack.cs
r14328 r14392 2 2 using System.Collections; 3 3 using System.Collections.Generic; 4 using System.Text;5 4 6 5 namespace HeuristicLab.Algorithms.PushGP.Stack … … 17 16 { 18 17 private readonly List<T> data; 19 private const string delimiter = " ";18 private const string Delimiter = " "; 20 19 21 20 public PushGPStack(int capacity = 0) … … 25 24 26 25 public T Top { get { return this.data[Count - 1]; } } 26 public T TopOrDefault { get { return Count > 0 ? this.data[Count - 1] : default(T); } } 27 public T Bottom { get { return this.data[0]; } } 28 public T BottomOrDefault { get { return Count > 0 ? this.data[0] : default(T); } } 27 29 public int Count { get { return this.data.Count; } } 28 30 public int Capacity { get { return this.data.Capacity; } } 29 31 public bool IsEmpty { get { return this.Count == 0; } } 30 32 31 public bool IsReadOnly 32 { 33 get 34 { 35 throw new NotImplementedException(); 36 } 37 } 33 public bool IsReadOnly { get { return false; } } 38 34 39 35 public void Add(T item) … … 65 61 { 66 62 return this.data[index]; 63 } 64 65 66 public T ReverseElementAt(int offset) 67 { 68 return this.data[this.Count - 1 - offset]; 69 } 70 71 public void SetTop(T value) 72 { 73 this.data[Count - 1] = value; 74 } 75 76 public T this[int key] 77 { 78 get { return this.data[key]; } 79 set { this.data[key] = value; } 80 } 81 82 public void Swap(int count) 83 { 84 var top = this.Top; 85 var bottomIndex = this.Count - count; 86 87 for (var i = this.Count - 1; i > bottomIndex; i--) 88 { 89 this.data[i] = this.data[i - 1]; 90 } 91 92 this.data[bottomIndex] = top; 93 } 94 95 public void Yank(int index) 96 { 97 var item = this.ElementAt(index); 98 this.data.RemoveAt(index); 99 this.data.Add(item); 67 100 } 68 101 … … 78 111 { 79 112 var startIndex = Count - count; 80 var items = this.data.GetRange(startIndex, count); 81 82 this.data.RemoveRange(startIndex, count); 83 84 // is faster than remove range?? 85 for (var i = this.Count - 1; i > startIndex - 1; i--) 86 { 87 this.data.RemoveAt(i); 88 } 89 90 return items.ToArray(); 113 114 var items = new T[count]; 115 this.data.CopyTo(startIndex, items, 0, count); 116 this.Remove(count); 117 118 return items; 91 119 } 92 120 … … 96 124 } 97 125 126 public void Push(object[] items) 127 { 128 for (var i = 0; i < items.Length; i++) 129 { 130 this.data.Add((T)items[i]); 131 } 132 } 133 134 public void PushResult(int count, Func<T[], T> templateFunc) 135 { 136 var startIndex = Count - count; 137 var items = new T[count]; 138 139 this.data.CopyTo(startIndex, items, 0, count); 140 this.Remove(count - 1); 141 142 this.data[Count - 1] = templateFunc(items); 143 } 144 98 145 public void Push(params T[] items) 99 146 { 100 for each (var item in items)101 { 102 this.data.Add(item );147 for (var i = 0; i < items.Length; i++) 148 { 149 this.data.Add(items[i]); 103 150 } 104 151 } … … 138 185 } 139 186 187 public void RemoveTop() 188 { 189 this.data.RemoveAt(this.Count - 1); 190 } 191 192 public void Remove(int count) 193 { 194 for (var i = 0; i < count; i++) 195 { 196 this.data.RemoveAt(Count - 1); 197 } 198 } 199 200 public void RemoveAt(int index) 201 { 202 this.data.RemoveAt(index); 203 } 204 205 public void RemoveAt(int index, int count) 206 { 207 this.data.RemoveRange(index, count); 208 } 209 140 210 public bool TryPop(out T item) 141 211 { … … 159 229 public override string ToString() 160 230 { 161 if (this.Count == 0) 162 { 163 return string.Empty; 164 } 165 166 var sb = new StringBuilder(); 167 168 for (var i = this.Count - 1; i > 0; i--) 169 { 170 sb.Append(this.data[i] + delimiter); 171 } 172 173 sb.Append(this.data[0]); 174 175 return sb.ToString(); 231 return string.Join(Delimiter, this.data); 176 232 } 177 233 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r14328 r14392 8 8 <AppDesignerFolder>Properties</AppDesignerFolder> 9 9 <RootNamespace>HeuristicLab.Tests</RootNamespace> 10 <AssemblyName> HeuristicLab.Tests</AssemblyName>10 <AssemblyName>F</AssemblyName> 11 11 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> 12 12 <FileAlignment>512</FileAlignment> … … 38 38 </PropertyGroup> 39 39 <ItemGroup> 40 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 41 <SpecificVersion>False</SpecificVersion> 42 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath> 43 </Reference> 44 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 45 <SpecificVersion>False</SpecificVersion> 46 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath> 47 </Reference> 40 48 <Reference Include="System" /> 49 <Reference Include="System.IO.Compression" /> 41 50 </ItemGroup> 42 51 <Choose> … … 53 62 </Choose> 54 63 <ItemGroup> 55 <Compile Include="Expressions\ExampleTests.cs" /> 56 <Compile Include="Expressions\NameExpressionTests.cs" /> 57 <Compile Include="Expressions\FloatExpressionTests.cs" /> 58 <Compile Include="Expressions\BooleanExpressionTests.cs" /> 59 <Compile Include="Expressions\ExecExpressionTests.cs" /> 60 <Compile Include="Expressions\CodeExpressionTests.cs" /> 61 <Compile Include="Expressions\IntegerExpressionTests.cs" /> 62 <Compile Include="InterpreterTest.cs" /> 63 <Compile Include="Problems\Checksum.cs" /> 64 <Compile Include="Benchmark\Example.cs" /> 65 <Compile Include="Benchmark\ExampleConverter.cs" /> 66 <Compile Include="Benchmark\Problem\CountOdds.cs" /> 67 <Compile Include="Benchmark\Problem\Problem.cs" /> 68 <Compile Include="Interpreter\Expressions\CommonTests.cs" /> 69 <Compile Include="Interpreter\Expressions\ExampleTests.cs" /> 70 <Compile Include="Interpreter\Expressions\NameExpressionTests.cs" /> 71 <Compile Include="Interpreter\Expressions\FloatExpressionTests.cs" /> 72 <Compile Include="Interpreter\Expressions\BooleanExpressionTests.cs" /> 73 <Compile Include="Interpreter\Expressions\ExecExpressionTests.cs" /> 74 <Compile Include="Interpreter\Expressions\CodeExpressionTests.cs" /> 75 <Compile Include="Interpreter\Expressions\IntegerExpressionTests.cs" /> 76 <Compile Include="Interpreter\InterpreterTest.cs" /> 64 77 <Compile Include="Properties\AssemblyInfo.cs" /> 65 78 </ItemGroup> … … 71 84 </ItemGroup> 72 85 <ItemGroup> 73 < Folder Include="Problems\Data\" />86 <EmbeddedResource Include="Benchmark\Data\BenchmarkExamples.zip" /> 74 87 </ItemGroup> 88 <ItemGroup /> 75 89 <Choose> 76 90 <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
Note: See TracChangeset
for help on using the changeset viewer.