Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/02/16 16:38:11 (8 years ago)
Author:
bburlacu
Message:

#2704: Rename expression label to name, and remove label from expression template as it should be specified for each individual instance.

Location:
branches/HeuristicLab.ExpressionGenerator
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/Expression.cs

    r14410 r14448  
    3030namespace HeuristicLab.ExpressionGenerator {
    3131  public class Expression : IExpression {
    32     public string Label { get; set; }
     32    public string Name { get; set; }
    3333
    3434    public ExpressionType Type { get; }
     
    4545    public double Value { get; }
    4646
    47     public Expression(string label, double value) {
     47    public Expression(string name, double value) {
    4848      Type = ExpressionType.Constant;
    4949      Value = value;
    50       Label = label;
     50      Name = name;
    5151    }
    5252
    53     public Expression(string label, IRandom distribution) {
     53    public Expression(string name, IRandom distribution) {
    5454      Type = ExpressionType.RandomVariable;
    5555      Distribution = distribution;
    56       Label = label;
     56      Name = name;
    5757    }
    5858
    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) {
    6060      Type = ExpressionType.Function;
    6161      Transform = transform;
    6262      this.arguments = this.arguments ?? new List<Expression>();
    6363      this.arguments.AddRange(arguments);
    64       Label = label;
     64      Name = name;
    6565    }
    6666
     
    8585          break;
    8686        case ExpressionType.RandomVariable:
    87           sb.Append(string.Format("{0} ~ {1}", Label, GetStringDescription(Distribution)));
     87          sb.Append(string.Format("{0} ~ {1}", Name, GetStringDescription(Distribution)));
    8888          break;
    8989        case ExpressionType.Function:
    90           sb.Append(string.Format("{0} (", Label));
     90          sb.Append(string.Format("{0} = f(", Name));
    9191          if (Arguments.Any()) {
    9292            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));
    9595          }
    9696          break;
    9797      }
     98
     99      return sb.ToString();
     100    }
     101
     102    public string PrintInfix() {
     103      var sb = new StringBuilder();
    98104
    99105      return sb.ToString();
     
    114120
    115121        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();
    118124          sb.AppendLine(string.Format("\"{0}\" -> \"{1}\";", from, to));
    119125          stack.Push(arg);
  • branches/HeuristicLab.ExpressionGenerator/HeuristicLab.ExpressionGenerator/3.4/ExpressionTemplate.cs

    r14411 r14448  
    3030    private List<Tuple<Expression, double>> arguments;
    3131    private readonly Func<IEnumerable<double>, double> transform;
    32     private readonly string label;
    3332
    34     protected Expression Instantiate(IRandom random, int n, bool sampleWithRepetition = false) {
     33    protected Expression Instantiate(string label, IRandom random, int n, bool sampleWithRepetition = false) {
    3534      var weights = arguments.Select(x => x.Item2);
    3635      var args = sampleWithRepetition
     
    4039    }
    4140
    42     public abstract Expression Instantiate(IRandom random, bool sampleWithRepetition = false);
     41    public abstract Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false);
    4342
    44     protected ExpressionTemplate(string label, Func<IEnumerable<double>, double> transform) {
     43    protected ExpressionTemplate(Func<IEnumerable<double>, double> transform) {
    4544      this.transform = transform;
    46       this.label = label;
    4745    }
    4846
     
    6664    private readonly IRandom arityDistribution;
    6765
    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) {
    6967      this.arityDistribution = arityDistribution;
    7068    }
    7169
    72     public override Expression Instantiate(IRandom random, bool sampleWithRepetition = false) {
     70    public override Expression Instantiate(string name, IRandom random, bool sampleWithRepetition = false) {
    7371      var arity = (int)Math.Round(arityDistribution.NextDouble());
    74       return Instantiate(random, arity, sampleWithRepetition);
     72      return Instantiate(name, random, arity, sampleWithRepetition);
    7573    }
    7674  }
     
    7876  public class FixedArityTemplate : ExpressionTemplate {
    7977    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) {
    8179      this.arity = arity;
    8280    }
    8381
    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);
    8684    }
    8785  }
Note: See TracChangeset for help on using the changeset viewer.