Changeset 13625
- Timestamp:
- 02/18/16 19:36:09 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/SchemaDiversification/SchemaCreator.cs
r13565 r13625 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Text; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 201 202 select v; 202 203 203 var schemas = new List<ISymbolicExpressionTree>(GenerateSchemas(vertices, MinimumSchemaLength ));204 var schemas = new List<ISymbolicExpressionTree>(GenerateSchemas(vertices, MinimumSchemaLength, StrictSchemaMatching)); 204 205 205 206 #region create schemas and add subscopes representing the individuals … … 223 224 } 224 225 225 public static IEnumerable<ISymbolicExpressionTree> GenerateSchemas(IEnumerable<IGenealogyGraphNode<ISymbolicExpressionTree>> vertices, int minimumSchemaLength ) {226 public static IEnumerable<ISymbolicExpressionTree> GenerateSchemas(IEnumerable<IGenealogyGraphNode<ISymbolicExpressionTree>> vertices, int minimumSchemaLength, bool strict = true) { 226 227 var anySubtreeSymbol = new AnySubtreeSymbol(); 227 228 // var anyNodeSymbol = new AnyNodeSymbol(); 228 229 var groups = vertices.GroupBy(x => x.Parents.First()).OrderByDescending(g => g.Count()).ToList(); 229 230 var hash = new HashSet<string>(); 230 var formatter = new SymbolicExpressionTreeStringFormatter { Indent = false, AppendNewLines = false };231 // var formatter = new SymbolicExpressionTreeStringFormatter { Indent = false, AppendNewLines = false }; 231 232 foreach (var g in groups) { 232 233 var parent = g.Key; … … 256 257 } 257 258 if (replaced) { 258 var str = formatter.Format(schema.Root.GetSubtree(0).GetSubtree(0)); 259 // var str = formatter.Format(schema.Root.GetSubtree(0).GetSubtree(0)); 260 var str = SubtreeToString(schema.Root.GetSubtree(0).GetSubtree(0), strict); 259 261 if (hash.Contains(str)) continue; 260 262 yield return schema; … … 283 285 } 284 286 } 287 288 private static string SubtreeToString(ISymbolicExpressionTreeNode node, bool strict = false) { 289 StringBuilder strBuilder = new StringBuilder(); 290 // internal nodes or leaf nodes? 291 if (node is AnySubtree) 292 return "# "; 293 294 if (node.SubtreeCount > 0) { 295 strBuilder.Append("("); 296 // symbol on same line as '(' 297 string label = string.Empty; 298 if (node is AnyNode) 299 label = "="; 300 else { 301 label = node.Symbol.Name; 302 } 303 strBuilder.Append(label + " "); 304 // each subtree expression on a new line 305 // and closing ')' also on new line 306 foreach (var subtree in node.Subtrees) { 307 strBuilder.Append(SubtreeToString(subtree, strict)); 308 } 309 strBuilder.Append(") "); 310 } else { 311 // symbol in the same line with as '(' and ')' 312 var v = node as VariableTreeNode; 313 var c = node as ConstantTreeNode; 314 var w = node as AnyNode; // wildcard 315 string label = string.Empty; 316 if (w != null) 317 label = "="; 318 else if (v != null) 319 label = strict ? string.Format("{0:0.00}_{1}", v.Weight, v.VariableName) : string.Format("{0}", v.VariableName); 320 else if (c != null) 321 label = strict ? string.Format("{0:0.00}", c.Value) : "C"; 322 strBuilder.Append(label); 323 if (node.Parent != null && node != node.Parent.Subtrees.Last()) 324 strBuilder.Append(" "); 325 //strBuilder.Append(")"); 326 } 327 return strBuilder.ToString(); 328 } 285 329 } 286 330 }
Note: See TracChangeset
for help on using the changeset viewer.