- Timestamp:
- 07/28/09 19:24:23 (15 years ago)
- 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 26 26 using HeuristicLab.Core; 27 27 using System.Xml; 28 using HeuristicLab.Data; 29 using HeuristicLab.Constraints; 28 30 29 31 namespace 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; } 45 36 } 46 37 47 #endregion 38 public FunctionLibrary() 39 : base() { 40 } 48 41 49 42 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); 53 46 } 54 47 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); 57 76 } 58 77 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); 63 94 } 64 65 #region persistence66 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 #endregion77 95 78 96 #region IEditable Members 79 97 80 98 public IEditor CreateEditor() { 81 return new GPOperatorLibraryEditor(this);99 return new FunctionLibraryEditor(this); 82 100 } 83 101
Note: See TracChangeset
for help on using the changeset viewer.