Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/09 19:24:23 (15 years ago)
Author:
gkronber
Message:

Created a branch for #713

Location:
branches/GP-Refactoring-713
Files:
2 copied

Legend:

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

    r2183 r2202  
    2626using HeuristicLab.Core;
    2727using System.Xml;
     28using HeuristicLab.Data;
     29using HeuristicLab.Constraints;
    2830
    2931namespace HeuristicLab.GP {
    30   public class GPOperatorLibrary : ItemBase, IOperatorLibrary, IEditable  {
    31     // constants for variable names
    32     internal const string MIN_TREE_HEIGHT = "MinTreeHeight";
    33     internal const string MIN_TREE_SIZE = "MinTreeSize";
    34     internal const string TICKETS = "Tickets";
    35 
    36     private GPOperatorGroup group;
    37 
    38     public GPOperatorGroup GPOperatorGroup {
    39       get { return group; }
    40     }
    41     #region IOperatorLibrary Members
    42 
    43     public IOperatorGroup Group {
    44       get { return group; }
     32  public class FunctionLibrary : ItemBase, IEditable {
     33    private List<IFunction> functions = new List<IFunction>();
     34    public IEnumerable<IFunction> Functions {
     35      get { return functions; }
    4536    }
    4637
    47     #endregion
     38    public FunctionLibrary()
     39      : base() {
     40    }
    4841
    4942
    50     public GPOperatorLibrary()
    51       : base() {
    52       group = new GPOperatorGroup();
     43    public void AddFunction(IFunction fun) {
     44      if (!functions.Contains(fun)) functions.Add(fun);
     45      // OnFunctionAdded(fun);
    5346    }
    5447
    55     public override IView CreateView() {
    56       return new GPOperatorLibraryEditor(this);
     48    //void UpdateTreeBounds(object sender, EventArgs e) {
     49    //  RecalculateMinimalTreeBounds();
     50    //}
     51
     52
     53    //private void GetMinMaxArity(IOperator op, out int minArity, out int maxArity) {
     54    //  foreach (IConstraint constraint in op.Constraints) {
     55    //    NumberOfSubOperatorsConstraint theConstraint = constraint as NumberOfSubOperatorsConstraint;
     56    //    if (theConstraint != null) {
     57    //      minArity = theConstraint.MinOperators.Data;
     58    //      maxArity = theConstraint.MaxOperators.Data;
     59    //      return;
     60    //    }
     61    //  }
     62    //  // the default arity is 2
     63    //  minArity = 2;
     64    //  maxArity = 2;
     65    //}
     66
     67    public void RemoveFunction(IFunction fun) {
     68      functions.Remove(fun);
     69
     70      // remove the operator from the allowed sub-functions of the remaining operators
     71      foreach (IFunction f in Functions) {
     72        if (f != fun) {
     73        }
     74      }
     75      // OnFunctionRemoved(fun);
    5776    }
    5877
    59     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    60       GPOperatorLibrary clone = (GPOperatorLibrary)base.Clone(clonedObjects);
    61       clone.group = (GPOperatorGroup)group.Clone(clonedObjects);
    62       return clone;
     78    //public event EventHandler FunctionAdded;
     79    //public event EventHandler FunctionRemoved;
     80
     81    //protected virtual void OnFunctionAdded(IFunction fun) {
     82    //  if (FunctionAdded != null) {
     83    //    FunctionAdded(this, new EventArgs(fun));
     84    //  }
     85    //}
     86    //protected virtual void OnFunctionRemoved(IFunction fun) {
     87    //  if (FunctionRemoved != null) {
     88    //    FunctionRemoved(this, new EventArgs(fun));
     89    //  }
     90    //}
     91
     92    public override IView CreateView() {
     93      return new FunctionLibraryEditor(this);
    6394    }
    64 
    65     #region persistence
    66     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    67       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    68       node.AppendChild(PersistenceManager.Persist("Group", group, document, persistedObjects));
    69       return node;
    70     }
    71 
    72     public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    73       base.Populate(node, restoredObjects);
    74       group = (GPOperatorGroup) PersistenceManager.Restore(node.SelectSingleNode("Group"), restoredObjects);
    75     }
    76     #endregion
    7795
    7896    #region IEditable Members
    7997
    8098    public IEditor CreateEditor() {
    81       return new GPOperatorLibraryEditor(this);
     99      return new FunctionLibraryEditor(this);
    82100    }
    83101
Note: See TracChangeset for help on using the changeset viewer.