[185] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Functions {
|
---|
| 29 | public class ModelAnalyzerExporter : IFunctionVisitor {
|
---|
| 30 | private string prefix;
|
---|
| 31 | private string currentIndend = "";
|
---|
| 32 | private IFunctionTree currentBranch;
|
---|
| 33 | public string ModelAnalyzerPrefix {
|
---|
| 34 | get { return prefix; }
|
---|
| 35 | }
|
---|
| 36 | public void Reset() {
|
---|
| 37 | prefix = "";
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | private void VisitFunction(string name, IFunction f) {
|
---|
| 41 | prefix += currentIndend + "[F]" + name + "(\n";
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | #region IFunctionVisitor Members
|
---|
| 45 |
|
---|
| 46 | public void Visit(IFunction function) {
|
---|
| 47 | prefix += function.Name;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public void Visit(Addition addition) {
|
---|
| 51 | VisitFunction("Addition[0]", addition);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public void Visit(Constant constant) {
|
---|
| 55 | double value = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Constant.VALUE).Value).Data;
|
---|
[339] | 56 | prefix += currentIndend + "[T]Constant(" + value.ToString("r") + ";0;0)";
|
---|
[185] | 57 | }
|
---|
| 58 |
|
---|
| 59 | public void Visit(Cosinus cosinus) {
|
---|
| 60 | VisitFunction("Trigonometrics[1]", cosinus);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | public void Visit(Division division) {
|
---|
| 64 | VisitFunction("Division[0]", division);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public void Visit(Exponential exponential) {
|
---|
| 68 | VisitFunction("Exponential[0]", exponential);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public void Visit(Logarithm logarithm) {
|
---|
| 72 | VisitFunction("Logarithm[0]", logarithm);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | public void Visit(Multiplication multiplication) {
|
---|
| 76 | VisitFunction("Multiplication[0]", multiplication);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | public void Visit(Power power) {
|
---|
| 80 | VisitFunction("Power[0]", power);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public void Visit(Signum signum) {
|
---|
| 84 | VisitFunction("Signum[0]", signum);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public void Visit(Sinus sinus) {
|
---|
| 88 | VisitFunction("Trigonometrics[0]", sinus);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public void Visit(Sqrt sqrt) {
|
---|
| 92 | VisitFunction("Sqrt[0]", sqrt);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[308] | 95 | public void Visit(Subtraction substraction) {
|
---|
| 96 | VisitFunction("Subtraction[0]", substraction);
|
---|
[185] | 97 | }
|
---|
| 98 |
|
---|
| 99 | public void Visit(Tangens tangens) {
|
---|
| 100 | VisitFunction("Trigonometrics[2]", tangens);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | public void Visit(HeuristicLab.Functions.Variable variable) {
|
---|
| 104 | double weight = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.WEIGHT).Value).Data;
|
---|
| 105 | double index = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.INDEX).Value).Data;
|
---|
| 106 | double offset = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.OFFSET).Value).Data;
|
---|
| 107 |
|
---|
[339] | 108 | prefix += currentIndend + "[T]Variable(" + weight.ToString("r") + ";" + index + ";" + -offset + ")";
|
---|
[185] | 109 | }
|
---|
| 110 |
|
---|
| 111 | public void Visit(And and) {
|
---|
| 112 | VisitFunction("Logical[0]", and);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | public void Visit(Average average) {
|
---|
| 116 | VisitFunction("N/A (average)", average);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | public void Visit(IfThenElse ifThenElse) {
|
---|
| 120 | VisitFunction("Conditional[0]", ifThenElse);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public void Visit(Not not) {
|
---|
| 124 | VisitFunction("Logical[2]", not);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | public void Visit(Or or) {
|
---|
| 128 | VisitFunction("Logical[1]", or);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | public void Visit(Xor xor) {
|
---|
| 132 | VisitFunction("N/A (xor)", xor);
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | public void Visit(Equal equal) {
|
---|
| 136 | VisitFunction("Boolean[2]", equal);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | public void Visit(LessThan lessThan) {
|
---|
| 140 | VisitFunction("Boolean[0]", lessThan);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | public void Visit(GreaterThan greaterThan) {
|
---|
| 144 | VisitFunction("Boolean[4]", greaterThan);
|
---|
| 145 | }
|
---|
| 146 | #endregion
|
---|
| 147 |
|
---|
| 148 | public void Visit(IFunctionTree functionTree) {
|
---|
| 149 | currentBranch = functionTree;
|
---|
| 150 | functionTree.Function.Accept(this);
|
---|
| 151 | currentIndend += " ";
|
---|
| 152 | foreach(IFunctionTree subTree in functionTree.SubTrees) {
|
---|
| 153 | Visit(subTree);
|
---|
| 154 | prefix += ";\n";
|
---|
| 155 | }
|
---|
| 156 | prefix = prefix.TrimEnd(';', '\n');
|
---|
[310] | 157 | if(functionTree.SubTrees.Count>0) prefix += ")";
|
---|
[185] | 158 | currentIndend = currentIndend.Remove(0, 2);
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 | }
|
---|