Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/09 19:41:58 (15 years ago)
Author:
gkronber
Message:

GP Refactoring #713

  • cleaned code
  • reintegrated GP.Boolean and GP.SantaFe
  • worked on serialization of function trees
Location:
branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3
Files:
1 added
5 edited
7 moved

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/AntInterpreter.cs

    r1529 r2216  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using HeuristicLab.DataAnalysis;
    27 using HeuristicLab.Core;
    28 using System.Xml;
    29 using System.Diagnostics;
     23using HeuristicLab.GP.Interfaces;
    3024
    3125namespace HeuristicLab.GP.SantaFe {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Evaluator.cs

    r1529 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2622using HeuristicLab.Core;
    2723using HeuristicLab.Data;
    28 using HeuristicLab.DataAnalysis;
     24using HeuristicLab.GP.Interfaces;
    2925
    3026namespace HeuristicLab.GP.SantaFe {
     
    3228    public Evaluator()
    3329      : base() {
    34       AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the ant", typeof(IFunctionTree), VariableKind.In));
     30      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the ant", typeof(IGeneticProgrammingModel), VariableKind.In));
    3531      AddVariableInfo(new VariableInfo("FoodEaten", "Number of food items that the ant found", typeof(DoubleData), VariableKind.New | VariableKind.Out));
    3632    }
    3733
    3834    public override IOperation Apply(IScope scope) {
    39       IFunctionTree tree = GetVariableValue<IFunctionTree>("FunctionTree", scope, false);
     35      IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>("FunctionTree", scope, false);
    4036      AntInterpreter interpreter = new AntInterpreter();
    4137      interpreter.MaxTimeSteps = 600;
    42       interpreter.Run(tree);
     38      interpreter.Run(gpModel.FunctionTree);
    4339
    4440      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FoodEaten"), new DoubleData(interpreter.FoodEaten)));
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/FunctionLibraryInjector.cs

    r2202 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
    26 using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    28 using HeuristicLab.DataAnalysis;
    29 using HeuristicLab.Constraints;
     22using HeuristicLab.GP.Interfaces;
    3023
    3124namespace HeuristicLab.GP.SantaFe {
    32   public class FunctionLibraryInjector : OperatorBase {
    33     private const string OPERATORLIBRARY = "FunctionLibrary";
    34 
    35     private FunctionLibrary operatorLibrary;
     25  public class FunctionLibraryInjector : FunctionLibraryInjectorBase {
    3626
    3727    public override string Description {
     
    4131    public FunctionLibraryInjector()
    4232      : base() {
    43       AddVariableInfo(new VariableInfo(OPERATORLIBRARY, "Preconfigured default operator library", typeof(FunctionLibrary), VariableKind.New));
    4433    }
    4534
    46     public override IOperation Apply(IScope scope) {
    47       InitDefaultOperatorLibrary();
    48       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OPERATORLIBRARY), operatorLibrary));
    49       return null;
    50     }
    51 
    52     private void InitDefaultOperatorLibrary() {
     35    protected override FunctionLibrary CreateFunctionLibrary() {
     36      FunctionLibrary funLib = new FunctionLibrary();
    5337      IfFoodAhead ifFoodAhead = new IfFoodAhead();
    5438      Prog2 prog2 = new Prog2();
     
    7155      SetAllowedSubOperators(prog3, allFunctions);
    7256
    73       operatorLibrary = new FunctionLibrary();
    74       operatorLibrary.FunctionGroup.AddFunction(ifFoodAhead);
    75       operatorLibrary.FunctionGroup.AddFunction(prog2);
    76       operatorLibrary.FunctionGroup.AddFunction(prog3);
    77       operatorLibrary.FunctionGroup.AddFunction(move);
    78       operatorLibrary.FunctionGroup.AddFunction(left);
    79       operatorLibrary.FunctionGroup.AddFunction(right);
    80     }
    81 
    82     private void SetAllowedSubOperators(IFunction f, IFunction[] gs) {
    83       foreach(IConstraint c in f.Constraints) {
    84         if(c is SubOperatorTypeConstraint) {
    85           SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    86           typeConstraint.Clear();
    87           foreach(IFunction g in gs) {
    88             typeConstraint.AddOperator(g);
    89           }
    90         } else if(c is AllSubOperatorsTypeConstraint) {
    91           AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    92           typeConstraint.Clear();
    93           foreach(IFunction g in gs) {
    94             typeConstraint.AddOperator(g);
    95           }
    96         }
    97       }
     57      funLib.AddFunction(ifFoodAhead);
     58      funLib.AddFunction(prog2);
     59      funLib.AddFunction(prog3);
     60      funLib.AddFunction(move);
     61      funLib.AddFunction(left);
     62      funLib.AddFunction(right);
     63      return funLib;
    9864    }
    9965  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/HeuristicLab.GP.SantaFe-3.3.csproj

    r1534 r2216  
    8383    <Compile Include="AntInterpreter.cs" />
    8484    <Compile Include="FunctionLibraryInjector.cs" />
    85     <Compile Include="Prog3.cs" />
    86     <Compile Include="Prog2.cs" />
    87     <Compile Include="IfFoodAhead.cs" />
    88     <Compile Include="Right.cs" />
    89     <Compile Include="Left.cs" />
    90     <Compile Include="Move.cs" />
    9185    <Compile Include="HeuristicLabGPSantaFePlugin.cs" />
    9286    <Compile Include="Properties\AssemblyInfo.cs" />
    9387    <Compile Include="Evaluator.cs" />
    94     <Compile Include="SymbolTable.cs" />
     88    <Compile Include="Symbols\IfFoodAhead.cs" />
     89    <Compile Include="Symbols\Left.cs" />
     90    <Compile Include="Symbols\Move.cs" />
     91    <Compile Include="Symbols\Prog2.cs" />
     92    <Compile Include="Symbols\Prog3.cs" />
     93    <Compile Include="Symbols\Right.cs" />
     94    <Compile Include="Symbols\SymbolTable.cs" />
    9595  </ItemGroup>
    9696  <ItemGroup>
    97     <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">
    98       <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>
    99       <Name>HeuristicLab.Constraints-3.2</Name>
    100     </ProjectReference>
    10197    <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj">
    10298      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    10399      <Name>HeuristicLab.Core-3.2</Name>
    104100    </ProjectReference>
    105     <ProjectReference Include="..\..\HeuristicLab.DataAnalysis\3.2\HeuristicLab.DataAnalysis-3.2.csproj">
    106       <Project>{7DD3A97A-56E9-462F-90E2-A351FE7AF5C2}</Project>
    107       <Name>HeuristicLab.DataAnalysis-3.2</Name>
    108     </ProjectReference>
    109101    <ProjectReference Include="..\..\HeuristicLab.Data\3.2\HeuristicLab.Data-3.2.csproj">
    110102      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
    111103      <Name>HeuristicLab.Data-3.2</Name>
     104    </ProjectReference>
     105    <ProjectReference Include="..\..\HeuristicLab.GP.Interfaces\3.3\HeuristicLab.GP.Interfaces-3.3.csproj">
     106      <Project>{924B6BEA-9A99-40FE-9334-5C01E8D540EC}</Project>
     107      <Name>HeuristicLab.GP.Interfaces-3.3</Name>
    112108    </ProjectReference>
    113109    <ProjectReference Include="..\..\HeuristicLab.GP\3.3\HeuristicLab.GP-3.3.csproj">
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/HeuristicLabGPSantaFePlugin.cs

    r1529 r2216  
    2828  [ClassInfo(Name = "HeuristicLab.GP.SantaFe-3.3")]
    2929  [PluginFile(Filename = "HeuristicLab.GP.SantaFe-3.3.dll", Filetype = PluginFileType.Assembly)]
    30   [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]
    31   [Dependency(Dependency = "HeuristicLab.GP-3.3")]
    3230  [Dependency(Dependency = "HeuristicLab.Core-3.2")]
    3331  [Dependency(Dependency = "HeuristicLab.Data-3.2")]
     32  [Dependency(Dependency = "HeuristicLab.GP-3.3")]
     33  [Dependency(Dependency = "HeuristicLab.GP.Interfaces-3.3")]
    3434  [Dependency(Dependency = "HeuristicLab.DataAnalysis-3.2")]
    3535  [Dependency(Dependency = "HeuristicLab.Random-3.2")]
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/IfFoodAhead.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class IfFoodAhead : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public IfFoodAhead()
    40       : base() {
    41       MinArity = 2; MaxArity = 2;
    42     }
     23  public sealed class IfFoodAhead : BinaryFunction {
    4324  }
    4425}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Left.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Left : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public Left()
    40       : base() {
    41       MinArity = 0; MaxArity = 0;
    42     }
     23  public sealed class Left : Terminal {
    4324  }
    4425}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Move.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Move : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public Move()
    40       : base() {
    41       MinArity = 0; MaxArity = 0;
    42     }
     23  public sealed class Move : Terminal {
    4324  }
    4425}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Prog2.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    3122
    3223namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Prog2 : FunctionBase {
    34 
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    39     public Prog2()
    40       : base() {
    41       MinArity = 2; MaxArity = 2;
    42     }
     24  public sealed class Prog2 : BinaryFunction {
    4325  }
    4426}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Prog3.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    3323  public sealed class Prog3 : FunctionBase {
    3424
    35     public override string Description {
    36       get { return ""; }
    37     }
    38 
    3925    public Prog3()
    4026      : base() {
    41       MinArity = 3; MaxArity = 3;
     27      MinSubTrees = 3; MaxSubTrees = 3;
    4228    }
    4329  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Right.cs

    r2211 r2216  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using HeuristicLab.Data;
    26 using HeuristicLab.Core;
    27 using System.Xml;
    28 using HeuristicLab.Constraints;
    29 using HeuristicLab.DataAnalysis;
    30 using HeuristicLab.Random;
    31 
    3222namespace HeuristicLab.GP.SantaFe {
    33   public sealed class Right : FunctionBase {
    34     public override string Description {
    35       get { return ""; }
    36     }
    37 
    38     public Right()
    39       : base() {
    40       MinArity = 0; MaxArity = 0;
    41     }
     23  public sealed class Right : Terminal {
    4224  }
    4325}
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/SymbolTable.cs

    r2211 r2216  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2624using HeuristicLab.Core;
    27 using System.Xml;
     25using HeuristicLab.GP.Interfaces;
    2826
    2927namespace HeuristicLab.GP.SantaFe {
Note: See TracChangeset for help on using the changeset viewer.