- Timestamp:
- 10/05/16 13:27:41 (8 years ago)
- Location:
- branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP
- Files:
-
- 10 added
- 5 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/ExpressionCreatorTable.cs
r14320 r14323 2 2 using System.Collections.Generic; 3 3 using HeuristicLab.Algorithms.PushGP.Expressions; 4 5 using LinqExpression = System.Linq.Expressions.Expression; 4 6 5 7 namespace HeuristicLab.Algorithms.PushGP … … 72 74 private static Func<Expression> GetExpressionCreator(Type type) 73 75 { 74 return System.Linq.Expressions.Expression.Lambda<Func<Expression>>(75 System.Linq.Expressions.Expression.New(type.GetConstructor(Type.EmptyTypes))76 76 return LinqExpression.Lambda<Func<Expression>>( 77 LinqExpression.New(type.GetConstructor(Type.EmptyTypes)) 78 ).Compile(); 77 79 } 78 80 … … 83 85 else throw new NotSupportedException("OpCode: " + opCode); 84 86 } 87 88 public static bool TryGetCreator(OpCode opCode, out Func<Expression> creator) 89 { 90 return symbolTable.TryGetValue(opCode, out creator); 91 } 85 92 } 86 93 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Boolean/BooleanPushExpression.cs
r14320 r14323 19 19 public override string ToString() 20 20 { 21 return $"{ base.ToString()}({this.Value})";21 return $"{this.Value.ToString().ToUpper()}"; 22 22 } 23 23 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecExpandExpression.cs
r14320 r14323 23 23 public override string ToString() 24 24 { 25 return $"( {string.Join(", ", this.Expressions.Reverse())})";25 return $"( {string.Join(" ", this.Expressions.Reverse())} )"; 26 26 } 27 27 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecYExpression.cs
r14320 r14323 20 20 }); 21 21 22 interpreterService.ExecStack.Insert( 1, expandExpression);22 interpreterService.ExecStack.Insert(interpreterService.ExecStack.Count - 1, expandExpression); 23 23 } 24 24 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Expression.cs
r14320 r14323 44 44 return; 45 45 46 var value = stack. ElementAt(0);46 var value = stack.Top; 47 47 stack.Push(value); 48 48 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Float/FloatPushExpression.cs
r14320 r14323 19 19 public override string ToString() 20 20 { 21 return $"{ base.ToString()}({this.Value})";21 return $"{this.Value}"; 22 22 } 23 23 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Integer/IntegerPushExpression.cs
r14320 r14323 19 19 public override string ToString() 20 20 { 21 return $"{ base.ToString()}({this.Value})";21 return $"{this.Value}"; 22 22 } 23 23 } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.csproj
r14320 r14323 41 41 </ItemGroup> 42 42 <ItemGroup> 43 <Compile Include=" Data\Configuration.cs" />43 <Compile Include="Interpreter\Configuration.cs" /> 44 44 <Compile Include="Data\Expression.cs" /> 45 45 <Compile Include="Expressions\Boolean\BooleanAndExpression.cs" /> … … 96 96 <Compile Include="Expressions\Name\NameDuplicateExpression.cs" /> 97 97 <Compile Include="Expressions\Name\NameDefineXExecExpression.cs" /> 98 <Compile Include="Generators\CodeGenerator.cs" /> 99 <Compile Include="Generators\Configuration.cs" /> 98 100 <Compile Include="InstructionSets\ExecInstructionSet.cs" /> 99 101 <Compile Include="InstructionSets\CodeInstructionSet.cs" /> … … 106 108 <Compile Include="OpCodeExtensions.cs" /> 107 109 <Compile Include="OperationTable.cs" /> 108 <Compile Include="Parser.cs" /> 110 <Compile Include="Parser\Parser.cs" /> 111 <Compile Include="StaticRandom.cs" /> 109 112 <Compile Include="Stack\IStack.cs" /> 110 <Compile Include="Interpreter .cs" />113 <Compile Include="Interpreter\Interpreter.cs" /> 111 114 <Compile Include="Properties\AssemblyInfo.cs" /> 112 115 <Compile Include="Stack\IInterpreterService.cs" /> 113 116 <Compile Include="Stack\PushGPStack.cs" /> 114 <Compile Include="SymbolTable.cs" /> 115 </ItemGroup> 116 <ItemGroup> 117 <Folder Include="Generator\" /> 117 <Compile Include="Parser\SymbolTable.cs" /> 118 118 </ItemGroup> 119 119 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/InstructionSets/CommonInstructionSet.cs
r14320 r14323 45 45 // return; 46 46 47 // var value = stack. ElementAt(0);47 // var value = stack.Top; 48 48 // stack.Push(value); 49 49 // } -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/OpCodeExtensions.cs
r14320 r14323 1 namespace HeuristicLab.Algorithms.PushGP 1 using System; 2 using System.Linq; 3 4 namespace HeuristicLab.Algorithms.PushGP 2 5 { 3 6 public static class OpCodeExtensions 4 7 { 8 public readonly static byte Min = 0; 9 public readonly static byte Max = Enum.GetValues(typeof(OpCode)).Cast<byte>().Last(); 10 5 11 public static bool IsCodeOp(this OpCode opCode) 6 12 { -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/IStack.cs
r14320 r14323 5 5 public interface IStack<T> : IEnumerable<T>, ICollection<T> 6 6 { 7 bool IsEmpty { get; } 7 8 void Push(T item); 8 9 -
branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/PushGPStack.cs
r14320 r14323 2 2 using System.Collections; 3 3 using System.Collections.Generic; 4 using System.Linq;5 4 6 5 namespace HeuristicLab.Algorithms.PushGP.Stack … … 18 17 private List<T> data = new List<T>(); 19 18 20 public T Top => this.ElementAt(0); 21 19 public T Top => this.data[Count - 1]; 22 20 public int Count => data.Count; 21 public bool IsEmpty => this.Count == 0; 23 22 24 23 public bool IsReadOnly … … 62 61 public T Pop() 63 62 { 64 var value = this.data[0]; 65 this.data.RemoveAt(0); 63 var index = Count - 1; 64 var value = this.data[index]; 65 this.data.RemoveAt(index); 66 66 67 67 return value; … … 70 70 public T[] Pop(int count) 71 71 { 72 var items = this.data.GetRange(0, count).ToArray();73 this.data.RemoveRange(0, count);72 var startIndex = Count - count; 73 var items = this.data.GetRange(startIndex, count); 74 74 75 return items; 75 this.data.RemoveRange(startIndex, count); 76 77 items.Reverse(); 78 return items.ToArray(); 76 79 } 77 80 78 81 public void Push(T item) 79 82 { 80 this.data. Insert(0,item);83 this.data.Add(item); 81 84 } 82 85 83 86 public void Push(params T[] items) 84 87 { 85 this.data. InsertRange(0, items.Reverse());88 this.data.AddRange(items); 86 89 } 87 90 88 91 public void Push(IEnumerable<T> items) 89 92 { 90 this.data. InsertRange(0,items);93 this.data.AddRange(items); 91 94 } 92 95 … … 98 101 public void Insert(int index, params T[] items) 99 102 { 100 this.data.InsertRange(index, items .Reverse());103 this.data.InsertRange(index, items); 101 104 } 102 105 103 106 public void Insert(int index, IEnumerable<T> items) 104 107 { 105 this.data.InsertRange(index, items .Reverse());108 this.data.InsertRange(index, items); 106 109 } 107 110 108 111 public bool Remove(T item) 109 112 { 110 if (this.data.Count > 0 && this.data[0].Equals(item)) 113 var index = Count - 1; 114 if (this.data.Count > 0 && this.data[index].Equals(item)) 111 115 { 112 this.data.RemoveAt( 0);116 this.data.RemoveAt(index); 113 117 return true; 114 118 } … … 123 127 if (this.data.Count > 0) 124 128 { 125 item = this. data[0];129 item = this.Pop(); 126 130 return true; 127 131 }
Note: See TracChangeset
for help on using the changeset viewer.