Changeset 2216 for branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Variable.cs
- Timestamp:
- 07/30/09 19:41:58 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Boolean/3.3/Symbols/Variable.cs
r2211 r2216 26 26 using HeuristicLab.Core; 27 27 using System.Xml; 28 using HeuristicLab.Constraints;29 using HeuristicLab.DataAnalysis;30 28 using HeuristicLab.Operators; 31 29 using HeuristicLab.Random; 32 30 33 31 namespace HeuristicLab.GP.Boolean { 34 public sealed class Variable : FunctionBase { 35 public const string INDEX = "Variable"; 36 37 private int minIndex; 38 private int maxIndex; 39 40 public override string Description { 41 get { return ""; } 42 } 32 public sealed class Variable : Terminal { 33 public const string VARIABLENAME = "Variable"; 43 34 44 35 public Variable() 45 36 : base() { 46 AddVariableInfo(new VariableInfo(INDEX, "Index of the variable in the dataset representing this feature", typeof(ConstrainedIntData), VariableKind.None));47 GetVariableInfo(INDEX).Local = true;48 AddVariableInfo(new VariableInfo(INITIALIZATION, "Initialization operator for variables", typeof(CombinedOperator), VariableKind.None));49 GetVariableInfo(INITIALIZATION).Local = false;50 AddVariableInfo(new VariableInfo(MANIPULATION, "Manipulation operator for variables", typeof(CombinedOperator), VariableKind.None));51 GetVariableInfo(MANIPULATION).Local = false;52 53 MinArity = 0; MaxArity = 0;54 55 ConstrainedIntData variable = new ConstrainedIntData();56 AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));57 minIndex = 0; maxIndex = 100;58 59 37 SetupInitialization(); 60 38 SetupManipulation(); 39 } 61 40 41 public override HeuristicLab.GP.Interfaces.IFunctionTree GetTreeNode() { 42 return new VariableFunctionTree(this); 62 43 } 63 44 … … 65 46 CombinedOperator combinedOp = new CombinedOperator(); 66 47 SequentialProcessor seq = new SequentialProcessor(); 67 UniformRandomizer indexRandomizer = new UniformRandomizer(); 68 indexRandomizer.Min = minIndex; 69 indexRandomizer.Max = maxIndex + 1; // uniform randomizer generates numbers in the range [min, max[ 70 indexRandomizer.GetVariableInfo("Value").ActualName = INDEX; 71 indexRandomizer.Name = "Index Randomizer"; 48 UniformItemChooser variableRandomizer = new UniformItemChooser(); 49 variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME; 50 variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables"; 51 variableRandomizer.Name = "Variable randomizer"; 72 52 73 53 combinedOp.OperatorGraph.AddOperator(seq); 74 combinedOp.OperatorGraph.AddOperator( indexRandomizer);54 combinedOp.OperatorGraph.AddOperator(variableRandomizer); 75 55 combinedOp.OperatorGraph.InitialOperator = seq; 76 seq.AddSubOperator( indexRandomizer);56 seq.AddSubOperator(variableRandomizer); 77 57 Initializer = combinedOp; 78 58 } … … 82 62 CombinedOperator combinedOp = new CombinedOperator(); 83 63 SequentialProcessor seq = new SequentialProcessor(); 84 UniformRandomizer indexRandomizer = new UniformRandomizer(); 85 indexRandomizer.Min = minIndex; 86 indexRandomizer.Max = maxIndex + 1; 87 indexRandomizer.GetVariableInfo("Value").ActualName = INDEX; 88 indexRandomizer.Name = "Index Randomizer"; 64 UniformItemChooser variableRandomizer = new UniformItemChooser(); 65 variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME; 66 variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables"; 67 variableRandomizer.Name = "Variable randomizer"; 89 68 90 69 combinedOp.OperatorGraph.AddOperator(seq); 91 combinedOp.OperatorGraph.AddOperator( indexRandomizer);70 combinedOp.OperatorGraph.AddOperator(variableRandomizer); 92 71 combinedOp.OperatorGraph.InitialOperator = seq; 93 seq.AddSubOperator( indexRandomizer);72 seq.AddSubOperator(variableRandomizer); 94 73 Manipulator = combinedOp; 95 }96 97 public void SetConstraints(int[] allowedIndexes) {98 //ConstrainedIntData index = GetVariableValue<ConstrainedIntData>(INDEX, null, false);99 Array.Sort(allowedIndexes);100 minIndex = allowedIndexes[0]; maxIndex = allowedIndexes[allowedIndexes.Length - 1];101 List<IConstraint> constraints = new List<IConstraint>();102 int start = allowedIndexes[0];103 int prev = start;104 for(int i = 1; i < allowedIndexes.Length; i++) {105 if(allowedIndexes[i] != prev + 1) {106 IntBoundedConstraint lastRange = new IntBoundedConstraint();107 lastRange.LowerBound = start;108 lastRange.LowerBoundEnabled = true;109 lastRange.LowerBoundIncluded = true;110 lastRange.UpperBound = prev;111 lastRange.UpperBoundEnabled = true;112 lastRange.UpperBoundIncluded = true;113 constraints.Add(lastRange);114 start = allowedIndexes[i];115 prev = start;116 }117 prev = allowedIndexes[i];118 }119 IntBoundedConstraint range = new IntBoundedConstraint();120 range.LowerBound = start;121 range.LowerBoundEnabled = true;122 range.LowerBoundIncluded = true;123 range.UpperBound = prev;124 range.UpperBoundEnabled = true;125 range.UpperBoundIncluded = true;126 constraints.Add(range);127 if(constraints.Count > 1) {128 OrConstraint or = new OrConstraint();129 foreach(IConstraint c in constraints) or.Clauses.Add(c);130 index.AddConstraint(or);131 } else {132 index.AddConstraint(constraints[0]);133 }134 135 SetupInitialization();136 SetupManipulation();137 74 } 138 75 }
Note: See TracChangeset
for help on using the changeset viewer.