Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3746


Ignore:
Timestamp:
05/10/10 16:34:35 (14 years ago)
Author:
gkronber
Message:

Added project for HeuristicLab.Problems.DataAnalysis.Tests. #791

Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r3705 r3746  
    77    ..\documentation\License\gpl-3.0.txt = ..\documentation\License\gpl-3.0.txt
    88    HeuristicLab 3.3.vsmdi = HeuristicLab 3.3.vsmdi
     9    HeuristicLab 3.31.vsmdi = HeuristicLab 3.31.vsmdi
    910    LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
    1011    PreBuildEvent.cmd = PreBuildEvent.cmd
     
    244245Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.OneMax.Views-3.3", "HeuristicLab.Problems.OneMax.Views\3.3\HeuristicLab.Problems.OneMax.Views-3.3.csproj", "{4FE983A1-AAF8-4977-B9E2-52B3224510CB}"
    245246EndProject
     247Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Tests-3.3", "HeuristicLab.Problems.DataAnalysis\3.3\Tests\HeuristicLab.Problems.DataAnalysis.Tests-3.3.csproj", "{5A4679EF-A8F3-4647-B722-441A36B3BA6B}"
     248EndProject
    246249Global
     250  GlobalSection(TestCaseManagementSettings) = postSolution
     251    CategoryFile = HeuristicLab 3.31.vsmdi
     252  EndGlobalSection
    247253  GlobalSection(SolutionConfigurationPlatforms) = preSolution
    248254    Debug|Any CPU = Debug|Any CPU
     
    13431349    {4FE983A1-AAF8-4977-B9E2-52B3224510CB}.Services|x64.ActiveCfg = Release|x64
    13441350    {4FE983A1-AAF8-4977-B9E2-52B3224510CB}.Services|x86.ActiveCfg = Release|x86
     1351    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     1352    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
     1353    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Debug|x64.ActiveCfg = Debug|Any CPU
     1354    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Debug|x86.ActiveCfg = Debug|Any CPU
     1355    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
     1356    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Release|Any CPU.Build.0 = Release|Any CPU
     1357    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Release|x64.ActiveCfg = Release|Any CPU
     1358    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Release|x86.ActiveCfg = Release|Any CPU
     1359    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Services|Any CPU.ActiveCfg = Release|Any CPU
     1360    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Services|Any CPU.Build.0 = Release|Any CPU
     1361    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Services|x64.ActiveCfg = Release|Any CPU
     1362    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Services|x86.ActiveCfg = Release|Any CPU
    13451363  EndGlobalSection
    13461364  GlobalSection(SolutionProperties) = preSolution
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/SimpleArithmeticExpressionInterpreterTest.cs

    r3733 r3746  
    8989    public void SimpleArithmeticExpressionInterpreterEvaluateTest() {
    9090
    91       Dataset ds = new Dataset(new string[] { "y", "a", "b" }, new double[,] {
     91      Dataset ds = new Dataset(new string[] { "Y", "A", "B" }, new double[,] {
    9292        { 1.0, 1.0, 1.0 },
    9393        { 2.0, 2.0, 2.0 },
     
    133133      Evaluate(interpreter, ds, "(/ 8.0 2.0 2.0)", 0, 2.0);
    134134
    135       // TODO ADF     
     135      // ADF     
     136      Evaluate(interpreter, ds, @"(PROG
     137                                    (MAIN
     138                                      (CALL ADF0))
     139                                    (defun ADF0 1.0))", 1, 1.0);
     140      Evaluate(interpreter, ds, @"(PROG
     141                                    (MAIN
     142                                      (* (CALL ADF0) (CALL ADF0)))
     143                                    (defun ADF0 2.0))", 1, 4.0);
     144      Evaluate(interpreter, ds, @"(PROG
     145                                    (MAIN
     146                                      (CALL ADF0 2.0 3.0))
     147                                    (defun ADF0
     148                                      (+ (ARG 0) (ARG 1))))", 1, 5.0);
     149      Evaluate(interpreter, ds, @"(PROG
     150                                    (MAIN (CALL ADF1 2.0 3.0))
     151                                    (defun ADF0
     152                                      (- (ARG 1) (ARG 0)))
     153                                    (defun ADF1
     154                                      (+ (CALL ADF0 (ARG 1) (ARG 0))
     155                                         (CALL ADF0 (ARG 0) (ARG 1)))))", 1, 0.0);
     156      Evaluate(interpreter, ds, @"(PROG
     157                                    (MAIN (CALL ADF1 (variable 2.0 a) 3.0))
     158                                    (defun ADF0
     159                                      (- (ARG 1) (ARG 0)))
     160                                    (defun ADF1                                                                             
     161                                      (CALL ADF0 (ARG 1) (ARG 0))))", 1, 1.0);
     162      Evaluate(interpreter, ds, @"(PROG
     163                                    (MAIN (CALL ADF1 (variable 2.0 a) 3.0))
     164                                    (defun ADF0
     165                                      (- (ARG 1) (ARG 0)))
     166                                    (defun ADF1                                                                             
     167                                      (+ (CALL ADF0 (ARG 1) (ARG 0))
     168                                         (CALL ADF0 (ARG 0) (ARG 1)))))", 1, 0.0);
    136169    }
    137170
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/SymbolicExpressionImporter.cs

    r3733 r3746  
    3232namespace HeuristicLab.Problems.DataAnalysis.Tests {
    3333  internal class SymbolicExpressionImporter {
    34     private const string VARSTART = "var";
     34    private const string VARSTART = "VAR";
     35    private const string DEFUNSTART = "DEFUN";
     36    private const string ARGSTART = "ARG";
     37    private const string INVOKESTART = "CALL";
    3538    private Dictionary<string, Symbol> knownSymbols = new Dictionary<string, Symbol>()
    3639      {
     
    3942        {"*", new Multiplication()},
    4043        {"-", new Subtraction()},
     44        {"PROG", new ProgramRootSymbol()},
     45        {"MAIN", new StartSymbol()}
     46      };
    4147
    42       };
    4348    Constant constant = new Constant();
    4449    Variable variable = new Variable();
     50    Defun defun = new Defun();
     51
    4552    ProgramRootSymbol programRootSymbol = new ProgramRootSymbol();
    4653    StartSymbol startSymbol = new StartSymbol();
     
    5461      SymbolicExpressionTreeNode start = startSymbol.CreateTreeNode();
    5562      SymbolicExpressionTreeNode mainBranch = ParseSexp(new Queue<Token>(GetTokenStream(str)));
    56       root.AddSubTree(start);
    57       start.AddSubTree(mainBranch);
     63      if (mainBranch.Symbol is ProgramRootSymbol) {
     64        // when a root symbol was parsed => use main branch as root
     65        root = mainBranch;
     66      } else {
     67        // only a main branch was given => insert the main branch into the default tree template
     68        root.AddSubTree(start);
     69        start.AddSubTree(mainBranch);
     70      }
    5871      return new SymbolicExpressionTree(root);
    5972    }
     
    7386        if (tokens.Peek().StringValue.StartsWith(VARSTART)) {
    7487          tree = ParseVariable(tokens);
     88        } else if (tokens.Peek().StringValue.StartsWith(DEFUNSTART)) {
     89          tree = ParseDefun(tokens);
     90          while (!tokens.Peek().Equals(Token.RPAR)) {
     91            tree.AddSubTree(ParseSexp(tokens));
     92          }
     93        } else if (tokens.Peek().StringValue.StartsWith(ARGSTART)) {
     94          tree = ParseArgument(tokens);
     95        } else if (tokens.Peek().StringValue.StartsWith(INVOKESTART)) {
     96          tree = ParseInvoke(tokens);
     97          while (!tokens.Peek().Equals(Token.RPAR)) {
     98            tree.AddSubTree(ParseSexp(tokens));
     99          }
    75100        } else {
    76101          Token curToken = tokens.Dequeue();
     
    89114    }
    90115
     116    private SymbolicExpressionTreeNode ParseInvoke(Queue<Token> tokens) {
     117      Token invokeTok = tokens.Dequeue();
     118      Debug.Assert(invokeTok.StringValue == "CALL");
     119      InvokeFunction invokeSym = new InvokeFunction(tokens.Dequeue().StringValue);
     120      SymbolicExpressionTreeNode invokeNode = invokeSym.CreateTreeNode();
     121      return invokeNode;
     122    }
     123
     124    private SymbolicExpressionTreeNode ParseArgument(Queue<Token> tokens) {
     125      Token argTok = tokens.Dequeue();
     126      Debug.Assert(argTok.StringValue == "ARG");
     127      Argument argument = new Argument((int)tokens.Dequeue().DoubleValue);
     128      SymbolicExpressionTreeNode argNode = argument.CreateTreeNode();
     129      return argNode;
     130    }
     131
     132    private SymbolicExpressionTreeNode ParseDefun(Queue<Token> tokens) {
     133      Token defTok = tokens.Dequeue();
     134      Debug.Assert(defTok.StringValue == "DEFUN");
     135      DefunTreeNode t = (DefunTreeNode)defun.CreateTreeNode();
     136      t.FunctionName = tokens.Dequeue().StringValue;
     137      return t;
     138    }
     139
    91140    private SymbolicExpressionTreeNode ParseVariable(Queue<Token> tokens) {
    92141      Token varTok = tokens.Dequeue();
    93       Debug.Assert(varTok.StringValue == "variable");
     142      Debug.Assert(varTok.StringValue == "VARIABLE");
    94143      VariableTreeNode t = (VariableTreeNode)variable.CreateTreeNode();
    95144      t.Weight = tokens.Dequeue().DoubleValue;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/Token.cs

    r3733 r3746  
    6262      } else {
    6363        t.Symbol = TokenSymbol.SYMB;
     64        t.StringValue = t.StringValue.ToUpper();
    6465      }
    6566      return t;
Note: See TracChangeset for help on using the changeset viewer.