Changeset 11742 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization
- Timestamp:
- 01/09/15 14:57:28 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/EvenParityProblem.cs
r11732 r11742 51 51 } 52 52 53 public string Hash(string terminalPhrase) {53 public string CanonicalRepresentation(string terminalPhrase) { 54 54 return terminalPhrase; 55 55 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/HardPalindromeProblem.cs
r11732 r11742 39 39 } 40 40 41 public string Hash(string terminalPhrase) {41 public string CanonicalRepresentation(string terminalPhrase) { 42 42 return terminalPhrase; 43 43 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/IProblem.cs
r11732 r11742 9 9 IGrammar Grammar { get; } 10 10 double Evaluate(string sentence); 11 string Hash(string terminalPhrase);11 string CanonicalRepresentation(string terminalPhrase); 12 12 } 13 13 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/PalindromeProblem.cs
r11732 r11742 80 80 } 81 81 82 public string Hash(string terminalPhrase) {82 public string CanonicalRepresentation(string terminalPhrase) { 83 83 return terminalPhrase; 84 84 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/ReadonlySequence.cs
r11732 r11742 4 4 public class ReadonlySequence : Sequence { 5 5 public ReadonlySequence(string s) 6 : base(s ) {6 : base(s, s.Length) { 7 7 } 8 8 9 9 public ReadonlySequence(char ch) 10 : base(ch ) {10 : base(ch, 1) { 11 11 } 12 12 13 13 public ReadonlySequence(Sequence s) 14 : base(s ) {14 : base(s, s.Length) { 15 15 } 16 16 … … 32 32 public override int GetHashCode() { 33 33 int h = 31 * Length; 34 foreach (var ch in this) { h += 31 * (byte)h; } 34 for (int i = 0; i < Length; i++) { 35 h += 31 * (byte)this[i]; 36 } 35 37 return h; 36 38 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/RoyalPairProblem.cs
r11732 r11742 34 34 } 35 35 36 public string Hash(string terminalPhrase) {36 public string CanonicalRepresentation(string terminalPhrase) { 37 37 return terminalPhrase; 38 38 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/RoyalRoadProblem.cs
r11732 r11742 29 29 throw new NotImplementedException(); 30 30 } 31 public string Hash(string terminalPhrase) {31 public string CanonicalRepresentation(string terminalPhrase) { 32 32 return terminalPhrase; 33 33 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/RoyalSymbolProblem.cs
r11732 r11742 33 33 return regex.Matches(sentence).Count; 34 34 } 35 public string Hash(string terminalPhrase) {35 public string CanonicalRepresentation(string terminalPhrase) { 36 36 return terminalPhrase; 37 37 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/RoyalTreeProblem.cs
r11732 r11742 29 29 throw new NotImplementedException(); 30 30 } 31 public string Hash(string terminalPhrase) {31 public string CanonicalRepresentation(string terminalPhrase) { 32 32 return terminalPhrase; 33 33 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/SantaFeAntProblem.cs
r11732 r11742 98 98 } 99 99 100 public string Hash(string terminalPhrase) {100 public string CanonicalRepresentation(string terminalPhrase) { 101 101 return terminalPhrase.Replace("rl", "").Replace("lr", ""); 102 102 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Sequence.cs
r11732 r11742 46 46 } 47 47 48 private Sequence( ) {49 this.symbols = new char[max Idx + 1];48 private Sequence(int maxLength) { 49 this.symbols = new char[maxLength]; 50 50 } 51 51 52 52 // create a sequence from a character 53 53 public Sequence(char ch) 54 : this() { 54 : this(ch, maxIdx + 1) { 55 } 56 57 protected Sequence(char ch, int maxLength) 58 : this(maxLength) { 55 59 this.len = 1; 56 60 symbols[0] = ch; … … 61 65 62 66 // create a sequence from a string 63 public Sequence(string s) 64 : this() { 67 public Sequence(string s) : this(s, maxIdx + 1) { } 68 protected Sequence(string s, int maxLength) 69 : this(maxLength) { 65 70 if (string.IsNullOrEmpty(s)) throw new ArgumentException(); 66 71 if (s.Length > (maxIdx + 1)) throw new ArgumentException(); … … 77 82 78 83 // cloning ctor 79 public Sequence(Sequence original) 80 : this() { 84 public Sequence(Sequence original) : this(original, maxIdx + 1) { } 85 protected Sequence(Sequence original, int maxLength) 86 : this(maxLength) { 81 87 this.len = original.len; 82 88 Array.Copy(original.symbols, this.symbols, len); … … 128 134 if (startIdx >= this.len) throw new ArgumentException(); 129 135 if (startIdx + len > this.len) throw new ArgumentException(); 130 var subsequence = new Sequence { len = len };136 var subsequence = new Sequence(maxIdx + 1) { len = len }; 131 137 132 138 Array.Copy(this.symbols, startIdx, subsequence.symbols, 0, len); -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/SymbolicRegressionPoly10Problem.cs
r11732 r11742 21 21 22 22 private readonly IGrammar grammar; 23 private readonly ExpressionInterpreter interpreter;24 23 25 24 private readonly int N; … … 29 28 public SymbolicRegressionPoly10Problem() { 30 29 this.grammar = new Grammar(grammarString); 31 this.interpreter = new ExpressionInterpreter();32 30 33 31 this.N = 500; … … 67 65 68 66 public double Evaluate(string sentence) { 67 var interpreter = new ExpressionInterpreter(); 69 68 return HeuristicLab.Common.Extensions.RSq(y, Enumerable.Range(0, N).Select(i => interpreter.Interpret(sentence, x[i])).ToArray()); 70 69 } … … 73 72 74 73 // right now only + and * is supported 75 public string Hash(string terminalPhrase) {74 public string CanonicalRepresentation(string terminalPhrase) { 76 75 var terms = terminalPhrase.Split('+'); 77 76 return string.Join("+", terms.Select(term => string.Join("", term.Replace("*", "").OrderBy(ch => ch)))
Note: See TracChangeset
for help on using the changeset viewer.