Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/15 11:42:02 (9 years ago)
Author:
gkronber
Message:

#2472: merged r12921,r12936:12938,r12940,r12947,r13055:13058,r13163,r13267,r13269 from trunk to stable

Location:
stable
Files:
12 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Interpreter.cs

    r12911 r13280  
    3232    public int FoodEaten { get; private set; }
    3333    public BoolMatrix World { get; private set; }
    34 
    3534    public ISymbolicExpressionTree Expression { get; private set; }
    3635
     36    public int ElapsedTime { get; set; }
    3737
    38     public int ElapsedTime { get; set; }
    3938    private int currentDirection;
    4039    private int currentAntLocationRow;
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r12911 r13280  
    2222using System;
    2323using System.Diagnostics.Contracts;
    24 using System.Drawing.Text;
    2524using System.Linq;
    2625using HeuristicLab.Common;
     
    3837  [StorableClass]
    3938  public sealed class Problem : SymbolicExpressionTreeProblem, IStorableContent {
    40     public string Filename { get; set; }
    4139
    4240    #region constant for default world (Santa Fe)
     
    104102    }
    105103
     104    #region item cloning and persistence
     105    // persistence
     106    [StorableConstructor]
     107    private Problem(bool deserializing) : base(deserializing) { }
     108    [StorableHook(HookType.AfterDeserialization)]
     109    private void AfterDeserialization() { }
     110
     111    // cloning
     112    private Problem(Problem original, Cloner cloner) : base(original, cloner) { }
     113    public override IDeepCloneable Clone(Cloner cloner) {
     114      return new Problem(this, cloner);
     115    }
     116    #endregion
     117
    106118    public Problem()
    107119      : base() {
     
    114126      g.AddSymbols(new string[] { "IfFoodAhead", "Prog2" }, 2, 2);
    115127      g.AddSymbols(new string[] { "Prog3" }, 3, 3);
    116       g.AddTerminalSymbols(new string[] { "Left", "Right", "Move" });
     128      g.AddTerminalSymbols(new string[] { "Move", "Left", "Right" });
    117129      base.Encoding = new SymbolicExpressionTreeEncoding(g, 20, 10);
    118130    }
     
    137149    }
    138150
    139     // persistence
    140     [StorableConstructor]
    141     private Problem(bool deserializing) : base(deserializing) { }
    142     [StorableHook(HookType.AfterDeserialization)]
    143     private void AfterDeserialization() {
    144     }
    145 
    146     // cloning
    147     private Problem(Problem original, Cloner cloner)
    148       : base(original, cloner) {
    149     }
    150     public override IDeepCloneable Clone(Cloner cloner) {
    151       return new Problem(this, cloner);
    152     }
    153 
    154151    #region helpers
    155152    private bool[,] ToBoolMatrix(char[][] ch) {
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Trail.cs

    r12911 r13280  
    2020#endregion
    2121
    22 using System;
    2322using System.Drawing;
    2423using HeuristicLab.Common;
     
    5453    }
    5554
     55    #region item cloning and persistence
    5656    [StorableConstructor]
    5757    private Solution(bool deserializing) : base(deserializing) { }
     
    7070      return new Solution(this, cloner);
    7171    }
     72    #endregion
    7273  }
    7374}
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r12937 r13280  
    3939
    4040    #region parameter names
    41 
    4241    private const string ProblemDataParameterName = "ProblemData";
    43 
    4442    #endregion
    45 
    46     public event EventHandler ProblemDataChanged;
    4743
    4844    #region Parameter Properties
     
    5248      get { return (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
    5349    }
    54 
    5550    #endregion
    5651
    5752    #region Properties
    58 
    5953    public IRegressionProblemData ProblemData {
    6054      get { return ProblemDataParameter.Value; }
     
    6256    }
    6357    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData { get { return ProblemData; } }
     58    #endregion
    6459
    65 
    66     #endregion
     60    public event EventHandler ProblemDataChanged;
    6761
    6862    public override bool Maximization {
    6963      get { return true; }
    7064    }
     65
     66    #region item cloning and persistence
     67    // persistence
     68    [StorableConstructor]
     69    private Problem(bool deserializing) : base(deserializing) { }
     70    [StorableHook(HookType.AfterDeserialization)]
     71    private void AfterDeserialization() {
     72      RegisterEventHandlers();
     73    }
     74
     75    // cloning
     76    private Problem(Problem original, Cloner cloner)
     77      : base(original, cloner) {
     78      RegisterEventHandlers();
     79    }
     80    public override IDeepCloneable Clone(Cloner cloner) { return new Problem(this, cloner); }
     81    #endregion
    7182
    7283    public Problem()
     
    103114    }
    104115
    105 
    106116    private IEnumerable<double> InterpretRec(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) {
    107       var eval = CreateEvalClosure(dataset, rows);
     117      Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<double, double, double>, IEnumerable<double>> binaryEval =
     118        (left, right, f) => InterpretRec(left, dataset, rows).Zip(InterpretRec(right, dataset, rows), f);
    108119
    109120      switch (node.Symbol.Name) {
    110         case "+": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x + y);
    111         case "*": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x * y);
    112         case "-": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x - y);
    113         case "%": return eval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => y.IsAlmost(0.0) ? 0.0 : x / y); // protected division
     121        case "+": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x + y);
     122        case "*": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x * y);
     123        case "-": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x - y);
     124        case "%": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => y.IsAlmost(0.0) ? 0.0 : x / y); // protected division
    114125        default: {
    115126            double erc;
     
    124135    }
    125136
    126     private Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<double, double, double>, IEnumerable<double>> CreateEvalClosure(IDataset dataset, IEnumerable<int> rows) {
    127       // capture dataset and rows in scope
    128       return (a, b, f) => {
    129         var leftResult = InterpretRec(a, dataset, rows);
    130         var rightResult = InterpretRec(b, dataset, rows);
    131         return leftResult.Zip(rightResult, f);
    132       };
    133     }
    134 
    135     #region item cloning and persistence
    136     // persistence
    137     [StorableConstructor]
    138     private Problem(bool deserializing) : base(deserializing) { }
    139 
    140     [StorableHook(HookType.AfterDeserialization)]
    141     private void AfterDeserialization() {
    142       RegisterEventHandlers();
    143     }
    144 
    145     // cloning
    146     private Problem(Problem original, Cloner cloner)
    147       : base(original, cloner) {
    148       RegisterEventHandlers();
    149     }
    150     public override IDeepCloneable Clone(Cloner cloner) {
    151       return new Problem(this, cloner);
    152     }
    153     #endregion
    154137
    155138    #region events
    156 
    157139    private void RegisterEventHandlers() {
    158140      ProblemDataParameter.ValueChanged += new EventHandler(ProblemDataParameter_ValueChanged);
     
    197179      Encoding.Grammar = g;
    198180    }
    199 
    200181    #endregion
    201182
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r12938 r13280  
    3838
    3939    #region parameter names
    40 
    4140    private const string NumberOfBitsParameterName = "NumberOfBits";
    42 
    4341    #endregion
    4442
     
    4745      get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; }
    4846    }
    49 
    5047    #endregion
    5148
    5249    #region Properties
    53 
    5450    public int NumberOfBits {
    5551      get { return NumberOfBitsParameter.Value.Value; }
    5652      set { NumberOfBitsParameter.Value.Value = value; }
    5753    }
    58 
    59 
    6054    #endregion
    6155
     
    6357      get { return true; }
    6458    }
     59
     60    #region item cloning and persistence
     61    // persistence
     62    [StorableConstructor]
     63    private EvenParityProblem(bool deserializing) : base(deserializing) { }
     64    [StorableHook(HookType.AfterDeserialization)]
     65    private void AfterDeserialization() {
     66      RegisterEventHandlers();
     67    }
     68
     69    // cloning
     70    private EvenParityProblem(EvenParityProblem original, Cloner cloner)
     71      : base(original, cloner) {
     72      RegisterEventHandlers();
     73    }
     74    public override IDeepCloneable Clone(Cloner cloner) {
     75      return new EvenParityProblem(this, cloner);
     76    }
     77    #endregion
    6578
    6679    public EvenParityProblem()
     
    8497
    8598      Encoding.Grammar = g;
     99
     100      BestKnownQuality = Math.Pow(2, NumberOfBits); // this is a benchmark problem (the best achievable quality is known for a given number of bits)
    86101    }
    87102
     
    108123    }
    109124
    110 
    111125    private static IEnumerable<bool> InterpretRec(ISymbolicExpressionTreeNode node, IEnumerable<int> bs) {
    112       Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> eval2 =
     126      Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> binaryEval =
    113127        (left, right, f) => InterpretRec(left, bs).Zip(InterpretRec(right, bs), f);
    114128
    115129      switch (node.Symbol.Name) {
    116         case "AND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
    117         case "OR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
    118         case "NAND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y));
    119         case "NOR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));
     130        case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
     131        case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
     132        case "NAND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y));
     133        case "NOR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));
    120134        default: {
    121135            byte bitPos;
     
    131145    }
    132146
    133     #region item cloning and persistence
    134     // persistence
    135     [StorableConstructor]
    136     private EvenParityProblem(bool deserializing) : base(deserializing) { }
    137 
    138     [StorableHook(HookType.AfterDeserialization)]
    139     private void AfterDeserialization() {
    140       RegisterEventHandlers();
    141     }
    142 
    143     // cloning
    144     private EvenParityProblem(EvenParityProblem original, Cloner cloner)
    145       : base(original, cloner) {
    146       RegisterEventHandlers();
    147     }
    148     public override IDeepCloneable Clone(Cloner cloner) {
    149       return new EvenParityProblem(this, cloner);
    150     }
    151     #endregion
    152 
    153147    #region events
    154 
    155148    private void RegisterEventHandlers() {
    156149      NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar();
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r12938 r13280  
    4040
    4141    #region parameter names
    42 
    4342    private const string NumberOfBitsParameterName = "NumberOfBits";
    44 
    4543    #endregion
    4644
    4745    #region Parameter Properties
    48 
    4946    public IFixedValueParameter<IntValue> NumberOfBitsParameter {
    5047      get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; }
    5148    }
    52 
    5349    #endregion
    5450
    5551    #region Properties
    56 
    5752    public int NumberOfBits {
    5853      get { return NumberOfBitsParameter.Value.Value; }
    5954      set { NumberOfBitsParameter.Value.Value = value; }
    6055    }
    61 
    62 
    6356    #endregion
    6457
     
    6659      get { return true; }
    6760    }
     61
     62    #region item cloning and persistence
     63    // persistence
     64    [StorableConstructor]
     65    private MultiplexerProblem(bool deserializing) : base(deserializing) { }
     66    [StorableHook(HookType.AfterDeserialization)]
     67    private void AfterDeserialization() {
     68      RegisterEventHandlers();
     69    }
     70
     71    // cloning
     72    private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
     73      : base(original, cloner) {
     74      RegisterEventHandlers();
     75    }
     76    public override IDeepCloneable Clone(Cloner cloner) {
     77      return new MultiplexerProblem(this, cloner);
     78    }
     79    #endregion
     80
    6881
    6982    public MultiplexerProblem()
     
    98111
    99112      Encoding.Grammar = g;
     113
     114      BestKnownQuality = Math.Pow(2, NumberOfBits); // this is a benchmark problem (the best achievable quality is known for a given number of bits)
    100115    }
    101116
     
    103118    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
    104119      if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero.");
    105       if (NumberOfBits > 40) throw new NotSupportedException("Mupltiplexer does not support problems with number of bits > 37.");
     120      if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37.");
    106121      var bs = Enumerable.Range(0, (int)Math.Pow(2, NumberOfBits));
    107122      var addrBits = (int)Math.Log(NumberOfBits, 2); // largest power of two that fits into the number of bits
     
    132147
    133148    private static IEnumerable<bool> InterpretRec(ISymbolicExpressionTreeNode node, IEnumerable<int> bs, byte addrBits) {
    134       Func<ISymbolicExpressionTreeNode, Func<bool, bool>, IEnumerable<bool>> eval1 =
     149      Func<ISymbolicExpressionTreeNode, Func<bool, bool>, IEnumerable<bool>> unaryEval =
    135150        (child, f) => InterpretRec(child, bs, addrBits).Select(f);
    136       Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> eval2 =
     151      Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> binaryEval =
    137152        (left, right, f) => InterpretRec(left, bs, addrBits).Zip(InterpretRec(right, bs, addrBits), f);
    138153
    139154      switch (node.Symbol.Name) {
    140         case "AND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
    141         case "OR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
    142         case "NOT": return eval1(node.GetSubtree(0), (x) => !x);
     155        case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
     156        case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
     157        case "NOT": return unaryEval(node.GetSubtree(0), (x) => !x);
    143158        case "IF": return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits);
    144159        default: {
     
    176191    }
    177192
    178     #region item cloning and persistence
    179     // persistence
    180     [StorableConstructor]
    181     private MultiplexerProblem(bool deserializing) : base(deserializing) { }
    182 
    183     [StorableHook(HookType.AfterDeserialization)]
    184     private void AfterDeserialization() {
    185       RegisterEventHandlers();
    186     }
    187 
    188     // cloning
    189     private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
    190       : base(original, cloner) {
    191       RegisterEventHandlers();
    192     }
    193     public override IDeepCloneable Clone(Cloner cloner) {
    194       return new MultiplexerProblem(this, cloner);
    195     }
    196     #endregion
    197 
    198193    #region events
    199 
    200194    private void RegisterEventHandlers() {
    201195      NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar();
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/HeuristicLab.Problems.GeneticProgramming-3.3.csproj

    r12911 r13280  
    109109    <Compile Include="ArtificialAnt\Problem.cs" />
    110110    <Compile Include="ArtificialAnt\Trail.cs" />
     111    <Compile Include="BasicSymbolicRegression\Problem.cs" />
     112    <Compile Include="Boolean\MultiplexerProblem.cs" />
     113    <Compile Include="Boolean\EvenParityProblem.cs" />
    111114    <Compile Include="LawnMower\Interpreter.cs" />
    112115    <Compile Include="LawnMower\Problem.cs" />
     
    174177      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    175178      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
     179      <Private>False</Private>
     180    </ProjectReference>
     181    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
     182      <Project>{DF87C13E-A889-46FF-8153-66DCAA8C5674}</Project>
     183      <Name>HeuristicLab.Problems.DataAnalysis-3.4</Name>
     184      <Private>False</Private>
     185    </ProjectReference>
     186    <ProjectReference Include="..\..\HeuristicLab.Problems.Instances\3.3\HeuristicLab.Problems.Instances-3.3.csproj">
     187      <Project>{3540E29E-4793-49E7-8EE2-FEA7F61C3994}</Project>
     188      <Name>HeuristicLab.Problems.Instances-3.3</Name>
    176189      <Private>False</Private>
    177190    </ProjectReference>
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Interpreter.cs

    r12911 r13280  
    2626
    2727namespace HeuristicLab.Problems.GeneticProgramming.LawnMower {
    28   public class Interpreter {
     28  public static class Interpreter {
    2929    private enum Heading {
    3030      South,
     
    4545    }
    4646
    47 
    4847    public static bool[,] EvaluateLawnMowerProgram(int length, int width, ISymbolicExpressionTree tree) {
    49 
    5048      bool[,] lawn = new bool[length, width];
    5149      var mowerState = new MowerState();
     
    5654      return lawn;
    5755    }
    58 
    5956
    6057    private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, MowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) {
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r12911 r13280  
    5050    }
    5151
     52    #region item cloning and persistence
    5253    [StorableConstructor]
    53     protected Problem(bool deserializing)
    54       : base(deserializing) {
     54    protected Problem(bool deserializing) : base(deserializing) { }
     55    [StorableHook(HookType.AfterDeserialization)]
     56    private void AfterDeserialization() { }
     57
     58    protected Problem(Problem original, Cloner cloner) : base(original, cloner) { }
     59    public override IDeepCloneable Clone(Cloner cloner) {
     60      return new Problem(this, cloner);
    5561    }
    56     protected Problem(Problem original, Cloner cloner)
    57       : base(original, cloner) {
    58     }
     62    #endregion
     63
    5964    public Problem()
    6065      : base() {
     
    8792    }
    8893
    89 
    90     [StorableHook(HookType.AfterDeserialization)]
    91     private void AfterDeserialization() { }
    92 
    9394    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
    9495      var length = LawnLengthParameter.Value.Value;
     
    105106      return numberOfMowedCells;
    106107    }
    107 
    108     public override IDeepCloneable Clone(Cloner cloner) {
    109       return new Problem(this, cloner);
    110     }
    111108  }
    112109}
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Solution.cs

    r12911 r13280  
    3737    public double Quality { get; private set; }
    3838
     39    #region item cloning and persistence
    3940    [StorableConstructor]
    4041    private Solution(bool deserializing) : base(deserializing) { }
     42    [StorableHook(HookType.AfterDeserialization)]
     43    private void AfterDeserialization() { }
     44
    4145    private Solution(Solution original, Cloner cloner)
    4246      : base(original, cloner) {
     
    4650      this.Quality = original.Quality;
    4751    }
     52    public override IDeepCloneable Clone(Cloner cloner) {
     53      return new Solution(this, cloner);
     54    }
     55    #endregion
    4856
    4957    public Solution(ISymbolicExpressionTree tree, int length, int width, double quality)
     
    5462      this.Quality = quality;
    5563    }
    56     [StorableHook(HookType.AfterDeserialization)]
    57     private void AfterDeserialization() {
    58     }
    59     public override IDeepCloneable Clone(Cloner cloner) {
    60       return new Solution(this, cloner);
    61     }
    6264  }
    6365}
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/Plugin.cs.frame

    r13279 r13280  
    3737  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3838  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     39  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
     40  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
    3941  [PluginDependency("HeuristicLab.Random", "3.3")]
    4042  public class HeuristicLabProblemsGeneticProgrammingPlugin : PluginBase {
Note: See TracChangeset for help on using the changeset viewer.