Free cookie consent management tool by TermsFeed Policy Generator

Changeset 146


Ignore:
Timestamp:
04/22/08 10:01:18 (17 years ago)
Author:
gkronber
Message:
  • fixed function-tree display in tree-view
  • added string constants for the variable names of Variable and Constant
Location:
branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/Constant.cs

    r142 r146  
    3131namespace HeuristicLab.Functions {
    3232  public class Constant : FunctionBase {
     33    public static readonly string VALUE = "Value";
     34
    3335    public override string Description {
    3436      get { return "Returns the value of local variable 'Value'."; }
     
    4446    public Constant()
    4547      : 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;
    4850
    4951      ConstrainedDoubleData valueData = new ConstrainedDoubleData();
     
    5254
    5355      // 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);
    5557      AddVariable(value);
    5658
     
    6163    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    6264      Constant clone = (Constant)base.Clone(clonedObjects);
    63       clone.value = (ConstrainedDoubleData)clone.GetVariable("Value").Value;
     65      clone.value = (ConstrainedDoubleData)clone.GetVariable(VALUE).Value;
    6466      return clone;
    6567    }
     
    6769    public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    6870      base.Populate(node, restoredObjects);
    69       value = (ConstrainedDoubleData)GetVariable("Value").Value;
     71      value = (ConstrainedDoubleData)GetVariable(VALUE).Value;
    7072    }
    7173
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/FunctionView.cs

    r142 r146  
    3030using HeuristicLab.Core;
    3131using HeuristicLab.PluginInfrastructure;
     32using HeuristicLab.Data;
    3233
    3334namespace HeuristicLab.Functions {
     
    5253    protected override void UpdateControls() {
    5354      functionTreeView.Nodes.Clear();
    54       //functionTree.Accept(functionNameVisitor);
     55      functionNameVisitor.Visit(functionTree);
    5556      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;
    5859      rootNode.Tag = functionTree;
    5960      rootNode.ContextMenuStrip = treeNodeContextMenu;
     
    6869    private void CreateTree(TreeNode rootNode, IFunctionTree functionTree) {
    6970      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;
    7374      node.Tag = functionTree;
    7475      node.ContextMenuStrip = treeNodeContextMenu;
     
    121122      if(functionTreeView.SelectedNode != null && functionTreeView.SelectedNode.Tag != null) {
    122123        TreeNode node = functionTreeView.SelectedNode;
    123         // selectedFunctionTree.Accept(functionNameVisitor);
    124         node.Text = "TASK"; // functionNameVisitor.Name;
     124        functionNameVisitor.Visit(selectedBranch);
     125        node.Text = functionNameVisitor.Name;
    125126      }
    126127    }
     
    134135      if(node == null || node.Tag == null) return;
    135136
    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);
    139140    }
    140141
    141142    private class FunctionNameVisitor : IFunctionVisitor {
    142143      string name;
     144      IFunctionTree currentBranch;
    143145
    144146      public string Name {
     
    146148      }
    147149
     150      public void Visit(IFunctionTree tree) {
     151        currentBranch = tree;
     152        tree.Function.Accept(this);
     153      }
     154
    148155      #region IFunctionVisitor Members
    149 
    150156      public void Visit(IFunction function) {
    151157        name = function.Name;
     
    157163
    158164      public void Visit(Constant constant) {
    159         name = constant.Value + "";
     165        name = ((ConstrainedDoubleData)(currentBranch.GetLocalVariable(HeuristicLab.Functions.Constant.VALUE).Value)).Data + "";
    160166      }
    161167
     
    206212      public void Visit(Variable variable) {
    207213        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 + ")";
    212221        } else {
    213222          timeOffset = "";
    214223        }
    215         name = "Var" + variable.VariableIndex + timeOffset + " * " + variable.Weight;
     224        name = "Var" + variableIndex + timeOffset + " * " + weight;
    216225      }
    217226
     
    251260    }
    252261
    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    }
    372390  }
    373391}
  • branches/FunctionsAndStructIdRefactoring/HeuristicLab.Functions/Variable.cs

    r142 r146  
    3232  public class Variable : FunctionBase {
    3333
     34    public static readonly string WEIGHT = "Weight";
     35    public static readonly string OFFSET = "SampleOffset";
     36    public static readonly string INDEX = "Variable";
     37
    3438    private ConstrainedIntData variable;
    3539    private ConstrainedDoubleData weight;
     
    5660    public Variable()
    5761      : 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;
    6468
    6569      variable = new ConstrainedIntData();
    66       AddVariable(new HeuristicLab.Core.Variable("Variable", variable));
     70      AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
    6771
    6872      weight = new ConstrainedDoubleData();
    6973      // initialize a totally arbitrary range for the weight = [-20.0, 20.0]
    7074      weight.AddConstraint(new DoubleBoundedConstraint(-20.0, 20.0));
    71       AddVariable(new HeuristicLab.Core.Variable("Weight", weight));
     75      AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));
    7276
    7377      sampleOffset = new ConstrainedIntData();
    7478      // initialize a totally arbitrary default range for sampleoffset = [-10, 10]
    7579      sampleOffset.AddConstraint(new IntBoundedConstraint(0, 0));
    76       AddVariable(new HeuristicLab.Core.Variable("SampleOffset", sampleOffset));
     80      AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
    7781
    7882      // samplefeature can't have suboperators
     
    8286    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    8387      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;
    8791      return clone;
    8892    }
     
    9094    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    9195      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;
    9599    }
    96100
Note: See TracChangeset for help on using the changeset viewer.