- Timestamp:
- 12/02/16 16:38:11 (8 years ago)
- Location:
- branches/HeuristicLab.ExpressionGenerator
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/Expression.cs
r14410 r14448 30 30 namespace HeuristicLab.ExpressionGenerator { 31 31 public class Expression : IExpression { 32 public string Label{ get; set; }32 public string Name { get; set; } 33 33 34 34 public ExpressionType Type { get; } … … 45 45 public double Value { get; } 46 46 47 public Expression(string label, double value) {47 public Expression(string name, double value) { 48 48 Type = ExpressionType.Constant; 49 49 Value = value; 50 Label = label;50 Name = name; 51 51 } 52 52 53 public Expression(string label, IRandom distribution) {53 public Expression(string name, IRandom distribution) { 54 54 Type = ExpressionType.RandomVariable; 55 55 Distribution = distribution; 56 Label = label;56 Name = name; 57 57 } 58 58 59 public Expression(string label, Func<IEnumerable<double>, double> transform, IEnumerable<Expression> arguments) {59 public Expression(string name, Func<IEnumerable<double>, double> transform, IEnumerable<Expression> arguments) { 60 60 Type = ExpressionType.Function; 61 61 Transform = transform; 62 62 this.arguments = this.arguments ?? new List<Expression>(); 63 63 this.arguments.AddRange(arguments); 64 Label = label;64 Name = name; 65 65 } 66 66 … … 85 85 break; 86 86 case ExpressionType.RandomVariable: 87 sb.Append(string.Format("{0} ~ {1}", Label, GetStringDescription(Distribution)));87 sb.Append(string.Format("{0} ~ {1}", Name, GetStringDescription(Distribution))); 88 88 break; 89 89 case ExpressionType.Function: 90 sb.Append(string.Format("{0} (", Label));90 sb.Append(string.Format("{0} = f(", Name)); 91 91 if (Arguments.Any()) { 92 92 for (int i = 0; i < arguments.Count - 1; ++i) 93 sb.Append(string.Format("{0}, ", arguments[i] ));94 sb.Append(string.Format("{0})", arguments.Last() ));93 sb.Append(string.Format("{0}, ", arguments[i].Name)); 94 sb.Append(string.Format("{0})", arguments.Last().Name)); 95 95 } 96 96 break; 97 97 } 98 99 return sb.ToString(); 100 } 101 102 public string PrintInfix() { 103 var sb = new StringBuilder(); 98 104 99 105 return sb.ToString(); … … 114 120 115 121 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();122 var from = top.Arguments.Any() ? top.Name : top.ToString(); 123 var to = arg.Arguments.Any() ? arg.Name : arg.ToString(); 118 124 sb.AppendLine(string.Format("\"{0}\" -> \"{1}\";", from, to)); 119 125 stack.Push(arg); -
branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs
r14411 r14448 30 30 private List<Tuple<Expression, double>> arguments; 31 31 private readonly Func<IEnumerable<double>, double> transform; 32 private readonly string label;33 32 34 protected Expression Instantiate( IRandom random, int n, bool sampleWithRepetition = false) {33 protected Expression Instantiate(string label, IRandom random, int n, bool sampleWithRepetition = false) { 35 34 var weights = arguments.Select(x => x.Item2); 36 35 var args = sampleWithRepetition … … 40 39 } 41 40 42 public abstract Expression Instantiate( IRandom random, bool sampleWithRepetition = false);41 public abstract Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false); 43 42 44 protected ExpressionTemplate( string label,Func<IEnumerable<double>, double> transform) {43 protected ExpressionTemplate(Func<IEnumerable<double>, double> transform) { 45 44 this.transform = transform; 46 this.label = label;47 45 } 48 46 … … 66 64 private readonly IRandom arityDistribution; 67 65 68 public RandomArityTemplate( string label, Func<IEnumerable<double>, double> transform, IRandom arityDistribution) : base(label,transform) {66 public RandomArityTemplate(Func<IEnumerable<double>, double> transform, IRandom arityDistribution) : base(transform) { 69 67 this.arityDistribution = arityDistribution; 70 68 } 71 69 72 public override Expression Instantiate( IRandom random, bool sampleWithRepetition = false) {70 public override Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false) { 73 71 var arity = (int)Math.Round(arityDistribution.NextDouble()); 74 return Instantiate( random, arity, sampleWithRepetition);72 return Instantiate(name, random, arity, sampleWithRepetition); 75 73 } 76 74 } … … 78 76 public class FixedArityTemplate : ExpressionTemplate { 79 77 private readonly int arity; 80 public FixedArityTemplate( string label, Func<IEnumerable<double>, double> transform, int arity) : base(label,transform) {78 public FixedArityTemplate(Func<IEnumerable<double>, double> transform, int arity) : base(transform) { 81 79 this.arity = arity; 82 80 } 83 81 84 public override Expression Instantiate( IRandom random, bool sampleWithRepetition = false) {85 return Instantiate( random, arity, sampleWithRepetition);82 public override Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false) { 83 return Instantiate(name, random, arity, sampleWithRepetition); 86 84 } 87 85 }
Note: See TracChangeset
for help on using the changeset viewer.