Changeset 2625 for trunk/sources
- Timestamp:
- 01/13/10 19:31:02 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs
r2624 r2625 94 94 return tree; 95 95 } else if (tree.Function is Flip) { 96 return InvertChain(tree.SubTrees[0]); 96 if (tree.SubTrees[0].Function is OpenParameter) return tree.SubTrees[0]; 97 else return ApplyFlips(InvertChain(tree.SubTrees[0])); 97 98 } else { 98 99 IFunctionTree tmp = ApplyFlips(tree.SubTrees[0]); … … 134 135 } 135 136 // append open param at the end 136 invParent. AddSubTree(openParam);137 invParent.InsertSubTree(0, openParam); 137 138 return root; 138 139 } … … 194 195 private static IFunctionTree AppendLeft(IFunctionTree tree, IFunctionTree node) { 195 196 IFunctionTree originalTree = tree; 196 while ( tree.SubTrees[0].SubTrees.Count > 0) tree = tree.SubTrees[0];197 while (!IsBottomLeft(tree)) tree = tree.SubTrees[0]; 197 198 tree.InsertSubTree(0, node); 198 199 return originalTree; 200 } 201 202 private static bool IsBottomLeft(IFunctionTree tree) { 203 if(tree.SubTrees.Count==0) return true; 204 else if(tree.SubTrees[0].Function is Variable) return true; 205 else if(tree.SubTrees[0].Function is Constant) return true; 206 else return false; 199 207 } 200 208 -
trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs
r2624 r2625 162 162 }); 163 163 } 164 165 164 { 165 IFunctionTree tree = importer.Import("(open-- (open-log (open-log (open-param - 0))) (open-exp (open-exp (open-param - 0))) (f1-* (open-param - 0) 2.0))"); 166 167 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 168 169 IFunctionTree t0 = importer.Import(@"(exp (exp (- (exp (exp (variable 1.0 b 0))) 170 (* (variable 1.0 c 0) 2.0)))))"); 171 IFunctionTree t1 = importer.Import(@"(log (log (+ (log (log (variable 1.0 a 0))) 172 (* (variable 1.0 c 0) 2.0))))"); 173 IFunctionTree t2 = importer.Import(@"(/ (+ (log (log (variable 1.0 a 0))) 174 (exp (exp (variable 1.0 b 0)))) 2.0)"); 175 176 CompareTrees(actualTrees, new List<IFunctionTree>() { 177 t0, t1, t2 178 }); 179 } 180 { 181 IFunctionTree tree = importer.Import(@"(open-- (flip (open-log (open-param - 0))) 182 (flip (f1-* (open-param - 0) 2.0)) 183 (flip (flip (f1-* (open-param - 0) 2.0))))"); 184 185 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 186 187 IFunctionTree t0 = importer.Import(@"(log (- (/ (variable 1.0 b 0) 2.0) 188 (* (variable 1.0 c 0) 2.0)))"); 189 IFunctionTree t1 = importer.Import(@"(* (+ (exp (variable 1.0 a 0)) 190 (* (variable 1.0 c 0) 2.0)) 2.0)"); 191 IFunctionTree t2 = importer.Import(@"(/ (+ (exp (variable 1.0 a 0)) 192 (/ (variable 1.0 b 0) 2.0)) 2.0)"); 193 194 CompareTrees(actualTrees, new List<IFunctionTree>() { 195 t0, t1, t2 196 }); 197 } 198 { 199 IFunctionTree tree = importer.Import(@"(cycle (open-+ 200 (flip (f1-+ 201 (flip (f1-- 202 (flip (f1-/ 203 (open-param - 0) 4.0)) 3.0)) 2.0)) 204 (open-param - 0) 205 (open-param - 0)))"); 206 // -3*4-2 x 207 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 208 209 IFunctionTree t0 = importer.Import("(+ (/ (- (+ (variable 1.0 b 0) (variable 1.0 c 0)) 3.0) 4.0) 2.0)"); 210 IFunctionTree t1 = importer.Import("(- (- (* (- (variable 1.0 a 0) 2.0) 4.0) 3.0) (variable 1.0 c 0))"); 211 IFunctionTree t2 = importer.Import("(- (- (* (- (variable 1.0 a 0) 2.0) 4.0) 3.0) (variable 1.0 b 0))"); 212 213 214 CompareTrees(actualTrees, new List<IFunctionTree>() { 215 t0, t1, t2 216 }); 217 } 166 218 167 219 } … … 172 224 if (!expectedEnumerator.MoveNext()) Assert.Fail(); 173 225 IFunctionTree expectedTree = expectedEnumerator.Current; 174 var e = (from x in FunctionTreeIterator.IterateP ostfix(expectedTree)226 var e = (from x in FunctionTreeIterator.IteratePrefix(expectedTree) 175 227 select x).GetEnumerator(); 176 var a = (from x in FunctionTreeIterator.IterateP ostfix(actualTree)228 var a = (from x in FunctionTreeIterator.IteratePrefix(actualTree) 177 229 select x).GetEnumerator(); 178 230 Assert.AreEqual(expectedTree.GetSize(), actualTree.GetSize()); 179 231 while (e.MoveNext() && a.MoveNext()) { 180 Assert.AreEqual(e.Current. GetType(), a.Current.GetType());232 Assert.AreEqual(e.Current.Function.GetType(), a.Current.Function.GetType()); 181 233 if (e.Current.Function is HeuristicLab.GP.StructureIdentification.Variable) { 182 234 var expectedVar = (VariableFunctionTree)e.Current; -
trunk/sources/HeuristicLab.GP.Tests/Token.cs
r2447 r2625 29 29 using HeuristicLab.GP.StructureIdentification; 30 30 using System.Diagnostics; 31 using System.Globalization; 31 32 32 33 namespace HeuristicLab.GP.Test { … … 59 60 } else if (strToken == ")") { 60 61 t.Symbol = TokenSymbol.RPAR; 61 } else if (double.TryParse(strToken, out temp)) {62 } else if (double.TryParse(strToken, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out temp)) { 62 63 t.Symbol = TokenSymbol.NUMBER; 63 t.DoubleValue = double.Parse(strToken );64 t.DoubleValue = double.Parse(strToken, CultureInfo.InvariantCulture.NumberFormat); 64 65 } else { 65 66 t.Symbol = TokenSymbol.SYMB;
Note: See TracChangeset
for help on using the changeset viewer.