Changeset 14410
- Timestamp:
- 11/24/16 16:38:20 (8 years ago)
- Location:
- branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/Expression.cs
r14409 r14410 89 89 case ExpressionType.Function: 90 90 sb.Append(string.Format("{0} (", Label)); 91 if ( arguments != null) {91 if (Arguments.Any()) { 92 92 for (int i = 0; i < arguments.Count - 1; ++i) 93 93 sb.Append(string.Format("{0}, ", arguments[i])); … … 97 97 } 98 98 99 return sb.ToString(); 100 } 101 102 public string PrintDot() { 103 var stack = new Stack<Expression>(); 104 stack.Push(this); 105 106 var sb = new StringBuilder(); 107 sb.AppendLine("digraph g {"); 108 109 while (stack.Count > 0) { 110 var top = stack.Pop(); 111 112 if (!top.Arguments.Any()) 113 continue; 114 115 foreach (var arg in top.Arguments) { 116 var from = top.Arguments.Any() ? top.Label : top.ToString(); 117 var to = arg.Arguments.Any() ? arg.Label : arg.ToString(); 118 sb.AppendLine(string.Format("\"{0}\" -> \"{1}\";", from, to)); 119 stack.Push(arg); 120 } 121 } 122 123 sb.AppendLine("}"); 99 124 return sb.ToString(); 100 125 } -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs
r14409 r14410 32 32 protected readonly string label; 33 33 34 public abstract Expression Instantiate(IRandom random );34 public abstract Expression Instantiate(IRandom random, bool sampleWithRepetition = false); 35 35 36 36 protected ExpressionTemplate(string label, Func<IEnumerable<double>, double> transform) { … … 62 62 } 63 63 64 public override Expression Instantiate(IRandom random ) {64 public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) { 65 65 var arity = (int)Math.Round(arityDistribution.NextDouble()); 66 var args = arguments.SampleProportional(random, arity, arguments.Select(x => x.Item2)).Select(x => x.Item1); 66 var weights = arguments.Select(x => x.Item2); 67 var args = sampleWithRepetition 68 ? arguments.SampleProportional(random, arity, weights).Select(x => x.Item1) 69 : arguments.SampleProportionalWithoutRepetition(random, arity, weights).Select(x => x.Item1); 67 70 return Expression.Function(label, transform, args); 68 71 } … … 75 78 } 76 79 77 public override Expression Instantiate(IRandom random ) {80 public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) { 78 81 var args = arguments.SampleProportional(random, arity, arguments.Select(x => x.Item2)).Select(x => x.Item1); 79 82 return Expression.Function(label, transform, args); -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/Interfaces/IExpression.cs
r14409 r14410 29 29 public interface IExpression { 30 30 ExpressionType Type { get; } 31 Func<IEnumerable<double>, double> Transform { get; } 31 32 IEnumerable<Expression> Arguments { get; } 33 IRandom Distribution { get; } 32 34 double Value { get; } 33 IRandom Distribution { get; }34 Func<IEnumerable<double>, double> Transform { get; }35 35 } 36 36 }
Note: See TracChangeset
for help on using the changeset viewer.