Changeset 2700


Ignore:
Timestamp:
01/28/10 16:42:24 (10 years ago)
Author:
gkronber
Message:

Renamed FunctionBase to Function and FunctionTreeBase to FunctionTree. #748 (FunctionLibraryView is empty).

Location:
trunk/sources
Files:
18 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Prog3.cs

    r2222 r2700  
    2121
    2222namespace HeuristicLab.GP.SantaFe {
    23   public sealed class Prog3 : FunctionBase {
     23  public sealed class Prog3 : Function {
    2424
    2525    public Prog3()
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenAddition.cs

    r2616 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification.Networks {
    24   public sealed class OpenAddition : FunctionBase {
     24  public sealed class OpenAddition : Function {
    2525    public override string Description {
    2626      get { return "Unbound +."; }
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenDivision.cs

    r2616 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification.Networks {
    24   public sealed class OpenDivision : FunctionBase {
     24  public sealed class OpenDivision : Function {
    2525    public override string Description {
    2626      get { return "Unbound /."; }
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenMultiplication.cs

    r2616 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification.Networks {
    24   public sealed class OpenMultiplication : FunctionBase {
     24  public sealed class OpenMultiplication : Function {
    2525    public override string Description {
    2626      get { return "Unbound *."; }
  • trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenSubtraction.cs

    r2616 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification.Networks {
    24   public sealed class OpenSubtraction : FunctionBase {
     24  public sealed class OpenSubtraction : Function {
    2525    public override string Description {
    2626      get { return "Unbound -."; }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/BaseClasses/FunctionTreeBase.cs

    r2235 r2700  
    2727
    2828namespace HeuristicLab.GP.StructureIdentification {
    29   public class FunctionTreeBase : HeuristicLab.GP.FunctionTreeBase {
     29  public class FunctionTreeBase : HeuristicLab.GP.FunctionTree {
    3030    public FunctionTreeBase(IFunction function) : base(function) { }
    3131    public FunctionTreeBase(FunctionTreeBase original) : base(original) { }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Addition.cs

    r2490 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class Addition : FunctionBase {
     24  public sealed class Addition : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/And.cs

    r2235 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class And : FunctionBase {
     24  public sealed class And : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Average.cs

    r2235 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class Average : FunctionBase {
     24  public sealed class Average : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Division.cs

    r2490 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class Division : FunctionBase {
     24  public sealed class Division : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/IfThenElse.cs

    r2235 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class IfThenElse : FunctionBase {
     24  public sealed class IfThenElse : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Multiplication.cs

    r2490 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class Multiplication : FunctionBase {
     24  public sealed class Multiplication : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Or.cs

    r2235 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class Or : FunctionBase {
     24  public sealed class Or : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Subtraction.cs

    r2490 r2700  
    2222
    2323namespace HeuristicLab.GP.StructureIdentification {
    24   public sealed class Subtraction : FunctionBase {
     24  public sealed class Subtraction : Function {
    2525    public override string Description {
    2626      get {
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/BinaryFunction.cs

    r2222 r2700  
    2626
    2727namespace HeuristicLab.GP {
    28   public abstract class BinaryFunction : FunctionBase {
     28  public abstract class BinaryFunction : Function {
    2929    public BinaryFunction()
    3030      : base() {
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/Function.cs

    r2687 r2700  
    3030
    3131namespace HeuristicLab.GP {
    32   public abstract class FunctionBase : ItemBase, IFunction {
     32  public abstract class Function : ItemBase, IFunction {
    3333    private List<List<IFunction>> allowedSubFunctions = new List<List<IFunction>>();
    3434    private int minArity = -1;
     
    4040    private int minTreeSize = -1;
    4141
     42    private string name;
    4243    public virtual string Name {
    43       get { return this.GetType().Name; }
     44      get { return name; }
     45      set {
     46        if (string.IsNullOrEmpty(value)) throw new ArgumentException();
     47        if (value != name) {
     48          name = value;
     49          FireChanged();
     50        }
     51      }
     52    }
     53
     54    protected Function() {
     55      name = this.GetType().Name;
    4456    }
    4557
     
    5264        return minArity;
    5365      }
    54       protected set {
    55         minArity = value;
    56         while (minArity > allowedSubFunctions.Count) allowedSubFunctions.Add(new List<IFunction>());
     66      protected internal set {
     67        if (value < 0) throw new ArgumentException();
     68        if (minArity != value) {
     69          minArity = value;
     70          while (minArity > allowedSubFunctions.Count) allowedSubFunctions.Add(new List<IFunction>());
     71          ResetCachedValues();
     72          FireChanged();
     73        }
    5774      }
    5875    }
     
    6279        return maxArity;
    6380      }
    64       protected set {
    65         maxArity = value;
    66         while (allowedSubFunctions.Count > maxArity) allowedSubFunctions.RemoveAt(allowedSubFunctions.Count - 1);
    67         while (maxArity > allowedSubFunctions.Count) allowedSubFunctions.Add(new List<IFunction>());
     81      protected internal set {
     82        if (value < 0) throw new ArgumentException();
     83        if (value < minArity) throw new ArgumentException();
     84        if (value != maxArity) {
     85          maxArity = value;
     86          while (allowedSubFunctions.Count > maxArity) allowedSubFunctions.RemoveAt(allowedSubFunctions.Count - 1);
     87          while (maxArity > allowedSubFunctions.Count) {
     88            if (allowedSubFunctions.Count > 0) {
     89              // copy the list of allowed sub-functions from the previous slot
     90              allowedSubFunctions.Add(new List<IFunction>(allowedSubFunctions[allowedSubFunctions.Count - 1]));
     91            } else {
     92              // add empty list
     93              allowedSubFunctions.Add(new List<IFunction>());
     94            }
     95          }
     96          ResetCachedValues();
     97          FireChanged();
     98        }
    6899      }
    69100    }
     
    72103    public int MinTreeSize {
    73104      get {
    74         if (minTreeSize <= 0) RecalculateMinimalTreeSize();
     105        if (minTreeSize <= 0) {
     106          RecalculateMinimalTreeSize();
     107          FireChanged();
     108        }
    75109        Debug.Assert(minTreeSize > 0);
    76110        return minTreeSize;
     
    80114    public int MinTreeHeight {
    81115      get {
    82         if (minTreeHeight <= 0) RecalculateMinimalTreeHeight();
     116        if (minTreeHeight <= 0) {
     117          RecalculateMinimalTreeHeight();
     118          FireChanged();
     119        }
    83120        Debug.Assert(minTreeHeight > 0);
    84121        return minTreeHeight;
     
    90127      set {
    91128        if (value < 0.0) throw new ArgumentException("Number of tickets must be positive");
    92         else tickets = value;
     129        if (value != tickets) {
     130          tickets = value;
     131          FireChanged();
     132        }
    93133      }
    94134    }
     
    96136    public IOperator Initializer {
    97137      get { return initializer; }
    98       set { initializer = value; }
     138      set {
     139        if (initializer != value) {
     140          initializer = value;
     141          FireChanged();
     142        }
     143      }
    99144    }
    100145
    101146    public IOperator Manipulator {
    102147      get { return manipulator; }
    103       set { manipulator = value; }
     148      set {
     149        if (manipulator != value) {
     150          manipulator = value;
     151          FireChanged();
     152        }
     153      }
    104154    }
    105155
    106156    public virtual IFunctionTree GetTreeNode() {
    107       return new FunctionTreeBase(this);
     157      return new FunctionTree(this);
    108158    }
    109159
     
    121171        allowedSubFunctions[index].Add(function);
    122172      }
    123     }
    124 
     173      ResetCachedValues();
     174      FireChanged();
     175    }
    125176    public void RemoveAllowedSubFunction(IFunction function, int index) {
    126177      if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index);
    127       allowedSubFunctions[index].Add(function);
     178      if (allowedSubFunctions[index].Contains(function)) {
     179        allowedSubFunctions[index].Remove(function);
     180        ResetCachedValues();
     181        FireChanged();
     182      }
     183    }
     184
     185    private void ResetCachedValues() {
     186      minTreeHeight = -1;
     187      minTreeSize = -1;
    128188    }
    129189
     
    135195      if (MinSubTrees == 0) minTreeSize = 1;
    136196      else {
    137         minTreeSize = int.MaxValue; // prevent infinite recursion
     197        minTreeSize = int.MaxValue; // prevent infinite recursion       
    138198        minTreeSize = 1 + (from slot in Enumerable.Range(0, MinSubTrees)
    139199                           let minForSlot = (from function in GetAllowedSubFunctions(slot)
    140200                                             where function != this
    141                                              select function.MinTreeSize).Min()
     201                                             select function.MinTreeSize).DefaultIfEmpty(0).Min()
    142202                           select minForSlot).Sum();
    143203      }
     
    151211                             let minForSlot = (from function in GetAllowedSubFunctions(slot)
    152212                                               where function != this
    153                                                select function.MinTreeHeight).Min()
     213                                               select function.MinTreeHeight).DefaultIfEmpty(0).Min()
    154214                             select minForSlot).Max();
    155215      }
    156216    }
    157217
     218    public override IView CreateView() {
     219      return new FunctionView(this);
     220    }
     221
     222    public override string ToString() {
     223      return name;
     224    }
     225
     226    #region persistence
    158227    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    159       FunctionBase clone = (FunctionBase)base.Clone(clonedObjects);
     228      Function clone = (Function)base.Clone(clonedObjects);
    160229      clone.initializer = (IOperator)Auxiliary.Clone(initializer, clonedObjects);
    161230      clone.manipulator = (IOperator)Auxiliary.Clone(manipulator, clonedObjects);
     
    207276      }
    208277    }
     278    #endregion
    209279  }
    210280}
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTree.cs

    r2687 r2700  
    2828
    2929namespace HeuristicLab.GP {
    30   public class FunctionTreeBase : IFunctionTree {
     30  public class FunctionTree : IFunctionTree {
    3131    private List<IFunctionTree> subTrees;
    3232    private IFunction function;
    3333
    34     public FunctionTreeBase() {
     34    public FunctionTree() {
    3535    }
    3636
    37     public FunctionTreeBase(IFunction function) {
     37    public FunctionTree(IFunction function) {
    3838      subTrees = new List<IFunctionTree>();
    3939      this.function = function;
    4040    }
    4141
    42     protected FunctionTreeBase(FunctionTreeBase original) {
     42    protected FunctionTree(FunctionTree original) {
    4343      this.function = original.Function;
    4444      this.subTrees = new List<IFunctionTree>(original.SubTrees.Count);
     
    107107
    108108    public virtual object Clone() {
    109       return new FunctionTreeBase(this);
     109      return new FunctionTree(this);
    110110    }
    111111
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs

    r2222 r2700  
    2626
    2727namespace HeuristicLab.GP {
    28   public abstract class Terminal : FunctionBase {
     28  public abstract class Terminal : Function {
    2929    public Terminal()
    3030      : base() {
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/TerminalTreeNode.cs

    r2222 r2700  
    2727
    2828namespace HeuristicLab.GP {
    29   public class TerminalTreeNode : FunctionTreeBase {
     29  public class TerminalTreeNode : FunctionTree {
    3030    private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly();
    3131    public TerminalTreeNode(IFunction function) {
  • trunk/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs

    r2222 r2700  
    2626
    2727namespace HeuristicLab.GP {
    28   public abstract class UnaryFunction : FunctionBase {
     28  public abstract class UnaryFunction : Function {
    2929    public UnaryFunction()
    3030      : base() {
Note: See TracChangeset for help on using the changeset viewer.