Changeset 146
- Timestamp:
- 04/22/08 10:01:18 (17 years ago)
- Location:
- branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/Constant.cs
r142 r146 31 31 namespace HeuristicLab.Functions { 32 32 public class Constant : FunctionBase { 33 public static readonly string VALUE = "Value"; 34 33 35 public override string Description { 34 36 get { return "Returns the value of local variable 'Value'."; } … … 44 46 public Constant() 45 47 : base() { 46 AddVariableInfo(new VariableInfo( "Value", "The constant value", typeof(ConstrainedDoubleData), VariableKind.None));47 GetVariableInfo( "Value").Local = true;48 AddVariableInfo(new VariableInfo(VALUE, "The constant value", typeof(ConstrainedDoubleData), VariableKind.None)); 49 GetVariableInfo(VALUE).Local = true; 48 50 49 51 ConstrainedDoubleData valueData = new ConstrainedDoubleData(); … … 52 54 53 55 // create the local variable 54 HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable( "Value", valueData);56 HeuristicLab.Core.Variable value = new HeuristicLab.Core.Variable(VALUE, valueData); 55 57 AddVariable(value); 56 58 … … 61 63 public override object Clone(IDictionary<Guid, object> clonedObjects) { 62 64 Constant clone = (Constant)base.Clone(clonedObjects); 63 clone.value = (ConstrainedDoubleData)clone.GetVariable( "Value").Value;65 clone.value = (ConstrainedDoubleData)clone.GetVariable(VALUE).Value; 64 66 return clone; 65 67 } … … 67 69 public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) { 68 70 base.Populate(node, restoredObjects); 69 value = (ConstrainedDoubleData)GetVariable( "Value").Value;71 value = (ConstrainedDoubleData)GetVariable(VALUE).Value; 70 72 } 71 73 -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionView.cs
r142 r146 30 30 using HeuristicLab.Core; 31 31 using HeuristicLab.PluginInfrastructure; 32 using HeuristicLab.Data; 32 33 33 34 namespace HeuristicLab.Functions { … … 52 53 protected override void UpdateControls() { 53 54 functionTreeView.Nodes.Clear(); 54 //functionTree.Accept(functionNameVisitor);55 functionNameVisitor.Visit(functionTree); 55 56 TreeNode rootNode = new TreeNode(); 56 rootNode.Name = "TASK";// function.Name;57 rootNode.Text = "TASK"; //functionNameVisitor.Name;57 rootNode.Name = functionTree.Function.Name; 58 rootNode.Text = functionNameVisitor.Name; 58 59 rootNode.Tag = functionTree; 59 60 rootNode.ContextMenuStrip = treeNodeContextMenu; … … 68 69 private void CreateTree(TreeNode rootNode, IFunctionTree functionTree) { 69 70 TreeNode node = new TreeNode(); 70 //functionTree.Accept(functionNameVisitor);71 node.Name = "TASK"; // function.Name;72 node.Text = "TASK"; //functionNameVisitor.Name;71 functionNameVisitor.Visit(functionTree); 72 node.Name = functionTree.Function.Name; 73 node.Text = functionNameVisitor.Name; 73 74 node.Tag = functionTree; 74 75 node.ContextMenuStrip = treeNodeContextMenu; … … 121 122 if(functionTreeView.SelectedNode != null && functionTreeView.SelectedNode.Tag != null) { 122 123 TreeNode node = functionTreeView.SelectedNode; 123 // selectedFunctionTree.Accept(functionNameVisitor);124 node.Text = "TASK"; //functionNameVisitor.Name;124 functionNameVisitor.Visit(selectedBranch); 125 node.Text = functionNameVisitor.Name; 125 126 } 126 127 } … … 134 135 if(node == null || node.Tag == null) return; 135 136 136 //ModelAnalyzerExportVisitor visitor = new ModelAnalyzerExportVisitor();137 // ((IFunctionTree)node.Tag).Accept(visitor);138 //Clipboard.SetText(visitor.ModelAnalyzerPrefix);137 ModelAnalyzerExportVisitor visitor = new ModelAnalyzerExportVisitor(); 138 visitor.Visit((IFunctionTree)node.Tag); 139 Clipboard.SetText(visitor.ModelAnalyzerPrefix); 139 140 } 140 141 141 142 private class FunctionNameVisitor : IFunctionVisitor { 142 143 string name; 144 IFunctionTree currentBranch; 143 145 144 146 public string Name { … … 146 148 } 147 149 150 public void Visit(IFunctionTree tree) { 151 currentBranch = tree; 152 tree.Function.Accept(this); 153 } 154 148 155 #region IFunctionVisitor Members 149 150 156 public void Visit(IFunction function) { 151 157 name = function.Name; … … 157 163 158 164 public void Visit(Constant constant) { 159 name = constant.Value+ "";165 name = ((ConstrainedDoubleData)(currentBranch.GetLocalVariable(HeuristicLab.Functions.Constant.VALUE).Value)).Data + ""; 160 166 } 161 167 … … 206 212 public void Visit(Variable variable) { 207 213 string timeOffset = ""; 208 if(variable.SampleOffset < 0) { 209 timeOffset = "(t" + variable.SampleOffset + ")"; 210 } else if(variable.SampleOffset > 0) { 211 timeOffset = "(t+" + variable.SampleOffset + ")"; 214 int sampleOffset = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.OFFSET).Value).Data; 215 int variableIndex = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.INDEX).Value).Data; 216 double weight = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.WEIGHT).Value).Data; 217 if(sampleOffset < 0) { 218 timeOffset = "(t" + sampleOffset + ")"; 219 } else if(sampleOffset > 0) { 220 timeOffset = "(t+" + sampleOffset + ")"; 212 221 } else { 213 222 timeOffset = ""; 214 223 } 215 name = "Var" + variable .VariableIndex + timeOffset + " * " + variable.Weight;224 name = "Var" + variableIndex + timeOffset + " * " + weight; 216 225 } 217 226 … … 251 260 } 252 261 253 //private class ModelAnalyzerExportVisitor : IFunctionVisitor { 254 // private string prefix; 255 // private string currentIndend = ""; 256 // public string ModelAnalyzerPrefix { 257 // get { return prefix; } 258 // } 259 // public void Reset() { 260 // prefix = ""; 261 // } 262 263 // private void VisitFunction(string name, IFunction f) { 264 // prefix += currentIndend + "[F]"+name+"(\n"; 265 // currentIndend += " "; 266 // foreach(IFunction subFunction in f.SubTrees) { 267 // subFunction.Accept(this); 268 // prefix += ";\n"; 269 // } 270 // prefix = prefix.TrimEnd(';','\n'); 271 // prefix += ")"; 272 // currentIndend = currentIndend.Remove(0, 2); 273 // } 274 275 // #region IFunctionVisitor Members 276 277 // public void Visit(IFunction function) { 278 // prefix += function.Name; 279 // } 280 281 // public void Visit(Addition addition) { 282 // VisitFunction("Addition[0]", addition); 283 // } 284 285 // public void Visit(Constant constant) { 286 // prefix += currentIndend + "[T]Constant(" + constant.Value.Data.ToString() + ";0;0)"; 287 // } 288 289 // public void Visit(Cosinus cosinus) { 290 // VisitFunction("Trigonometrics[1]", cosinus); 291 // } 292 293 // public void Visit(Division division) { 294 // VisitFunction("Division[0]", division); 295 // } 296 297 // public void Visit(Exponential exponential) { 298 // VisitFunction("Exponential[0]", exponential); 299 // } 300 301 // public void Visit(Logarithm logarithm) { 302 // VisitFunction("Logarithm[0]", logarithm); 303 // } 304 305 // public void Visit(Multiplication multiplication) { 306 // VisitFunction("Multiplication[0]", multiplication); 307 // } 308 309 // public void Visit(Power power) { 310 // VisitFunction("Power[0]", power); 311 // } 312 313 // public void Visit(Signum signum) { 314 // VisitFunction("Signum[0]", signum); 315 // } 316 317 // public void Visit(Sinus sinus) { 318 // VisitFunction("Trigonometrics[0]", sinus); 319 // } 320 321 // public void Visit(Sqrt sqrt) { 322 // VisitFunction("Sqrt[0]", sqrt); 323 // } 324 325 // public void Visit(Substraction substraction) { 326 // VisitFunction("Substraction[0]", substraction); 327 // } 328 329 // public void Visit(Tangens tangens) { 330 // VisitFunction("Trigonometrics[2]", tangens); 331 // } 332 333 // public void Visit(HeuristicLab.Functions.Variable variable) { 334 // prefix += currentIndend + "[T]Variable(" + variable.Weight + ";" + variable.VariableIndex + ";" + -variable.SampleOffset + ")"; 335 // } 336 337 // public void Visit(And and) { 338 // VisitFunction("Logical[0]", and); 339 // } 340 341 // public void Visit(Average average) { 342 // VisitFunction("N/A (average)", average); 343 // } 344 345 // public void Visit(IfThenElse ifThenElse) { 346 // VisitFunction("Conditional[0]", ifThenElse); 347 // } 348 349 // public void Visit(Not not) { 350 // VisitFunction("Logical[2]", not); 351 // } 352 353 // public void Visit(Or or) { 354 // VisitFunction("Logical[1]", or); 355 // } 356 357 // public void Visit(Xor xor) { 358 // VisitFunction("N/A (xor)", xor); 359 // } 360 361 // public void Visit(Equal equal) { 362 // VisitFunction("Boolean[2]", equal); 363 // } 364 365 // public void Visit(LessThan lessThan) { 366 // VisitFunction("Boolean[0]", lessThan); 367 // } 368 369 // #endregion 370 //} 371 262 private class ModelAnalyzerExportVisitor : IFunctionVisitor { 263 private string prefix; 264 private string currentIndend = ""; 265 private IFunctionTree currentBranch; 266 public string ModelAnalyzerPrefix { 267 get { return prefix; } 268 } 269 public void Reset() { 270 prefix = ""; 271 } 272 273 private void VisitFunction(string name, IFunction f) { 274 prefix += currentIndend + "[F]" + name + "(\n"; 275 } 276 277 #region IFunctionVisitor Members 278 279 public void Visit(IFunction function) { 280 prefix += function.Name; 281 } 282 283 public void Visit(Addition addition) { 284 VisitFunction("Addition[0]", addition); 285 } 286 287 public void Visit(Constant constant) { 288 double value = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Constant.VALUE).Value).Data; 289 prefix += currentIndend + "[T]Constant(" + value + ";0;0)"; 290 } 291 292 public void Visit(Cosinus cosinus) { 293 VisitFunction("Trigonometrics[1]", cosinus); 294 } 295 296 public void Visit(Division division) { 297 VisitFunction("Division[0]", division); 298 } 299 300 public void Visit(Exponential exponential) { 301 VisitFunction("Exponential[0]", exponential); 302 } 303 304 public void Visit(Logarithm logarithm) { 305 VisitFunction("Logarithm[0]", logarithm); 306 } 307 308 public void Visit(Multiplication multiplication) { 309 VisitFunction("Multiplication[0]", multiplication); 310 } 311 312 public void Visit(Power power) { 313 VisitFunction("Power[0]", power); 314 } 315 316 public void Visit(Signum signum) { 317 VisitFunction("Signum[0]", signum); 318 } 319 320 public void Visit(Sinus sinus) { 321 VisitFunction("Trigonometrics[0]", sinus); 322 } 323 324 public void Visit(Sqrt sqrt) { 325 VisitFunction("Sqrt[0]", sqrt); 326 } 327 328 public void Visit(Substraction substraction) { 329 VisitFunction("Substraction[0]", substraction); 330 } 331 332 public void Visit(Tangens tangens) { 333 VisitFunction("Trigonometrics[2]", tangens); 334 } 335 336 public void Visit(HeuristicLab.Functions.Variable variable) { 337 double weight = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.WEIGHT).Value).Data; 338 double index = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.INDEX).Value).Data; 339 double offset = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.OFFSET).Value).Data; 340 341 prefix += currentIndend + "[T]Variable(" + weight + ";" + index + ";" + -offset + ")"; 342 } 343 344 public void Visit(And and) { 345 VisitFunction("Logical[0]", and); 346 } 347 348 public void Visit(Average average) { 349 VisitFunction("N/A (average)", average); 350 } 351 352 public void Visit(IfThenElse ifThenElse) { 353 VisitFunction("Conditional[0]", ifThenElse); 354 } 355 356 public void Visit(Not not) { 357 VisitFunction("Logical[2]", not); 358 } 359 360 public void Visit(Or or) { 361 VisitFunction("Logical[1]", or); 362 } 363 364 public void Visit(Xor xor) { 365 VisitFunction("N/A (xor)", xor); 366 } 367 368 public void Visit(Equal equal) { 369 VisitFunction("Boolean[2]", equal); 370 } 371 372 public void Visit(LessThan lessThan) { 373 VisitFunction("Boolean[0]", lessThan); 374 } 375 #endregion 376 377 public void Visit(IFunctionTree functionTree) { 378 currentBranch = functionTree; 379 functionTree.Function.Accept(this); 380 currentIndend += " "; 381 foreach(IFunctionTree subTree in functionTree.SubTrees) { 382 Visit(subTree); 383 prefix += ";\n"; 384 } 385 prefix = prefix.TrimEnd(';', '\n'); 386 prefix += ")"; 387 currentIndend = currentIndend.Remove(0, 2); 388 } 389 } 372 390 } 373 391 } -
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/Variable.cs
r142 r146 32 32 public class Variable : FunctionBase { 33 33 34 public static readonly string WEIGHT = "Weight"; 35 public static readonly string OFFSET = "SampleOffset"; 36 public static readonly string INDEX = "Variable"; 37 34 38 private ConstrainedIntData variable; 35 39 private ConstrainedDoubleData weight; … … 56 60 public Variable() 57 61 : base() { 58 AddVariableInfo(new VariableInfo( "Variable", "Index of the variable in the dataset representing this feature", typeof(ConstrainedIntData), VariableKind.None));59 GetVariableInfo( "Variable").Local = true;60 AddVariableInfo(new VariableInfo( "Weight", "Weight is multiplied to the feature value", typeof(ConstrainedDoubleData), VariableKind.None));61 GetVariableInfo( "Weight").Local = true;62 AddVariableInfo(new VariableInfo( "SampleOffset", "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None));63 GetVariableInfo( "SampleOffset").Local = true;62 AddVariableInfo(new VariableInfo(INDEX, "Index of the variable in the dataset representing this feature", typeof(ConstrainedIntData), VariableKind.None)); 63 GetVariableInfo(INDEX).Local = true; 64 AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(ConstrainedDoubleData), VariableKind.None)); 65 GetVariableInfo(WEIGHT).Local = true; 66 AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None)); 67 GetVariableInfo(OFFSET).Local = true; 64 68 65 69 variable = new ConstrainedIntData(); 66 AddVariable(new HeuristicLab.Core.Variable( "Variable", variable));70 AddVariable(new HeuristicLab.Core.Variable(INDEX, variable)); 67 71 68 72 weight = new ConstrainedDoubleData(); 69 73 // initialize a totally arbitrary range for the weight = [-20.0, 20.0] 70 74 weight.AddConstraint(new DoubleBoundedConstraint(-20.0, 20.0)); 71 AddVariable(new HeuristicLab.Core.Variable( "Weight", weight));75 AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight)); 72 76 73 77 sampleOffset = new ConstrainedIntData(); 74 78 // initialize a totally arbitrary default range for sampleoffset = [-10, 10] 75 79 sampleOffset.AddConstraint(new IntBoundedConstraint(0, 0)); 76 AddVariable(new HeuristicLab.Core.Variable( "SampleOffset", sampleOffset));80 AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset)); 77 81 78 82 // samplefeature can't have suboperators … … 82 86 public override object Clone(IDictionary<Guid, object> clonedObjects) { 83 87 HeuristicLab.Functions.Variable clone = (HeuristicLab.Functions.Variable)base.Clone(clonedObjects); 84 clone.variable = (ConstrainedIntData)clone.GetVariable( "Variable").Value;85 clone.weight = (ConstrainedDoubleData)clone.GetVariable( "Weight").Value;86 clone.sampleOffset = (ConstrainedIntData)clone.GetVariable( "SampleOffset").Value;88 clone.variable = (ConstrainedIntData)clone.GetVariable(INDEX).Value; 89 clone.weight = (ConstrainedDoubleData)clone.GetVariable(WEIGHT).Value; 90 clone.sampleOffset = (ConstrainedIntData)clone.GetVariable(OFFSET).Value; 87 91 return clone; 88 92 } … … 90 94 public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 91 95 base.Populate(node, restoredObjects); 92 variable = (ConstrainedIntData)GetVariable( "Variable").Value;93 weight = (ConstrainedDoubleData)GetVariable( "Weight").Value;94 sampleOffset = (ConstrainedIntData)GetVariable( "SampleOffset").Value;96 variable = (ConstrainedIntData)GetVariable(INDEX).Value; 97 weight = (ConstrainedDoubleData)GetVariable(WEIGHT).Value; 98 sampleOffset = (ConstrainedIntData)GetVariable(OFFSET).Value; 95 99 } 96 100
Note: See TracChangeset
for help on using the changeset viewer.