- Timestamp:
- 01/28/10 16:42:24 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 18 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.SantaFe/3.3/Symbols/Prog3.cs
r2222 r2700 21 21 22 22 namespace HeuristicLab.GP.SantaFe { 23 public sealed class Prog3 : Function Base{23 public sealed class Prog3 : Function { 24 24 25 25 public Prog3() -
trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenAddition.cs
r2616 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification.Networks { 24 public sealed class OpenAddition : Function Base{24 public sealed class OpenAddition : Function { 25 25 public override string Description { 26 26 get { return "Unbound +."; } -
trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenDivision.cs
r2616 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification.Networks { 24 public sealed class OpenDivision : Function Base{24 public sealed class OpenDivision : Function { 25 25 public override string Description { 26 26 get { return "Unbound /."; } -
trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenMultiplication.cs
r2616 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification.Networks { 24 public sealed class OpenMultiplication : Function Base{24 public sealed class OpenMultiplication : Function { 25 25 public override string Description { 26 26 get { return "Unbound *."; } -
trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenSubtraction.cs
r2616 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification.Networks { 24 public sealed class OpenSubtraction : Function Base{24 public sealed class OpenSubtraction : Function { 25 25 public override string Description { 26 26 get { return "Unbound -."; } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/BaseClasses/FunctionTreeBase.cs
r2235 r2700 27 27 28 28 namespace HeuristicLab.GP.StructureIdentification { 29 public class FunctionTreeBase : HeuristicLab.GP.FunctionTree Base{29 public class FunctionTreeBase : HeuristicLab.GP.FunctionTree { 30 30 public FunctionTreeBase(IFunction function) : base(function) { } 31 31 public FunctionTreeBase(FunctionTreeBase original) : base(original) { } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Addition.cs
r2490 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class Addition : Function Base{24 public sealed class Addition : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/And.cs
r2235 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class And : Function Base{24 public sealed class And : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Average.cs
r2235 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class Average : Function Base{24 public sealed class Average : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Division.cs
r2490 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class Division : Function Base{24 public sealed class Division : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/IfThenElse.cs
r2235 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class IfThenElse : Function Base{24 public sealed class IfThenElse : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Multiplication.cs
r2490 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class Multiplication : Function Base{24 public sealed class Multiplication : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Or.cs
r2235 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class Or : Function Base{24 public sealed class Or : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Subtraction.cs
r2490 r2700 22 22 23 23 namespace HeuristicLab.GP.StructureIdentification { 24 public sealed class Subtraction : Function Base{24 public sealed class Subtraction : Function { 25 25 public override string Description { 26 26 get { -
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/BinaryFunction.cs
r2222 r2700 26 26 27 27 namespace HeuristicLab.GP { 28 public abstract class BinaryFunction : Function Base{28 public abstract class BinaryFunction : Function { 29 29 public BinaryFunction() 30 30 : base() { -
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/Function.cs
r2687 r2700 30 30 31 31 namespace HeuristicLab.GP { 32 public abstract class Function Base: ItemBase, IFunction {32 public abstract class Function : ItemBase, IFunction { 33 33 private List<List<IFunction>> allowedSubFunctions = new List<List<IFunction>>(); 34 34 private int minArity = -1; … … 40 40 private int minTreeSize = -1; 41 41 42 private string name; 42 43 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; 44 56 } 45 57 … … 52 64 return minArity; 53 65 } 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 } 57 74 } 58 75 } … … 62 79 return maxArity; 63 80 } 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 } 68 99 } 69 100 } … … 72 103 public int MinTreeSize { 73 104 get { 74 if (minTreeSize <= 0) RecalculateMinimalTreeSize(); 105 if (minTreeSize <= 0) { 106 RecalculateMinimalTreeSize(); 107 FireChanged(); 108 } 75 109 Debug.Assert(minTreeSize > 0); 76 110 return minTreeSize; … … 80 114 public int MinTreeHeight { 81 115 get { 82 if (minTreeHeight <= 0) RecalculateMinimalTreeHeight(); 116 if (minTreeHeight <= 0) { 117 RecalculateMinimalTreeHeight(); 118 FireChanged(); 119 } 83 120 Debug.Assert(minTreeHeight > 0); 84 121 return minTreeHeight; … … 90 127 set { 91 128 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 } 93 133 } 94 134 } … … 96 136 public IOperator Initializer { 97 137 get { return initializer; } 98 set { initializer = value; } 138 set { 139 if (initializer != value) { 140 initializer = value; 141 FireChanged(); 142 } 143 } 99 144 } 100 145 101 146 public IOperator Manipulator { 102 147 get { return manipulator; } 103 set { manipulator = value; } 148 set { 149 if (manipulator != value) { 150 manipulator = value; 151 FireChanged(); 152 } 153 } 104 154 } 105 155 106 156 public virtual IFunctionTree GetTreeNode() { 107 return new FunctionTree Base(this);157 return new FunctionTree(this); 108 158 } 109 159 … … 121 171 allowedSubFunctions[index].Add(function); 122 172 } 123 } 124 173 ResetCachedValues(); 174 FireChanged(); 175 } 125 176 public void RemoveAllowedSubFunction(IFunction function, int index) { 126 177 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; 128 188 } 129 189 … … 135 195 if (MinSubTrees == 0) minTreeSize = 1; 136 196 else { 137 minTreeSize = int.MaxValue; // prevent infinite recursion 197 minTreeSize = int.MaxValue; // prevent infinite recursion 138 198 minTreeSize = 1 + (from slot in Enumerable.Range(0, MinSubTrees) 139 199 let minForSlot = (from function in GetAllowedSubFunctions(slot) 140 200 where function != this 141 select function.MinTreeSize). Min()201 select function.MinTreeSize).DefaultIfEmpty(0).Min() 142 202 select minForSlot).Sum(); 143 203 } … … 151 211 let minForSlot = (from function in GetAllowedSubFunctions(slot) 152 212 where function != this 153 select function.MinTreeHeight). Min()213 select function.MinTreeHeight).DefaultIfEmpty(0).Min() 154 214 select minForSlot).Max(); 155 215 } 156 216 } 157 217 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 158 227 public override object Clone(IDictionary<Guid, object> clonedObjects) { 159 Function Base clone = (FunctionBase)base.Clone(clonedObjects);228 Function clone = (Function)base.Clone(clonedObjects); 160 229 clone.initializer = (IOperator)Auxiliary.Clone(initializer, clonedObjects); 161 230 clone.manipulator = (IOperator)Auxiliary.Clone(manipulator, clonedObjects); … … 207 276 } 208 277 } 278 #endregion 209 279 } 210 280 } -
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTree.cs
r2687 r2700 28 28 29 29 namespace HeuristicLab.GP { 30 public class FunctionTree Base: IFunctionTree {30 public class FunctionTree : IFunctionTree { 31 31 private List<IFunctionTree> subTrees; 32 32 private IFunction function; 33 33 34 public FunctionTree Base() {34 public FunctionTree() { 35 35 } 36 36 37 public FunctionTree Base(IFunction function) {37 public FunctionTree(IFunction function) { 38 38 subTrees = new List<IFunctionTree>(); 39 39 this.function = function; 40 40 } 41 41 42 protected FunctionTree Base(FunctionTreeBase original) {42 protected FunctionTree(FunctionTree original) { 43 43 this.function = original.Function; 44 44 this.subTrees = new List<IFunctionTree>(original.SubTrees.Count); … … 107 107 108 108 public virtual object Clone() { 109 return new FunctionTree Base(this);109 return new FunctionTree(this); 110 110 } 111 111 -
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs
r2222 r2700 26 26 27 27 namespace HeuristicLab.GP { 28 public abstract class Terminal : Function Base{28 public abstract class Terminal : Function { 29 29 public Terminal() 30 30 : base() { -
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/TerminalTreeNode.cs
r2222 r2700 27 27 28 28 namespace HeuristicLab.GP { 29 public class TerminalTreeNode : FunctionTree Base{29 public class TerminalTreeNode : FunctionTree { 30 30 private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly(); 31 31 public TerminalTreeNode(IFunction function) { -
trunk/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs
r2222 r2700 26 26 27 27 namespace HeuristicLab.GP { 28 public abstract class UnaryFunction : Function Base{28 public abstract class UnaryFunction : Function { 29 29 public UnaryFunction() 30 30 : base() {
Note: See TracChangeset
for help on using the changeset viewer.