Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GPDL/HeuristicLab.Grammars/3.3/Test.cs @ 10051

Last change on this file since 10051 was 10051, checked in by gkronber, 11 years ago

#2026 worked on a plugin for grammars (work-in-progress)

File size: 2.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Diagnostics;
24using System.Linq;
25using HeuristicLab.PluginInfrastructure;
26
27namespace HeuristicLab.Grammars {
28  public class Test {
29    public static void Main(string[] args) {
30      var gStr =
31        @"S -> a B | b A
32          A-> a | a S | b A A
33          B -> b | b S | a B B
34         ";
35      var g = HeuristicLab.Grammars.Grammar.FromString(gStr);
36      var l = new Language(g);
37      var s2 = new string[][]
38        {
39          new string[] {"a", "b"},
40          new string[] {"b", "a"}
41        };
42      var s4 = new string[][]
43        {
44          new string[] {"a", "a", "b", "b"},
45          new string[] {"a", "b", "a", "b"},
46          new string[] {"a", "b", "b", "a"},
47          new string[] {"b", "b", "a", "a"},
48          new string[] {"b", "a", "b", "a"},
49          new string[] {"b", "a", "a", "b"}
50        };
51
52      var watch = new Stopwatch();
53      watch.Start();
54      var lPrime = l.Take(100000);
55      int s = 0;
56      foreach (var c in lPrime) {
57        s++;
58        /*
59        foreach (var symb in c)
60          Console.Write(symb);
61        Console.WriteLine();
62        */
63      }
64      watch.Stop();
65      Console.WriteLine(s);
66      Console.WriteLine("Generating 10000 sentences: {0}ms", watch.ElapsedMilliseconds);
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.