Changeset 2629
- Timestamp:
- 01/15/10 17:58:53 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.Boolean/3.3/BooleanTreeInterpreter.cs
r2328 r2629 72 72 case SymbolTable.UNKNOWN: 73 73 default: 74 throw new UnknownFunctionException(t.Function.Name);74 throw new NotImplementedException(t.Function.Name); 75 75 } 76 76 } -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ModelAnalyzerExporter.cs
r2235 r2629 22 22 using HeuristicLab.GP.Interfaces; 23 23 using System; 24 using System.Collections.Generic; 24 25 25 26 namespace HeuristicLab.GP.StructureIdentification { … … 34 35 35 36 public bool TryExport(IFunctionTree tree, out string exported) { 36 try {37 exported = Export(tree);38 return true;39 } catch(UnknownFunctionException) {40 exported = "";41 return false;42 }37 foreach (IFunctionTree t in FunctionTreeIterator.IteratePrefix(tree)) 38 if (!functionExporter.ContainsKey(t.Function.GetType())) { 39 exported = null; 40 return false; 41 } 42 exported = Export(tree); 43 return true; 43 44 } 44 45 45 46 public string Export(IFunctionTree tree) { 46 47 string result = ExportFunction(tree.Function, tree); 47 if (tree.SubTrees.Count>0)48 if (tree.SubTrees.Count > 0) 48 49 result += "(\n"; 49 foreach (IFunctionTree subTree in tree.SubTrees) {50 foreach (IFunctionTree subTree in tree.SubTrees) { 50 51 result += Export(subTree); 51 52 result += ";\n"; 52 53 } 53 54 result = result.TrimEnd(';', '\n'); 54 if (tree.SubTrees.Count > 0) result += ")";55 if (tree.SubTrees.Count > 0) result += ")"; 55 56 return result; 56 57 } 57 58 public IFunctionTree Import(string tree) {59 throw new UnknownFunctionException(tree);60 }61 62 public bool TryImport(string tree, out IFunctionTree importedTree) {63 try {64 importedTree = Import(tree);65 return true;66 }67 catch (UnknownFunctionException) {68 importedTree = null;69 return false;70 }71 }72 73 58 #endregion 74 59 60 // try-export checks the keys of this dictionary 61 private static Dictionary<Type, Func<IFunction, IFunctionTree, string>> functionExporter = new Dictionary<Type, Func<IFunction, IFunctionTree, string>>() { 62 { typeof(Addition), (function, tree) => ((Addition)function).ExportToHL2(tree)}, 63 { typeof(And), (function, tree) => ((And)function).ExportToHL2(tree)}, 64 { typeof(Average), (function, tree) => ((Average)function).ExportToHL2(tree)}, 65 { typeof(Constant), (function, tree) => ((Constant)function).ExportToHL2(tree)}, 66 { typeof(Cosinus), (function, tree) => ((Cosinus)function).ExportToHL2(tree)}, 67 { typeof(Differential), (function, tree) => ((Differential)function).ExportToHL2(tree)}, 68 { typeof(Division), (function, tree) => ((Division)function).ExportToHL2(tree)}, 69 { typeof(Equal), (function, tree) => ((Equal)function).ExportToHL2(tree)}, 70 { typeof(Exponential), (function, tree) => ((Exponential)function).ExportToHL2(tree)}, 71 { typeof(GreaterThan), (function, tree) => ((GreaterThan)function).ExportToHL2(tree)}, 72 { typeof(IfThenElse), (function, tree) => ((IfThenElse)function).ExportToHL2(tree)}, 73 { typeof(LessThan), (function, tree) => ((LessThan)function).ExportToHL2(tree)}, 74 { typeof(Logarithm), (function, tree) => ((Logarithm)function).ExportToHL2(tree)}, 75 { typeof(Multiplication), (function, tree) => ((Multiplication)function).ExportToHL2(tree)}, 76 { typeof(Not), (function, tree) => ((Not)function).ExportToHL2(tree)}, 77 { typeof(Or), (function, tree) => ((Or)function).ExportToHL2(tree)}, 78 { typeof(Power), (function, tree) => ((Power)function).ExportToHL2(tree)}, 79 { typeof(Signum), (function, tree) => ((Signum)function).ExportToHL2(tree)}, 80 { typeof(Sinus), (function, tree) => ((Sinus)function).ExportToHL2(tree)}, 81 { typeof(Sqrt), (function, tree) => ((Sqrt)function).ExportToHL2(tree)}, 82 { typeof(Subtraction), (function, tree) => ((Subtraction)function).ExportToHL2(tree)}, 83 { typeof(Tangens), (function, tree) => ((Tangens)function).ExportToHL2(tree)}, 84 { typeof(Variable), (function, tree) => ((Variable)function).ExportToHL2(tree)}, 85 { typeof(Xor), (function, tree) => ((Xor)function).ExportToHL2(tree)}, 86 }; 75 87 private static string ExportFunction(IFunction function, IFunctionTree tree) { 76 88 // this is smelly, if there is a cleaner way to have a 'dynamic' visitor 77 89 // please let me know! (gkronber 14.10.2008) 78 if(function is Addition) return ((Addition)function).ExportToHL2(tree); 79 if(function is And) return ((And)function).ExportToHL2(tree); 80 if(function is Average) return ((Average)function).ExportToHL2(tree); 81 if(function is Constant) return ((Constant)function).ExportToHL2(tree); 82 if(function is Cosinus) return ((Cosinus)function).ExportToHL2(tree); 83 if(function is Differential) return ((Differential)function).ExportToHL2(tree); 84 if(function is Division) return ((Division)function).ExportToHL2(tree); 85 if(function is Equal) return ((Equal)function).ExportToHL2(tree); 86 if(function is Exponential) return ((Exponential)function).ExportToHL2(tree); 87 if(function is GreaterThan) return ((GreaterThan)function).ExportToHL2(tree); 88 if(function is IfThenElse) return ((IfThenElse)function).ExportToHL2(tree); 89 if(function is LessThan) return ((LessThan)function).ExportToHL2(tree); 90 if(function is Logarithm) return ((Logarithm)function).ExportToHL2(tree); 91 if(function is Multiplication) return ((Multiplication)function).ExportToHL2(tree); 92 if(function is Not) return ((Not)function).ExportToHL2(tree); 93 if(function is Or) return ((Or)function).ExportToHL2(tree); 94 if(function is Power) return ((Power)function).ExportToHL2(tree); 95 if(function is Signum) return ((Signum)function).ExportToHL2(tree); 96 if(function is Sinus) return ((Sinus)function).ExportToHL2(tree); 97 if(function is Sqrt) return ((Sqrt)function).ExportToHL2(tree); 98 if(function is Subtraction) return ((Subtraction)function).ExportToHL2(tree); 99 if(function is Tangens) return ((Tangens)function).ExportToHL2(tree); 100 if(function is Variable) return ((Variable)function).ExportToHL2(tree); 101 if(function is Xor) return ((Xor)function).ExportToHL2(tree); 102 throw new UnknownFunctionException(function.Name); 90 if (functionExporter.ContainsKey(function.GetType())) return functionExporter[function.GetType()](function, tree); 91 else return function.Name; 103 92 } 104 93 105 94 public static string GetName(IFunctionTree tree) { 106 string name = ""; 107 try { 108 name = ExportFunction(tree.Function, tree); 109 } catch(UnknownFunctionException) { 110 name = "N/A"; 111 } 112 return name; 95 return ExportFunction(tree.Function, tree); 113 96 } 114 97 } … … 116 99 internal static class HL2ExporterExtensions { 117 100 private static string GetHL2FunctionName(string name) { 118 return "[F]" + name 101 return "[F]" + name; 119 102 } 120 103 -
trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/SymbolicExpressionExporter.cs
r2423 r2629 46 46 47 47 public bool TryExport(IFunctionTree tree, out string exported) { 48 try { 49 exported = Export(tree); 50 return true; 51 } 52 catch (UnknownFunctionException) { 53 exported = ""; 54 return false; 55 } 48 foreach (IFunctionTree t in FunctionTreeIterator.IteratePrefix(tree)) 49 if (!functionExporter.ContainsKey(t.Function.GetType())) { 50 exported = null; 51 return false; 52 } 53 exported = Export(tree); 54 return true; 56 55 } 57 56 … … 68 67 } 69 68 69 // try-export checks the keys of this dictionary 70 private static Dictionary<Type, Func<IFunction, IFunctionTree, string>> functionExporter = new Dictionary<Type, Func<IFunction, IFunctionTree, string>>() { 71 { typeof(Addition), (function, tree) => ((Addition)function).ExportToScheme()}, 72 { typeof(And), (function, tree) => ((And)function).ExportToScheme()}, 73 { typeof(Average), (function, tree) => ((Average)function).ExportToScheme()}, 74 { typeof(Constant), (function, tree) => ((Constant)function).ExportToScheme(tree)}, 75 { typeof(Cosinus), (function, tree) => ((Cosinus)function).ExportToScheme()}, 76 { typeof(Differential), (function, tree) => ((Differential)function).ExportToScheme(tree)}, 77 { typeof(Division), (function, tree) => ((Division)function).ExportToScheme()}, 78 { typeof(Equal), (function, tree) => ((Equal)function).ExportToScheme()}, 79 { typeof(Exponential), (function, tree) => ((Exponential)function).ExportToScheme()}, 80 { typeof(GreaterThan), (function, tree) => ((GreaterThan)function).ExportToScheme()}, 81 { typeof(IfThenElse), (function, tree) => ((IfThenElse)function).ExportToScheme()}, 82 { typeof(LessThan), (function, tree) => ((LessThan)function).ExportToScheme()}, 83 { typeof(Logarithm), (function, tree) => ((Logarithm)function).ExportToScheme()}, 84 { typeof(Multiplication), (function, tree) => ((Multiplication)function).ExportToScheme()}, 85 { typeof(Not), (function, tree) => ((Not)function).ExportToScheme()}, 86 { typeof(Or), (function, tree) => ((Or)function).ExportToScheme()}, 87 { typeof(Power), (function, tree) => ((Power)function).ExportToScheme()}, 88 { typeof(Signum), (function, tree) => ((Signum)function).ExportToScheme()}, 89 { typeof(Sinus), (function, tree) => ((Sinus)function).ExportToScheme()}, 90 { typeof(Sqrt), (function, tree) => ((Sqrt)function).ExportToScheme()}, 91 { typeof(Subtraction), (function, tree) => ((Subtraction)function).ExportToScheme()}, 92 { typeof(Tangens), (function, tree) => ((Tangens)function).ExportToScheme()}, 93 { typeof(Variable), (function, tree) => ((Variable)function).ExportToScheme(tree)}, 94 { typeof(Xor), (function, tree) => ((Xor)function).ExportToScheme()}, 95 }; 70 96 private static string ExportFunction(IFunction function, IFunctionTree tree) { 71 97 // this is smelly, if there is a cleaner way to have a 'dynamic' visitor 72 98 // please let me know! (gkronber 14.10.2008) 73 if (function is Addition) return ((Addition)function).ExportToScheme(); 74 if (function is And) return ((And)function).ExportToScheme(); 75 if (function is Average) return ((Average)function).ExportToScheme(); 76 if (function is Constant) return ((Constant)function).ExportToScheme(tree); 77 if (function is Cosinus) return ((Cosinus)function).ExportToScheme(); 78 if (function is Differential) return ((Differential)function).ExportToScheme(tree); 79 if (function is Division) return ((Division)function).ExportToScheme(); 80 if (function is Equal) return ((Equal)function).ExportToScheme(); 81 if (function is Exponential) return ((Exponential)function).ExportToScheme(); 82 if (function is GreaterThan) return ((GreaterThan)function).ExportToScheme(); 83 if (function is IfThenElse) return ((IfThenElse)function).ExportToScheme(); 84 if (function is LessThan) return ((LessThan)function).ExportToScheme(); 85 if (function is Logarithm) return ((Logarithm)function).ExportToScheme(); 86 if (function is Multiplication) return ((Multiplication)function).ExportToScheme(); 87 if (function is Not) return ((Not)function).ExportToScheme(); 88 if (function is Or) return ((Or)function).ExportToScheme(); 89 if (function is Power) return ((Power)function).ExportToScheme(); 90 if (function is Signum) return ((Signum)function).ExportToScheme(); 91 if (function is Sinus) return ((Sinus)function).ExportToScheme(); 92 if (function is Sqrt) return ((Sqrt)function).ExportToScheme(); 93 if (function is Subtraction) return ((Subtraction)function).ExportToScheme(); 94 if (function is Tangens) return ((Tangens)function).ExportToScheme(); 95 if (function is Variable) return ((Variable)function).ExportToScheme(tree); 96 if (function is Xor) return ((Xor)function).ExportToScheme(); 97 throw new UnknownFunctionException(function.Name); 98 } 99 99 if (functionExporter.ContainsKey(function.GetType())) return functionExporter[function.GetType()](function, tree); 100 else return function.Name; 101 } 100 102 101 103 #endregion 102 104 103 105 public static string GetName(IFunctionTree tree) { 104 string name = ""; 105 try { 106 name = ExportFunction(tree.Function, tree); 107 } 108 catch (UnknownFunctionException) { 109 name = "N/A"; 110 } 111 return name; 106 return ExportFunction(tree.Function, tree); 112 107 } 113 108 } -
trunk/sources/HeuristicLab.GP/3.3/HeuristicLab.GP-3.3.csproj
r2328 r2629 109 109 </Compile> 110 110 <Compile Include="GeneticProgrammingModel.cs" /> 111 <Compile Include="UnknownFunctionException.cs" />112 111 <Compile Include="HeuristicLabGPPlugin.cs" /> 113 112 <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset
for help on using the changeset viewer.