Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/05/16 13:27:41 (8 years ago)
Author:
pkimmesw
Message:

#2665 Added Unit Test Project, CodeGenerator and refactored project structure

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  
    22using System.Collections.Generic;
    33using HeuristicLab.Algorithms.PushGP.Expressions;
     4
     5using LinqExpression = System.Linq.Expressions.Expression;
    46
    57namespace HeuristicLab.Algorithms.PushGP
     
    7274        private static Func<Expression> GetExpressionCreator(Type type)
    7375        {
    74             return System.Linq.Expressions.Expression.Lambda<Func<Expression>>(
    75                        System.Linq.Expressions.Expression.New(type.GetConstructor(Type.EmptyTypes))
    76                      ).Compile();
     76            return LinqExpression.Lambda<Func<Expression>>(
     77                       LinqExpression.New(type.GetConstructor(Type.EmptyTypes))
     78                   ).Compile();
    7779        }
    7880
     
    8385            else throw new NotSupportedException("OpCode: " + opCode);
    8486        }
     87
     88        public static bool TryGetCreator(OpCode opCode, out Func<Expression> creator)
     89        {
     90            return symbolTable.TryGetValue(opCode, out creator);
     91        }
    8592    }
    8693}
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Boolean/BooleanPushExpression.cs

    r14320 r14323  
    1919        public override string ToString()
    2020        {
    21             return $"{base.ToString()}({this.Value})";
     21            return $"{this.Value.ToString().ToUpper()}";
    2222        }
    2323    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecExpandExpression.cs

    r14320 r14323  
    2323        public override string ToString()
    2424        {
    25             return $"({string.Join(", ", this.Expressions.Reverse())})";
     25            return $"( {string.Join(" ", this.Expressions.Reverse())} )";
    2626        }
    2727    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Exec/ExecYExpression.cs

    r14320 r14323  
    2020            });
    2121
    22             interpreterService.ExecStack.Insert(1, expandExpression);
     22            interpreterService.ExecStack.Insert(interpreterService.ExecStack.Count - 1, expandExpression);
    2323        }
    2424    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Expression.cs

    r14320 r14323  
    4444                return;
    4545
    46             var value = stack.ElementAt(0);
     46            var value = stack.Top;
    4747            stack.Push(value);
    4848        }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Float/FloatPushExpression.cs

    r14320 r14323  
    1919        public override string ToString()
    2020        {
    21             return $"{base.ToString()}({this.Value})";
     21            return $"{this.Value}";
    2222        }
    2323    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Integer/IntegerPushExpression.cs

    r14320 r14323  
    1919        public override string ToString()
    2020        {
    21             return $"{base.ToString()}({this.Value})";
     21            return $"{this.Value}";
    2222        }
    2323    }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.csproj

    r14320 r14323  
    4141  </ItemGroup>
    4242  <ItemGroup>
    43     <Compile Include="Data\Configuration.cs" />
     43    <Compile Include="Interpreter\Configuration.cs" />
    4444    <Compile Include="Data\Expression.cs" />
    4545    <Compile Include="Expressions\Boolean\BooleanAndExpression.cs" />
     
    9696    <Compile Include="Expressions\Name\NameDuplicateExpression.cs" />
    9797    <Compile Include="Expressions\Name\NameDefineXExecExpression.cs" />
     98    <Compile Include="Generators\CodeGenerator.cs" />
     99    <Compile Include="Generators\Configuration.cs" />
    98100    <Compile Include="InstructionSets\ExecInstructionSet.cs" />
    99101    <Compile Include="InstructionSets\CodeInstructionSet.cs" />
     
    106108    <Compile Include="OpCodeExtensions.cs" />
    107109    <Compile Include="OperationTable.cs" />
    108     <Compile Include="Parser.cs" />
     110    <Compile Include="Parser\Parser.cs" />
     111    <Compile Include="StaticRandom.cs" />
    109112    <Compile Include="Stack\IStack.cs" />
    110     <Compile Include="Interpreter.cs" />
     113    <Compile Include="Interpreter\Interpreter.cs" />
    111114    <Compile Include="Properties\AssemblyInfo.cs" />
    112115    <Compile Include="Stack\IInterpreterService.cs" />
    113116    <Compile Include="Stack\PushGPStack.cs" />
    114     <Compile Include="SymbolTable.cs" />
    115   </ItemGroup>
    116   <ItemGroup>
    117     <Folder Include="Generator\" />
     117    <Compile Include="Parser\SymbolTable.cs" />
    118118  </ItemGroup>
    119119  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/InstructionSets/CommonInstructionSet.cs

    r14320 r14323  
    4545//                return;
    4646
    47 //            var value = stack.ElementAt(0);
     47//            var value = stack.Top;
    4848//            stack.Push(value);
    4949//        }
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/OpCodeExtensions.cs

    r14320 r14323  
    1 namespace HeuristicLab.Algorithms.PushGP
     1using System;
     2using System.Linq;
     3
     4namespace HeuristicLab.Algorithms.PushGP
    25{
    36    public static class OpCodeExtensions
    47    {
     8        public readonly static byte Min = 0;
     9        public readonly static byte Max = Enum.GetValues(typeof(OpCode)).Cast<byte>().Last();
     10
    511        public static bool IsCodeOp(this OpCode opCode)
    612        {
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/IStack.cs

    r14320 r14323  
    55    public interface IStack<T> : IEnumerable<T>, ICollection<T>
    66    {
     7        bool IsEmpty { get; }
    78        void Push(T item);
    89
  • branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Stack/PushGPStack.cs

    r14320 r14323  
    22using System.Collections;
    33using System.Collections.Generic;
    4 using System.Linq;
    54
    65namespace HeuristicLab.Algorithms.PushGP.Stack
     
    1817        private List<T> data = new List<T>();
    1918
    20         public T Top => this.ElementAt(0);
    21 
     19        public T Top => this.data[Count - 1];
    2220        public int Count => data.Count;
     21        public bool IsEmpty => this.Count == 0;
    2322
    2423        public bool IsReadOnly
     
    6261        public T Pop()
    6362        {
    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);
    6666
    6767            return value;
     
    7070        public T[] Pop(int count)
    7171        {
    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);
    7474
    75             return items;
     75            this.data.RemoveRange(startIndex, count);
     76
     77            items.Reverse();
     78            return items.ToArray();
    7679        }
    7780
    7881        public void Push(T item)
    7982        {
    80             this.data.Insert(0, item);
     83            this.data.Add(item);
    8184        }
    8285
    8386        public void Push(params T[] items)
    8487        {
    85             this.data.InsertRange(0, items.Reverse());
     88            this.data.AddRange(items);
    8689        }
    8790
    8891        public void Push(IEnumerable<T> items)
    8992        {
    90             this.data.InsertRange(0, items);
     93            this.data.AddRange(items);
    9194        }
    9295
     
    98101        public void Insert(int index, params T[] items)
    99102        {
    100             this.data.InsertRange(index, items.Reverse());
     103            this.data.InsertRange(index, items);
    101104        }
    102105
    103106        public void Insert(int index, IEnumerable<T> items)
    104107        {
    105             this.data.InsertRange(index, items.Reverse());
     108            this.data.InsertRange(index, items);
    106109        }
    107110
    108111        public bool Remove(T item)
    109112        {
    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))
    111115            {
    112                 this.data.RemoveAt(0);
     116                this.data.RemoveAt(index);
    113117                return true;
    114118            }
     
    123127            if (this.data.Count > 0)
    124128            {
    125                 item = this.data[0];
     129                item = this.Pop();
    126130                return true;
    127131            }
Note: See TracChangeset for help on using the changeset viewer.