Free cookie consent management tool by TermsFeed Policy Generator

Changeset 185


Ignore:
Timestamp:
04/24/08 15:18:18 (17 years ago)
Author:
gkronber
Message:

fixed #114 (code-cleanup)

Location:
trunk/sources/HeuristicLab.Functions
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/FunctionView.cs

    r184 r185  
    135135      if(node == null || node.Tag == null) return;
    136136
    137       ModelAnalyzerExportVisitor visitor = new ModelAnalyzerExportVisitor();
     137      ModelAnalyzerExporter visitor = new ModelAnalyzerExporter();
    138138      visitor.Visit((IFunctionTree)node.Tag);
    139139      Clipboard.SetText(visitor.ModelAnalyzerPrefix);
     
    262262      #endregion
    263263    }
    264 
    265     private class ModelAnalyzerExportVisitor : IFunctionVisitor {
    266       private string prefix;
    267       private string currentIndend = "";
    268       private IFunctionTree currentBranch;
    269       public string ModelAnalyzerPrefix {
    270         get { return prefix; }
    271       }
    272       public void Reset() {
    273         prefix = "";
    274       }
    275 
    276       private void VisitFunction(string name, IFunction f) {
    277         prefix += currentIndend + "[F]" + name + "(\n";
    278       }
    279 
    280       #region IFunctionVisitor Members
    281 
    282       public void Visit(IFunction function) {
    283         prefix += function.Name;
    284       }
    285 
    286       public void Visit(Addition addition) {
    287         VisitFunction("Addition[0]", addition);
    288       }
    289 
    290       public void Visit(Constant constant) {
    291         double value = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Constant.VALUE).Value).Data;
    292         prefix += currentIndend + "[T]Constant(" + value + ";0;0)";
    293       }
    294 
    295       public void Visit(Cosinus cosinus) {
    296         VisitFunction("Trigonometrics[1]", cosinus);
    297       }
    298 
    299       public void Visit(Division division) {
    300         VisitFunction("Division[0]", division);
    301       }
    302 
    303       public void Visit(Exponential exponential) {
    304         VisitFunction("Exponential[0]", exponential);
    305       }
    306 
    307       public void Visit(Logarithm logarithm) {
    308         VisitFunction("Logarithm[0]", logarithm);
    309       }
    310 
    311       public void Visit(Multiplication multiplication) {
    312         VisitFunction("Multiplication[0]", multiplication);
    313       }
    314 
    315       public void Visit(Power power) {
    316         VisitFunction("Power[0]", power);
    317       }
    318 
    319       public void Visit(Signum signum) {
    320         VisitFunction("Signum[0]", signum);
    321       }
    322 
    323       public void Visit(Sinus sinus) {
    324         VisitFunction("Trigonometrics[0]", sinus);
    325       }
    326 
    327       public void Visit(Sqrt sqrt) {
    328         VisitFunction("Sqrt[0]", sqrt);
    329       }
    330 
    331       public void Visit(Substraction substraction) {
    332         VisitFunction("Substraction[0]", substraction);
    333       }
    334 
    335       public void Visit(Tangens tangens) {
    336         VisitFunction("Trigonometrics[2]", tangens);
    337       }
    338 
    339       public void Visit(HeuristicLab.Functions.Variable variable) {
    340         double weight = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.WEIGHT).Value).Data;
    341         double index = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.INDEX).Value).Data;
    342         double offset = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.OFFSET).Value).Data;
    343 
    344         prefix += currentIndend + "[T]Variable(" + weight + ";" + index + ";" + -offset + ")";
    345       }
    346 
    347       public void Visit(And and) {
    348         VisitFunction("Logical[0]", and);
    349       }
    350 
    351       public void Visit(Average average) {
    352         VisitFunction("N/A (average)", average);
    353       }
    354 
    355       public void Visit(IfThenElse ifThenElse) {
    356         VisitFunction("Conditional[0]", ifThenElse);
    357       }
    358 
    359       public void Visit(Not not) {
    360         VisitFunction("Logical[2]", not);
    361       }
    362 
    363       public void Visit(Or or) {
    364         VisitFunction("Logical[1]", or);
    365       }
    366 
    367       public void Visit(Xor xor) {
    368         VisitFunction("N/A (xor)", xor);
    369       }
    370 
    371       public void Visit(Equal equal) {
    372         VisitFunction("Boolean[2]", equal);
    373       }
    374 
    375       public void Visit(LessThan lessThan) {
    376         VisitFunction("Boolean[0]", lessThan);
    377       }
    378 
    379       public void Visit(GreaterThan greaterThan) {
    380         VisitFunction("Boolean[4]", greaterThan);
    381       }
    382       #endregion
    383 
    384       public void Visit(IFunctionTree functionTree) {
    385         currentBranch = functionTree;
    386         functionTree.Function.Accept(this);
    387         currentIndend += "  ";
    388         foreach(IFunctionTree subTree in functionTree.SubTrees) {
    389           Visit(subTree);
    390           prefix += ";\n";
    391         }
    392         prefix = prefix.TrimEnd(';', '\n');
    393         prefix += ")";
    394         currentIndend = currentIndend.Remove(0, 2);
    395       }
    396     }
    397264  }
    398265}
  • trunk/sources/HeuristicLab.Functions/HeuristicLab.Functions.csproj

    r159 r185  
    5555    <Compile Include="FunctionTree.cs" />
    5656    <Compile Include="IFunctionTree.cs" />
     57    <Compile Include="ModelAnalyzerExporter.cs" />
    5758    <Compile Include="ProgrammableFunction.cs" />
    5859    <Compile Include="Equal.cs" />
Note: See TracChangeset for help on using the changeset viewer.