Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/18/13 21:33:56 (11 years ago)
Author:
gkronber
Message:

#2026 worked on brute force solver for GPDL problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GPDL/HeuristicLab.Grammars/3.3/Symbol.cs

    r10063 r10067  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
     25
    2326namespace HeuristicLab.Grammars {
    24   public class Symbol : ISymbol, IEquatable<ISymbol> {
     27  public class Symbol : ISymbol {
    2528    public string Name { get; private set; }
    26     public IAttribute Attribute { get; private set; }
    27     public Symbol(string name, IAttribute attribute = null) {
     29    public IEnumerable<IAttribute> Attributes { get; private set; }
     30    public Symbol(string name, IEnumerable<IAttribute> attributes = null) {
    2831      this.Name = name;
    29       this.Attribute = attribute;
     32      if (attributes != null) this.Attributes = attributes;
     33      else this.Attributes = Enumerable.Empty<IAttribute>();
    3034    }
    3135
    32     public bool Equals(ISymbol other) {
    33       return Name == other.Name;
     36    public string GetAttributeString() {
     37      if (!Attributes.Any()) return string.Empty;
     38      return Attributes.Skip(1).Aggregate(Attributes.First().ToString(), (str, a) => str + ", " + a.ToString());
    3439    }
    3540
     
    3742      if (obj == null) return false;
    3843      if (obj == this) return true;
    39       var other = obj as ISymbol;
     44      var other = obj as Symbol;
    4045      if (other == null) return false;
    41       return Equals(other);
     46      return this.Name == other.Name; // compare names only
    4247    }
    4348
     
    4550      return Name.GetHashCode();
    4651    }
     52
     53    public override string ToString() {
     54      return Name + "<" + GetAttributeString() + ">";
     55    }
    4756  }
    4857}
Note: See TracChangeset for help on using the changeset viewer.